summaryrefslogtreecommitdiffstats
path: root/testsuite/unittests/test_lib_util_modules.c
blob: 647fc1fb82d1ecb9cbf95a04bf21ed5adc9c4242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#include <talloc.h>

#include "include/config.h"
#include "libcli/util/ntstatus.h"
#include "lib/util/samba_modules.h"

static int teardown(void **state)
{
	unsetenv("UNITTEST_DUMMY_MODULE_LOADED");

	return 0;
}

static void test_samba_module_probe_dummy(void **state)
{
	const char *module_env;
	NTSTATUS status;

	status = smb_probe_module("rpc", "test_dummy_module");
	assert_true(NT_STATUS_IS_OK(status));

	module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
	assert_non_null(module_env);
	assert_string_equal(module_env, "TRUE");
}

static void test_samba_module_probe_slash(void **state)
{
	char dummy_module_path[4096] = {0};
	const char *module_env;
	NTSTATUS status;

	snprintf(dummy_module_path,
		 sizeof(dummy_module_path),
		 "%s/bin/modules/rpc/test_dummy_module.so",
		 SRCDIR);

	status = smb_probe_module("rpc", dummy_module_path);
	assert_true(NT_STATUS_IS_ERR(status));

	module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
	assert_null(module_env);
}

int main(void) {
	const struct CMUnitTest tests[] = {
		cmocka_unit_test_teardown(test_samba_module_probe_dummy,
					  teardown),
		cmocka_unit_test_teardown(test_samba_module_probe_slash,
					  teardown),
	};

	cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
	return cmocka_run_group_tests(tests, NULL, NULL);
}