aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/headers/test_headers.c3
-rw-r--r--test/test_env.c80
-rw-r--r--test/test_node.c93
-rw-r--r--test/test_reader_writer.c107
-rw-r--r--test/test_uri.c53
-rw-r--r--test/test_writer.c48
6 files changed, 195 insertions, 189 deletions
diff --git a/test/headers/test_headers.c b/test/headers/test_headers.c
index c855c103..62be0976 100644
--- a/test/headers/test_headers.c
+++ b/test/headers/test_headers.c
@@ -3,8 +3,7 @@
#include "serd/serd.h" // IWYU pragma: keep
-SERD_CONST_FUNC
-int
+SERD_CONST_FUNC int
main(void)
{
return 0;
diff --git a/test/test_env.c b/test/test_env.c
index 8ef95f1a..198c7e9b 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -24,64 +24,68 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri)
static void
test_env(void)
{
- SerdNode u = serd_node_from_string(SERD_URI, "http://example.org/foo");
- SerdNode b = serd_node_from_string(SERD_CURIE, "invalid");
- SerdNode c = serd_node_from_string(SERD_CURIE, "eg.2:b");
- SerdEnv* env = serd_env_new(NULL);
+ SerdNode* u = serd_new_string(SERD_URI, "http://example.org/foo");
+ SerdNode* b = serd_new_string(SERD_CURIE, "invalid");
+ SerdNode* c = serd_new_string(SERD_CURIE, "eg.2:b");
+ SerdNode* s = serd_new_string(SERD_LITERAL, "hello");
+ SerdEnv* env = serd_env_new(NULL);
serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
- assert(!serd_env_set_base_uri(env, NULL));
- assert(serd_env_set_base_uri(env, &SERD_NODE_NULL));
- assert(serd_node_equals(serd_env_base_uri(env, NULL), &SERD_NODE_NULL));
+ assert(!serd_env_new(s));
- SerdStringView prefix;
- SerdStringView suffix;
- assert(!serd_env_qualify(NULL, &u, &u, &suffix));
- assert(serd_env_expand(NULL, &c, &prefix, &suffix));
- assert(serd_env_expand(env, &b, &prefix, &suffix));
+ const SerdNode* prefix_node = NULL;
+ SerdStringView prefix = serd_empty_string();
+ SerdStringView suffix = serd_empty_string();
- SerdNode nxnode = serd_env_expand_node(NULL, &c);
- assert(serd_node_equals(&nxnode, &SERD_NODE_NULL));
+ assert(!serd_env_qualify(NULL, u, &prefix_node, &suffix));
- SerdNode xnode = serd_env_expand_node(env, &SERD_NODE_NULL);
- assert(serd_node_equals(&xnode, &SERD_NODE_NULL));
+ assert(serd_env_expand(env, NULL, &prefix, &suffix) == SERD_BAD_CURIE);
- SerdNode xu = serd_env_expand_node(env, &u);
- assert(!strcmp(xu.buf, "http://example.org/foo"));
- serd_node_free(&xu);
+ assert(!serd_env_expand_node(NULL, u));
+ assert(!serd_env_expand_node(env, b));
+ assert(!serd_env_expand_node(env, s));
- SerdNode badpre = serd_node_from_string(SERD_CURIE, "hm:what");
- SerdNode xbadpre = serd_env_expand_node(env, &badpre);
- assert(serd_node_equals(&xbadpre, &SERD_NODE_NULL));
+ assert(!serd_env_set_base_uri(env, NULL));
- SerdNode xc = serd_env_expand_node(env, &c);
- assert(!strcmp(xc.buf, "http://example.org/b"));
- serd_node_free(&xc);
+ SerdNode* xu = serd_env_expand_node(env, u);
+ assert(!strcmp(serd_node_string(xu), "http://example.org/foo"));
+ serd_node_free(xu);
- assert(serd_env_set_prefix(env, &SERD_NODE_NULL, &SERD_NODE_NULL));
+ SerdNode* badpre = serd_new_string(SERD_CURIE, "hm:what");
+ SerdNode* xbadpre = serd_env_expand_node(env, badpre);
+ assert(!xbadpre);
- const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello");
- assert(serd_env_set_prefix(env, &b, &lit));
+ SerdNode* xc = serd_env_expand_node(env, c);
+ assert(!strcmp(serd_node_string(xc), "http://example.org/b"));
+ serd_node_free(xc);
- assert(!serd_env_new(&lit));
+ SerdNode* lit = serd_new_string(SERD_LITERAL, "hello");
+ assert(serd_env_set_prefix(env, b, lit));
- const SerdNode blank = serd_node_from_string(SERD_BLANK, "b1");
- const SerdNode xblank = serd_env_expand_node(env, &blank);
- assert(serd_node_equals(&xblank, &SERD_NODE_NULL));
+ SerdNode* blank = serd_new_string(SERD_BLANK, "b1");
+ assert(!serd_env_expand_node(env, blank));
+ serd_node_free(blank);
int n_prefixes = 0;
serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
serd_env_foreach(env, count_prefixes, &n_prefixes);
assert(n_prefixes == 1);
- SerdNode shorter_uri = serd_node_from_string(SERD_URI, "urn:foo");
- SerdNode prefix_name;
- assert(!serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix));
+ SerdNode* shorter_uri = serd_new_string(SERD_URI, "urn:foo");
+ assert(!serd_env_qualify(env, shorter_uri, &prefix_node, &suffix));
- assert(!serd_env_set_base_uri(env, &u));
- assert(serd_node_equals(serd_env_base_uri(env, NULL), &u));
+ assert(!serd_env_set_base_uri(env, u));
+ assert(serd_node_equals(serd_env_base_uri(env, NULL), u));
assert(!serd_env_set_base_uri(env, NULL));
- assert(!serd_env_base_uri(env, NULL)->buf);
+ assert(!serd_env_base_uri(env, NULL));
+
+ serd_node_free(shorter_uri);
+ serd_node_free(lit);
+ serd_node_free(badpre);
+ serd_node_free(s);
+ serd_node_free(c);
+ serd_node_free(b);
+ serd_node_free(u);
serd_env_free(env);
}
diff --git a/test/test_node.c b/test/test_node.c
index 21ef6feb..937d8a5f 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -6,6 +6,7 @@
#include "serd/memory.h"
#include "serd/node.h"
#include "serd/string.h"
+#include "serd/uri.h"
#include <assert.h>
#include <float.h>
@@ -80,14 +81,14 @@ test_double_to_node(void)
NULL};
for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) {
- SerdNode node = serd_new_decimal(dbl_test_nums[i], 8);
- const bool pass = (node.buf && dbl_test_strs[i])
- ? !strcmp(node.buf, dbl_test_strs[i])
- : (node.buf == dbl_test_strs[i]);
+ SerdNode* node = serd_new_decimal(dbl_test_nums[i], 8);
+ const char* node_str = node ? serd_node_string(node) : NULL;
+ const bool pass = (node_str && dbl_test_strs[i])
+ ? !strcmp(node_str, dbl_test_strs[i])
+ : (node_str == dbl_test_strs[i]);
assert(pass);
- const size_t len = node.buf ? strlen(node.buf) : 0;
- assert(node.n_bytes == len);
- serd_node_free(&node);
+ assert(!node || serd_node_length(node) == strlen(node_str));
+ serd_node_free(node);
}
}
@@ -102,10 +103,11 @@ test_integer_to_node(void)
"0", "0", "-23", "23", "-12340", "1000", "-1000"};
for (size_t i = 0; i < N_TEST_NUMS; ++i) {
- SerdNode node = serd_new_integer(int_test_nums[i]);
- assert(!strcmp(node.buf, int_test_strs[i]));
- assert(node.n_bytes == strlen(node.buf));
- serd_node_free(&node);
+ SerdNode* node = serd_new_integer(int_test_nums[i]);
+ const char* node_str = serd_node_string(node);
+ assert(!strcmp(node_str, int_test_strs[i]));
+ assert(serd_node_length(node) == strlen(node_str));
+ serd_node_free(node);
}
#undef N_TEST_NUMS
@@ -114,26 +116,28 @@ test_integer_to_node(void)
static void
test_blob_to_node(void)
{
+ assert(!serd_new_blob(&SERD_URI_NULL, 0, false));
+
for (size_t size = 1; size < 256; ++size) {
uint8_t* const data = (uint8_t*)malloc(size);
for (size_t i = 0; i < size; ++i) {
data[i] = (uint8_t)((size + i) % 256);
}
- SerdNode blob = serd_new_blob(data, size, size % 5);
-
- assert(blob.n_bytes == strlen(blob.buf));
+ size_t out_size = 0;
+ SerdNode* blob = serd_new_blob(data, size, size % 5);
+ const char* blob_str = serd_node_string(blob);
+ uint8_t* out =
+ (uint8_t*)serd_base64_decode(blob_str, serd_node_length(blob), &out_size);
- size_t out_size = 0;
- uint8_t* out =
- (uint8_t*)serd_base64_decode(blob.buf, blob.n_bytes, &out_size);
+ assert(serd_node_length(blob) == strlen(blob_str));
assert(out_size == size);
for (size_t i = 0; i < size; ++i) {
assert(out[i] == data[i]);
}
- serd_node_free(&blob);
+ serd_node_free(blob);
serd_free(out);
free(data);
}
@@ -143,46 +147,45 @@ static void
test_node_equals(void)
{
const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode lhs =
- serd_node_from_string(SERD_LITERAL, (const char*)replacement_char_str);
- SerdNode rhs = serd_node_from_string(SERD_LITERAL, "123");
- assert(!serd_node_equals(&lhs, &rhs));
+ SerdNode* lhs =
+ serd_new_string(SERD_LITERAL, (const char*)replacement_char_str);
+ SerdNode* rhs = serd_new_string(SERD_LITERAL, "123");
+ assert(!serd_node_equals(lhs, rhs));
+
+ SerdNode* qnode = serd_new_string(SERD_CURIE, "foo:bar");
+ assert(!serd_node_equals(lhs, qnode));
+ assert(serd_node_equals(lhs, lhs));
- SerdNode qnode = serd_node_from_string(SERD_CURIE, "foo:bar");
- assert(!serd_node_equals(&lhs, &qnode));
- assert(serd_node_equals(&lhs, &lhs));
+ assert(!serd_node_copy(NULL));
- SerdNode null_copy = serd_node_copy(&SERD_NODE_NULL);
- assert(serd_node_equals(&SERD_NODE_NULL, &null_copy));
+ serd_node_free(qnode);
+ serd_node_free(lhs);
+ serd_node_free(rhs);
}
static void
test_node_from_string(void)
{
- SerdNode node = serd_node_from_string(SERD_LITERAL, "hello\"");
- assert(node.n_bytes == 6 && node.flags == SERD_HAS_QUOTE &&
- !strcmp(node.buf, "hello\""));
+ SerdNode* hello = serd_new_string(SERD_LITERAL, "hello\"");
+ assert(serd_node_length(hello) == 6 &&
+ serd_node_flags(hello) == SERD_HAS_QUOTE &&
+ !strcmp(serd_node_string(hello), "hello\""));
- assert(node.n_bytes == 6 && node.flags == SERD_HAS_QUOTE &&
- !strcmp((const char*)node.buf, "hello\""));
-
- node = serd_node_from_string(SERD_URI, NULL);
- assert(serd_node_equals(&node, &SERD_NODE_NULL));
+ serd_node_free(hello);
}
static void
test_node_from_substring(void)
{
- SerdNode empty = serd_node_from_substring(SERD_LITERAL, NULL, 32);
- assert(!empty.buf && !empty.n_bytes && !empty.flags && !empty.type);
-
- SerdNode a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 3);
- assert(a_b.n_bytes == 3 && a_b.flags == SERD_HAS_QUOTE &&
- !strncmp(a_b.buf, "a\"b", 3));
-
- a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 10);
- assert(a_b.n_bytes == 4 && a_b.flags == SERD_HAS_QUOTE &&
- !strncmp(a_b.buf, "a\"bc", 4));
+ SerdNode* a_b = serd_new_substring(SERD_LITERAL, "a\"bc", 3);
+ assert(serd_node_length(a_b) == 3 && serd_node_flags(a_b) == SERD_HAS_QUOTE &&
+ !strncmp(serd_node_string(a_b), "a\"b", 3));
+
+ serd_node_free(a_b);
+ a_b = serd_new_substring(SERD_LITERAL, "a\"bc", 10);
+ assert(serd_node_length(a_b) == 4 && serd_node_flags(a_b) == SERD_HAS_QUOTE &&
+ !strncmp(serd_node_string(a_b), "a\"bc", 4));
+ serd_node_free(a_b);
}
int
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index f6dfe512..5aa2b850 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -458,25 +458,21 @@ test_writer(const char* const path)
serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
- const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello");
+ SerdNode* lit = serd_new_string(SERD_LITERAL, "hello");
- assert(serd_writer_set_base_uri(writer, &lit));
- assert(serd_writer_set_prefix(writer, &lit, &lit));
+ assert(serd_writer_set_base_uri(writer, lit));
+ assert(serd_writer_set_prefix(writer, lit, lit));
assert(serd_writer_end_anon(writer, NULL));
assert(serd_writer_env(writer) == env);
- uint8_t buf[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode s = serd_node_from_string(SERD_URI, "");
- SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/pred");
- SerdNode o = serd_node_from_string(SERD_LITERAL, (char*)buf);
+ uint8_t buf[] = {0xEF, 0xBF, 0xBD, 0};
+ SerdNode* s = serd_new_string(SERD_URI, "");
+ SerdNode* p = serd_new_string(SERD_URI, "http://example.org/pred");
+ SerdNode* o = serd_new_string(SERD_LITERAL, (char*)buf);
// Write 3 invalid statements (should write nothing)
- const SerdNode* junk[][5] = {{&s, &p, &SERD_NODE_NULL, NULL, NULL},
- {&s, &SERD_NODE_NULL, &o, NULL, NULL},
- {&SERD_NODE_NULL, &p, &o, NULL, NULL},
- {&s, &o, &o, NULL, NULL},
- {&o, &p, &o, NULL, NULL},
- {&s, &p, &SERD_NODE_NULL, NULL, NULL}};
+ 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,
@@ -488,18 +484,18 @@ test_writer(const char* const path)
junk[i][4]));
}
- const SerdNode t = serd_node_from_string(SERD_URI, "urn:Type");
- const SerdNode l = serd_node_from_string(SERD_LITERAL, "en");
- const SerdNode* good[][5] = {{&s, &p, &o, NULL, NULL},
- {&s, &p, &o, &SERD_NODE_NULL, &SERD_NODE_NULL},
- {&s, &p, &o, &t, NULL},
- {&s, &p, &o, NULL, &l},
- {&s, &p, &o, &t, &l},
- {&s, &p, &o, &t, &SERD_NODE_NULL},
- {&s, &p, &o, &SERD_NODE_NULL, &l},
- {&s, &p, &o, NULL, &SERD_NODE_NULL},
- {&s, &p, &o, &SERD_NODE_NULL, NULL},
- {&s, &p, &o, &SERD_NODE_NULL, NULL}};
+ 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,
@@ -512,53 +508,44 @@ test_writer(const char* const path)
}
// Write statements with bad UTF-8 (should be replaced)
- const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
- SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, (const char*)bad_str);
- SerdNode bad_uri = serd_node_from_string(SERD_URI, (const char*)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));
+ 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));
+ serd_node_free(bad_lit);
+ serd_node_free(bad_uri);
// Write 1 valid statement
- o = serd_node_from_string(SERD_LITERAL, "hello");
- assert(!serd_writer_write_statement(writer, 0, NULL, &s, &p, &o, NULL, NULL));
+ serd_node_free(o);
+ o = serd_new_string(SERD_LITERAL, "hello");
+ assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o, NULL, NULL));
serd_writer_free(writer);
+ serd_node_free(lit);
+ serd_node_free(o);
+ serd_node_free(t);
+ serd_node_free(l);
// Test buffer sink
SerdBuffer buffer = {NULL, 0};
writer =
serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_buffer_sink, &buffer);
- o = serd_node_from_string(SERD_URI, "http://example.org/base");
- assert(!serd_writer_set_base_uri(writer, &o));
+ o = serd_new_string(SERD_URI, "http://example.org/base");
+ assert(!serd_writer_set_base_uri(writer, o));
+ serd_node_free(o);
serd_writer_free(writer);
char* out = serd_buffer_sink_finish(&buffer);
assert(!strcmp(out, "@base <http://example.org/base> .\n"));
serd_free(out);
- // Test writing empty node
- SerdNode nothing = serd_node_from_string(SERD_NOTHING, "");
-
- buffer.buf = NULL;
- buffer.len = 0;
- writer =
- serd_writer_new(SERD_TURTLE, 0U, env, NULL, serd_buffer_sink, &buffer);
-
- assert(!serd_writer_write_statement(
- writer, 0, NULL, &s, &p, &nothing, NULL, NULL));
-
- assert(
- !strncmp((const char*)buffer.buf, "<>\n\t<http://example.org/pred> ", 30));
-
- serd_writer_free(writer);
- out = serd_buffer_sink_finish(&buffer);
-
- assert(!strcmp((const char*)out, "<>\n\t<http://example.org/pred> .\n"));
- serd_free(out);
+ serd_node_free(p);
+ serd_node_free(s);
serd_env_free(env);
fclose(fd);
@@ -581,8 +568,8 @@ test_reader(const char* path)
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
- SerdNode g = serd_node_from_string(SERD_URI, "http://example.org/");
- serd_reader_set_default_graph(reader, &g);
+ SerdNode* g = serd_new_string(SERD_URI, "http://example.org/");
+ serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");
#if defined(__GNUC__)
@@ -594,6 +581,8 @@ test_reader(const char* path)
# pragma GCC diagnostic pop
#endif
+ serd_node_free(g);
+
assert(serd_reader_read_file(reader, "http://notafile"));
assert(serd_reader_read_file(reader, "file:///better/not/exist"));
assert(serd_reader_read_file(reader, "file://"));
@@ -604,8 +593,8 @@ test_reader(const char* path)
assert(rt->n_prefix == 0);
assert(rt->n_statement == 13);
assert(rt->n_end == 0);
- assert(rt->graph && rt->graph->buf &&
- !strcmp(rt->graph->buf, "http://example.org/"));
+ assert(rt->graph && serd_node_string(rt->graph) &&
+ !strcmp(serd_node_string(rt->graph), "http://example.org/"));
assert(serd_reader_read_string(reader, "This isn't Turtle at all."));
diff --git a/test/test_uri.c b/test/test_uri.c
index d3ba5514..0942439f 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -44,17 +44,18 @@ test_file_uri(const char* const hostname,
expected_path = path;
}
- SerdNode node = serd_new_file_uri(path, hostname, 0);
- char* out_hostname = NULL;
- char* out_path = serd_file_uri_parse(node.buf, &out_hostname);
- assert(!strcmp(node.buf, expected_uri));
+ SerdNode* node = serd_new_file_uri(path, hostname, 0);
+ const char* node_str = serd_node_string(node);
+ char* out_hostname = NULL;
+ char* out_path = serd_file_uri_parse(node_str, &out_hostname);
+ assert(!strcmp(node_str, expected_uri));
assert((hostname && out_hostname) || (!hostname && !out_hostname));
assert(!hostname || !strcmp(hostname, out_hostname));
assert(!strcmp(out_path, expected_path));
serd_free(out_path);
serd_free(out_hostname);
- serd_node_free(&node);
+ serd_node_free(node);
}
static void
@@ -114,22 +115,20 @@ test_uri_parsing(void)
static void
test_uri_from_string(void)
{
- SerdNode nonsense = serd_new_uri_from_string(NULL, NULL, NULL);
- assert(nonsense.type == SERD_NOTHING);
+ assert(!serd_new_uri_from_string(NULL, NULL, NULL));
SerdURIView base_uri;
- SerdNode base =
+ SerdNode* base =
serd_new_uri_from_string("http://example.org/", NULL, &base_uri);
- SerdNode nil = serd_new_uri_from_string(NULL, &base_uri, NULL);
- SerdNode nil2 = serd_new_uri_from_string("", &base_uri, NULL);
- assert(nil.type == SERD_URI);
- assert(!strcmp(nil.buf, base.buf));
- assert(nil2.type == SERD_URI);
- assert(!strcmp(nil2.buf, base.buf));
- serd_node_free(&nil);
- serd_node_free(&nil2);
-
- serd_node_free(&base);
+ SerdNode* nil = serd_new_uri_from_string(NULL, &base_uri, NULL);
+ SerdNode* nil2 = serd_new_uri_from_string("", &base_uri, NULL);
+ assert(serd_node_type(nil) == SERD_URI);
+ assert(!strcmp(serd_node_string(nil), serd_node_string(base)));
+ assert(serd_node_type(nil2) == SERD_URI);
+ assert(!strcmp(serd_node_string(nil2), serd_node_string(base)));
+ serd_node_free(nil);
+ serd_node_free(nil2);
+ serd_node_free(base);
}
static inline bool
@@ -154,21 +153,21 @@ check_relative_uri(const char* const uri_string,
SerdURIView base = SERD_URI_NULL;
SerdURIView result = SERD_URI_NULL;
- SerdNode uri_node = serd_new_uri_from_string(uri_string, NULL, &uri);
- SerdNode base_node = serd_new_uri_from_string(base_string, NULL, &base);
+ SerdNode* uri_node = serd_new_uri_from_string(uri_string, NULL, &uri);
+ SerdNode* base_node = serd_new_uri_from_string(base_string, NULL, &base);
- SerdNode result_node = SERD_NODE_NULL;
+ SerdNode* result_node = NULL;
if (root_string) {
SerdURIView root = SERD_URI_NULL;
- SerdNode root_node = serd_new_uri_from_string(root_string, NULL, &root);
+ SerdNode* root_node = serd_new_uri_from_string(root_string, NULL, &root);
result_node = serd_new_relative_uri(&uri, &base, &root, &result);
- serd_node_free(&root_node);
+ serd_node_free(root_node);
} else {
result_node = serd_new_relative_uri(&uri, &base, NULL, &result);
}
- assert(!strcmp((const char*)result_node.buf, expected_string));
+ assert(!strcmp(serd_node_string(result_node), expected_string));
SerdURIView expected = SERD_URI_NULL;
assert(!serd_uri_parse(expected_string, &expected));
@@ -179,9 +178,9 @@ check_relative_uri(const char* const uri_string,
assert(chunk_equals(&result.query, &expected.query));
assert(chunk_equals(&result.fragment, &expected.fragment));
- serd_node_free(&result_node);
- serd_node_free(&base_node);
- serd_node_free(&uri_node);
+ serd_node_free(result_node);
+ serd_node_free(base_node);
+ serd_node_free(uri_node);
}
static void
diff --git a/test/test_writer.c b/test/test_writer.c
index 6a7a35b5..9d004076 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -27,12 +27,15 @@ test_write_long_literal(void)
assert(writer);
- SerdNode s = serd_node_from_string(SERD_URI, "http://example.org/s");
- SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/p");
- SerdNode o = serd_node_from_string(SERD_LITERAL, "hello \"\"\"world\"\"\"!");
+ SerdNode* s = serd_new_string(SERD_URI, "http://example.org/s");
+ 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, NULL, NULL));
+ serd_node_free(o);
+ serd_node_free(p);
+ serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
@@ -63,12 +66,12 @@ test_writer_cleanup(void)
SerdWriter* writer =
serd_writer_new(SERD_TURTLE, 0U, env, NULL, null_sink, NULL);
- SerdNode s = serd_node_from_string(SERD_URI, "http://example.org/s");
- SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/p");
- SerdNode o = serd_node_from_string(SERD_BLANK, "http://example.org/o");
+ SerdNode* s = serd_new_string(SERD_URI, "http://example.org/s");
+ 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);
+ writer, SERD_ANON_O_BEGIN, NULL, s, p, o, NULL, NULL);
assert(!st);
@@ -77,11 +80,12 @@ test_writer_cleanup(void)
char buf[12] = {0};
snprintf(buf, sizeof(buf), "b%u", i);
- SerdNode next_o = serd_node_from_string(SERD_BLANK, buf);
+ 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, NULL, NULL);
+ serd_node_free(o);
o = next_o;
}
@@ -92,6 +96,9 @@ test_writer_cleanup(void)
assert(!(st = serd_writer_set_base_uri(writer, NULL)));
// Free (which could leak if the writer doesn't clean up the stack properly)
+ serd_node_free(o);
+ serd_node_free(p);
+ serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
}
@@ -111,18 +118,22 @@ test_strict_write(void)
const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
- SerdNode s = serd_node_from_string(SERD_URI, "http://example.org/s");
- SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/p");
+ SerdNode* s = serd_new_string(SERD_URI, "http://example.org/s");
+ SerdNode* p = serd_new_string(SERD_URI, "http://example.org/p");
- SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, (const char*)bad_str);
- SerdNode bad_uri = serd_node_from_string(SERD_URI, (const char*)bad_str);
+ 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);
+ writer, 0, NULL, s, p, bad_lit, NULL, NULL) == SERD_BAD_TEXT);
assert(serd_writer_write_statement(
- writer, 0, NULL, &s, &p, &bad_uri, NULL, NULL) == SERD_BAD_TEXT);
+ writer, 0, NULL, s, p, bad_uri, NULL, NULL) == SERD_BAD_TEXT);
+ serd_node_free(bad_uri);
+ serd_node_free(bad_lit);
+ serd_node_free(p);
+ serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
fclose(fd);
@@ -146,15 +157,16 @@ test_write_error(void)
SerdWriter* writer = NULL;
SerdStatus st = SERD_SUCCESS;
- SerdNode u = serd_node_from_string(SERD_URI, "http://example.com/u");
+ SerdNode* u = serd_new_string(SERD_URI, "http://example.com/u");
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, NULL, NULL);
assert(st == SERD_BAD_WRITE);
serd_writer_free(writer);
+ serd_node_free(u);
serd_env_free(env);
}