>From ad138ded237a1f3433fa4f379c70f96d66d6797a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 3 Jul 2015 11:15:32 +0200 Subject: [PATCH 1/2] tests: Reduce duplication with new function test_ev_done --- src/tests/cmocka/test_ipa_subdomains_server.c | 11 ++--------- src/tests/cmocka/test_resolv_fake.c | 3 +-- src/tests/cmocka/test_responder_common.c | 8 ++++---- src/tests/common.h | 3 +++ src/tests/common_tev.c | 6 ++++++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/tests/cmocka/test_ipa_subdomains_server.c b/src/tests/cmocka/test_ipa_subdomains_server.c index 28e998b57489eccb5d3b0357df650f0faf3976fc..a4cb8c2b7538dc84b74e0227205b73780844b652 100644 --- a/src/tests/cmocka/test_ipa_subdomains_server.c +++ b/src/tests/cmocka/test_ipa_subdomains_server.c @@ -266,7 +266,6 @@ static int test_ipa_server_create_trusts_teardown(void **state) static void test_ipa_server_create_trusts_none(struct tevent_req *req); static void test_ipa_server_create_trusts_twoway(struct tevent_req *req); -static void test_ipa_server_create_trusts_finish(struct trust_test_ctx *test_ctx); static void test_ipa_server_create_trusts(void **state) { @@ -427,13 +426,7 @@ static void test_ipa_server_create_trusts_twoway(struct tevent_req *req) DOM_REALM); assert_null(test_ctx->ipa_ctx->server_mode->trusts->next); - test_ipa_server_create_trusts_finish(test_ctx); -} - -static void test_ipa_server_create_trusts_finish(struct trust_test_ctx *test_ctx) -{ - test_ctx->tctx->error = EOK; - test_ctx->tctx->done = true; + test_ev_done(test_ctx->tctx, EOK); } static void @@ -669,7 +662,7 @@ static void test_ipa_server_create_trusts_oneway(struct tevent_req *req) SUBDOM_REALM); assert_null(test_ctx->ipa_ctx->server_mode->trusts->next->next); - test_ipa_server_create_trusts_finish(test_ctx); + test_ev_done(test_ctx->tctx, EOK); } static void test_ipa_server_create_oneway_kt_exists(void **state) diff --git a/src/tests/cmocka/test_resolv_fake.c b/src/tests/cmocka/test_resolv_fake.c index 2c846ce4cc63cbf80b30bd15091136002ec84cb3..a1e9ee4cba9b17d506eeae7e6088de28c301364d 100644 --- a/src/tests/cmocka/test_resolv_fake.c +++ b/src/tests/cmocka/test_resolv_fake.c @@ -293,8 +293,7 @@ void test_resolv_fake_srv_done(struct tevent_req *req) assert_int_equal(ttl, 500); talloc_free(tmp_ctx); - test_ctx->ctx->error = EOK; - test_ctx->ctx->done = true; + test_ev_done(test_ctx->ctx, EOK); } void test_resolv_fake_srv(void **state) diff --git a/src/tests/cmocka/test_responder_common.c b/src/tests/cmocka/test_responder_common.c index 0a4d4bb49c5058b5a006912b6b3b61ab0332cc29..cb57c97fe6b0995c9ec69f969015ef500e065fad 100644 --- a/src/tests/cmocka/test_responder_common.c +++ b/src/tests/cmocka/test_responder_common.c @@ -161,8 +161,9 @@ void parse_inp_simple_done(struct tevent_req *req) char *domname = NULL; ret = sss_parse_inp_recv(req, parse_inp_ctx, &name, &domname); - parse_inp_ctx->tctx->done = true; assert_int_equal(ret, EOK); + + test_ev_done(parse_inp_ctx->tctx, EOK); talloc_free(req); assert_string_equal(name, NAME); @@ -239,8 +240,8 @@ void parse_inp_neg_done(struct tevent_req *req) char *domname = NULL; ret = sss_parse_inp_recv(req, parse_inp_ctx, &name, &domname); - parse_inp_ctx->tctx->done = true; assert_int_equal(ret, ERR_INPUT_PARSE); + test_ev_done(parse_inp_ctx->tctx, EOK); talloc_free(req); assert_null(name); @@ -273,8 +274,7 @@ struct sss_nc_ctx { errno_t sss_ncache_reset_repopulate_permanent(struct resp_ctx *rctx, struct sss_nc_ctx *dummy_ncache_ptr) { - dummy_ncache_ptr->pctx->tctx->error = EOK; - dummy_ncache_ptr->pctx->tctx->done = true; + test_ev_done(dummy_ncache_ptr->pctx->tctx, EOK); return EOK; } diff --git a/src/tests/common.h b/src/tests/common.h index 714be6988aa032d935c09bc7db524545a4c9154e..0b351f5d647a8f72bdbc399c6fe02579d4b4e1be 100644 --- a/src/tests/common.h +++ b/src/tests/common.h @@ -112,6 +112,9 @@ errno_t test_request_recv(struct tevent_req *req); int test_ev_loop(struct sss_test_ctx *tctx); +/* Mark the test as done with an error code */ +void test_ev_done(struct sss_test_ctx *tctx, errno_t ret); + bool ldb_modules_path_is_set(void); DBusConnection * diff --git a/src/tests/common_tev.c b/src/tests/common_tev.c index 770f97d83684696498ff691dc14b45c233008fd3..808efd459ca66a52874eda2897ab9cdd084523e1 100644 --- a/src/tests/common_tev.c +++ b/src/tests/common_tev.c @@ -83,3 +83,9 @@ int test_ev_loop(struct sss_test_ctx *tctx) return tctx->error; } + +void test_ev_done(struct sss_test_ctx *tctx, errno_t ret) +{ + tctx->error = ret; + tctx->done = true; +} -- 2.4.3