From f4d17db1d27289fce65b2e12e925952be4710531 Mon Sep 17 00:00:00 2001 From: Jan Kadlec <jan@hp4-jankadlec.(none)> Date: Tue, 16 Nov 2010 16:43:21 +0100 Subject: [PATCH] Intitial dnslib_node test for creating. Refs #116 --- src/tests/dnslib/dnslib_node_tests.c | 69 ++++++++++++++++++++++++++++ src/tests/dnslib_tests.c | 3 ++ 2 files changed, 72 insertions(+) create mode 100644 src/tests/dnslib/dnslib_node_tests.c diff --git a/src/tests/dnslib/dnslib_node_tests.c b/src/tests/dnslib/dnslib_node_tests.c new file mode 100644 index 0000000000..5c379efc82 --- /dev/null +++ b/src/tests/dnslib/dnslib_node_tests.c @@ -0,0 +1,69 @@ +#include "tap_unit.h" + +#include "common.h" +#include "dname.h" +#include "node.h" + +static int dnslib_node_tests_count(int argc, char *argv[]); +static int dnslib_node_tests_run(int argc, char *argv[]); + +/*! Exported unit API. + */ +unit_api dnslib_node_tests_api = { + "DNS library - node", //! Unit name + &dnslib_node_tests_count, //! Count scheduled tests + &dnslib_node_tests_run //! Run scheduled tests +}; + +/* + * Unit implementation. + */ + +// C will not accept const int in other const definition +enum { TEST_NODES = 1}; + +struct test_node { + dnslib_dname_t owner; + dnslib_node_t *parent; + uint size; +}; + +static struct test_node + test_nodes[TEST_NODES] = { + {{(uint8_t *)"\3www\7example\3com", 17}, (dnslib_node_t *)0xBADDCAFE} +}; + + +static int test_node_create() +{ + dnslib_node_t *tmp; + for (int i = 0; i < TEST_NODES; i++) { + tmp = dnslib_node_new(&test_nodes[i].owner, test_nodes[i].parent); + if (tmp == NULL || tmp->owner != &test_nodes[i].owner || + tmp->parent != test_nodes[i].parent || tmp->rrsets == NULL) { + return 0; + } + dnslib_node_free(&tmp); + } + return 1; +} + +static const int DNSLIB_NODE_TEST_COUNT = 1; + +/*! This helper routine should report number of + * scheduled tests for given parameters. + */ +static int dnslib_node_tests_count(int argc, char *argv[]) +{ + return DNSLIB_NODE_TEST_COUNT; +} + +/*! Run all scheduled tests for given parameters. + */ +static int dnslib_node_tests_run(int argc, char *argv[]) +{ + + ok(test_node_create(), "node: create"); + + return 0; +} diff --git a/src/tests/dnslib_tests.c b/src/tests/dnslib_tests.c index 0fc4f78e40..be425eeca8 100644 --- a/src/tests/dnslib_tests.c +++ b/src/tests/dnslib_tests.c @@ -2,6 +2,7 @@ #include "dnslib/dnslib_dname_tests.c" #include "dnslib/dnslib_rdata_tests.c" +#include "dnslib/dnslib_node_tests.c" static int dnslib_tests_count(int argc, char *argv[]); static int dnslib_tests_run(int argc, char *argv[]); @@ -36,6 +37,8 @@ static int dnslib_tests_run(int argc, char *argv[]) res = dnslib_dname_tests_run(argc, argv); note("Testing module: rdata"); res += dnslib_rdata_tests_run(argc, argv); + note("Testing module: node"); + res += dnslib_node_tests_run(argc, argv); return res; } -- GitLab