From b6c9214d2077c87fa19cc5431732f1b496797bed Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 23 Jun 2024 16:21:08 -0400 Subject: Fix writer cleanup test Because nodes are shallow, this wasn't actually writing a stack of nested objects. Fix the blank node ping-pong algorithm so that it does. --- test/test_writer.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'test/test_writer.c') diff --git a/test/test_writer.c b/test/test_writer.c index b02aba7e..75b311cf 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -134,7 +134,9 @@ test_writer_cleanup(void) SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s")); SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p")); - SerdNode o = serd_node_from_string(SERD_BLANK, USTR("http://example.org/o")); + + char o_buf[12] = {'b', '0', '\0'}; + SerdNode o = serd_node_from_string(SERD_BLANK, USTR(o_buf)); st = serd_writer_write_statement( writer, SERD_ANON_O_BEGIN, NULL, &s, &p, &o, NULL, NULL); @@ -142,16 +144,24 @@ test_writer_cleanup(void) assert(!st); // Write the start of several nested anonymous objects - for (unsigned i = 0U; !st && i < 8U; ++i) { - char buf[12] = {0}; - snprintf(buf, sizeof(buf), "b%u", i); + for (unsigned i = 1U; !st && i < 9U; ++i) { + char next_o_buf[12] = {'\0'}; + snprintf(next_o_buf, sizeof(next_o_buf), "b%u", i); + + SerdNode next_o = serd_node_from_string(SERD_BLANK, USTR(next_o_buf)); - SerdNode next_o = serd_node_from_string(SERD_BLANK, USTR(buf)); + st = serd_writer_write_statement(writer, + SERD_ANON_O_BEGIN | SERD_ANON_CONT, + NULL, + &o, + &p, + &next_o, + NULL, + NULL); - st = serd_writer_write_statement( - writer, SERD_ANON_O_BEGIN, NULL, &o, &p, &next_o, NULL, NULL); + assert(!st); - o = next_o; + memcpy(o_buf, next_o_buf, sizeof(o_buf)); } // Finish writing without terminating nodes -- cgit v1.2.1