From d65f692d7b7639ed8ba0f5cffa4f88b68056739a Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Wed, 22 May 2013 08:50:29 +0200 Subject: Making order in tests. --removed duplicated test-io --reusing library libsss_test_common in other tests --cmocka test sss_nss_idmap-tests was moved to cmocka dir --moved leak_check.c to libsss_test_common --moved common_tev.c,common_dom.c to libsss_test_common (leak_check.c,common_tev.c,common_dom.c) are test framework independent --- Makefile.am | 34 ++++------ src/tests/cmocka/sss_nss_idmap-tests.c | 118 +++++++++++++++++++++++++++++++++ src/tests/leak_check.c | 1 - src/tests/sss_nss_idmap-tests.c | 118 --------------------------------- 4 files changed, 132 insertions(+), 139 deletions(-) create mode 100644 src/tests/cmocka/sss_nss_idmap-tests.c delete mode 100644 src/tests/sss_nss_idmap-tests.c diff --git a/Makefile.am b/Makefile.am index 2bcb7145..250f9b67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,7 +150,6 @@ if HAVE_CMOCKA test-find-uid \ test-io \ sss_nss_idmap-tests \ - test-io \ dyndns-tests endif @@ -869,12 +868,14 @@ noinst_LTLIBRARIES += \ libsss_test_common.la libsss_test_common_la_SOURCES = \ + src/tests/common_tev.c \ + src/tests/common_dom.c \ + src/tests/leak_check.c \ src/tests/common.c if HAVE_CHECK libsss_test_common_la_SOURCES += \ - src/tests/common_check.c \ - src/tests/leak_check.c + src/tests/common_check.c sysdb_tests_DEPENDENCIES = \ $(ldblib_LTLIBRARIES) @@ -1149,14 +1150,6 @@ sss_idmap_tests_LDADD = \ libsss_test_common.la \ libsss_idmap.la -sss_nss_idmap_tests_SOURCES = \ - src/tests/sss_nss_idmap-tests.c -sss_nss_idmap_tests_CFLAGS = \ - $(AM_CFLAGS) -sss_nss_idmap_tests_LDADD = \ - $(CMOCKA_LIBS) \ - libsss_nss_idmap.la - pac_responder_tests_SOURCES = \ src/tests/pac_responder-tests.c \ src/responder/pac/pacsrv_utils.c @@ -1222,14 +1215,8 @@ krb5_child_test_LDADD = \ libsss_test_common.la if HAVE_CMOCKA -TEST_MOCK_OBJ = \ - src/tests/common.c \ - src/tests/leak_check.c TEST_MOCK_RESP_OBJ = \ - $(TEST_MOCK_OBJ) \ - src/tests/common_tev.c \ - src/tests/common_dom.c \ src/tests/cmocka/common_mock_resp.c \ src/responder/common/responder_packet.c \ src/responder/common/responder_cmd.c \ @@ -1255,6 +1242,7 @@ nss_srv_tests_LDFLAGS = \ -Wl,-wrap,sss_cmd_done nss_srv_tests_LDADD = \ $(CMOCKA_LIBS) \ + libsss_test_common.la \ libsss_idmap.la \ libsss_util.la @@ -1285,13 +1273,18 @@ test_io_CFLAGS = \ test_io_LDADD = \ $(CMOCKA_LIBS) +sss_nss_idmap_tests_SOURCES = \ + src/tests/cmocka/sss_nss_idmap-tests.c +sss_nss_idmap_tests_CFLAGS = \ + $(AM_CFLAGS) +sss_nss_idmap_tests_LDADD = \ + $(CMOCKA_LIBS) \ + libsss_nss_idmap.la + dyndns_tests_DEPENDENCIES = \ $(ldblib_LTLIBRARIES) dyndns_tests_SOURCES = \ - $(TEST_MOCK_OBJ) \ $(SSSD_RESOLV_OBJ) \ - src/tests/common_tev.c \ - src/tests/common_dom.c \ src/tests/cmocka/test_dyndns.c \ src/providers/data_provider_opts.c dyndns_tests_CFLAGS = \ @@ -1304,6 +1297,7 @@ dyndns_tests_LDFLAGS = \ dyndns_tests_LDADD = \ $(CARES_LIBS) \ $(CMOCKA_LIBS) \ + libsss_test_common.la \ libsss_util.la endif diff --git a/src/tests/cmocka/sss_nss_idmap-tests.c b/src/tests/cmocka/sss_nss_idmap-tests.c new file mode 100644 index 00000000..e4831a33 --- /dev/null +++ b/src/tests/cmocka/sss_nss_idmap-tests.c @@ -0,0 +1,118 @@ +/* + Authors: + Sumit Bose + + Copyright (C) 2013 Red Hat + + Test for the NSS Responder ID-SID mapping interface + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include + + +#include "util/util.h" + +#include "sss_client/idmap/sss_nss_idmap.h" +#include "tests/cmocka/common_mock.h" + +#include +#include "sss_client/sss_cli.h" + +struct sss_nss_make_request_test_data { + uint8_t *repbuf; + size_t replen; + int errnop; + enum nss_status nss_status; +}; + +uint8_t buf1[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; +uint8_t buf2[] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; +uint8_t buf3[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; +uint8_t buf4[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 'x'}; +enum nss_status sss_nss_make_request(enum sss_cli_command cmd, + struct sss_cli_req_data *rd, + uint8_t **repbuf, size_t *replen, + int *errnop) +{ + struct sss_nss_make_request_test_data *d; + + d = sss_mock_ptr_type(struct sss_nss_make_request_test_data *); + + *replen = d->replen; + *errnop = d->errnop; + + /* the caller must be able to free repbuf. */ + if (*replen != 0 && d->repbuf != NULL) { + *repbuf = malloc(*replen); + assert_non_null(*repbuf); + memcpy(*repbuf, d->repbuf, *replen); + } + + return d->nss_status; +} + +void test_getsidbyname(void **state) { + int ret; + char *sid; + size_t c; + enum sss_id_type type; + + struct test_data { + struct sss_nss_make_request_test_data d; + int ret; + const char *str; + } d[] = { + {{buf1, sizeof(buf1), 0, NSS_STATUS_SUCCESS}, EOK, "test"}, + {{buf2, sizeof(buf2), 0, NSS_STATUS_SUCCESS}, EBADMSG, NULL}, + {{buf3, sizeof(buf3), 0, NSS_STATUS_SUCCESS}, ENOENT, NULL}, + {{buf4, sizeof(buf4), 0, NSS_STATUS_SUCCESS}, EBADMSG, NULL}, + {{NULL, 0, 0, 0}, 0, NULL} + }; + + ret = sss_nss_getsidbyname(NULL, NULL, NULL); + assert_int_equal(ret, EINVAL); + + ret = sss_nss_getsidbyname("", NULL, NULL); + assert_int_equal(ret, EINVAL); + + ret = sss_nss_getsidbyname("", &sid, NULL); + assert_int_equal(ret, EINVAL); + + for (c = 0; d[c].d.repbuf != NULL; c++) { + will_return(sss_nss_make_request, &d[0].d); + + ret = sss_nss_getsidbyname("test", &sid, &type); + assert_int_equal(ret, d[0].ret); + if (ret == EOK) { + assert_string_equal(sid, d[0].str); + assert_int_equal(type, 0); + } + } +} + +int main(int argc, const char *argv[]) +{ + + const UnitTest tests[] = { + unit_test(test_getsidbyname), + }; + + return run_tests(tests); +} diff --git a/src/tests/leak_check.c b/src/tests/leak_check.c index 89dac357..06941195 100644 --- a/src/tests/leak_check.c +++ b/src/tests/leak_check.c @@ -23,7 +23,6 @@ */ #include -#include #include "tests/common.h" #include "util/util.h" #include "util/dlinklist.h" diff --git a/src/tests/sss_nss_idmap-tests.c b/src/tests/sss_nss_idmap-tests.c deleted file mode 100644 index e4831a33..00000000 --- a/src/tests/sss_nss_idmap-tests.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - Authors: - Sumit Bose - - Copyright (C) 2013 Red Hat - - Test for the NSS Responder ID-SID mapping interface - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include - - -#include "util/util.h" - -#include "sss_client/idmap/sss_nss_idmap.h" -#include "tests/cmocka/common_mock.h" - -#include -#include "sss_client/sss_cli.h" - -struct sss_nss_make_request_test_data { - uint8_t *repbuf; - size_t replen; - int errnop; - enum nss_status nss_status; -}; - -uint8_t buf1[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; -uint8_t buf2[] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; -uint8_t buf3[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 0x00}; -uint8_t buf4[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 't', 'e', 's', 't', 'x'}; -enum nss_status sss_nss_make_request(enum sss_cli_command cmd, - struct sss_cli_req_data *rd, - uint8_t **repbuf, size_t *replen, - int *errnop) -{ - struct sss_nss_make_request_test_data *d; - - d = sss_mock_ptr_type(struct sss_nss_make_request_test_data *); - - *replen = d->replen; - *errnop = d->errnop; - - /* the caller must be able to free repbuf. */ - if (*replen != 0 && d->repbuf != NULL) { - *repbuf = malloc(*replen); - assert_non_null(*repbuf); - memcpy(*repbuf, d->repbuf, *replen); - } - - return d->nss_status; -} - -void test_getsidbyname(void **state) { - int ret; - char *sid; - size_t c; - enum sss_id_type type; - - struct test_data { - struct sss_nss_make_request_test_data d; - int ret; - const char *str; - } d[] = { - {{buf1, sizeof(buf1), 0, NSS_STATUS_SUCCESS}, EOK, "test"}, - {{buf2, sizeof(buf2), 0, NSS_STATUS_SUCCESS}, EBADMSG, NULL}, - {{buf3, sizeof(buf3), 0, NSS_STATUS_SUCCESS}, ENOENT, NULL}, - {{buf4, sizeof(buf4), 0, NSS_STATUS_SUCCESS}, EBADMSG, NULL}, - {{NULL, 0, 0, 0}, 0, NULL} - }; - - ret = sss_nss_getsidbyname(NULL, NULL, NULL); - assert_int_equal(ret, EINVAL); - - ret = sss_nss_getsidbyname("", NULL, NULL); - assert_int_equal(ret, EINVAL); - - ret = sss_nss_getsidbyname("", &sid, NULL); - assert_int_equal(ret, EINVAL); - - for (c = 0; d[c].d.repbuf != NULL; c++) { - will_return(sss_nss_make_request, &d[0].d); - - ret = sss_nss_getsidbyname("test", &sid, &type); - assert_int_equal(ret, d[0].ret); - if (ret == EOK) { - assert_string_equal(sid, d[0].str); - assert_int_equal(type, 0); - } - } -} - -int main(int argc, const char *argv[]) -{ - - const UnitTest tests[] = { - unit_test(test_getsidbyname), - }; - - return run_tests(tests); -} -- cgit