diff options
author | David Robillard <d@drobilla.net> | 2018-10-28 14:00:47 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 800f2d0d4960061a1739a36d8b608a13896b321e (patch) | |
tree | f885ae3e85efad463f06b62a8ee48cfb23d3ff5e /test | |
parent | f0c30e3fff0072746252eb9a37334e740975f389 (diff) | |
download | serd-800f2d0d4960061a1739a36d8b608a13896b321e.tar.gz serd-800f2d0d4960061a1739a36d8b608a13896b321e.tar.bz2 serd-800f2d0d4960061a1739a36d8b608a13896b321e.zip |
Add SerdNodes class for storing a cache of nodes
Diffstat (limited to 'test')
-rw-r--r-- | test/meson.build | 1 | ||||
-rw-r--r-- | test/test_free_null.c | 1 | ||||
-rw-r--r-- | test/test_nodes.c | 93 |
3 files changed, 95 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build index e46e75ab..94477318 100644 --- a/test/meson.build +++ b/test/meson.build @@ -7,6 +7,7 @@ unit_tests = [ 'env', 'free_null', 'node', + 'nodes', 'read_chunk', 'reader_writer', 'string', diff --git a/test/test_free_null.c b/test/test_free_null.c index f629a285..62615a02 100644 --- a/test/test_free_null.c +++ b/test/test_free_null.c @@ -31,6 +31,7 @@ main(void) serd_sink_free(NULL); serd_reader_free(NULL); serd_writer_free(NULL); + serd_nodes_free(NULL); serd_cursor_free(NULL); return 0; diff --git a/test/test_nodes.c b/test/test_nodes.c new file mode 100644 index 00000000..f515edd0 --- /dev/null +++ b/test/test_nodes.c @@ -0,0 +1,93 @@ +/* + Copyright 2018 David Robillard <d@drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#undef NDEBUG + +#include "serd/serd.h" + +#include <assert.h> +#include <stddef.h> + +static int +test_intern(void) +{ + SerdNodes* nodes = serd_nodes_new(); + SerdNode* node = serd_new_string(SERD_STATIC_STRING("node")); + + const SerdNode* interned1 = serd_nodes_intern(nodes, node); + assert(serd_node_equals(node, interned1)); + + const SerdNode* interned2 = serd_nodes_intern(nodes, node); + assert(serd_node_equals(node, interned2)); + assert(interned1 == interned2); + + serd_node_free(node); + serd_nodes_free(nodes); + return 0; +} + +static int +test_manage(void) +{ + SerdNodes* nodes = serd_nodes_new(); + SerdNode* node = serd_new_string(SERD_STATIC_STRING("node")); + + assert(!serd_nodes_manage(nodes, NULL)); + + const SerdNode* managed1 = serd_nodes_manage(nodes, node); + assert(managed1 == node); + + SerdNode* equal = serd_new_string(SERD_STATIC_STRING("node")); + const SerdNode* managed2 = serd_nodes_manage(nodes, equal); + assert(managed2 == node); + + serd_nodes_free(nodes); + return 0; +} + +static int +test_deref(void) +{ + SerdNodes* nodes = serd_nodes_new(); + const SerdNode* managed = + serd_nodes_manage(nodes, serd_new_string(SERD_STATIC_STRING("node"))); + + serd_nodes_deref(nodes, managed); + + SerdNode* node = serd_new_string(SERD_STATIC_STRING("node")); + const SerdNode* interned = serd_nodes_intern(nodes, node); + + assert(interned != node); + + serd_node_free(node); + serd_nodes_free(nodes); + return 0; +} + +int +main(void) +{ + typedef int (*TestFunc)(void); + + const TestFunc tests[] = {test_intern, test_manage, test_deref, NULL}; + + int ret = 0; + for (const TestFunc* t = tests; *t; ++t) { + ret += (*t)(); + } + + return ret; +} |