[PATCH 10/11] libsemanage: test semanage_context_* functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add new test suite for other libsemanage functions. Add tests for
semanage_context_* functions.

Signed-off-by: Jan Zarsky <jzarsky@xxxxxxxxxx>
---
 libsemanage/tests/libsemanage-tests.c |  2 +
 libsemanage/tests/test_other.c        | 97 +++++++++++++++++++++++++++
 libsemanage/tests/test_other.h        | 30 +++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 libsemanage/tests/test_other.c
 create mode 100644 libsemanage/tests/test_other.h

diff --git a/libsemanage/tests/libsemanage-tests.c b/libsemanage/tests/libsemanage-tests.c
index 64039b5d..2ae4a21b 100644
--- a/libsemanage/tests/libsemanage-tests.c
+++ b/libsemanage/tests/libsemanage-tests.c
@@ -29,6 +29,7 @@
 #include "test_node.h"
 #include "test_port.h"
 #include "test_user.h"
+#include "test_other.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -75,6 +76,7 @@ static bool do_tests(int interactive, int verbose)
 	DECLARE_SUITE(node);
 	DECLARE_SUITE(port);
 	DECLARE_SUITE(user);
+	DECLARE_SUITE(other);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
diff --git a/libsemanage/tests/test_other.c b/libsemanage/tests/test_other.c
new file mode 100644
index 00000000..437064d2
--- /dev/null
+++ b/libsemanage/tests/test_other.c
@@ -0,0 +1,97 @@
+/*
+ * Authors: Jan Zarsky <jzarsky@xxxxxxxxxx>
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "utilities.h"
+#include "test_other.h"
+
+/* context_record.h */
+void test_semanage_context(void);
+
+extern semanage_handle_t *sh;
+
+int other_test_init(void)
+{
+	return 0;
+}
+
+int other_test_cleanup(void)
+{
+	return 0;
+}
+
+int other_add_tests(CU_pSuite suite)
+{
+	CU_add_test(suite, "semanage_context", test_semanage_context);
+
+	return 0;
+}
+
+/* Function semanage_context_get_user, semanage_context_set_user,
+ * semanage_context_get_role, semanage_context_set_role,
+ * semanage_context_get_type, semanage_context_set_type,
+ * semanage_context_get_mls, semanage_context_set_mls,
+ * semanage_context_create, semanage_context_clone,
+ * semanage_context_free, semanage_context_from_string
+ * semanage_context_to_string
+ */
+void test_semanage_context(void)
+{
+	semanage_context_t *con = NULL;
+	semanage_context_t *con_clone = NULL;
+	char *str = NULL;
+
+	/* setup */
+	setup_handle(SH_CONNECT);
+
+	/* test */
+	CU_ASSERT(semanage_context_create(sh, &con) >= 0);
+
+	CU_ASSERT(semanage_context_set_user(sh, con, "user_u") >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_user(con), "user_u");
+	CU_ASSERT(semanage_context_set_role(sh, con, "role_r") >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_role(con), "role_r");
+	CU_ASSERT(semanage_context_set_type(sh, con, "type_t") >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_type(con), "type_t");
+	CU_ASSERT(semanage_context_set_mls(sh, con, "s0") >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_mls(con), "s0");
+
+	CU_ASSERT(semanage_context_to_string(sh, con, &str) >= 0);
+	CU_ASSERT_PTR_NOT_NULL(str);
+	assert(str);
+	CU_ASSERT_STRING_EQUAL(str, "user_u:role_r:type_t:s0");
+
+	CU_ASSERT(semanage_context_from_string(sh, "my_u:my_r:my_t:s0",
+					       &con) >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_user(con), "my_u");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_role(con), "my_r");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_type(con), "my_t");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_mls(con), "s0");
+
+	CU_ASSERT(semanage_context_clone(sh, con, &con_clone) >= 0);
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_user(con_clone), "my_u");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_role(con_clone), "my_r");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_type(con_clone), "my_t");
+	CU_ASSERT_STRING_EQUAL(semanage_context_get_mls(con_clone), "s0");
+
+	/* cleanup */
+	semanage_context_free(con);
+	semanage_context_free(con_clone);
+	cleanup_handle(SH_CONNECT);
+}
diff --git a/libsemanage/tests/test_other.h b/libsemanage/tests/test_other.h
new file mode 100644
index 00000000..40d2dcf8
--- /dev/null
+++ b/libsemanage/tests/test_other.h
@@ -0,0 +1,30 @@
+/*
+ * Authors: Jan Zarsky <jzarsky@xxxxxxxxxx>
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __TEST_OTHER_H__
+#define __TEST_OTHER_H__
+
+#include <CUnit/Basic.h>
+
+int other_test_init(void);
+int other_test_cleanup(void);
+int other_add_tests(CU_pSuite suite);
+
+#endif
-- 
2.20.1




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux