diff options
author | Andreas Schneider <asn@samba.org> | 2017-05-11 11:29:25 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2017-06-06 18:36:06 +0200 |
commit | 90b69ba95d5ea53f5aadf3e3c271e8c4d50d21b5 (patch) | |
tree | 12ff0f310b70d49312d67658d865227b022ef773 /testsuite | |
parent | 0aadb5068f7565c0c05837c577003c5f9d6667a3 (diff) | |
download | samba-90b69ba95d5ea53f5aadf3e3c271e8c4d50d21b5.tar.gz |
unittest: Add testsuite for is_known_pipename()
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/rpc_test_dummy_module.c | 20 | ||||
-rw-r--r-- | testsuite/unittests/test_sambafs_srv_pipe.c | 76 | ||||
-rw-r--r-- | testsuite/unittests/wscript | 17 |
3 files changed, 113 insertions, 0 deletions
diff --git a/testsuite/unittests/rpc_test_dummy_module.c b/testsuite/unittests/rpc_test_dummy_module.c new file mode 100644 index 00000000000..d067b6e2d2b --- /dev/null +++ b/testsuite/unittests/rpc_test_dummy_module.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <unistd.h> + +int samba_init_module(void); +int samba_init_module(void) +{ + int rc; + + fprintf(stderr, "Test dummy executed!\n"); + + rc = setenv("UNITTEST_DUMMY_MODULE_LOADED", "TRUE", 1); + if (rc < 0) { + kill(getpid(), SIGILL); + exit(-1); + } + + return 0; +} diff --git a/testsuite/unittests/test_sambafs_srv_pipe.c b/testsuite/unittests/test_sambafs_srv_pipe.c new file mode 100644 index 00000000000..641e99d932b --- /dev/null +++ b/testsuite/unittests/test_sambafs_srv_pipe.c @@ -0,0 +1,76 @@ +#include <errno.h> +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <unistd.h> +#include <sys/stat.h> +#include <cmocka.h> + +#include "include/config.h" +#include "librpc/gen_ndr/ndr_samr.h" +#include "source3/rpc_server/srv_pipe.h" +#include "librpc/gen_ndr/srv_samr.h" + +static int setup_samr(void **state) +{ + rpc_samr_init(NULL); + + return 0; +} + +static int teardown(void **state) +{ + unsetenv("UNITTEST_DUMMY_MODULE_LOADED"); + + return 0; +} + +static int teardown_samr(void **state) +{ + rpc_samr_shutdown(); + + teardown(state); + + return 0; +} + +static void test_is_known_pipename(void **state) +{ + struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id; + bool is_pipename_ok; + + is_pipename_ok = is_known_pipename("samr", &syntax_id); + assert_true(is_pipename_ok); +} + +static void test_is_known_pipename_slash(void **state) +{ + struct ndr_syntax_id syntax_id = ndr_table_samr.syntax_id; + bool is_pipename_ok; + char dummy_module_path[4096] = {0}; + const char *module_env; + + snprintf(dummy_module_path, + sizeof(dummy_module_path), + "%s/bin/modules/rpc/test_dummy_module.so", + SRCDIR); + + is_pipename_ok = is_known_pipename(dummy_module_path, &syntax_id); + assert_false(is_pipename_ok); + + module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED"); + assert_null(module_env); +} + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(test_is_known_pipename, + setup_samr, + teardown_samr), + cmocka_unit_test_teardown(test_is_known_pipename_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 355ab0cc10a..bb29fd8cba2 100644 --- a/testsuite/unittests/wscript +++ b/testsuite/unittests/wscript @@ -10,3 +10,20 @@ def build(bld): source='test_krb5_samba.c', deps='krb5samba cmocka', install=False) + + bld.SAMBA_BINARY('test_sambafs_srv_pipe', + source='test_sambafs_srv_pipe.c', + deps=''' + RPC_SERVER + RPC_SAMR + cmocka + ''', + install=False) + + bld.SAMBA_MODULE('rpc_test_dummy_module', + source='rpc_test_dummy_module.c', + deps='ndr', + subsystem='rpc', + allow_undefined_symbols=True, + init_function='', + internal_module=False) |