aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_uri.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-01-12 20:41:41 -0500
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:29 -0500
commitd91b3c9ec59976c40742c852d25dccf67b445e61 (patch)
tree0984d9b9a0890b6f4d5aa3a6278ac99bff8b4b91 /test/test_uri.c
parentfd735236cca8af5364f98e5587b2984b3d798378 (diff)
downloadserd-d91b3c9ec59976c40742c852d25dccf67b445e61.tar.gz
serd-d91b3c9ec59976c40742c852d25dccf67b445e61.tar.bz2
serd-d91b3c9ec59976c40742c852d25dccf67b445e61.zip
Use SerdNodes instead of manual memory management in tests
Diffstat (limited to 'test/test_uri.c')
-rw-r--r--test/test_uri.c48
1 files changed, 27 insertions, 21 deletions
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