aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
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 a16aa889..3df678cc 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -152,19 +152,22 @@ 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_SUBSTRING((const char*)replacement_char_str, 3));
+
+ assert(serd_node_equals(lhs, lhs));
+
+ SerdNode* const rhs = serd_new_string(SERD_STRING("123"));
assert(!serd_node_equals(lhs, rhs));
- SerdNode* qnode = serd_new_string(SERD_CURIE, "foo:bar");
+ SerdNode* const qnode = serd_new_curie(SERD_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,29 +175,31 @@ 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_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_SUBSTRING("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_STRING("Literal")));
+}
+
+static void
check_copy_equals(const SerdNode* const node)
{
SerdNode* const copy = serd_node_copy(node);
@@ -207,14 +212,18 @@ check_copy_equals(const SerdNode* const node)
static void
test_literal(void)
{
- SerdNode* hello2 = serd_new_literal("hello\"", NULL, NULL);
+ SerdNode* hello2 = serd_new_literal(
+ SERD_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\""));
check_copy_equals(hello2);
serd_node_free(hello2);
- SerdNode* hello_l = serd_new_literal("hello_l\"", NULL, "en");
+ SerdNode* hello_l = serd_new_literal(
+ SERD_STRING("hello_l\""), SERD_EMPTY_STRING(), SERD_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));
@@ -225,8 +234,10 @@ test_literal(void)
check_copy_equals(hello_l);
serd_node_free(hello_l);
- SerdNode* hello_dt =
- serd_new_literal("hello_dt\"", "http://example.org/Thing", NULL);
+ SerdNode* hello_dt = serd_new_literal(SERD_STRING("hello_dt\""),
+ SERD_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));
@@ -239,6 +250,16 @@ test_literal(void)
serd_node_free(hello_dt);
}
+static void
+test_blank(void)
+{
+ SerdNode* blank = serd_new_blank(SERD_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)
{
@@ -249,7 +270,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;