diff options
author | David Robillard <d@drobilla.net> | 2021-07-10 22:22:09 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 2019d1581c1296cc534c731a1f454ce08b460dcc (patch) | |
tree | fa2737fbe62772806e37669aef7d56f4a10b4f7b /test/test_writer.c | |
parent | b839af39ad87fbf0fe30fd500b596a5593c13a69 (diff) | |
download | serd-2019d1581c1296cc534c731a1f454ce08b460dcc.tar.gz serd-2019d1581c1296cc534c731a1f454ce08b460dcc.tar.bz2 serd-2019d1581c1296cc534c731a1f454ce08b460dcc.zip |
Use SerdNodes to simplify some tests
Diffstat (limited to 'test/test_writer.c')
-rw-r--r-- | test/test_writer.c | 117 |
1 files changed, 62 insertions, 55 deletions
diff --git a/test/test_writer.c b/test/test_writer.c index 7e72ec5c..a80783f6 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -163,6 +163,7 @@ static void test_write_long_literal(void) { SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -171,20 +172,21 @@ test_write_long_literal(void) serd_writer_new(world, SERD_TURTLE, 0U, env, &output, 1U); assert(writer); - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); - SerdNode* o = - serd_node_new(NULL, - serd_a_literal(serd_string("hello \"\"\"world\"\"\"!"), - SERD_IS_LONG, - serd_empty_string())); + const SerdNode* s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); + + const SerdNode* o = + serd_nodes_get(nodes, + serd_a_literal(serd_string("hello \"\"\"world\"\"\"!"), + SERD_IS_LONG, + serd_empty_string())); assert(serd_node_flags(o) & SERD_IS_LONG); assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL)); - serd_node_free(NULL, o); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_writer_free(writer); serd_close_output(&output); serd_env_free(env); @@ -219,6 +221,7 @@ test_writer_cleanup(void) { SerdStatus st = SERD_SUCCESS; SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); SerdOutputStream output = serd_open_output_stream(null_sink, NULL, NULL, NULL); @@ -228,9 +231,13 @@ test_writer_cleanup(void) const SerdSink* sink = serd_writer_sink(writer); - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); - SerdNode* o = serd_node_new(NULL, serd_a_blank_string("start")); + const SerdNode* const s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* const p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); + + const SerdNode* o = serd_nodes_get(nodes, serd_a_string("start")); st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL); assert(!st); @@ -240,26 +247,21 @@ test_writer_cleanup(void) char buf[12] = {0}; snprintf(buf, sizeof(buf), "b%u", i); - SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf)); + const SerdNode* next_o = serd_nodes_get(nodes, serd_a_blank_string(buf)); st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL); - - serd_node_free(NULL, o); - o = next_o; + o = next_o; } // Finish writing without terminating nodes assert(!(st = serd_writer_finish(writer))); // Set the base to an empty URI - SerdNode* empty_uri = serd_node_new(NULL, serd_a_uri_string("")); + const SerdNode* const empty_uri = + serd_nodes_get(nodes, serd_a_uri_string("")); assert(!(st = serd_sink_write_base(sink, empty_uri))); - serd_node_free(NULL, empty_uri); // Free (which could leak if the writer doesn't clean up the stack properly) - serd_node_free(NULL, o); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_writer_free(writer); serd_env_free(env); serd_world_free(world); @@ -347,9 +349,9 @@ test_write_error(void) static void test_writer_stack_overflow(void) { - SerdWorld* world = serd_world_new(NULL); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); - + SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); + SerdEnv* env = serd_env_new(NULL, serd_empty_string()); SerdOutputStream output = serd_open_output_stream(null_sink, NULL, NULL, NULL); @@ -358,12 +360,14 @@ test_writer_stack_overflow(void) const SerdSink* sink = serd_writer_sink(writer); - SerdNode* const s = - serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* const p = - serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); + const SerdNode* const s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* const p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); + + const SerdNode* o = serd_nodes_get(nodes, serd_a_blank_string("blank")); - SerdNode* o = serd_node_new(NULL, serd_a_blank_string("blank")); SerdStatus st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL); assert(!st); @@ -372,12 +376,10 @@ test_writer_stack_overflow(void) char buf[1024]; snprintf(buf, sizeof(buf), "b%u", i); - SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf)); + const SerdNode* next_o = serd_nodes_get(nodes, serd_a_blank_string(buf)); st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL); - - serd_node_free(NULL, o); - o = next_o; + o = next_o; if (st) { assert(st == SERD_BAD_STACK); @@ -387,9 +389,6 @@ test_writer_stack_overflow(void) assert(st == SERD_BAD_STACK); - serd_node_free(NULL, o); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_writer_free(writer); serd_close_output(&output); serd_env_free(env); @@ -400,11 +399,17 @@ static void test_write_empty_syntax(void) { SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); - SerdNode* o = serd_node_new(NULL, serd_a_uri_string("http://example.org/o")); + const SerdNode* s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); + + const SerdNode* o = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/o")); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -423,9 +428,6 @@ test_write_empty_syntax(void) serd_free(NULL, buffer.buf); serd_writer_free(writer); - serd_node_free(NULL, o); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_close_output(&output); serd_env_free(env); serd_world_free(world); @@ -435,6 +437,7 @@ static void check_pname_escape(const char* const lname, const char* const expected) { SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -448,20 +451,21 @@ check_pname_escape(const char* const lname, const char* const expected) serd_env_set_prefix(env, serd_string("eg"), serd_string(prefix)); - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); + const SerdNode* s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); char* const uri = (char*)calloc(1, prefix_len + strlen(lname) + 1); memcpy(uri, prefix, prefix_len + 1); memcpy(uri + prefix_len, lname, strlen(lname) + 1); - SerdNode* node = serd_node_new(NULL, serd_a_uri_string(uri)); + const SerdNode* node = serd_nodes_get(nodes, serd_a_uri_string(uri)); + assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, node, NULL)); - serd_node_free(NULL, node); free(uri); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_writer_free(writer); serd_close_output(&output); serd_env_free(env); @@ -509,10 +513,16 @@ static void test_write_bad_uri(void) { SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); - SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); - SerdNode* rel = serd_node_new(NULL, serd_a_uri_string("rel")); + + const SerdNode* s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); + + const SerdNode* p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); + + const SerdNode* rel = serd_nodes_get(nodes, serd_a_uri_string("rel")); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -530,9 +540,6 @@ test_write_bad_uri(void) serd_writer_free(writer); serd_close_output(&output); serd_free(NULL, buffer.buf); - serd_node_free(NULL, rel); - serd_node_free(NULL, p); - serd_node_free(NULL, s); serd_env_free(env); serd_world_free(world); } |