diff options
author | Andreas Schneider <asn@samba.org> | 2017-05-12 14:13:42 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2017-06-06 18:36:07 +0200 |
commit | 61f827bcdde494d3b4a094d6816ff7556f0ff608 (patch) | |
tree | 973c163e93db1c76c2627fa312e7d1025a9628ad /testsuite | |
parent | eaf8e3a88889bed2bcd0932c9642bb7a5a26abe4 (diff) | |
download | samba-61f827bcdde494d3b4a094d6816ff7556f0ff608.tar.gz |
unittest: Add testsuite for smb_probe_module()
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>
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/unittests/test_lib_util_modules.c | 76 | ||||
-rw-r--r-- | testsuite/unittests/wscript | 8 |
2 files changed, 84 insertions, 0 deletions
diff --git a/testsuite/unittests/test_lib_util_modules.c b/testsuite/unittests/test_lib_util_modules.c new file mode 100644 index 00000000000..c92dafd161e --- /dev/null +++ b/testsuite/unittests/test_lib_util_modules.c @@ -0,0 +1,76 @@ +#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(void **state) +{ + NTSTATUS status; + + status = smb_probe_module("auth", "unix"); + assert_true(NT_STATUS_IS_OK(status)); +} + +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, + teardown), + 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); +} diff --git a/testsuite/unittests/wscript b/testsuite/unittests/wscript index bb29fd8cba2..ba6ad3cbed9 100644 --- a/testsuite/unittests/wscript +++ b/testsuite/unittests/wscript @@ -20,6 +20,14 @@ def build(bld): ''', install=False) + bld.SAMBA_BINARY('test_lib_util_modules', + source='test_lib_util_modules.c', + deps=''' + samba-modules + cmocka + ''', + install=False) + bld.SAMBA_MODULE('rpc_test_dummy_module', source='rpc_test_dummy_module.c', deps='ndr', |