Commit 072887b0 authored by Marek Vavruša's avatar Marek Vavruša

tests/unit: rplan query push test

parent f01e17c3
......@@ -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. */
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment