aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/test_caret.c12
-rw-r--r--test/test_env.c35
-rw-r--r--test/test_reader_writer.c43
-rw-r--r--test/test_sink.c21
-rw-r--r--test/test_statement.c36
-rw-r--r--test/test_writer.c41
6 files changed, 89 insertions, 99 deletions
diff --git a/test/test_caret.c b/test/test_caret.c
index 3683a458..54037a30 100644
--- a/test/test_caret.c
+++ b/test/test_caret.c
@@ -24,8 +24,9 @@
int
main(void)
{
- SerdNode* const node = serd_new_string(SERD_STRING("node"));
- SerdCaret* const caret = serd_caret_new(node, 46, 2);
+ SerdNodes* const nodes = serd_nodes_new();
+ const SerdNode* const node = serd_nodes_string(nodes, SERD_STRING("node"));
+ SerdCaret* const caret = serd_caret_new(node, 46, 2);
assert(serd_caret_equals(caret, caret));
assert(serd_caret_name(caret) == node);
@@ -37,7 +38,9 @@ main(void)
assert(serd_caret_equals(caret, copy));
assert(!serd_caret_copy(NULL));
- SerdNode* const other_node = serd_new_string(SERD_STRING("other"));
+ const SerdNode* const other_node =
+ serd_nodes_string(nodes, SERD_STRING("other"));
+
SerdCaret* const other_file = serd_caret_new(other_node, 46, 2);
SerdCaret* const other_line = serd_caret_new(node, 47, 2);
SerdCaret* const other_col = serd_caret_new(node, 46, 3);
@@ -51,10 +54,9 @@ main(void)
serd_caret_free(other_col);
serd_caret_free(other_line);
serd_caret_free(other_file);
- serd_node_free(other_node);
serd_caret_free(copy);
serd_caret_free(caret);
- serd_node_free(node);
+ serd_nodes_free(nodes);
return 0;
}
diff --git a/test/test_env.c b/test/test_env.c
index 3753ab35..1748b4cf 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -34,12 +34,17 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri)
static void
test_env(void)
{
- SerdNode* u = serd_new_uri(SERD_STRING("http://example.org/foo"));
- SerdNode* b = serd_new_curie(SERD_STRING("invalid"));
- SerdNode* e = serd_new_uri(SERD_EMPTY_STRING());
- SerdNode* c = serd_new_curie(SERD_STRING("eg.2:b"));
- SerdNode* s = serd_new_string(SERD_STRING("hello"));
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdNodes* nodes = serd_nodes_new();
+
+ const SerdNode* u =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/foo"));
+
+ const SerdNode* b = serd_nodes_curie(nodes, SERD_STRING("invalid"));
+ const SerdNode* e = serd_nodes_uri(nodes, SERD_EMPTY_STRING());
+ const SerdNode* c = serd_nodes_curie(nodes, SERD_STRING("eg.2:b"));
+ const SerdNode* s = serd_nodes_string(nodes, SERD_STRING("hello"));
+
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
const SerdNode* prefix_node = NULL;
SerdStringView prefix = SERD_EMPTY_STRING();
@@ -71,17 +76,16 @@ test_env(void)
assert(!strcmp(serd_node_string(xu), "http://example.org/foo"));
serd_node_free(xu);
- SerdNode* badpre = serd_new_curie(SERD_STRING("hm:what"));
- SerdNode* xbadpre = serd_env_expand_node(env, badpre);
+ const SerdNode* badpre = serd_nodes_curie(nodes, SERD_STRING("hm:what"));
+ SerdNode* xbadpre = serd_env_expand_node(env, badpre);
assert(!xbadpre);
SerdNode* xc = serd_env_expand_node(env, c);
assert(!strcmp(serd_node_string(xc), "http://example.org/b"));
serd_node_free(xc);
- SerdNode* blank = serd_new_blank(SERD_STRING("b1"));
+ const SerdNode* blank = serd_nodes_blank(nodes, SERD_STRING("b1"));
assert(!serd_env_expand_node(env, blank));
- serd_node_free(blank);
int n_prefixes = 0;
serd_env_set_prefix(
@@ -89,7 +93,7 @@ test_env(void)
serd_env_foreach(env, count_prefixes, &n_prefixes);
assert(n_prefixes == 1);
- SerdNode* shorter_uri = serd_new_uri(SERD_STRING("urn:foo"));
+ const SerdNode* shorter_uri = serd_nodes_uri(nodes, SERD_STRING("urn:foo"));
assert(!serd_env_qualify(env, shorter_uri, &prefix_node, &suffix));
assert(!serd_env_set_base_uri(env, serd_node_string_view(u)));
@@ -103,14 +107,7 @@ test_env(void)
assert(!serd_env_set_base_uri(env, SERD_EMPTY_STRING()));
assert(!serd_env_base_uri(env));
- serd_node_free(shorter_uri);
- serd_node_free(badpre);
- serd_node_free(s);
- serd_node_free(c);
- serd_node_free(e);
- serd_node_free(b);
- serd_node_free(u);
-
+ serd_nodes_free(nodes);
serd_env_free(env);
}
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index bbec9377..11939e2c 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -183,6 +183,7 @@ test_writer(const char* const path)
assert(fd);
SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
SerdWriter* writer =
serd_writer_new(world, SERD_TURTLE, 0, env, (SerdWriteFunc)fwrite, fd);
@@ -191,7 +192,7 @@ test_writer(const char* const path)
serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
- SerdNode* lit = serd_new_string(SERD_STRING("hello"));
+ const SerdNode* lit = serd_nodes_string(nodes, SERD_STRING("hello"));
const SerdSink* const iface = serd_writer_sink(writer);
assert(serd_sink_write_base(iface, lit));
@@ -201,9 +202,11 @@ test_writer(const char* const path)
static const uint8_t bad_buf[] = {0xEF, 0xBF, 0xBD, 0};
const SerdStringView bad_buf_view = {(const char*)bad_buf, 3};
- SerdNode* s = serd_new_uri(SERD_STRING("http://example.org"));
- SerdNode* p = serd_new_uri(SERD_STRING("http://example.org/pred"));
- SerdNode* bad = serd_new_string(bad_buf_view);
+ const SerdNode* s = serd_nodes_uri(nodes, SERD_STRING("http://example.org"));
+ const SerdNode* p =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/pred"));
+
+ const SerdNode* bad = serd_nodes_string(nodes, bad_buf_view);
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][3] = {{s, bad, bad}, {bad, p, bad}, {s, bad, p}};
@@ -211,14 +214,15 @@ test_writer(const char* const path)
assert(serd_sink_write(iface, 0, junk[i][0], junk[i][1], junk[i][2], NULL));
}
- serd_node_free(bad);
-
static const SerdStringView urn_Type = SERD_STRING("urn:Type");
static const SerdStringView en = SERD_STRING("en");
- SerdNode* const o = serd_new_string(SERD_STRING("o"));
- SerdNode* const t = serd_new_typed_literal(SERD_STRING("t"), urn_Type);
- SerdNode* const l = serd_new_plain_literal(SERD_STRING("l"), en);
+ const SerdNode* const o = serd_nodes_string(nodes, SERD_STRING("o"));
+ const SerdNode* const t =
+ serd_nodes_typed_literal(nodes, SERD_STRING("t"), urn_Type);
+
+ const SerdNode* const l =
+ serd_nodes_plain_literal(nodes, SERD_STRING("l"), en);
const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}};
@@ -233,44 +237,33 @@ test_writer(const char* const path)
static const char* const bad_uri_str = (const char*)bad_uri_buf;
// Write statements with bad UTF-8 (should be replaced)
- SerdNode* bad_lit = serd_new_string(SERD_STRING(bad_lit_str));
- SerdNode* bad_uri = serd_new_uri(SERD_STRING(bad_uri_str));
+ const SerdNode* bad_lit = serd_nodes_string(nodes, SERD_STRING(bad_lit_str));
+ const SerdNode* bad_uri = serd_nodes_uri(nodes, SERD_STRING(bad_uri_str));
assert(!serd_sink_write(iface, 0, s, p, bad_lit, 0));
assert(!serd_sink_write(iface, 0, s, p, bad_uri, 0));
- serd_node_free(bad_uri);
- serd_node_free(bad_lit);
// Write 1 valid statement
- SerdNode* const hello = serd_new_string(SERD_STRING("hello"));
+ const SerdNode* const hello = serd_nodes_string(nodes, SERD_STRING("hello"));
assert(!serd_sink_write(iface, 0, s, p, hello, 0));
- serd_node_free(hello);
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(world, SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
- SerdNode* const base = serd_new_uri(SERD_STRING("http://example.org/base"));
+ const SerdNode* const base =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/base"));
serd_writer_set_base_uri(writer, base);
- serd_node_free(base);
serd_writer_free(writer);
char* out = serd_buffer_sink_finish(&buffer);
assert(!strcmp(out, "@base <http://example.org/base> .\n"));
serd_free(out);
- serd_node_free(p);
- serd_node_free(s);
-
serd_env_free(env);
serd_world_free(world);
fclose(fd);
diff --git a/test/test_sink.c b/test/test_sink.c
index 9f029a10..8b69d1df 100644
--- a/test/test_sink.c
+++ b/test/test_sink.c
@@ -79,16 +79,20 @@ on_end(void* handle, const SerdNode* node)
static void
test_callbacks(void)
{
- SerdNode* const base = serd_new_uri(SERD_STRING(NS_EG));
- SerdNode* const name = serd_new_string(SERD_STRING("eg"));
- SerdNode* const uri = serd_new_uri(SERD_STRING(NS_EG "uri"));
- SerdNode* const blank = serd_new_blank(SERD_STRING("b1"));
- SerdEnv* env = serd_env_new(serd_node_string_view(base));
- State state = {0, 0, 0, 0, 0, SERD_SUCCESS};
+ SerdNodes* const nodes = serd_nodes_new();
+
+ const SerdNode* base = serd_nodes_uri(nodes, SERD_STRING(NS_EG));
+ const SerdNode* name = serd_nodes_string(nodes, SERD_STRING("eg"));
+ const SerdNode* uri = serd_nodes_uri(nodes, SERD_STRING(NS_EG "uri"));
+ const SerdNode* blank = serd_nodes_blank(nodes, SERD_STRING("b1"));
+
+ SerdEnv* env = serd_env_new(serd_node_string_view(base));
SerdStatement* const statement =
serd_statement_new(base, uri, blank, NULL, NULL);
+ State state = {0, 0, 0, 0, 0, SERD_SUCCESS};
+
// Call functions on a sink with no functions set
SerdSink* null_sink = serd_sink_new(&state, NULL);
@@ -124,10 +128,7 @@ test_callbacks(void)
serd_statement_free(statement);
serd_env_free(env);
- serd_node_free(blank);
- serd_node_free(uri);
- serd_node_free(name);
- serd_node_free(base);
+ serd_nodes_free(nodes);
}
static void
diff --git a/test/test_statement.c b/test/test_statement.c
index e4219b68..6f92513f 100644
--- a/test/test_statement.c
+++ b/test/test_statement.c
@@ -28,11 +28,13 @@ test_copy(void)
{
assert(!serd_statement_copy(NULL));
- SerdNode* const f = serd_new_string(SERD_STRING("file"));
- SerdNode* const s = serd_new_uri(SERD_STRING(NS_EG "s"));
- SerdNode* const p = serd_new_uri(SERD_STRING(NS_EG "p"));
- SerdNode* const o = serd_new_uri(SERD_STRING(NS_EG "o"));
- SerdNode* const g = serd_new_uri(SERD_STRING(NS_EG "g"));
+ SerdNodes* const nodes = serd_nodes_new();
+
+ const SerdNode* const f = serd_nodes_string(nodes, SERD_STRING("file"));
+ const SerdNode* const s = serd_nodes_uri(nodes, SERD_STRING(NS_EG "s"));
+ const SerdNode* const p = serd_nodes_uri(nodes, SERD_STRING(NS_EG "p"));
+ const SerdNode* const o = serd_nodes_uri(nodes, SERD_STRING(NS_EG "o"));
+ const SerdNode* const g = serd_nodes_uri(nodes, SERD_STRING(NS_EG "g"));
SerdCaret* const caret = serd_caret_new(f, 1, 1);
SerdStatement* const statement = serd_statement_new(s, p, o, g, caret);
@@ -44,11 +46,7 @@ test_copy(void)
serd_statement_free(copy);
serd_caret_free(caret);
serd_statement_free(statement);
- serd_node_free(g);
- serd_node_free(o);
- serd_node_free(p);
- serd_node_free(s);
- serd_node_free(f);
+ serd_nodes_free(nodes);
}
static void
@@ -60,11 +58,13 @@ test_free(void)
static void
test_fields(void)
{
- SerdNode* const f = serd_new_string(SERD_STRING("file"));
- SerdNode* const s = serd_new_uri(SERD_STRING(NS_EG "s"));
- SerdNode* const p = serd_new_uri(SERD_STRING(NS_EG "p"));
- SerdNode* const o = serd_new_uri(SERD_STRING(NS_EG "o"));
- SerdNode* const g = serd_new_uri(SERD_STRING(NS_EG "g"));
+ SerdNodes* const nodes = serd_nodes_new();
+
+ const SerdNode* const f = serd_nodes_string(nodes, SERD_STRING("file"));
+ const SerdNode* const s = serd_nodes_uri(nodes, SERD_STRING(NS_EG "s"));
+ const SerdNode* const p = serd_nodes_uri(nodes, SERD_STRING(NS_EG "p"));
+ const SerdNode* const o = serd_nodes_uri(nodes, SERD_STRING(NS_EG "o"));
+ const SerdNode* const g = serd_nodes_uri(nodes, SERD_STRING(NS_EG "g"));
SerdCaret* const caret = serd_caret_new(f, 1, 1);
SerdStatement* const statement = serd_statement_new(s, p, o, g, caret);
@@ -103,11 +103,7 @@ test_fields(void)
serd_statement_free(statement);
serd_caret_free(caret);
- serd_node_free(g);
- serd_node_free(o);
- serd_node_free(p);
- serd_node_free(s);
- serd_node_free(f);
+ serd_nodes_free(nodes);
}
int
diff --git a/test/test_writer.c b/test/test_writer.c
index e24a8218..6f336ca4 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -26,6 +26,7 @@ static void
test_write_bad_prefix(void)
{
SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
SerdBuffer buffer = {NULL, 0};
SerdWriter* writer =
@@ -33,8 +34,8 @@ test_write_bad_prefix(void)
assert(writer);
- SerdNode* name = serd_new_string(SERD_STRING("eg"));
- SerdNode* uri = serd_new_uri(SERD_STRING("rel"));
+ const SerdNode* name = serd_nodes_string(nodes, SERD_STRING("eg"));
+ const SerdNode* uri = serd_nodes_uri(nodes, SERD_STRING("rel"));
assert(serd_sink_write_prefix(serd_writer_sink(writer), name, uri) ==
SERD_ERR_BAD_ARG);
@@ -44,8 +45,6 @@ test_write_bad_prefix(void)
assert(!strcmp(out, ""));
serd_free(out);
- serd_node_free(uri);
- serd_node_free(name);
serd_writer_free(writer);
serd_env_free(env);
serd_world_free(world);
@@ -55,6 +54,7 @@ static void
test_write_long_literal(void)
{
SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
SerdBuffer buffer = {NULL, 0};
SerdWriter* writer =
@@ -62,15 +62,15 @@ test_write_long_literal(void)
assert(writer);
- SerdNode* s = serd_new_uri(SERD_STRING("http://example.org/s"));
- SerdNode* p = serd_new_uri(SERD_STRING("http://example.org/p"));
- SerdNode* o = serd_new_string(SERD_STRING("hello \"\"\"world\"\"\"!"));
+ const SerdNode* s =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/s"));
+ const SerdNode* p =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/p"));
+ const SerdNode* o =
+ serd_nodes_string(nodes, SERD_STRING("hello \"\"\"world\"\"\"!"));
assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL));
- serd_node_free(o);
- serd_node_free(p);
- serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
@@ -102,6 +102,7 @@ static void
test_writer_stack_overflow(void)
{
SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
SerdWriter* writer =
@@ -109,10 +110,15 @@ test_writer_stack_overflow(void)
const SerdSink* sink = serd_writer_sink(writer);
- SerdNode* const s = serd_new_uri(SERD_STRING("http://example.org/s"));
- SerdNode* const p = serd_new_uri(SERD_STRING("http://example.org/p"));
+ const SerdNode* const s =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/s"));
+
+ const SerdNode* const p =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/p"));
+
+ const SerdNode* o =
+ serd_nodes_blank(nodes, SERD_STRING("http://example.org/o"));
- SerdNode* o = serd_new_blank(SERD_STRING("http://example.org/o"));
SerdStatus st = serd_sink_write(sink, SERD_ANON_O_BEGIN, s, p, o, NULL);
assert(!st);
@@ -121,12 +127,10 @@ test_writer_stack_overflow(void)
char buf[1024];
snprintf(buf, sizeof(buf), "b%u", i);
- SerdNode* next_o = serd_new_blank(SERD_STRING(buf));
+ const SerdNode* next_o = serd_nodes_blank(nodes, SERD_STRING(buf));
st = serd_sink_write(sink, SERD_ANON_O_BEGIN, o, p, next_o, NULL);
-
- serd_node_free(o);
- o = next_o;
+ o = next_o;
if (st) {
assert(st == SERD_ERR_OVERFLOW);
@@ -136,9 +140,6 @@ test_writer_stack_overflow(void)
assert(st == SERD_ERR_OVERFLOW);
- serd_node_free(o);
- serd_node_free(p);
- serd_node_free(s);
serd_writer_free(writer);
serd_env_free(env);
serd_world_free(world);