diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2015-05-29 15:42:46 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-06-14 21:47:19 +0200 |
commit | d43c9d18fb263b1ea4071b20e93ce4994583f62f (patch) | |
tree | 48a13f6a0427f5d3af4c7dcf4e967e191d12fa7f | |
parent | b1a822a16e3ef97e31d167f9e97efec06fc121dc (diff) | |
download | sssd-d43c9d18fb263b1ea4071b20e93ce4994583f62f.tar.gz sssd-d43c9d18fb263b1ea4071b20e93ce4994583f62f.tar.xz sssd-d43c9d18fb263b1ea4071b20e93ce4994583f62f.zip |
TESTS: Add a common mock_be_ctx function
Reduces code duplication between tests.
Reviewed-by: Sumit Bose <sbose@redhat.com>
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | src/tests/cmocka/common_mock_be.c | 39 | ||||
-rw-r--r-- | src/tests/cmocka/common_mock_be.h | 30 | ||||
-rw-r--r-- | src/tests/cmocka/test_be_ptask.c | 8 | ||||
-rw-r--r-- | src/tests/cmocka/test_dyndns.c | 6 | ||||
-rw-r--r-- | src/tests/cmocka/test_nested_groups.c | 5 |
6 files changed, 83 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index 6912fa971..db5b23242 100644 --- a/Makefile.am +++ b/Makefile.am @@ -620,6 +620,7 @@ dist_noinst_HEADERS = \ src/tests/cmocka/common_mock_sdap.h \ src/tests/cmocka/common_mock_sysdb_objects.h \ src/tests/cmocka/common_mock_krb5.h \ + src/tests/cmocka/common_mock_be.h \ src/tests/cmocka/test_expire_common.h \ src/sss_client/pam_message.h \ src/sss_client/ssh/sss_ssh_client.h \ @@ -1935,6 +1936,7 @@ EXTRA_dyndns_tests_DEPENDENCIES = \ $(ldblib_LTLIBRARIES) dyndns_tests_SOURCES = \ $(SSSD_RESOLV_OBJ) \ + src/tests/cmocka/common_mock_be.c \ src/tests/cmocka/test_dyndns.c \ src/providers/data_provider_opts.c dyndns_tests_CFLAGS = \ @@ -1966,6 +1968,7 @@ nestedgroups_tests_SOURCES = \ $(TEST_MOCK_PROVIDER_OBJ) \ src/providers/ldap/sdap_idmap.c \ src/tests/cmocka/test_nested_groups.c \ + src/tests/cmocka/common_mock_be.c \ src/providers/ldap/sdap_async_nested_groups.c \ src/providers/ldap/sdap_ad_groups.c \ $(NULL) @@ -2269,6 +2272,7 @@ test_sysdb_utils_LDADD = \ $(NULL) test_be_ptask_SOURCES = \ + src/tests/cmocka/common_mock_be.c \ src/tests/cmocka/test_be_ptask.c \ src/providers/dp_ptask.c \ $(NULL) diff --git a/src/tests/cmocka/common_mock_be.c b/src/tests/cmocka/common_mock_be.c new file mode 100644 index 000000000..a83f0aed7 --- /dev/null +++ b/src/tests/cmocka/common_mock_be.c @@ -0,0 +1,39 @@ +/* + Authors: + Jakub Hrozek <jhrozek@redhat.com> + + Copyright (C) 2015 Red Hat + + SSSD tests: Fake back end + + 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 <http://www.gnu.org/licenses/>. +*/ + +#include "util/util.h" +#include "tests/cmocka/common_mock_resp.h" + +struct be_ctx *mock_be_ctx(TALLOC_CTX *mem_ctx, struct sss_test_ctx *tctx) +{ + struct be_ctx *be_ctx; + + be_ctx = talloc_zero(mem_ctx, struct be_ctx); + assert_non_null(be_ctx); + + be_ctx->cdb = tctx->confdb; + be_ctx->ev = tctx->ev; + be_ctx->domain = tctx->dom; + be_ctx->conf_path = tctx->conf_dom_path; + + return be_ctx; +} diff --git a/src/tests/cmocka/common_mock_be.h b/src/tests/cmocka/common_mock_be.h new file mode 100644 index 000000000..3397e0226 --- /dev/null +++ b/src/tests/cmocka/common_mock_be.h @@ -0,0 +1,30 @@ +/* + Authors: + Jakub Hrozek <jhrozek@redhat.com> + + Copyright (C) 2015 Red Hat + + SSSD tests: Fake back end + + 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef __COMMON_MOCK_BE_H_ +#define __COMMON_MOCK_BE_H_ + +#include "tests/cmocka/common_mock.h" + +struct be_ctx *mock_be_ctx(TALLOC_CTX *mem_ctx, struct sss_test_ctx *tctx); + +#endif /* __COMMON_MOCK_BE_H_ */ diff --git a/src/tests/cmocka/test_be_ptask.c b/src/tests/cmocka/test_be_ptask.c index f4a120c0c..a0daaf967 100644 --- a/src/tests/cmocka/test_be_ptask.c +++ b/src/tests/cmocka/test_be_ptask.c @@ -28,6 +28,7 @@ #include "providers/dp_ptask_private.h" #include "providers/dp_ptask.h" #include "tests/cmocka/common_mock.h" +#include "tests/cmocka/common_mock_be.h" #include "tests/common.h" #define DELAY 2 @@ -37,6 +38,7 @@ cmocka_unit_test_setup_teardown(test_ ## test, test_setup, test_teardown) struct test_ctx { + struct sss_test_ctx *tctx; struct be_ctx *be_ctx; time_t when; @@ -274,8 +276,10 @@ static int test_setup(void **state) test_ctx = talloc_zero(global_talloc_context, struct test_ctx); assert_non_null(test_ctx); - /* create be_ctx, only ev and offline field should be used */ - test_ctx->be_ctx = talloc_zero(test_ctx, struct be_ctx); + test_ctx->tctx = create_ev_test_ctx(test_ctx); + assert_non_null(test_ctx->tctx); + + test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx); assert_non_null(test_ctx->be_ctx); test_ctx->be_ctx->ev = tevent_context_init(test_ctx->be_ctx); diff --git a/src/tests/cmocka/test_dyndns.c b/src/tests/cmocka/test_dyndns.c index 97fac9425..689e333d4 100644 --- a/src/tests/cmocka/test_dyndns.c +++ b/src/tests/cmocka/test_dyndns.c @@ -33,6 +33,7 @@ #include "providers/dp_dyndns.c" #include "tests/cmocka/common_mock.h" +#include "tests/cmocka/common_mock_be.h" #include "src/providers/dp_dyndns.h" #define TESTS_PATH "tests_dyndns" @@ -412,12 +413,9 @@ static int dyndns_test_setup(void **state) TEST_ID_PROVIDER, params); assert_non_null(dyndns_test_ctx->tctx); - dyndns_test_ctx->be_ctx = talloc_zero(dyndns_test_ctx, struct be_ctx); + dyndns_test_ctx->be_ctx = mock_be_ctx(dyndns_test_ctx, dyndns_test_ctx->tctx); assert_non_null(dyndns_test_ctx->be_ctx); - dyndns_test_ctx->be_ctx->cdb = dyndns_test_ctx->tctx->confdb; - dyndns_test_ctx->be_ctx->ev = dyndns_test_ctx->tctx->ev; - dyndns_test_ctx->be_ctx->conf_path = dyndns_test_ctx->tctx->conf_dom_path; return 0; } diff --git a/src/tests/cmocka/test_nested_groups.c b/src/tests/cmocka/test_nested_groups.c index 4f748a170..75fb3a19f 100644 --- a/src/tests/cmocka/test_nested_groups.c +++ b/src/tests/cmocka/test_nested_groups.c @@ -25,6 +25,7 @@ #include "tests/cmocka/common_mock.h" #include "tests/cmocka/common_mock_sdap.h" +#include "tests/cmocka/common_mock_be.h" #include "tests/cmocka/common_mock_sysdb_objects.h" #include "providers/ldap/ldap_common.h" #include "providers/ldap/sdap.h" @@ -599,12 +600,10 @@ static int nested_groups_test_setup(void **state) struct sdap_id_ctx); assert_non_null(test_ctx->sdap_id_ctx); - test_ctx->sdap_id_ctx->be = talloc_zero(test_ctx->sdap_id_ctx, - struct be_ctx); + test_ctx->sdap_id_ctx->be = mock_be_ctx(test_ctx, test_ctx->tctx); assert_non_null(test_ctx->sdap_id_ctx->be); test_ctx->sdap_id_ctx->opts = test_ctx->sdap_opts; - test_ctx->sdap_id_ctx->be->domain = test_ctx->tctx->dom; ret = sdap_idmap_init(test_ctx, test_ctx->sdap_id_ctx, &test_ctx->idmap_ctx); assert_int_equal(ret, EOK); |