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_reader_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_reader_writer.c')
-rw-r--r-- | test/test_reader_writer.c | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 9a4c988f..7a57daed 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -9,6 +9,7 @@ #include "serd/input_stream.h" #include "serd/memory.h" #include "serd/node.h" +#include "serd/nodes.h" #include "serd/output_stream.h" #include "serd/reader.h" #include "serd/sink.h" @@ -142,6 +143,7 @@ static void test_writer(const char* const path) { 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_file(path); @@ -151,7 +153,7 @@ test_writer(const char* const path) assert(writer); - SerdNode* lit = serd_node_new(NULL, serd_a_string("hello")); + const SerdNode* lit = serd_nodes_get(nodes, serd_a_string("hello")); const SerdSink* const iface = serd_writer_sink(writer); assert(serd_sink_write_base(iface, lit)); @@ -161,10 +163,13 @@ test_writer(const char* const path) static const uint8_t bad_buf[] = {0xEF, 0xBF, 0xBD, 0}; const SerdStringView bad_buf_view = {(const char*)bad_buf, 3}; - SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org")); - SerdNode* p = - serd_node_new(NULL, serd_a_uri_string("http://example.org/pred")); - SerdNode* bad = serd_node_new(NULL, serd_a_string_view(bad_buf_view)); + const SerdNode* s = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org")); + + const SerdNode* p = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/pred")); + + const SerdNode* bad = serd_nodes_get(nodes, serd_a_string_view(bad_buf_view)); // Write 3 invalid statements (should write nothing) const SerdNode* junk[][3] = {{s, bad, bad}, {bad, p, bad}, {s, bad, p}}; @@ -172,18 +177,15 @@ test_writer(const char* const path) assert(serd_sink_write(iface, 0, junk[i][0], junk[i][1], junk[i][2], NULL)); } - serd_node_free(NULL, bad); - - const SerdStringView urn_Type = serd_string("urn:Type"); - const SerdStringView en = serd_string("en"); + const SerdStringView urn_Type = serd_string("urn:Type"); + const SerdStringView en = serd_string("en"); + const SerdNode* const o = serd_nodes_get(nodes, serd_a_string("o")); - SerdNode* const o = serd_node_new(NULL, serd_a_string("o")); + const SerdNode* const t = + serd_nodes_get(nodes, serd_a_typed_literal(serd_string("t"), urn_Type)); - SerdNode* const t = - serd_node_new(NULL, serd_a_typed_literal(serd_string("t"), urn_Type)); - - SerdNode* const l = - serd_node_new(NULL, serd_a_plain_literal(serd_string("l"), en)); + const SerdNode* const l = + serd_nodes_get(nodes, serd_a_plain_literal(serd_string("l"), en)); const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}}; @@ -198,37 +200,32 @@ test_writer(const char* const path) static const char* const bad_uri_str = (const char*)bad_uri_buf; // Write statements with bad UTF-8 (should be replaced) - SerdNode* bad_lit = serd_node_new(NULL, serd_a_string(bad_lit_str)); - SerdNode* bad_uri = serd_node_new(NULL, serd_a_uri_string(bad_uri_str)); + + const SerdNode* bad_lit = serd_nodes_get(nodes, serd_a_string(bad_lit_str)); + const SerdNode* bad_uri = + serd_nodes_get(nodes, serd_a_uri_string(bad_uri_str)); + assert(!serd_sink_write(iface, 0, s, p, bad_lit, 0)); assert(!serd_sink_write(iface, 0, s, p, bad_uri, 0)); - serd_node_free(NULL, bad_uri); - serd_node_free(NULL, bad_lit); // Write 1 valid statement - SerdNode* const hello = serd_node_new(NULL, serd_a_string("hello")); + const SerdNode* const hello = serd_nodes_get(nodes, serd_a_string("hello")); assert(!serd_sink_write(iface, 0, s, p, hello, 0)); - serd_node_free(NULL, hello); serd_writer_free(writer); serd_close_output(&output); - serd_node_free(NULL, lit); - serd_node_free(NULL, o); - serd_node_free(NULL, t); - serd_node_free(NULL, l); - // Test buffer sink - SerdBuffer buffer = {NULL, NULL, 0}; - SerdNode* const base = - serd_node_new(NULL, serd_a_uri_string("http://example.org/base")); + SerdBuffer buffer = {NULL, NULL, 0}; + + const SerdNode* const base = + serd_nodes_get(nodes, serd_a_uri_string("http://example.org/base")); output = serd_open_output_buffer(&buffer); writer = serd_writer_new(world, SERD_TURTLE, 0, env, &output, 1U); serd_sink_write_base(serd_writer_sink(writer), base); - serd_node_free(NULL, base); serd_writer_free(writer); serd_close_output(&output); @@ -237,9 +234,6 @@ test_writer(const char* const path) assert(!strcmp(out, "@base <http://example.org/base> .\n")); serd_free(NULL, buffer.buf); - serd_node_free(NULL, p); - serd_node_free(NULL, s); - serd_env_free(env); serd_world_free(world); } |