aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-14 16:05:10 +0200
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commit6f03ae92415a7758fdc74f6720ec4955bc67fc0c (patch)
tree027582bca0844f8fe650db707eb14dc3b46c7598 /test
parent194d6f42583745c3fde6387b14abab2311b4f0b7 (diff)
downloadserd-6f03ae92415a7758fdc74f6720ec4955bc67fc0c.tar.gz
serd-6f03ae92415a7758fdc74f6720ec4955bc67fc0c.tar.bz2
serd-6f03ae92415a7758fdc74f6720ec4955bc67fc0c.zip
Merge datatype/language into node
This moves closer to the sord API, and is more convenient in most cases.
Diffstat (limited to 'test')
-rw-r--r--test/test_node.c32
-rw-r--r--test/test_read_chunk.c6
-rw-r--r--test/test_reader_writer.c58
3 files changed, 48 insertions, 48 deletions
diff --git a/test/test_node.c b/test/test_node.c
index be3576ff..00a24b99 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -194,6 +194,37 @@ test_node_from_substring(void)
serd_node_free(a_b);
}
+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\""));
+ 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"));
+ 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"));
+ serd_node_free(hello_dt);
+}
+
int
main(void)
{
@@ -204,6 +235,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..dd2961ac 100644
--- a/test/test_read_chunk.c
+++ b/test/test_read_chunk.c
@@ -54,9 +54,7 @@ on_statement(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)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 a97a44c0..d79fbbdd 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;
@@ -187,57 +183,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);
@@ -297,7 +269,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/"));