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>2023-12-02 16:27:02 -0500
commit672e90382da08efa8f593fdc9081e31d0e548fa0 (patch)
tree3f70c13dda1e60e7b058c750002ec320bfaa6a73 /test
parentfff826f406e0b9975fd8672041e50dd1a342339f (diff)
downloadserd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.gz
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.tar.bz2
serd-672e90382da08efa8f593fdc9081e31d0e548fa0.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.c46
-rw-r--r--test/test_reader_writer.c58
-rw-r--r--test/test_writer.c18
3 files changed, 69 insertions, 53 deletions
diff --git a/test/test_node.c b/test/test_node.c
index 11351e31..1d4d1107 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -196,6 +196,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)
{
@@ -206,6 +251,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_reader_writer.c b/test/test_reader_writer.c
index 5aa2b850..245f5328 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -91,16 +91,12 @@ test_statement_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_statement;
@@ -471,57 +467,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);
@@ -591,7 +563,7 @@ test_reader(const char* path)
assert(!st);
assert(rt->n_base == 0);
assert(rt->n_prefix == 0);
- assert(rt->n_statement == 13);
+ assert(rt->n_statement == 6);
assert(rt->n_end == 0);
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 9d004076..68d9e14e 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -31,7 +31,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);
@@ -70,9 +70,7 @@ test_writer_cleanup(void)
SerdNode* p = serd_new_string(SERD_URI, "http://example.org/p");
SerdNode* o = serd_new_string(SERD_BLANK, "http://example.org/o");
- st = serd_writer_write_statement(
- writer, SERD_ANON_O_BEGIN, NULL, s, p, o, NULL, NULL);
-
+ st = serd_writer_write_statement(writer, SERD_ANON_O_BEGIN, NULL, s, p, o);
assert(!st);
// Write the start of several nested anonymous objects
@@ -83,7 +81,7 @@ test_writer_cleanup(void)
SerdNode* next_o = serd_new_string(SERD_BLANK, buf);
st = serd_writer_write_statement(
- writer, SERD_ANON_O_BEGIN, NULL, o, p, next_o, NULL, NULL);
+ writer, SERD_ANON_O_BEGIN, NULL, o, p, next_o);
serd_node_free(o);
o = next_o;
@@ -124,11 +122,11 @@ test_strict_write(void)
SerdNode* bad_lit = serd_new_string(SERD_LITERAL, (const char*)bad_str);
SerdNode* bad_uri = serd_new_string(SERD_URI, (const char*)bad_str);
- assert(serd_writer_write_statement(
- writer, 0, NULL, s, p, bad_lit, NULL, NULL) == SERD_BAD_TEXT);
+ assert(serd_writer_write_statement(writer, 0, NULL, s, p, bad_lit) ==
+ SERD_BAD_TEXT);
- assert(serd_writer_write_statement(
- writer, 0, NULL, s, p, bad_uri, NULL, NULL) == SERD_BAD_TEXT);
+ assert(serd_writer_write_statement(writer, 0, NULL, s, p, bad_uri) ==
+ SERD_BAD_TEXT);
serd_node_free(bad_uri);
serd_node_free(bad_lit);
@@ -162,7 +160,7 @@ test_write_error(void)
writer = serd_writer_new(
SERD_TURTLE, (SerdWriterFlags)0, env, NULL, error_sink, NULL);
assert(writer);
- st = serd_writer_write_statement(writer, 0U, NULL, u, u, u, NULL, NULL);
+ st = serd_writer_write_statement(writer, 0U, NULL, u, u, u);
assert(st == SERD_BAD_WRITE);
serd_writer_free(writer);