aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_env.c59
-rw-r--r--test/test_node.c23
-rw-r--r--test/test_node_syntax.c77
-rw-r--r--test/test_overflow.c5
-rw-r--r--test/test_reader.c12
-rw-r--r--test/test_uri.c48
6 files changed, 132 insertions, 92 deletions
diff --git a/test/test_env.c b/test/test_env.c
index e6d6cbe5..4577e0ce 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -220,9 +220,10 @@ count_prefixes(void* handle, const SerdEvent* event)
static void
test_base_uri(void)
{
- SerdWorld* const world = serd_world_new(NULL);
- SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
- SerdNode* const eg = serd_new_uri(NULL, SERD_STRING(NS_EG));
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
+ const SerdNode* const eg = serd_nodes_uri(nodes, SERD_STRING(NS_EG));
// Test that invalid calls work as expected
assert(!serd_env_base_uri(env));
@@ -241,7 +242,6 @@ test_base_uri(void)
assert(!serd_env_set_base_uri(env, SERD_EMPTY_STRING()));
assert(!serd_env_base_uri(env));
- serd_node_free(NULL, eg);
serd_env_free(env);
serd_world_free(world);
}
@@ -285,14 +285,14 @@ test_set_prefix(void)
static void
test_expand_untyped_literal(void)
{
- SerdWorld* const world = serd_world_new(NULL);
- SerdNode* const untyped = serd_new_string(NULL, SERD_STRING("data"));
- SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ const SerdNode* const untyped = serd_nodes_string(nodes, SERD_STRING("data"));
+ SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
assert(!serd_env_expand_node(env, untyped));
serd_env_free(env);
- serd_node_free(NULL, untyped);
serd_world_free(world);
}
@@ -321,20 +321,19 @@ test_expand_uri(void)
{
static const SerdStringView base = SERD_STRING("http://example.org/b/");
- SerdWorld* const world = serd_world_new(NULL);
- SerdEnv* const env = serd_env_new(world, base);
- SerdNode* const rel = serd_new_uri(NULL, SERD_STRING("rel"));
- SerdNode* const rel_out = serd_env_expand_node(env, rel);
- SerdNode* const empty = serd_new_uri(NULL, SERD_EMPTY_STRING());
- SerdNode* const empty_out = serd_env_expand_node(env, empty);
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ SerdEnv* const env = serd_env_new(world, base);
+ const SerdNode* const rel = serd_nodes_uri(nodes, SERD_STRING("rel"));
+ SerdNode* const rel_out = serd_env_expand_node(env, rel);
+ const SerdNode* const empty = serd_nodes_uri(nodes, SERD_EMPTY_STRING());
+ SerdNode* const empty_out = serd_env_expand_node(env, empty);
assert(!strcmp(serd_node_string(rel_out), "http://example.org/b/rel"));
assert(!strcmp(serd_node_string(empty_out), "http://example.org/b/"));
serd_node_free(serd_world_allocator(world), empty_out);
- serd_node_free(NULL, empty);
serd_node_free(serd_world_allocator(world), rel_out);
- serd_node_free(NULL, rel);
serd_env_free(env);
serd_world_free(world);
}
@@ -344,30 +343,30 @@ test_expand_empty_uri_ref(void)
{
static const SerdStringView base = SERD_STRING("http://example.org/b/");
- SerdWorld* const world = serd_world_new(NULL);
- SerdNode* const rel = serd_new_uri(NULL, SERD_STRING("rel"));
- SerdEnv* const env = serd_env_new(world, base);
- SerdNode* const rel_out = serd_env_expand_node(env, rel);
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ const SerdNode* const rel = serd_nodes_uri(nodes, SERD_STRING("rel"));
+ SerdEnv* const env = serd_env_new(world, base);
+ SerdNode* const rel_out = serd_env_expand_node(env, rel);
assert(!strcmp(serd_node_string(rel_out), "http://example.org/b/rel"));
serd_node_free(serd_world_allocator(world), rel_out);
serd_env_free(env);
- serd_node_free(NULL, rel);
serd_world_free(world);
}
static void
test_expand_bad_uri(void)
{
- SerdWorld* const world = serd_world_new(NULL);
- SerdNode* const bad_uri = serd_new_uri(NULL, SERD_STRING("rel"));
- SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ const SerdNode* const bad_uri = serd_nodes_uri(nodes, SERD_STRING("rel"));
+ SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
assert(!serd_env_expand_node(env, bad_uri));
serd_env_free(env);
- serd_node_free(NULL, bad_uri);
serd_world_free(world);
}
@@ -411,14 +410,16 @@ test_expand_bad_curie(void)
static void
test_expand_blank(void)
{
- SerdWorld* const world = serd_world_new(NULL);
- SerdNode* const blank = serd_new_token(NULL, SERD_BLANK, SERD_STRING("b1"));
- SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
+ const SerdNode* const blank =
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("b1"));
+
+ SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
assert(!serd_env_expand_node(env, blank));
serd_env_free(env);
- serd_node_free(NULL, blank);
serd_world_free(world);
}
diff --git a/test/test_node.c b/test/test_node.c
index 5cba7013..416d975b 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -609,6 +609,28 @@ test_new(void)
}
static void
+test_uri(void)
+{
+ static const SerdStringView base = SERD_STRING("http://example.org/base/");
+ static const SerdStringView rel = SERD_STRING("a/b");
+ static const SerdStringView abs = SERD_STRING("http://example.org/base/a/b");
+
+ const SerdURIView base_uri = serd_parse_uri(base.buf);
+ const SerdURIView rel_uri = serd_parse_uri(rel.buf);
+ const SerdURIView abs_uri = serd_resolve_uri(rel_uri, base_uri);
+
+ SerdNode* const from_string = serd_new_uri(NULL, abs);
+ SerdNode* const from_uri = serd_new_parsed_uri(NULL, abs_uri);
+
+ assert(from_string);
+ assert(from_uri);
+ assert(!strcmp(serd_node_string(from_string), serd_node_string(from_uri)));
+
+ serd_node_free(NULL, from_uri);
+ serd_node_free(NULL, from_string);
+}
+
+static void
test_literal(void)
{
static const SerdStringView hello_str = SERD_STRING("hello");
@@ -773,6 +795,7 @@ main(void)
test_node_from_syntax();
test_node_from_substring();
test_new();
+ test_uri();
test_literal();
test_blank();
test_compare();
diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c
index a8e0a163..47b67c9f 100644
--- a/test/test_node_syntax.c
+++ b/test/test_node_syntax.c
@@ -29,7 +29,8 @@ test_failed_alloc(void)
{
SerdFailingAllocator allocator = serd_failing_allocator();
- SerdNode* const node = serd_new_string(&allocator.base, SERD_STRING("node"));
+ SerdNode* const node =
+ serd_new_token(&allocator.base, SERD_LITERAL, SERD_STRING("node"));
// Successfully convert a node to count the number of allocations
@@ -54,8 +55,8 @@ test_failed_alloc(void)
assert(!s || !c);
- serd_free(&allocator.base, s);
serd_node_free(&allocator.base, c);
+ serd_free(&allocator.base, s);
}
serd_node_free(&allocator.base, copy);
@@ -64,10 +65,10 @@ test_failed_alloc(void)
}
static bool
-check(SerdWorld* const world,
- const SerdSyntax syntax,
- SerdNode* const node,
- const char* const expected)
+check(SerdWorld* const world,
+ const SerdSyntax syntax,
+ const SerdNode* const node,
+ const char* const expected)
{
SerdEnv* const env =
serd_env_new(world, SERD_STRING("http://example.org/base/"));
@@ -79,7 +80,6 @@ check(SerdWorld* const world,
serd_node_free(serd_world_allocator(world), copy);
serd_free(serd_world_allocator(world), str);
- serd_node_free(NULL, node);
serd_env_free(env);
return success;
}
@@ -92,69 +92,74 @@ test_common(SerdWorld* const world, const SerdSyntax syntax)
static const SerdStringView datatype =
SERD_STRING("http://example.org/Datatype");
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+
assert(check(
- world, syntax, serd_new_string(NULL, SERD_STRING("node")), "\"node\""));
+ world, syntax, serd_nodes_string(nodes, SERD_STRING("node")), "\"node\""));
assert(
check(world,
syntax,
- serd_new_literal(
- NULL, SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
+ serd_nodes_literal(
+ nodes, SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
"\"hallo\"@de"));
- assert(
- check(world,
- syntax,
- serd_new_literal(NULL, SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
- "\"X\"^^<http://example.org/Datatype>"));
+ assert(check(
+ world,
+ syntax,
+ serd_nodes_literal(nodes, SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
+ "\"X\"^^<http://example.org/Datatype>"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("blank")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("blank")),
"_:blank"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("b0")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("b0")),
"_:b0"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("named1")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("named1")),
"_:named1"));
assert(check(world,
syntax,
- serd_new_uri(NULL, SERD_STRING("http://example.org/")),
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/")),
"<http://example.org/>"));
assert(check(world,
syntax,
- serd_new_value(NULL, serd_double(1.25)),
+ serd_nodes_value(nodes, serd_double(1.25)),
"\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#double>"));
assert(check(world,
syntax,
- serd_new_value(NULL, serd_float(1.25f)),
+ serd_nodes_value(nodes, serd_float(1.25f)),
"\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#float>"));
assert(
check(world,
syntax,
- serd_new_base64(NULL, data, sizeof(data)),
+ serd_nodes_base64(nodes, data, sizeof(data)),
"\"BAAAAAIAAAA=\"^^<http://www.w3.org/2001/XMLSchema#base64Binary>"));
+
+ serd_nodes_free(nodes);
}
static void
test_ntriples(void)
{
SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_nodes_new(NULL);
test_common(world, SERD_NTRIPLES);
{
// No relative URIs in NTriples, so converting one fails without an env
- SerdNode* const rel = serd_new_uri(NULL, SERD_STRING("rel/uri"));
+ const SerdNode* const rel = serd_nodes_uri(nodes, SERD_STRING("rel/uri"));
assert(!serd_node_to_syntax(NULL, rel, SERD_NTRIPLES, NULL));
assert(!serd_node_from_syntax(NULL, "<rel/uri>", SERD_NTRIPLES, NULL));
@@ -171,29 +176,29 @@ test_ntriples(void)
serd_node_free(serd_world_allocator(world), copy);
serd_env_free(env);
serd_free(serd_world_allocator(world), str);
- serd_node_free(NULL, rel);
}
assert(check(world,
SERD_NTRIPLES,
- serd_new_decimal(NULL, 1.25),
+ serd_nodes_decimal(nodes, 1.25),
"\"1.25\"^^<http://www.w3.org/2001/XMLSchema#decimal>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_integer(NULL, 1234),
+ serd_nodes_integer(nodes, 1234),
"\"1234\"^^<http://www.w3.org/2001/XMLSchema#integer>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_value(NULL, serd_bool(true)),
+ serd_nodes_value(nodes, serd_bool(true)),
"\"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_value(NULL, serd_bool(false)),
+ serd_nodes_value(nodes, serd_bool(false)),
"\"false\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
+ serd_nodes_free(nodes);
serd_world_free(world);
}
@@ -201,22 +206,24 @@ static void
test_turtle(void)
{
SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
test_common(world, SERD_TURTLE);
check(world,
SERD_TURTLE,
- serd_new_uri(NULL, SERD_STRING("rel/uri")),
+ serd_nodes_uri(nodes, SERD_STRING("rel/uri")),
"<rel/uri>");
- assert(check(world, SERD_TURTLE, serd_new_decimal(NULL, 1.25), "1.25"));
- assert(check(world, SERD_TURTLE, serd_new_integer(NULL, 1234), "1234"));
+ assert(check(world, SERD_TURTLE, serd_nodes_decimal(nodes, 1.25), "1.25"));
- assert(
- check(world, SERD_TURTLE, serd_new_value(NULL, serd_bool(true)), "true"));
+ assert(check(world, SERD_TURTLE, serd_nodes_integer(nodes, 1234), "1234"));
- assert(
- check(world, SERD_TURTLE, serd_new_value(NULL, serd_bool(false)), "false"));
+ assert(check(
+ world, SERD_TURTLE, serd_nodes_value(nodes, serd_bool(true)), "true"));
+
+ assert(check(
+ world, SERD_TURTLE, serd_nodes_value(nodes, serd_bool(false)), "false"));
serd_world_free(world);
}
diff --git a/test/test_overflow.c b/test/test_overflow.c
index 2461d713..c4e90354 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -31,6 +31,8 @@ test_size(SerdWorld* const world,
const SerdReaderFlags flags,
const size_t stack_size)
{
+ SerdNodes* const nodes = serd_world_nodes(world);
+
SerdSink* sink = serd_sink_new(world, NULL, NULL, NULL);
SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
SerdReader* const reader =
@@ -38,7 +40,7 @@ test_size(SerdWorld* const world,
assert(reader);
- SerdNode* string_name = serd_new_string(NULL, SERD_STRING("string"));
+ const SerdNode* string_name = serd_nodes_string(nodes, SERD_STRING("string"));
const char* position = str;
SerdInputStream in = serd_open_input_string(&position);
serd_reader_start(reader, &in, string_name, 1);
@@ -46,7 +48,6 @@ test_size(SerdWorld* const world,
const SerdStatus st = serd_reader_read_document(reader);
serd_close_input(&in);
- serd_node_free(NULL, string_name);
serd_reader_free(reader);
serd_env_free(env);
serd_sink_free(sink);
diff --git a/test/test_reader.c b/test/test_reader.c
index 095f736e..6b807d89 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -463,7 +463,8 @@ check_cursor(void* handle, const SerdEvent* event)
static void
test_error_cursor(void)
{
- SerdWorld* world = serd_world_new(NULL);
+ SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
bool called = false;
SerdSink* sink = serd_sink_new(world, &called, check_cursor, NULL);
SerdEnv* const env = serd_env_new(world, SERD_EMPTY_STRING());
@@ -477,9 +478,11 @@ test_error_cursor(void)
"<http://example.org/s> <http://example.org/p> "
"<http://example.org/o> .";
- SerdNode* const string_name = serd_new_string(NULL, SERD_STRING("string"));
- const char* position = string;
- SerdInputStream in = serd_open_input_string(&position);
+ const SerdNode* const string_name =
+ serd_nodes_string(nodes, SERD_STRING("string"));
+
+ const char* position = string;
+ SerdInputStream in = serd_open_input_string(&position);
SerdStatus st = serd_reader_start(reader, &in, string_name, 1);
assert(!st);
@@ -488,7 +491,6 @@ test_error_cursor(void)
assert(called);
assert(!serd_close_input(&in));
- serd_node_free(NULL, string_name);
serd_reader_free(reader);
serd_env_free(env);
serd_sink_free(sink);
diff --git a/test/test_uri.c b/test/test_uri.c
index 49d72630..2b0c9b16 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -133,18 +133,20 @@ test_uri_parsing(void)
static void
test_parse_uri(void)
{
- const SerdStringView base = SERD_STRING("http://example.org/a/b/c/");
+ static const SerdStringView base = SERD_STRING("http://example.org/a/b/c/");
const SerdURIView base_uri = serd_parse_uri(base.buf);
const SerdURIView empty_uri = serd_parse_uri("");
- SerdNode* const nil =
- serd_new_parsed_uri(NULL, serd_resolve_uri(empty_uri, base_uri));
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+
+ const SerdNode* const nil =
+ serd_nodes_parsed_uri(nodes, serd_resolve_uri(empty_uri, base_uri));
assert(serd_node_type(nil) == SERD_URI);
assert(!strcmp(serd_node_string(nil), base.buf));
- serd_node_free(NULL, nil);
+ serd_nodes_free(nodes);
}
static void
@@ -187,28 +189,33 @@ check_rel_uri(const char* uri_string,
const SerdNode* root,
const char* expected)
{
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+
const SerdURIView base_uri = serd_node_uri_view(base);
const SerdURIView uri = serd_parse_uri(uri_string);
const bool is_within =
!root || serd_uri_is_within(uri, serd_node_uri_view(root));
- SerdNode* const rel =
- is_within ? serd_new_parsed_uri(NULL, serd_relative_uri(uri, base_uri))
- : serd_new_uri(NULL, SERD_STRING(uri_string));
+ const SerdNode* const rel =
+ is_within ? serd_nodes_parsed_uri(nodes, serd_relative_uri(uri, base_uri))
+ : serd_nodes_uri(nodes, SERD_STRING(uri_string));
const int ret = strcmp(serd_node_string(rel), expected);
- serd_node_free(NULL, rel);
assert(!ret);
+
+ serd_nodes_free(nodes);
}
static void
test_relative_uri(void)
{
- SerdNode* const root =
- serd_new_uri(NULL, SERD_STRING("http://example.org/a/b/ignored"));
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+
+ const SerdNode* const root =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/a/b/ignored"));
- SerdNode* const base =
- serd_new_uri(NULL, SERD_STRING("http://example.org/a/b/c/"));
+ const SerdNode* const base =
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/a/b/c/"));
check_rel_uri("http://example.org/a/b/c/foo", base, NULL, "foo");
check_rel_uri("http://example.org/a/", base, NULL, "../../");
@@ -219,13 +226,12 @@ test_relative_uri(void)
{
// Check making a relative URI from a resolved URI
- const SerdURIView ref = serd_parse_uri("child");
- const SerdURIView abs = serd_resolve_uri(ref, serd_node_uri_view(base));
- const SerdURIView rel = serd_relative_uri(abs, serd_node_uri_view(root));
- SerdNode* const node = serd_new_parsed_uri(NULL, rel);
+ const SerdURIView ref = serd_parse_uri("child");
+ const SerdURIView abs = serd_resolve_uri(ref, serd_node_uri_view(base));
+ const SerdURIView rel = serd_relative_uri(abs, serd_node_uri_view(root));
+ const SerdNode* const node = serd_nodes_parsed_uri(nodes, rel);
assert(!strcmp(serd_node_string(node), "c/child"));
- serd_node_free(NULL, node);
}
{
// Check failure when path_prefix is not available for use
@@ -237,8 +243,7 @@ test_relative_uri(void)
assert(!memcmp(&upref, &SERD_URI_NULL, sizeof(ref)));
}
- serd_node_free(NULL, base);
- serd_node_free(NULL, root);
+ serd_nodes_free(nodes);
}
static void
@@ -254,10 +259,11 @@ test_uri_resolution(void)
const SerdURIView rel_foo_uri = serd_relative_uri(abs_foo_uri, base_uri);
const SerdURIView resolved_uri = serd_resolve_uri(rel_foo_uri, base_uri);
- SerdNode* const resolved = serd_new_parsed_uri(NULL, resolved_uri);
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+ const SerdNode* const resolved = serd_nodes_parsed_uri(nodes, resolved_uri);
assert(!strcmp(serd_node_string(resolved), "http://example.org/a/b/c/foo"));
- serd_node_free(NULL, resolved);
+ serd_nodes_free(nodes);
}
int