diff options
author | David Robillard <d@drobilla.net> | 2023-05-05 09:43:57 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 4711fdf527f416faee8ff19e15f050d4b48dcfb2 (patch) | |
tree | 6b18712ec44cce5713ddef1a21aec5f12651d901 /test/test_writer.c | |
parent | 248a874d7425749d29cf900a1c3783c624ea8d8c (diff) | |
download | serd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.tar.gz serd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.tar.bz2 serd-4711fdf527f416faee8ff19e15f050d4b48dcfb2.zip |
[WIP] Generalize node construction API
Diffstat (limited to 'test/test_writer.c')
-rw-r--r-- | test/test_writer.c | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/test/test_writer.c b/test/test_writer.c index 39bcd34a..8f4fef5c 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -78,13 +78,14 @@ test_write_failed_alloc(void) SerdBuffer buffer = {&allocator.base, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p1 = serd_new_uri(NULL, serd_string("http://example.org/p")); + SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s")); + SerdNode* p1 = serd_node_new(NULL, serd_a_uri_string("http://example.org/p")); - SerdNode* p2 = serd_new_uri( - NULL, serd_string("http://example.org/dramatically/longer/predicate")); + SerdNode* p2 = serd_node_new( + NULL, + serd_a_uri_string("http://example.org/dramatically/longer/predicate")); - SerdNode* o = serd_new_token(NULL, SERD_BLANK, serd_string("o")); + SerdNode* o = serd_node_new(NULL, serd_a_blank_string("o")); const size_t n_setup_allocs = allocator.n_allocations; @@ -168,12 +169,13 @@ test_write_long_literal(void) serd_writer_new(world, SERD_TURTLE, 0U, env, &output, 1U); assert(writer); - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); - SerdNode* o = serd_new_literal(NULL, - serd_string("hello \"\"\"world\"\"\"!"), + 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()); + serd_empty_string())); assert(serd_node_flags(o) & SERD_IS_LONG); assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL)); @@ -224,9 +226,9 @@ test_writer_cleanup(void) const SerdSink* sink = serd_writer_sink(writer); - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); - SerdNode* o = serd_new_blank(NULL, serd_string("start")); + 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")); st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL); assert(!st); @@ -236,7 +238,7 @@ test_writer_cleanup(void) char buf[12] = {0}; snprintf(buf, sizeof(buf), "b%u", i); - SerdNode* next_o = serd_new_blank(NULL, serd_string(buf)); + SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf)); st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL); @@ -248,7 +250,7 @@ test_writer_cleanup(void) assert(!(st = serd_writer_finish(writer))); // Set the base to an empty URI - SerdNode* empty_uri = serd_new_uri(NULL, serd_string("")); + SerdNode* empty_uri = serd_node_new(NULL, serd_a_uri_string("")); assert(!(st = serd_sink_write_base(sink, empty_uri))); serd_node_free(NULL, empty_uri); @@ -280,11 +282,12 @@ test_strict_write(void) const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0}; - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); + 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* bad_lit = serd_new_string(NULL, serd_string((const char*)bad_str)); - SerdNode* bad_uri = serd_new_uri(NULL, serd_string((const char*)bad_str)); + SerdNode* bad_lit = serd_node_new(NULL, serd_a_string((const char*)bad_str)); + SerdNode* bad_uri = + serd_node_new(NULL, serd_a_uri_string((const char*)bad_str)); assert(serd_sink_write(sink, 0, s, p, bad_lit, NULL) == SERD_BAD_TEXT); assert(serd_sink_write(sink, 0, s, p, bad_uri, NULL) == SERD_BAD_TEXT); @@ -322,7 +325,7 @@ test_write_error(void) SerdOutputStream out = serd_open_output_stream(error_sink, NULL, NULL, NULL); SerdStatus st = SERD_SUCCESS; - SerdNode* u = serd_new_uri(NULL, serd_string("http://example.com/u")); + SerdNode* u = serd_node_new(NULL, serd_a_uri_string("http://example.com/u")); SerdWriter* const writer = serd_writer_new(world, SERD_TURTLE, (SerdWriterFlags)0, env, &out, 1U); @@ -353,10 +356,12 @@ test_writer_stack_overflow(void) const SerdSink* sink = serd_writer_sink(writer); - SerdNode* const s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* const p = serd_new_uri(NULL, serd_string("http://example.org/p")); + 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")); - SerdNode* o = serd_new_blank(NULL, serd_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); @@ -365,7 +370,7 @@ test_writer_stack_overflow(void) char buf[1024]; snprintf(buf, sizeof(buf), "b%u", i); - SerdNode* next_o = serd_new_blank(NULL, serd_string(buf)); + SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf)); st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL); @@ -395,9 +400,9 @@ test_write_empty_syntax(void) SerdWorld* world = serd_world_new(NULL); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); - SerdNode* o = serd_new_uri(NULL, serd_string("http://example.org/o")); + 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")); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -441,14 +446,14 @@ 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_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); + 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")); 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_new_uri(NULL, serd_string(uri)); + SerdNode* node = serd_node_new(NULL, serd_a_uri_string(uri)); assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, node, NULL)); serd_node_free(NULL, node); @@ -503,9 +508,9 @@ test_write_bad_uri(void) { SerdWorld* world = serd_world_new(NULL); SerdEnv* env = serd_env_new(NULL, serd_empty_string()); - SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s")); - SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p")); - SerdNode* rel = serd_new_uri(NULL, serd_string("rel")); + 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")); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); |