From 072887b059fb5c2531137cefbb9852027979789f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz> Date: Tue, 24 Feb 2015 00:35:17 +0100 Subject: [PATCH] tests/unit: rplan query push test --- tests/test.h | 16 ++++++++++++---- tests/test_rplan.c | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/test.h b/tests/test.h index 4d864009e..6e165381c 100644 --- a/tests/test.h +++ b/tests/test.h @@ -25,16 +25,24 @@ #include <stdio.h> #include <dirent.h> #include <unistd.h> +#include <cmocka.h> +#include "lib/defines.h" #include <libknot/internal/mempattern.h> #include <libknot/descriptor.h> #include <libknot/rrset.h> -#include <libknot/errcode.h> + +/* Helpers */ +static inline void *mm_test_malloc(void *ctx, size_t n) +{ return test_malloc(n); } +static inline void mm_test_free(void *p) +{ return test_free(p); } /*! \brief Memory context using CMocka allocator. */ static inline void test_mm_ctx_init(mm_ctx_t *mm) { - mm_ctx_init(mm); + mm->alloc = &mm_test_malloc; + mm->free = &mm_test_free; } /*! \brief Recursively delete directory. */ @@ -44,7 +52,7 @@ static inline int test_tmpdir_remove(const char *path) struct dirent *ent = NULL; DIR *dir = opendir(path); if (dir == NULL) { - return KNOT_ERROR; + return kr_error(errno); } while ((ent = readdir(dir)) != NULL) { /* Skip special dirs (this presumes no files begin with '.') */ @@ -55,7 +63,7 @@ static inline int test_tmpdir_remove(const char *path) remove(buf); } remove(path); - return KNOT_EOK; + return 0; } /*! \brief Create temporary directory. */ diff --git a/tests/test_rplan.c b/tests/test_rplan.c index 3f4c885a0..88ad4c29c 100644 --- a/tests/test_rplan.c +++ b/tests/test_rplan.c @@ -18,6 +18,7 @@ #include <cmocka.h> #include "lib/rplan.h" +#include "lib/context.h" static void test_rplan_params(void **state) { @@ -45,10 +46,27 @@ static void test_rplan_params(void **state) kr_rplan_deinit(&rplan); } +static void test_rplan_push(void **state) +{ + mm_ctx_t mm; + test_mm_ctx_init(&mm); + struct kr_context context; + kr_context_init(&context, &mm); + struct kr_rplan rplan; + kr_rplan_init(&rplan, &context, &mm); + + /* Push query. */ + assert_non_null(kr_rplan_push(&rplan, NULL, (knot_dname_t *)"", 0, 0)); + + kr_rplan_deinit(&rplan); + kr_context_deinit(&context); +} + int main(void) { const UnitTest tests[] = { - unit_test(test_rplan_params) + unit_test(test_rplan_params), + unit_test(test_rplan_push) }; return run_tests(tests); -- GitLab