diff options
author | David Robillard <d@drobilla.net> | 2023-05-10 21:06:16 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | e750f4b6734d086e433e3c9c05b2252f43f4be8f (patch) | |
tree | 6eb84ef00642ac32f40bca8a242a9b0d2a6ef3f3 /test/test_statement.c | |
parent | 8346ac7f529f5aeb8d8b0e48837e680ea14e8893 (diff) | |
download | serd-e750f4b6734d086e433e3c9c05b2252f43f4be8f.tar.gz serd-e750f4b6734d086e433e3c9c05b2252f43f4be8f.tar.bz2 serd-e750f4b6734d086e433e3c9c05b2252f43f4be8f.zip |
Add SerdNodes for storing a cache of interned nodes
Diffstat (limited to 'test/test_statement.c')
-rw-r--r-- | test/test_statement.c | 104 |
1 files changed, 59 insertions, 45 deletions
diff --git a/test/test_statement.c b/test/test_statement.c index fe1ce818..4cc3a0fa 100644 --- a/test/test_statement.c +++ b/test/test_statement.c @@ -4,7 +4,9 @@ #undef NDEBUG #include "serd/caret.h" +#include "serd/memory.h" #include "serd/node.h" +#include "serd/nodes.h" #include "serd/statement.h" #include <assert.h> @@ -15,36 +17,44 @@ static void test_new(void) { - SerdNode* const u = serd_node_new(NULL, serd_a_uri_string(NS_EG "s")); - SerdNode* const b = serd_node_new(NULL, serd_a_blank_string("b0")); - SerdNode* const l = serd_node_new(NULL, serd_a_string("str")); - - assert(!serd_statement_new(NULL, u, b, u, NULL, NULL)); - assert(!serd_statement_new(NULL, l, u, u, NULL, NULL)); - assert(!serd_statement_new(NULL, l, u, b, u, NULL)); - assert(!serd_statement_new(NULL, u, l, b, NULL, NULL)); - assert(!serd_statement_new(NULL, u, l, b, u, NULL)); - assert(!serd_statement_new(NULL, u, u, u, l, NULL)); - - serd_node_free(NULL, l); - serd_node_free(NULL, b); - serd_node_free(NULL, u); + SerdAllocator* const allocator = serd_default_allocator(); + + assert(!serd_statement_copy(allocator, NULL)); + + SerdNodes* const nodes = serd_nodes_new(allocator); + + const SerdNode* const s = serd_nodes_get(nodes, serd_a_string("s")); + const SerdNode* const u = serd_nodes_get(nodes, serd_a_uri_string(NS_EG "u")); + const SerdNode* const b = + serd_nodes_get(nodes, serd_a_blank_string(NS_EG "b")); + + // S, P, and G may not be strings (must be resources) + assert(!serd_statement_new(allocator, s, u, u, u, NULL)); + assert(!serd_statement_new(allocator, u, s, u, u, NULL)); + assert(!serd_statement_new(allocator, u, u, u, s, NULL)); + + // P may not be a blank node + assert(!serd_statement_new(allocator, u, b, u, u, NULL)); + + serd_nodes_free(nodes); } static void test_copy(void) { + SerdAllocator* const alloc = NULL; + assert(!serd_statement_copy(NULL, NULL)); - SerdNode* const f = serd_node_new(NULL, serd_a_string("file")); - SerdNode* const s = serd_node_new(NULL, serd_a_uri_string(NS_EG "s")); - SerdNode* const p = serd_node_new(NULL, serd_a_uri_string(NS_EG "p")); - SerdNode* const o = serd_node_new(NULL, serd_a_uri_string(NS_EG "o")); - SerdNode* const g = serd_node_new(NULL, serd_a_uri_string(NS_EG "g")); + SerdNode* const f = serd_node_new(alloc, serd_a_string("file")); + SerdNode* const s = serd_node_new(alloc, serd_a_uri_string(NS_EG "s")); + SerdNode* const p = serd_node_new(alloc, serd_a_uri_string(NS_EG "p")); + SerdNode* const o = serd_node_new(alloc, serd_a_uri_string(NS_EG "o")); + SerdNode* const g = serd_node_new(alloc, serd_a_uri_string(NS_EG "g")); - SerdCaret* const caret = serd_caret_new(NULL, f, 1, 1); - SerdStatement* const statement = serd_statement_new(NULL, s, p, o, g, caret); - SerdStatement* const copy = serd_statement_copy(NULL, statement); + SerdCaret* const caret = serd_caret_new(alloc, f, 1, 1); + SerdStatement* const statement = serd_statement_new(alloc, s, p, o, g, caret); + SerdStatement* const copy = serd_statement_copy(alloc, statement); assert(serd_statement_equals(copy, statement)); assert(serd_caret_equals(serd_statement_caret(copy), caret)); @@ -62,20 +72,24 @@ test_copy(void) static void test_free(void) { + serd_statement_free(serd_default_allocator(), NULL); serd_statement_free(NULL, NULL); } static void test_fields(void) { - SerdNode* const f = serd_node_new(NULL, serd_a_string("file")); - SerdNode* const s = serd_node_new(NULL, serd_a_uri_string(NS_EG "s")); - SerdNode* const p = serd_node_new(NULL, serd_a_uri_string(NS_EG "p")); - SerdNode* const o = serd_node_new(NULL, serd_a_uri_string(NS_EG "o")); - SerdNode* const g = serd_node_new(NULL, serd_a_uri_string(NS_EG "g")); + SerdAllocator* const alloc = NULL; + + SerdNode* const f = serd_node_new(alloc, serd_a_string("file")); + SerdNode* const s = serd_node_new(alloc, serd_a_uri_string(NS_EG "s")); + SerdNode* const p = serd_node_new(alloc, serd_a_uri_string(NS_EG "p")); + SerdNode* const o = serd_node_new(alloc, serd_a_uri_string(NS_EG "o")); + SerdNode* const g = serd_node_new(alloc, serd_a_uri_string(NS_EG "g")); + + SerdCaret* const caret = serd_caret_new(alloc, f, 1, 1); - SerdCaret* const caret = serd_caret_new(NULL, f, 1, 1); - SerdStatement* const statement = serd_statement_new(NULL, s, p, o, g, caret); + SerdStatement* const statement = serd_statement_new(alloc, s, p, o, g, caret); assert(serd_statement_equals(statement, statement)); assert(!serd_statement_equals(statement, NULL)); @@ -102,29 +116,29 @@ test_fields(void) assert(!serd_statement_matches(statement, NULL, NULL, s, NULL)); assert(!serd_statement_matches(statement, NULL, NULL, NULL, s)); - SerdStatement* const diff_s = serd_statement_new(NULL, o, p, o, g, caret); + SerdStatement* const diff_s = serd_statement_new(alloc, o, p, o, g, caret); assert(!serd_statement_equals(statement, diff_s)); - serd_statement_free(NULL, diff_s); + serd_statement_free(alloc, diff_s); - SerdStatement* const diff_p = serd_statement_new(NULL, s, o, o, g, caret); + SerdStatement* const diff_p = serd_statement_new(alloc, s, o, o, g, caret); assert(!serd_statement_equals(statement, diff_p)); - serd_statement_free(NULL, diff_p); + serd_statement_free(alloc, diff_p); - SerdStatement* const diff_o = serd_statement_new(NULL, s, p, s, g, caret); + SerdStatement* const diff_o = serd_statement_new(alloc, s, p, s, g, caret); assert(!serd_statement_equals(statement, diff_o)); - serd_statement_free(NULL, diff_o); + serd_statement_free(alloc, diff_o); - SerdStatement* const diff_g = serd_statement_new(NULL, s, p, o, s, caret); + SerdStatement* const diff_g = serd_statement_new(alloc, s, p, o, s, caret); assert(!serd_statement_equals(statement, diff_g)); - serd_statement_free(NULL, diff_g); - - serd_statement_free(NULL, statement); - serd_caret_free(NULL, caret); - serd_node_free(NULL, g); - serd_node_free(NULL, o); - serd_node_free(NULL, p); - serd_node_free(NULL, s); - serd_node_free(NULL, f); + serd_statement_free(alloc, diff_g); + + serd_statement_free(alloc, statement); + serd_caret_free(alloc, caret); + serd_node_free(alloc, g); + serd_node_free(alloc, o); + serd_node_free(alloc, p); + serd_node_free(alloc, s); + serd_node_free(alloc, f); } int |