pyldb: avoid segfault when adding an element with no name
[sfrench/samba-autobuild/.git] / testsuite / unittests / test_lib_util_modules.c
1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
5
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <unistd.h>
11 #include <sys/stat.h>
12 #include <talloc.h>
13
14 #include "include/config.h"
15 #include "libcli/util/ntstatus.h"
16 #include "lib/util/samba_modules.h"
17
18 static int teardown(void **state)
19 {
20         unsetenv("UNITTEST_DUMMY_MODULE_LOADED");
21
22         return 0;
23 }
24
25 static void test_samba_module_probe(void **state)
26 {
27         NTSTATUS status;
28
29         status = smb_probe_module("auth", "skel");
30         assert_true(NT_STATUS_IS_OK(status));
31 }
32
33 static void test_samba_module_probe_dummy(void **state)
34 {
35         const char *module_env;
36         NTSTATUS status;
37
38         status = smb_probe_module("rpc", "test_dummy_module");
39         assert_true(NT_STATUS_IS_OK(status));
40
41         module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
42         assert_non_null(module_env);
43         assert_string_equal(module_env, "TRUE");
44 }
45
46 static void test_samba_module_probe_slash(void **state)
47 {
48         char dummy_module_path[4096] = {0};
49         const char *module_env;
50         NTSTATUS status;
51
52         snprintf(dummy_module_path,
53                  sizeof(dummy_module_path),
54                  "%s/bin/modules/rpc/test_dummy_module.so",
55                  SRCDIR);
56
57         status = smb_probe_module("rpc", dummy_module_path);
58         assert_true(NT_STATUS_IS_ERR(status));
59
60         module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
61         assert_null(module_env);
62 }
63
64 int main(void) {
65         const struct CMUnitTest tests[] = {
66                 cmocka_unit_test_teardown(test_samba_module_probe,
67                                           teardown),
68                 cmocka_unit_test_teardown(test_samba_module_probe_dummy,
69                                           teardown),
70                 cmocka_unit_test_teardown(test_samba_module_probe_slash,
71                                           teardown),
72         };
73
74         cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
75         return cmocka_run_group_tests(tests, NULL, NULL);
76 }