unittest: Add testsuite for is_known_pipename()
[sfrench/samba-autobuild/.git] / testsuite / unittests / test_sambafs_srv_pipe.c
1 #include <errno.h>
2 #include <stdarg.h>
3 #include <stddef.h>
4 #include <setjmp.h>
5 #include <unistd.h>
6 #include <sys/stat.h>
7 #include <cmocka.h>
8
9 #include "include/config.h"
10 #include "librpc/gen_ndr/ndr_samr.h"
11 #include "source3/rpc_server/srv_pipe.h"
12 #include "librpc/gen_ndr/srv_samr.h"
13
14 static int setup_samr(void **state)
15 {
16         rpc_samr_init(NULL);
17
18         return 0;
19 }
20
21 static int teardown(void **state)
22 {
23         unsetenv("UNITTEST_DUMMY_MODULE_LOADED");
24
25         return 0;
26 }
27
28 static int teardown_samr(void **state)
29 {
30         rpc_samr_shutdown();
31
32         teardown(state);
33
34         return 0;
35 }
36
37 static void test_is_known_pipename(void **state)
38 {
39         struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id;
40         bool is_pipename_ok;
41
42         is_pipename_ok = is_known_pipename("samr", &syntax_id);
43         assert_true(is_pipename_ok);
44 }
45
46 static void test_is_known_pipename_slash(void **state)
47 {
48         struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id;
49         bool is_pipename_ok;
50         char dummy_module_path[4096] = {0};
51         const char *module_env;
52
53         snprintf(dummy_module_path,
54                  sizeof(dummy_module_path),
55                  "%s/bin/modules/rpc/test_dummy_module.so",
56                  SRCDIR);
57
58         is_pipename_ok = is_known_pipename(dummy_module_path, &syntax_id);
59         assert_false(is_pipename_ok);
60
61         module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
62         assert_null(module_env);
63 }
64
65 int main(void) {
66         const struct CMUnitTest tests[] = {
67                 cmocka_unit_test_setup_teardown(test_is_known_pipename,
68                                                 setup_samr,
69                                                 teardown_samr),
70                 cmocka_unit_test_teardown(test_is_known_pipename_slash,
71                                           teardown),
72         };
73
74         cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
75         return cmocka_run_group_tests(tests, NULL, NULL);
76 }