diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_node.c | 46 | ||||
-rw-r--r-- | test/test_read_chunk.c | 16 | ||||
-rw-r--r-- | test/test_reader_writer.c | 58 | ||||
-rw-r--r-- | test/test_writer.c | 2 |
4 files changed, 68 insertions, 54 deletions
diff --git a/test/test_node.c b/test/test_node.c index be3576ff..a16aa889 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -194,6 +194,51 @@ test_node_from_substring(void) serd_node_free(a_b); } +static void +check_copy_equals(const SerdNode* const node) +{ + SerdNode* const copy = serd_node_copy(node); + + assert(serd_node_equals(node, copy)); + + serd_node_free(copy); +} + +static void +test_literal(void) +{ + SerdNode* hello2 = serd_new_literal("hello\"", NULL, NULL); + assert(serd_node_length(hello2) == 6 && + serd_node_flags(hello2) == SERD_HAS_QUOTE && + !strcmp(serd_node_string(hello2), "hello\"")); + check_copy_equals(hello2); + serd_node_free(hello2); + + SerdNode* hello_l = serd_new_literal("hello_l\"", NULL, "en"); + assert(serd_node_length(hello_l) == 8); + assert(!strcmp(serd_node_string(hello_l), "hello_l\"")); + assert(serd_node_flags(hello_l) == (SERD_HAS_QUOTE | SERD_HAS_LANGUAGE)); + + const SerdNode* const lang = serd_node_language(hello_l); + assert(lang); + assert(!strcmp(serd_node_string(lang), "en")); + check_copy_equals(hello_l); + serd_node_free(hello_l); + + SerdNode* hello_dt = + serd_new_literal("hello_dt\"", "http://example.org/Thing", NULL); + assert(serd_node_length(hello_dt) == 9); + assert(!strcmp(serd_node_string(hello_dt), "hello_dt\"")); + assert(serd_node_flags(hello_dt) == (SERD_HAS_QUOTE | SERD_HAS_DATATYPE)); + + const SerdNode* const datatype = serd_node_datatype(hello_dt); + assert(datatype); + assert(!strcmp(serd_node_string(datatype), "http://example.org/Thing")); + + check_copy_equals(hello_dt); + serd_node_free(hello_dt); +} + int main(void) { @@ -204,6 +249,7 @@ main(void) test_node_equals(); test_node_from_string(); test_node_from_substring(); + test_literal(); printf("Success\n"); return 0; diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c index d97713a4..009cbd14 100644 --- a/test/test_read_chunk.c +++ b/test/test_read_chunk.c @@ -49,14 +49,12 @@ on_prefix(void* handle, const SerdNode* name, const SerdNode* uri) } static SerdStatus -on_statement(void* handle, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang) +on_statement(void* const handle, + const SerdStatementFlags flags, + const SerdNode* const graph, + const SerdNode* const subject, + const SerdNode* const predicate, + const SerdNode* const object) { (void)handle; (void)flags; @@ -64,8 +62,6 @@ on_statement(void* handle, (void)subject; (void)predicate; (void)object; - (void)object_datatype; - (void)object_lang; ++n_statement; return SERD_SUCCESS; diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index e81fb348..258b3c91 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -36,16 +36,12 @@ test_sink(void* handle, const SerdNode* graph, const SerdNode* subject, const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang) + const SerdNode* object) { (void)flags; (void)subject; (void)predicate; (void)object; - (void)object_datatype; - (void)object_lang; ReaderTest* rt = (ReaderTest*)handle; ++rt->n_statements; @@ -204,57 +200,33 @@ test_writer(const char* const path) SerdNode* o = serd_new_string(SERD_LITERAL, (char*)buf); // Write 3 invalid statements (should write nothing) - const SerdNode* junk[][5] = { - {s, o, o, NULL, NULL}, {o, p, o, NULL, NULL}, {s, o, p, NULL, NULL}}; - for (size_t i = 0; i < sizeof(junk) / (sizeof(SerdNode*) * 5); ++i) { - assert(serd_writer_write_statement(writer, - 0, - NULL, - junk[i][0], - junk[i][1], - junk[i][2], - junk[i][3], - junk[i][4])); + const SerdNode* junk[][3] = {{s, o, o}, {o, p, o}, {s, o, p}}; + for (size_t i = 0; i < sizeof(junk) / (sizeof(SerdNode*) * 3); ++i) { + assert(serd_writer_write_statement( + writer, 0, NULL, junk[i][0], junk[i][1], junk[i][2])); } - SerdNode* t = serd_new_string(SERD_URI, "urn:Type"); - SerdNode* l = serd_new_string(SERD_LITERAL, "en"); - const SerdNode* good[][5] = {{s, p, o, NULL, NULL}, - {s, p, o, NULL, NULL}, - {s, p, o, t, NULL}, - {s, p, o, NULL, l}, - {s, p, o, t, l}, - {s, p, o, t, NULL}, - {s, p, o, NULL, l}, - {s, p, o, NULL, NULL}, - {s, p, o, NULL, NULL}, - {s, p, o, NULL, NULL}}; - for (size_t i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 5); ++i) { - assert(!serd_writer_write_statement(writer, - 0, - NULL, - good[i][0], - good[i][1], - good[i][2], - good[i][3], - good[i][4])); + SerdNode* t = serd_new_literal((char*)buf, "urn:Type", NULL); + SerdNode* l = serd_new_literal((char*)buf, NULL, "en"); + const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}}; + for (size_t i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 3); ++i) { + assert(!serd_writer_write_statement( + writer, 0, NULL, good[i][0], good[i][1], good[i][2])); } // Write statements with bad UTF-8 (should be replaced) const char bad_str[] = {(char)0xFF, (char)0x90, 'h', 'i', 0}; SerdNode* bad_lit = serd_new_string(SERD_LITERAL, bad_str); SerdNode* bad_uri = serd_new_string(SERD_URI, bad_str); - assert( - !serd_writer_write_statement(writer, 0, NULL, s, p, bad_lit, NULL, NULL)); - assert( - !serd_writer_write_statement(writer, 0, NULL, s, p, bad_uri, NULL, NULL)); + assert(!serd_writer_write_statement(writer, 0, NULL, s, p, bad_lit)); + assert(!serd_writer_write_statement(writer, 0, NULL, s, p, bad_uri)); serd_node_free(bad_lit); serd_node_free(bad_uri); // Write 1 valid statement serd_node_free(o); o = serd_new_string(SERD_LITERAL, "hello"); - assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o, NULL, NULL)); + assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o)); serd_writer_free(writer); serd_node_free(lit); @@ -314,7 +286,7 @@ test_reader(const char* path) const SerdStatus st = serd_reader_read_file(reader, path); assert(!st); - assert(rt->n_statements == 13); + assert(rt->n_statements == 6); assert(rt->graph && serd_node_string(rt->graph) && !strcmp(serd_node_string(rt->graph), "http://example.org/")); diff --git a/test/test_writer.c b/test/test_writer.c index 7568984d..531e229d 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -35,7 +35,7 @@ test_write_long_literal(void) SerdNode* p = serd_new_string(SERD_URI, "http://example.org/p"); SerdNode* o = serd_new_string(SERD_LITERAL, "hello \"\"\"world\"\"\"!"); - assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o, NULL, NULL)); + assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o)); serd_node_free(o); serd_node_free(p); |