aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-12-02 17:11:23 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commitb13ad41a4d65b577b4db67660a9edf3056bdf7af (patch)
treee89535f6098a1b860f38ec8a7a1b698b30a72545 /test/test_node.c
parent0db18e483f11ac2f9518d96e137d217040ed1339 (diff)
downloadserd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.tar.gz
serd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.tar.bz2
serd-b13ad41a4d65b577b4db67660a9edf3056bdf7af.zip
Use SerdNodes instead of manual memory management in tests
Diffstat (limited to 'test/test_node.c')
-rw-r--r--test/test_node.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/test/test_node.c b/test/test_node.c
index c1b83140..7ed6e3c5 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -158,6 +158,7 @@ test_boolean(void)
{
SerdNode* const true_node =
serd_node_new(NULL, serd_a_primitive(serd_bool(true)));
+
assert(true_node);
assert(!strcmp(serd_node_string(true_node), "true"));
assert(serd_node_value(true_node).data.as_bool);
@@ -170,6 +171,7 @@ test_boolean(void)
{
SerdNode* const false_node =
serd_node_new(NULL, serd_a_primitive(serd_bool(false)));
+
assert(false_node);
assert(!strcmp(serd_node_string(false_node), "false"));
assert(!serd_node_value(false_node).data.as_bool);
@@ -264,8 +266,9 @@ test_double(void)
"0.0E0", "-0.0E0", "1.2E0", "-2.3E0", "4.56789E6"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(double); ++i) {
- SerdNode* node =
+ SerdNode* const node =
serd_node_new(NULL, serd_a_primitive(serd_double(test_values[i])));
+
const char* node_str = serd_node_string(node);
assert(!strcmp(node_str, test_strings[i]));
@@ -336,8 +339,9 @@ test_float(void)
"0.0E0", "-0.0E0", "1.5E0", "-2.5E0", "4.56789E6"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(float); ++i) {
- SerdNode* node =
+ SerdNode* const node =
serd_node_new(NULL, serd_a_primitive(serd_float(test_values[i])));
+
const char* node_str = serd_node_string(node);
assert(!strcmp(node_str, test_strings[i]));
@@ -635,6 +639,7 @@ static void
test_node_from_syntax(void)
{
SerdNode* const hello = serd_node_new(NULL, serd_a_string("hello\""));
+
assert(serd_node_length(hello) == 6);
assert(!serd_node_flags(hello));
assert(!strncmp(serd_node_string(hello), "hello\"", 6));
@@ -656,6 +661,7 @@ test_node_from_substring(void)
{
SerdNode* const a_b =
serd_node_new(NULL, serd_a_string_view(serd_substring("a\"bc", 3)));
+
assert(serd_node_length(a_b) == 3);
assert(!serd_node_flags(a_b));
assert(strlen(serd_node_string(a_b)) == 3);
@@ -674,16 +680,45 @@ check_copy_equals(const SerdNode* const node)
}
static void
+test_uri(void)
+{
+ const SerdStringView base = serd_string("http://example.org/base/");
+ const SerdStringView rel = serd_string("a/b");
+ const SerdStringView abs = serd_string("http://example.org/base/a/b");
+
+ const SerdURIView base_uri = serd_parse_uri(base.data);
+ const SerdURIView rel_uri = serd_parse_uri(rel.data);
+ const SerdURIView abs_uri = serd_resolve_uri(rel_uri, base_uri);
+
+ SerdNode* const from_string = serd_node_new(NULL, serd_a_uri(abs));
+
+ SerdNode* const from_uri = serd_node_new(NULL, serd_a_parsed_uri(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)
{
const SerdStringView hello_str = serd_string("hello");
const SerdStringView empty_str = serd_empty_string();
+ assert(!serd_node_new(NULL,
+ serd_a_literal(hello_str,
+ SERD_HAS_DATATYPE | SERD_HAS_LANGUAGE,
+ serd_string("whatever"))));
+
assert(!serd_node_new(NULL, serd_a_typed_literal(hello_str, empty_str)));
assert(!serd_node_new(NULL, serd_a_plain_literal(hello_str, empty_str)));
assert(
!serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("Type"))));
+
assert(
!serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("de"))));
@@ -756,12 +791,11 @@ test_compare(void)
SerdNode* angst_de = serd_node_new(
NULL, serd_a_plain_literal(serd_string("angst"), serd_string("de")));
- assert(angst_de);
SerdNode* angst_en = serd_node_new(
NULL, serd_a_plain_literal(serd_string("angst"), serd_string("en")));
SerdNode* hallo = serd_node_new(
- NULL, serd_a_typed_literal(serd_string("Hallo"), serd_string("de")));
+ NULL, serd_a_plain_literal(serd_string("Hallo"), serd_string("de")));
SerdNode* hello = serd_node_new(NULL, serd_a_string("Hello"));
SerdNode* universe = serd_node_new(NULL, serd_a_string("Universe"));
@@ -828,6 +862,7 @@ main(void)
test_node_equals();
test_node_from_syntax();
test_node_from_substring();
+ test_uri();
test_literal();
test_blank();
test_compare();