aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-29 18:29:03 +0200
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commit471ef4960aba6b5e1c9445229cddc0b3eb9ca148 (patch)
treeae6ff30025ec510624c50aa6364a9171aca879bc /test/test_node.c
parent941b14a0ab8f7c80f94e04762e65a48f9ed02f6e (diff)
downloadserd-471ef4960aba6b5e1c9445229cddc0b3eb9ca148.tar.gz
serd-471ef4960aba6b5e1c9445229cddc0b3eb9ca148.tar.bz2
serd-471ef4960aba6b5e1c9445229cddc0b3eb9ca148.zip
Simplify node construction API
Diffstat (limited to 'test/test_node.c')
-rw-r--r--test/test_node.c71
1 files changed, 47 insertions, 24 deletions
diff --git a/test/test_node.c b/test/test_node.c
index 7fd4cb29..eeafe5fc 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -152,19 +152,20 @@ test_blob_to_node(void)
static void
test_node_equals(void)
{
- const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode* lhs =
- serd_new_string(SERD_LITERAL, (const char*)replacement_char_str);
- SerdNode* rhs = serd_new_string(SERD_LITERAL, "123");
+ static const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
+
+ SerdNode* const lhs =
+ serd_new_string(SERD_STRING_VIEW((const char*)replacement_char_str, 3));
+
+ SerdNode* const rhs = serd_new_string(SERD_STATIC_STRING("123"));
assert(!serd_node_equals(lhs, rhs));
- SerdNode* qnode = serd_new_string(SERD_CURIE, "foo:bar");
+ SerdNode* const qnode = serd_new_curie(SERD_STATIC_STRING("foo:bar"));
assert(!serd_node_equals(lhs, qnode));
- assert(serd_node_equals(lhs, lhs));
+ serd_node_free(qnode);
assert(!serd_node_copy(NULL));
- serd_node_free(qnode);
serd_node_free(lhs);
serd_node_free(rhs);
}
@@ -172,38 +173,45 @@ test_node_equals(void)
static void
test_node_from_string(void)
{
- 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\""));
-
+ SerdNode* const hello = serd_new_string(SERD_STATIC_STRING("hello\""));
+ assert(serd_node_length(hello) == 6);
+ assert(serd_node_flags(hello) == SERD_HAS_QUOTE);
+ assert(!strncmp(serd_node_string(hello), "hello\"", 6));
serd_node_free(hello);
}
static void
test_node_from_substring(void)
{
- 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));
+ SerdNode* const a_b = serd_new_string(SERD_STRING_VIEW("a\"bc", 3));
+ assert(serd_node_length(a_b) == 3);
+ assert(serd_node_flags(a_b) == SERD_HAS_QUOTE);
+ assert(strlen(serd_node_string(a_b)) == 3);
+ assert(!strncmp(serd_node_string(a_b), "a\"b", 3));
serd_node_free(a_b);
}
static void
+test_simple_node(void)
+{
+ assert(!serd_new_simple_node(SERD_LITERAL, SERD_STATIC_STRING("Literal")));
+}
+
+static void
test_literal(void)
{
- SerdNode* hello2 = serd_new_literal("hello\"", NULL, NULL);
+ SerdNode* hello2 = serd_new_literal(
+ SERD_STATIC_STRING("hello\""), SERD_EMPTY_STRING(), SERD_EMPTY_STRING());
+
assert(serd_node_length(hello2) == 6 &&
serd_node_flags(hello2) == SERD_HAS_QUOTE &&
!strcmp(serd_node_string(hello2), "hello\""));
serd_node_free(hello2);
- SerdNode* hello_l = serd_new_literal("hello_l\"", NULL, "en");
+ SerdNode* hello_l = serd_new_literal(SERD_STATIC_STRING("hello_l\""),
+ SERD_EMPTY_STRING(),
+ SERD_STATIC_STRING("en"));
+
assert(serd_node_length(hello_l) == 8);
assert(!strcmp(serd_node_string(hello_l), "hello_l\""));
assert(serd_node_flags(hello_l) == (SERD_HAS_QUOTE | SERD_HAS_LANGUAGE));
@@ -213,8 +221,11 @@ test_literal(void)
assert(!strcmp(serd_node_string(lang), "en"));
serd_node_free(hello_l);
- SerdNode* const hello_dt =
- serd_new_literal("hello_dt\"", "http://example.org/Thing", NULL);
+ SerdNode* hello_dt =
+ serd_new_literal(SERD_STATIC_STRING("hello_dt\""),
+ SERD_STATIC_STRING("http://example.org/Thing"),
+ SERD_EMPTY_STRING());
+
assert(serd_node_length(hello_dt) == 9);
assert(!strcmp(serd_node_string(hello_dt), "hello_dt\""));
assert(serd_node_flags(hello_dt) == (SERD_HAS_QUOTE | SERD_HAS_DATATYPE));
@@ -225,6 +236,16 @@ test_literal(void)
serd_node_free(hello_dt);
}
+static void
+test_blank(void)
+{
+ SerdNode* blank = serd_new_blank(SERD_STATIC_STRING("b0"));
+ assert(serd_node_length(blank) == 2);
+ assert(serd_node_flags(blank) == 0);
+ assert(!strcmp(serd_node_string(blank), "b0"));
+ serd_node_free(blank);
+}
+
int
main(void)
{
@@ -235,7 +256,9 @@ main(void)
test_node_equals();
test_node_from_string();
test_node_from_substring();
+ test_simple_node();
test_literal();
+ test_blank();
printf("Success\n");
return 0;