From: Jan Zarsky <jzarsky@redhat.com>
To: selinux@vger.kernel.org
Subject: [PATCH 10/11] libsemanage: test semanage_context_* functions
Date: Wed, 12 Jun 2019 10:04:03 +0200 [thread overview]
Message-ID: <20190612080404.4529-11-jzarsky@redhat.com> (raw)
In-Reply-To: <20190612080404.4529-1-jzarsky@redhat.com>
Add new test suite for other libsemanage functions. Add tests for
semanage_context_* functions.
Signed-off-by: Jan Zarsky <jzarsky@redhat.com>
---
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@redhat.com>
+ *
+ * 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@redhat.com>
+ *
+ * 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
next prev parent reply other threads:[~2019-06-12 8:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-12 8:03 [PATCH 00/11] libsemanage: add tests Jan Zarsky
2019-06-12 8:03 ` [PATCH 01/11] libsemanage: add helper functions to tests Jan Zarsky
2019-06-12 8:03 ` [PATCH 02/11] libsemanage: test semanage_handle_* functions Jan Zarsky
2019-06-12 8:03 ` [PATCH 03/11] libsemanage: test semanage_bool_* functions Jan Zarsky
2019-06-12 8:03 ` [PATCH 04/11] libsemanage: test semanage_fcontext functions Jan Zarsky
2019-06-12 8:03 ` [PATCH 05/11] libsemanage: test semanage_iface_* functions Jan Zarsky
2019-06-12 8:03 ` [PATCH 06/11] libsemanage: test semanage_ibendport_* functions Jan Zarsky
2019-06-12 8:04 ` [PATCH 07/11] libsemanage: test semanage_node_* functions Jan Zarsky
2019-06-12 8:04 ` [PATCH 08/11] libsemanage: test semanage_port_* functions Jan Zarsky
2019-06-12 8:04 ` [PATCH 09/11] libsemanage: test semanage_user_* functions Jan Zarsky
2019-06-12 8:04 ` Jan Zarsky [this message]
2019-06-12 8:04 ` [PATCH 11/11] libsemanage: test semanage_msg_default_handler Jan Zarsky
2019-06-12 19:57 ` [PATCH 00/11] libsemanage: add tests William Roberts
2019-06-19 16:04 ` William Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190612080404.4529-11-jzarsky@redhat.com \
--to=jzarsky@redhat.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).