aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-01 20:33:33 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:21:57 +0200
commit9252a3f52012e6199b7a27b5c329c226614cc127 (patch)
tree4add6a2d526e04a6e3771b272ac56b4ef6499127 /tests
parent6042bd82cad4fbe4493218a8f67e7e6904ed81d5 (diff)
downloadserd-9252a3f52012e6199b7a27b5c329c226614cc127.tar.gz
serd-9252a3f52012e6199b7a27b5c329c226614cc127.tar.bz2
serd-9252a3f52012e6199b7a27b5c329c226614cc127.zip
Merge datatype and/or language into node
This moves closer to the sord API, and is more convenient in most cases.
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c93
1 files changed, 62 insertions, 31 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index b8f9051e..b96de49f 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;
@@ -335,6 +333,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)) {
@@ -489,40 +521,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);
}
}
@@ -532,10 +563,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);
@@ -545,7 +576,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");
}