diff options
Diffstat (limited to 'tests/serd_test.c')
-rw-r--r-- | tests/serd_test.c | 93 |
1 files changed, 62 insertions, 31 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c index c6fb975a..67289b5d 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -71,9 +71,7 @@ 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) { ReaderTest* rt = (ReaderTest*)handle; ++rt->n_statements; @@ -343,6 +341,40 @@ main(void) } serd_node_free(a_b); + // Test serd_node_new_literal + + if (serd_node_new_literal(NULL, NULL, NULL)) { + FAIL("Successfully created node from NULL string\n"); + } + + SerdNode* hello2 = serd_node_new_literal("hello\"", NULL, NULL); + if (serd_node_get_length(hello2) != 6 || + serd_node_get_flags(hello2) != SERD_HAS_QUOTE || + strcmp(serd_node_get_string(hello2), "hello\"")) { + FAILF("Bad node %s\n", serd_node_get_string(hello2)); + } + serd_node_free(hello2); + + SerdNode* hello_l = serd_node_new_literal("hello_l\"", NULL, "en"); + if (serd_node_get_length(hello_l) != 8 || + strcmp(serd_node_get_string(hello_l), "hello_l\"") || + serd_node_get_flags(hello_l) != (SERD_HAS_QUOTE | SERD_HAS_LANGUAGE) || + strcmp(serd_node_get_string(serd_node_get_language(hello_l)), "en")) { + FAILF("Bad node %s\n", serd_node_get_string(hello_l)); + } + serd_node_free(hello_l); + + SerdNode* hello_dt = + serd_node_new_literal("hello_dt\"", "http://example.org/Thing", NULL); + if (serd_node_get_length(hello_dt) != 9 || + strcmp(serd_node_get_string(hello_dt), "hello_dt\"") || + serd_node_get_flags(hello_dt) != (SERD_HAS_QUOTE | SERD_HAS_DATATYPE) || + strcmp(serd_node_get_string(serd_node_get_datatype(hello_dt)), + "http://example.org/Thing")) { + FAILF("Bad node %s\n", serd_node_get_string(hello_dt)); + } + serd_node_free(hello_dt); + // Test serd_node_new_uri_from_string if (serd_node_new_uri_from_string(NULL, NULL, NULL)) { @@ -523,40 +555,39 @@ main(void) SerdNode* o = serd_node_new_string(SERD_LITERAL, (char*)buf); // Write 3 invalid statements (should write nothing) - const SerdNode* junk[][5] = { { s, p, NULL, NULL, NULL }, - { s, NULL, o, NULL, NULL }, - { NULL, p, o, NULL, NULL }, - { s, p, NULL, NULL, NULL }, - { s, NULL, o, NULL, NULL }, - { NULL, p, o, NULL, NULL }, - { s, o, o, NULL, NULL }, - { o, p, o, NULL, NULL }, - { s, p, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL } }; + const SerdNode* junk[][5] = { { s, p, NULL }, + { s, NULL, o }, + { NULL, p, o }, + { s, p, NULL }, + { s, NULL, o }, + { NULL, p, o }, + { s, o, o }, + { o, p, o }, + { s, p, NULL }, + { NULL, NULL, NULL } }; for (unsigned i = 0; i < sizeof(junk) / (sizeof(SerdNode*) * 5); ++i) { if (!serd_writer_write_statement( writer, 0, NULL, - junk[i][0], junk[i][1], junk[i][2], junk[i][3], junk[i][4])) { + junk[i][0], junk[i][1], junk[i][2])) { FAILF("Successfully wrote junk statement %d\n", i); } } - SerdNode* t = serd_node_new_string(SERD_URI, "urn:Type"); - SerdNode* l = serd_node_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 } }; + SerdNode* t = serd_node_new_literal((char*)buf, "urn:Type", NULL); + SerdNode* l = serd_node_new_literal((char*)buf, NULL, "en"); + const SerdNode* good[][5] = { { s, p, o }, + { s, p, o }, + { s, p, t }, + { s, p, l }, + { s, p, l }, + { s, p, t }, + { s, p, l }, + { s, p, o }, + { s, p, o }, + { s, p, o } }; for (unsigned i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 5); ++i) { if (serd_writer_write_statement( - writer, 0, NULL, - good[i][0], good[i][1], good[i][2], good[i][3], good[i][4])) { + writer, 0, NULL, good[i][0], good[i][1], good[i][2])) { FAILF("Failed to write good statement %d\n", i); } } @@ -566,10 +597,10 @@ main(void) SerdNode* bad_lit = serd_node_new_string(SERD_LITERAL, bad_str); SerdNode* bad_uri = serd_node_new_string(SERD_URI, bad_str); if (serd_writer_write_statement(writer, 0, NULL, - s, p, bad_lit, NULL, NULL)) { + s, p, bad_lit)) { FAIL("Failed to write junk UTF-8 literal\n"); } else if (serd_writer_write_statement(writer, 0, NULL, - s, p, bad_uri, NULL, NULL)) { + s, p, bad_uri)) { FAIL("Failed to write junk UTF-8 URI\n"); } serd_node_free(bad_uri); @@ -579,7 +610,7 @@ main(void) serd_node_free(o); o = serd_node_new_string(SERD_LITERAL, "hello"); if (serd_writer_write_statement(writer, 0, NULL, - s, p, o, NULL, NULL)) { + s, p, o)) { FAIL("Failed to write valid statement\n"); } |