]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
selinux-h: Add tests.
authorBruno Haible <bruno@clisp.org>
Sat, 17 Jan 2026 00:52:50 +0000 (01:52 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 17 Jan 2026 00:54:16 +0000 (01:54 +0100)
* tests/test-selinux-context-h.c: New file.
* tests/test-selinux-label-h.c: New file.
* tests/test-selinux-selinux-h.c: New file.
* modules/selinux-h-tests: New file.
* tests/test-selinux-context-h-c++.cc: New file.
* tests/test-selinux-label-h-c++.cc: New file.
* tests/test-selinux-selinux-h-c++.cc: New file.
* modules/selinux-h-c++-tests: New file.

ChangeLog
modules/selinux-h-c++-tests [new file with mode: 0644]
modules/selinux-h-tests [new file with mode: 0644]
tests/test-selinux-context-h-c++.cc [new file with mode: 0644]
tests/test-selinux-context-h.c [new file with mode: 0644]
tests/test-selinux-label-h-c++.cc [new file with mode: 0644]
tests/test-selinux-label-h.c [new file with mode: 0644]
tests/test-selinux-selinux-h-c++.cc [new file with mode: 0644]
tests/test-selinux-selinux-h.c [new file with mode: 0644]

index a8555e59e99a71decd90c497c4c91684317379bc..b393e61cfeacdcf6b20bea0963557a8e683a9090 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-01-16  Bruno Haible  <bruno@clisp.org>
+
+       selinux-h: Add tests.
+       * tests/test-selinux-context-h.c: New file.
+       * tests/test-selinux-label-h.c: New file.
+       * tests/test-selinux-selinux-h.c: New file.
+       * modules/selinux-h-tests: New file.
+       * tests/test-selinux-context-h-c++.cc: New file.
+       * tests/test-selinux-label-h-c++.cc: New file.
+       * tests/test-selinux-selinux-h-c++.cc: New file.
+       * modules/selinux-h-c++-tests: New file.
+
 2026-01-16  Bruno Haible  <bruno@clisp.org>
 
        selinux-h: Fix compilation errors and link errors in C++ mode.
diff --git a/modules/selinux-h-c++-tests b/modules/selinux-h-c++-tests
new file mode 100644 (file)
index 0000000..6e52409
--- /dev/null
@@ -0,0 +1,30 @@
+Files:
+tests/test-selinux-context-h-c++.cc
+tests/test-selinux-label-h-c++.cc
+tests/test-selinux-selinux-h-c++.cc
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += \
+  test-selinux-context-h-c++ \
+  test-selinux-label-h-c++ \
+  test-selinux-selinux-h-c++
+check_PROGRAMS += \
+  test-selinux-context-h-c++ \
+  test-selinux-label-h-c++ \
+  test-selinux-selinux-h-c++
+test_selinux_context_h_c___SOURCES = test-selinux-context-h-c++.cc
+test_selinux_context_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_label_h_c___SOURCES = test-selinux-label-h-c++.cc
+test_selinux_label_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_selinux_h_c___SOURCES = test-selinux-selinux-h-c++.cc
+test_selinux_selinux_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+endif
diff --git a/modules/selinux-h-tests b/modules/selinux-h-tests
new file mode 100644 (file)
index 0000000..b2cd570
--- /dev/null
@@ -0,0 +1,22 @@
+Files:
+tests/test-selinux-context-h.c
+tests/test-selinux-label-h.c
+tests/test-selinux-selinux-h.c
+
+Depends-on:
+selinux-h-c++-tests
+
+configure.ac:
+
+Makefile.am:
+TESTS += \
+  test-selinux-context-h \
+  test-selinux-label-h \
+  test-selinux-selinux-h
+check_PROGRAMS += \
+  test-selinux-context-h \
+  test-selinux-label-h \
+  test-selinux-selinux-h
+test_selinux_context_h_LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_label_h_LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_selinux_h_LDADD = $(LDADD) @LIB_SELINUX@
diff --git a/tests/test-selinux-context-h-c++.cc b/tests/test-selinux-context-h-c++.cc
new file mode 100644 (file)
index 0000000..62f0045
--- /dev/null
@@ -0,0 +1,19 @@
+/* Test of <selinux/context.h> substitute in C++ mode.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include "test-selinux-context-h.c"
diff --git a/tests/test-selinux-context-h.c b/tests/test-selinux-context-h.c
new file mode 100644 (file)
index 0000000..34c4a0a
--- /dev/null
@@ -0,0 +1,42 @@
+/* Test of <selinux/context.h> substitute.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include <config.h>
+
+#include <selinux/context.h>
+
+/* Check that context_t is defined.  */
+context_t t1;
+
+int
+main ()
+{
+  context_t c = context_new ("system_u:system_r:init_t:s0");
+  context_type_set (c, "bar");
+  context_range_set (c, "bar");
+  context_role_set (c, "bar");
+  context_user_set (c, "bar");
+  (void) context_type_get (c);
+  (void) context_range_get (c);
+  (void) context_role_get (c);
+  (void) context_user_get (c);
+  (void) context_str (c);
+  context_free (c);
+
+  return 0;
+}
diff --git a/tests/test-selinux-label-h-c++.cc b/tests/test-selinux-label-h-c++.cc
new file mode 100644 (file)
index 0000000..bb51e94
--- /dev/null
@@ -0,0 +1,19 @@
+/* Test of <selinux/label.h> substitute in C++ mode.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include "test-selinux-label-h.c"
diff --git a/tests/test-selinux-label-h.c b/tests/test-selinux-label-h.c
new file mode 100644 (file)
index 0000000..0fd4064
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test of <selinux/label.h> substitute.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include <config.h>
+
+#include <selinux/label.h>
+
+#include <stddef.h>
+
+int
+main ()
+{
+  struct selabel_handle *l = selabel_open (SELABEL_CTX_FILE, NULL, 0);
+  if (l)
+    selabel_close (l);
+
+  return 0;
+}
diff --git a/tests/test-selinux-selinux-h-c++.cc b/tests/test-selinux-selinux-h-c++.cc
new file mode 100644 (file)
index 0000000..fdea56e
--- /dev/null
@@ -0,0 +1,19 @@
+/* Test of <selinux/selinux.h> substitute in C++ mode.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include "test-selinux-selinux-h.c"
diff --git a/tests/test-selinux-selinux-h.c b/tests/test-selinux-selinux-h.c
new file mode 100644 (file)
index 0000000..5715672
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test of <selinux/selinux.h> substitute.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2026.  */
+
+#include <config.h>
+
+#include <selinux/selinux.h>
+
+int
+main ()
+{
+  /* The people at the NSA who created this API obviously did not know
+     French.  */
+  char *con;
+  if (getcon (&con) == 0)
+    freecon (con);
+
+  return 0;
+}