diff --git a/src/tests/cmocka/test_be_ptask.c b/src/tests/cmocka/test_be_ptask.c index 00acce2..63c14b9 100644 --- a/src/tests/cmocka/test_be_ptask.c +++ b/src/tests/cmocka/test_be_ptask.c @@ -171,6 +171,27 @@ errno_t test_be_ptask_sync(TALLOC_CTX *mem_ctx, return ERR_OK; } +errno_t test_be_ptask_sync_ENOENT(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct be_ctx *be_ctx, + struct be_ptask *be_ptask, + void *pvt) +{ + struct test_ctx *test_ctx = NULL; + + assert_non_null(ev); + assert_non_null(be_ctx); + assert_non_null(be_ptask); + assert_non_null(pvt); + + test_ctx = talloc_get_type(pvt, struct test_ctx); + assert_non_null(test_ctx); + + test_ctx->when = time(NULL); + test_ctx->done = true; + + return ENOENT; +} void test_setup(void **state) { struct test_ctx *test_ctx = NULL; @@ -610,6 +631,39 @@ void test_be_ptask_create_sync(void **state) assert_null(ptask); } +void test_be_ptask_create_sync_error(void **state) +{ + struct test_ctx *test_ctx = (struct test_ctx *)(*state); + struct be_ptask *ptask = NULL; + time_t now; + errno_t ret; + + now = time(NULL); + ret = be_ptask_create_sync(test_ctx, test_ctx->be_ctx, 10, 0, 0, 0, 0, + BE_PTASK_OFFLINE_SKIP, 0, test_be_ptask_sync_ENOENT, + test_ctx, "Test ptask", &ptask); + assert_int_equal(ret, ERR_OK); + assert_non_null(ptask); + assert_non_null(ptask->timer); + + enum tevent_req_state tev_state; + uint64_t error; + + while (ptask->req == NULL + || ( tevent_req_is_error(ptask->req, &tev_state, &error) + && tev_state != TEVENT_REQ_USER_ERROR)) { + tevent_loop_once(test_ctx->be_ctx->ev); + } + + assert_int_equal(error, ENOENT); + assert_true(now <= ptask->last_execution); + assert_true(now <= test_ctx->when); + assert_true(ptask->last_execution <= test_ctx->when); + + be_ptask_destroy(&ptask); + assert_null(ptask); +} + int main(int argc, const char *argv[]) { poptContext pc; @@ -637,7 +691,8 @@ int main(int argc, const char *argv[]) new_test(be_ptask_reschedule_ok), new_test(be_ptask_reschedule_error), new_test(be_ptask_get_period), - new_test(be_ptask_create_sync) + new_test(be_ptask_create_sync), + new_test(be_ptask_create_sync_error), }; /* Set debug level to invalid value so we can deside if -d 0 was used. */