summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-05-29 15:42:46 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-06-14 21:47:19 +0200
commitd43c9d18fb263b1ea4071b20e93ce4994583f62f (patch)
tree48a13f6a0427f5d3af4c7dcf4e967e191d12fa7f /src/tests
parentb1a822a16e3ef97e31d167f9e97efec06fc121dc (diff)
downloadsssd-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>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/common_mock_be.c39
-rw-r--r--src/tests/cmocka/common_mock_be.h30
-rw-r--r--src/tests/cmocka/test_be_ptask.c8
-rw-r--r--src/tests/cmocka/test_dyndns.c6
-rw-r--r--src/tests/cmocka/test_nested_groups.c5
5 files changed, 79 insertions, 9 deletions
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);