unittest: Add testsuite for is_known_pipename()
authorAndreas Schneider <asn@samba.org>
Thu, 11 May 2017 09:29:25 +0000 (11:29 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 6 Jun 2017 16:36:06 +0000 (18:36 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/tests.py
testsuite/unittests/rpc_test_dummy_module.c [new file with mode: 0644]
testsuite/unittests/test_sambafs_srv_pipe.c [new file with mode: 0644]
testsuite/unittests/wscript

index e3dd914..9f298a6 100644 (file)
@@ -145,3 +145,5 @@ if with_pam:
 if with_cmocka:
     plantestsuite("samba.unittests.krb5samba", "none",
                   [os.path.join(bindir(), "default/testsuite/unittests/test_krb5samba")])
+    plantestsuite("samba.unittests.sambafs_srv_pipe", "none",
+                  [os.path.join(bindir(), "default/testsuite/unittests/test_sambafs_srv_pipe")])
diff --git a/testsuite/unittests/rpc_test_dummy_module.c b/testsuite/unittests/rpc_test_dummy_module.c
new file mode 100644 (file)
index 0000000..d067b6e
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+int samba_init_module(void);
+int samba_init_module(void)
+{
+       int rc;
+
+       fprintf(stderr, "Test dummy executed!\n");
+
+       rc = setenv("UNITTEST_DUMMY_MODULE_LOADED", "TRUE", 1);
+       if (rc < 0) {
+               kill(getpid(), SIGILL);
+               exit(-1);
+       }
+
+       return 0;
+}
diff --git a/testsuite/unittests/test_sambafs_srv_pipe.c b/testsuite/unittests/test_sambafs_srv_pipe.c
new file mode 100644 (file)
index 0000000..641e99d
--- /dev/null
@@ -0,0 +1,76 @@
+#include <errno.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <cmocka.h>
+
+#include "include/config.h"
+#include "librpc/gen_ndr/ndr_samr.h"
+#include "source3/rpc_server/srv_pipe.h"
+#include "librpc/gen_ndr/srv_samr.h"
+
+static int setup_samr(void **state)
+{
+       rpc_samr_init(NULL);
+
+       return 0;
+}
+
+static int teardown(void **state)
+{
+       unsetenv("UNITTEST_DUMMY_MODULE_LOADED");
+
+       return 0;
+}
+
+static int teardown_samr(void **state)
+{
+       rpc_samr_shutdown();
+
+       teardown(state);
+
+       return 0;
+}
+
+static void test_is_known_pipename(void **state)
+{
+       struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id;
+       bool is_pipename_ok;
+
+       is_pipename_ok = is_known_pipename("samr", &syntax_id);
+       assert_true(is_pipename_ok);
+}
+
+static void test_is_known_pipename_slash(void **state)
+{
+       struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id;
+       bool is_pipename_ok;
+       char dummy_module_path[4096] = {0};
+       const char *module_env;
+
+       snprintf(dummy_module_path,
+                sizeof(dummy_module_path),
+                "%s/bin/modules/rpc/test_dummy_module.so",
+                SRCDIR);
+
+       is_pipename_ok = is_known_pipename(dummy_module_path, &syntax_id);
+       assert_false(is_pipename_ok);
+
+       module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
+       assert_null(module_env);
+}
+
+int main(void) {
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test_setup_teardown(test_is_known_pipename,
+                                               setup_samr,
+                                               teardown_samr),
+               cmocka_unit_test_teardown(test_is_known_pipename_slash,
+                                         teardown),
+       };
+
+       cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
+       return cmocka_run_group_tests(tests, NULL, NULL);
+}
index 355ab0c..bb29fd8 100644 (file)
@@ -10,3 +10,20 @@ def build(bld):
                      source='test_krb5_samba.c',
                      deps='krb5samba cmocka',
                      install=False)
+
+    bld.SAMBA_BINARY('test_sambafs_srv_pipe',
+                     source='test_sambafs_srv_pipe.c',
+                     deps='''
+                          RPC_SERVER
+                          RPC_SAMR
+                          cmocka
+                          ''',
+                     install=False)
+
+    bld.SAMBA_MODULE('rpc_test_dummy_module',
+                     source='rpc_test_dummy_module.c',
+                     deps='ndr',
+                     subsystem='rpc',
+                     allow_undefined_symbols=True,
+                     init_function='',
+                     internal_module=False)