s3:utils: Use #ifdef instead of #if for config.h definitions
[Samba.git] / testsuite / unittests / test_lib_util_modules.c
blobca62857d86d8fa972e8247fc256844ae0b6bd51c
1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
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>
14 #include "include/config.h"
15 #include "libcli/util/ntstatus.h"
16 #include "lib/util/samba_modules.h"
18 static int teardown(void **state)
20 unsetenv("UNITTEST_DUMMY_MODULE_LOADED");
22 return 0;
25 static void test_samba_module_probe(void **state)
27 NTSTATUS status;
29 status = smb_probe_module("auth", "skel");
30 assert_true(NT_STATUS_IS_OK(status));
33 static void test_samba_module_probe_dummy(void **state)
35 const char *module_env;
36 NTSTATUS status;
38 status = smb_probe_module("rpc", "test_dummy_module");
39 assert_true(NT_STATUS_IS_OK(status));
41 module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
42 assert_non_null(module_env);
43 assert_string_equal(module_env, "TRUE");
46 static void test_samba_module_probe_slash(void **state)
48 char dummy_module_path[4096] = {0};
49 const char *module_env;
50 NTSTATUS status;
52 snprintf(dummy_module_path,
53 sizeof(dummy_module_path),
54 "%s/bin/modules/rpc/test_dummy_module.so",
55 SRCDIR);
57 status = smb_probe_module("rpc", dummy_module_path);
58 assert_true(NT_STATUS_IS_ERR(status));
60 module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
61 assert_null(module_env);
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),
74 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
75 return cmocka_run_group_tests(tests, NULL, NULL);