aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_caret.c12
-rw-r--r--test/test_env.c16
-rw-r--r--test/test_log.c3
-rw-r--r--test/test_node.c608
-rw-r--r--test/test_overflow.c2
-rw-r--r--test/test_reader.c2
-rw-r--r--test/test_reader_writer.c23
-rw-r--r--test/test_sink.c9
-rw-r--r--test/test_statement.c27
-rw-r--r--test/test_terse_write.c20
-rw-r--r--test/test_uri.c35
-rw-r--r--test/test_writer.c71
12 files changed, 521 insertions, 307 deletions
diff --git a/test/test_caret.c b/test/test_caret.c
index a97b3d0f..9374f65b 100644
--- a/test/test_caret.c
+++ b/test/test_caret.c
@@ -7,7 +7,6 @@
#include "serd/caret.h"
#include "serd/node.h"
-#include "serd/string_view.h"
#include <assert.h>
#include <stddef.h>
@@ -16,7 +15,7 @@
static int
test_caret(void)
{
- SerdNode* const node = serd_new_string(NULL, serd_string("node"));
+ SerdNode* const node = serd_node_new(NULL, serd_a_string("node"));
SerdCaret* const caret = serd_caret_new(NULL, node, 46, 2);
assert(serd_caret_equals(caret, caret));
@@ -29,7 +28,7 @@ test_caret(void)
assert(serd_caret_equals(caret, copy));
assert(!serd_caret_copy(NULL, NULL));
- SerdNode* const other_node = serd_new_string(NULL, serd_string("other"));
+ SerdNode* const other_node = serd_node_new(NULL, serd_a_string("other"));
SerdCaret* const other_file = serd_caret_new(NULL, other_node, 46, 2);
SerdCaret* const other_line = serd_caret_new(NULL, node, 47, 2);
SerdCaret* const other_col = serd_caret_new(NULL, node, 46, 3);
@@ -54,8 +53,12 @@ test_caret(void)
static void
test_failed_alloc(void)
{
- SerdNode* node = serd_new_token(NULL, SERD_LITERAL, serd_string("node"));
+ char node_buf[32];
+ assert(!serd_node_construct(sizeof(node_buf), node_buf, serd_a_string("node"))
+ .status);
+
+ const SerdNode* node = (const SerdNode*)node_buf;
SerdFailingAllocator allocator = serd_failing_allocator();
// Successfully allocate a new caret to count the number of allocations
@@ -84,7 +87,6 @@ test_failed_alloc(void)
serd_caret_free(&allocator.base, copy);
serd_caret_free(&allocator.base, caret);
- serd_node_free(NULL, node);
}
int
diff --git a/test/test_env.c b/test/test_env.c
index 89947826..eec8a2ef 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -202,7 +202,7 @@ static void
test_base_uri(void)
{
SerdEnv* const env = serd_env_new(NULL, serd_empty_string());
- SerdNode* const eg = serd_new_uri(NULL, serd_string(NS_EG));
+ SerdNode* const eg = serd_node_new(NULL, serd_a_uri_string(NS_EG));
// Test that invalid calls work as expected
assert(!serd_env_base_uri(env));
@@ -262,7 +262,7 @@ test_set_prefix(void)
static void
test_expand_untyped_literal(void)
{
- SerdNode* const untyped = serd_new_string(NULL, serd_string("data"));
+ SerdNode* const untyped = serd_node_new(NULL, serd_a_string("data"));
SerdEnv* const env = serd_env_new(NULL, serd_empty_string());
assert(!serd_env_expand_node(env, untyped));
@@ -277,7 +277,7 @@ test_expand_bad_uri_datatype(void)
const SerdStringView type = serd_string("Type");
SerdNode* const typed =
- serd_new_literal(NULL, serd_string("data"), SERD_HAS_DATATYPE, type);
+ serd_node_new(NULL, serd_a_typed_literal(serd_string("data"), type));
SerdEnv* const env = serd_env_new(NULL, serd_empty_string());
@@ -293,9 +293,9 @@ test_expand_uri(void)
const SerdStringView base = serd_string("http://example.org/b/");
SerdEnv* const env = serd_env_new(NULL, base);
- SerdNode* const rel = serd_new_uri(NULL, serd_string("rel"));
+ SerdNode* const rel = serd_node_new(NULL, serd_a_uri_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 = serd_node_new(NULL, serd_a_uri_string(""));
SerdNode* const empty_out = serd_env_expand_node(env, empty);
assert(!strcmp(serd_node_string(rel_out), "http://example.org/b/rel"));
@@ -313,7 +313,7 @@ test_expand_empty_uri_ref(void)
{
const SerdStringView base = serd_string("http://example.org/b/");
- SerdNode* const rel = serd_new_uri(NULL, serd_string("rel"));
+ SerdNode* const rel = serd_node_new(NULL, serd_a_uri_string("rel"));
SerdEnv* const env = serd_env_new(NULL, base);
SerdNode* const rel_out = serd_env_expand_node(env, rel);
@@ -327,7 +327,7 @@ test_expand_empty_uri_ref(void)
static void
test_expand_bad_uri(void)
{
- SerdNode* const bad_uri = serd_new_uri(NULL, serd_string("rel"));
+ SerdNode* const bad_uri = serd_node_new(NULL, serd_a_uri_string("rel"));
SerdEnv* const env = serd_env_new(NULL, serd_empty_string());
assert(!serd_env_expand_node(env, bad_uri));
@@ -372,7 +372,7 @@ test_expand_bad_curie(void)
static void
test_expand_blank(void)
{
- SerdNode* const blank = serd_new_blank(NULL, serd_string("b1"));
+ SerdNode* const blank = serd_node_new(NULL, serd_a_blank_string("b1"));
SerdEnv* const env = serd_env_new(NULL, serd_empty_string());
assert(!serd_env_expand_node(env, blank));
diff --git a/test/test_log.c b/test/test_log.c
index 5da8ec09..aba9fe23 100644
--- a/test/test_log.c
+++ b/test/test_log.c
@@ -83,7 +83,8 @@ static void
test_caret(void)
{
SerdWorld* const world = serd_world_new(NULL);
- SerdNode* const name = serd_new_string(NULL, serd_string("filename"));
+
+ SerdNode* const name = serd_node_new(NULL, serd_a_string("filename"));
SerdCaret* const caret = serd_caret_new(NULL, name, 46, 2);
serd_logf_at(world, SERD_LOG_LEVEL_NOTICE, caret, "is just ahead of me");
diff --git a/test/test_node.c b/test/test_node.c
index 23d1a45a..6b159007 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -7,6 +7,7 @@
#include "serd/status.h"
#include "serd/string_view.h"
#include "serd/uri.h"
+#include "serd/value.h"
#include "serd/write_result.h"
#include <assert.h>
@@ -48,54 +49,178 @@
#endif
static void
+test_new(void)
+{
+ const SerdNodeArgs bad_args = {(SerdNodeArgsType)-1,
+ {{(SerdNodeType)-1, {NULL, 0U}}}};
+
+ assert(!serd_node_new(NULL, bad_args));
+}
+
+static void
+test_value(void)
+{
+ static const double double_one = 1.0;
+ static const float float_two = 2.0f;
+
+ SerdNode* const null_node =
+ serd_node_new(NULL, serd_a_primitive(serd_nothing()));
+ SerdNode* const bool_node =
+ serd_node_new(NULL, serd_a_primitive(serd_bool(false)));
+ SerdNode* const double_node =
+ serd_node_new(NULL, serd_a_primitive(serd_double(1.0)));
+ SerdNode* const float_node =
+ serd_node_new(NULL, serd_a_primitive(serd_float(2.0f)));
+ SerdNode* const long_node =
+ serd_node_new(NULL, serd_a_primitive(serd_long(3)));
+ SerdNode* const int_node = serd_node_new(NULL, serd_a_primitive(serd_int(4)));
+ SerdNode* const short_node =
+ serd_node_new(NULL, serd_a_primitive(serd_short(5)));
+ SerdNode* const byte_node =
+ serd_node_new(NULL, serd_a_primitive(serd_byte(6)));
+ SerdNode* const ulong_node =
+ serd_node_new(NULL, serd_a_primitive(serd_ulong(7U)));
+ SerdNode* const uint_node =
+ serd_node_new(NULL, serd_a_primitive(serd_uint(8U)));
+ SerdNode* const ushort_node =
+ serd_node_new(NULL, serd_a_primitive(serd_ushort(9U)));
+ SerdNode* const ubyte_node =
+ serd_node_new(NULL, serd_a_primitive(serd_ubyte(10U)));
+
+ assert(!null_node);
+
+ assert(!strcmp(serd_node_string(bool_node), "false"));
+ assert(serd_node_value(bool_node).type == SERD_BOOL);
+ assert(serd_node_value(bool_node).data.as_bool == false);
+
+ assert(!strcmp(serd_node_string(double_node), "1.0E0"));
+ assert(serd_node_value(double_node).type == SERD_DOUBLE);
+ {
+ const double double_value = serd_node_value(double_node).data.as_double;
+ assert(!memcmp(&double_value, &double_one, sizeof(double)));
+ }
+
+ assert(!strcmp(serd_node_string(float_node), "2.0E0"));
+ assert(serd_node_value(float_node).type == SERD_FLOAT);
+ {
+ const float float_value = serd_node_value(float_node).data.as_float;
+ assert(!memcmp(&float_value, &float_two, sizeof(float)));
+ }
+
+ assert(!strcmp(serd_node_string(long_node), "3"));
+ assert(serd_node_value(long_node).type == SERD_LONG);
+ assert(serd_node_value(long_node).data.as_long == 3);
+
+ assert(!strcmp(serd_node_string(int_node), "4"));
+ assert(serd_node_value(int_node).type == SERD_INT);
+ assert(serd_node_value(int_node).data.as_int == 4);
+
+ assert(!strcmp(serd_node_string(short_node), "5"));
+ assert(serd_node_value(short_node).type == SERD_SHORT);
+ assert(serd_node_value(short_node).data.as_short == 5);
+
+ assert(!strcmp(serd_node_string(byte_node), "6"));
+ assert(serd_node_value(byte_node).type == SERD_BYTE);
+ assert(serd_node_value(byte_node).data.as_byte == 6);
+
+ assert(!strcmp(serd_node_string(ulong_node), "7"));
+ assert(serd_node_value(ulong_node).type == SERD_ULONG);
+ assert(serd_node_value(ulong_node).data.as_ulong == 7U);
+
+ assert(!strcmp(serd_node_string(uint_node), "8"));
+ assert(serd_node_value(uint_node).type == SERD_UINT);
+ assert(serd_node_value(uint_node).data.as_uint == 8U);
+
+ assert(!strcmp(serd_node_string(ushort_node), "9"));
+ assert(serd_node_value(ushort_node).type == SERD_USHORT);
+ assert(serd_node_value(ushort_node).data.as_ushort == 9U);
+
+ assert(!strcmp(serd_node_string(ubyte_node), "10"));
+ assert(serd_node_value(ubyte_node).type == SERD_UBYTE);
+ assert(serd_node_value(ubyte_node).data.as_ubyte == 10U);
+
+ serd_node_free(NULL, bool_node);
+ serd_node_free(NULL, double_node);
+ serd_node_free(NULL, float_node);
+ serd_node_free(NULL, long_node);
+ serd_node_free(NULL, int_node);
+ serd_node_free(NULL, short_node);
+ serd_node_free(NULL, byte_node);
+ serd_node_free(NULL, ulong_node);
+ serd_node_free(NULL, uint_node);
+ serd_node_free(NULL, ushort_node);
+ serd_node_free(NULL, ubyte_node);
+}
+
+static void
test_boolean(void)
{
- SerdNode* const true_node = serd_new_boolean(NULL, true);
- assert(!strcmp(serd_node_string(true_node), "true"));
- assert(serd_get_boolean(true_node));
-
- const SerdNode* const true_datatype = serd_node_datatype(true_node);
- assert(true_datatype);
- assert(!strcmp(serd_node_string(true_datatype), NS_XSD "boolean"));
- serd_node_free(NULL, true_node);
-
- SerdNode* const false_node = serd_new_boolean(NULL, false);
- assert(!strcmp(serd_node_string(false_node), "false"));
- assert(!serd_get_boolean(false_node));
-
- const SerdNode* const false_datatype = serd_node_datatype(false_node);
- assert(false_datatype);
- assert(!strcmp(serd_node_string(false_datatype), NS_XSD "boolean"));
- serd_node_free(NULL, false_node);
+ {
+ 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);
+
+ const SerdNode* const true_datatype = serd_node_datatype(true_node);
+ assert(true_datatype);
+ assert(!strcmp(serd_node_string(true_datatype), NS_XSD "boolean"));
+ serd_node_free(NULL, true_node);
+ }
+ {
+ 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);
+
+ const SerdNode* const false_datatype = serd_node_datatype(false_node);
+ assert(false_datatype);
+ assert(!strcmp(serd_node_string(false_datatype), NS_XSD "boolean"));
+ serd_node_free(NULL, false_node);
+ }
}
static void
-check_get_boolean(const char* string,
- const char* datatype_uri,
- const bool expected)
+check_get_bool(const char* string,
+ const char* datatype_uri,
+ const bool lossy,
+ const SerdValueType value_type,
+ const bool expected)
{
- SerdNode* const node = serd_new_literal(
- NULL, serd_string(string), SERD_HAS_DATATYPE, serd_string(datatype_uri));
+ SerdNode* const node = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri)));
assert(node);
- assert(serd_get_boolean(node) == expected);
+
+ const SerdValue value = serd_node_value_as(node, SERD_BOOL, lossy);
+
+ assert(value.type == value_type);
+ assert(value.data.as_bool == expected);
serd_node_free(NULL, node);
}
static void
-test_get_boolean(void)
+test_get_bool(void)
{
- check_get_boolean("false", NS_XSD "boolean", false);
- check_get_boolean("true", NS_XSD "boolean", true);
- check_get_boolean("0", NS_XSD "boolean", false);
- check_get_boolean("1", NS_XSD "boolean", true);
- check_get_boolean("0", NS_XSD "integer", false);
- check_get_boolean("1", NS_XSD "integer", true);
- check_get_boolean("0.0", NS_XSD "double", false);
- check_get_boolean("1.0", NS_XSD "double", true);
- check_get_boolean("unknown", NS_XSD "string", false);
- check_get_boolean("!invalid", NS_XSD "long", false);
+ check_get_bool("false", NS_XSD "boolean", false, SERD_BOOL, false);
+ check_get_bool("true", NS_XSD "boolean", false, SERD_BOOL, true);
+ check_get_bool("0", NS_XSD "boolean", false, SERD_BOOL, false);
+ check_get_bool("1", NS_XSD "boolean", false, SERD_BOOL, true);
+ check_get_bool("0", NS_XSD "integer", false, SERD_BOOL, false);
+ check_get_bool("1", NS_XSD "integer", false, SERD_BOOL, true);
+ check_get_bool("0.0", NS_XSD "double", false, SERD_BOOL, false);
+ check_get_bool("1.0", NS_XSD "double", false, SERD_BOOL, true);
+
+ check_get_bool("2", NS_XSD "integer", false, SERD_NOTHING, false);
+ check_get_bool("1.5", NS_XSD "double", false, SERD_NOTHING, false);
+
+ check_get_bool("2", NS_XSD "integer", true, SERD_BOOL, true);
+ check_get_bool("1.5", NS_XSD "double", true, SERD_BOOL, true);
+
+ check_get_bool("unknown", NS_XSD "string", true, SERD_NOTHING, false);
+ check_get_bool("!invalid", NS_XSD "long", true, SERD_NOTHING, false);
}
static void
@@ -114,7 +239,7 @@ test_decimal(void)
"0.0000000001"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(double); ++i) {
- SerdNode* node = serd_new_decimal(NULL, test_values[i], NULL);
+ SerdNode* node = serd_node_new(NULL, serd_a_decimal(test_values[i]));
const char* node_str = serd_node_string(node);
assert(!strcmp(node_str, test_strings[i]));
@@ -125,8 +250,8 @@ test_decimal(void)
assert(datatype);
assert(!strcmp(serd_node_string(datatype), NS_XSD "decimal"));
- const double value = serd_get_double(node);
- assert(!memcmp(&value, &test_values[i], sizeof(value)));
+ const SerdValue value = serd_node_value(node);
+ assert(!memcmp(&value.data.as_double, &test_values[i], sizeof(double)));
serd_node_free(NULL, node);
}
}
@@ -139,7 +264,8 @@ 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 = serd_new_double(NULL, test_values[i]);
+ SerdNode* 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]));
@@ -150,24 +276,35 @@ test_double(void)
assert(datatype);
assert(!strcmp(serd_node_string(datatype), NS_XSD "double"));
- const double value = serd_get_double(node);
- assert(!memcmp(&value, &test_values[i], sizeof(value)));
+ const SerdValue value = serd_node_value(node);
+ assert(!memcmp(&value.data.as_double, &test_values[i], sizeof(double)));
serd_node_free(NULL, node);
}
}
static void
-check_get_double(const char* string,
- const char* datatype_uri,
- const double expected)
+check_get_double(const char* string,
+ const char* datatype_uri,
+ const bool lossy,
+ const SerdValueType value_type,
+ const double expected)
{
- SerdNode* const node = serd_new_literal(
- NULL, serd_string(string), SERD_HAS_DATATYPE, serd_string(datatype_uri));
+ SerdNode* const node = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri)));
assert(node);
- const double value = serd_get_double(node);
- assert(!memcmp(&value, &expected, sizeof(value)));
+ const SerdValue value = serd_node_value_as(node, SERD_DOUBLE, lossy);
+
+ assert(value.type == value_type);
+
+ SERD_DISABLE_CONVERSION_WARNINGS
+
+ assert(value_type == SERD_NOTHING ||
+ ((isnan(value.data.as_double) && isnan(expected)) ||
+ !memcmp(&value.data.as_double, &expected, sizeof(double))));
+
+ SERD_RESTORE_WARNINGS
serd_node_free(NULL, node);
}
@@ -175,34 +312,19 @@ check_get_double(const char* string,
static void
test_get_double(void)
{
- check_get_double("1.2", NS_XSD "double", 1.2);
- check_get_double("-.5", NS_XSD "float", -0.5);
- check_get_double("-67", NS_XSD "long", -67.0);
- check_get_double("8.9", NS_XSD "decimal", 8.9);
- check_get_double("false", NS_XSD "boolean", 0.0);
- check_get_double("true", NS_XSD "boolean", 1.0);
-
- static const uint8_t blob[] = {1U, 2U, 3U, 4U};
+ check_get_double("1.2", NS_XSD "double", false, SERD_DOUBLE, 1.2);
+ check_get_double("-.5", NS_XSD "float", false, SERD_DOUBLE, -0.5);
+ check_get_double("-67", NS_XSD "long", false, SERD_DOUBLE, -67.0);
+ check_get_double("67", NS_XSD "unsignedLong", false, SERD_DOUBLE, 67.0);
+ check_get_double("8.9", NS_XSD "decimal", false, SERD_DOUBLE, 8.9);
+ check_get_double("false", NS_XSD "boolean", false, SERD_DOUBLE, 0.0);
+ check_get_double("true", NS_XSD "boolean", false, SERD_DOUBLE, 1.0);
SERD_DISABLE_CONVERSION_WARNINGS
-
- SerdNode* const nan = serd_new_string(NULL, serd_string("unknown"));
- assert(isnan(serd_get_double(nan)));
- serd_node_free(NULL, nan);
-
- SerdNode* const invalid = serd_new_literal(NULL,
- serd_string("!invalid"),
- SERD_HAS_DATATYPE,
- serd_string(NS_XSD "long"));
-
- assert(isnan(serd_get_double(invalid)));
- serd_node_free(NULL, invalid);
-
- SerdNode* const base64 = serd_new_base64(NULL, blob, sizeof(blob));
-
- assert(isnan(serd_get_double(base64)));
- serd_node_free(NULL, base64);
-
+ check_get_double("str", NS_XSD "string", true, SERD_NOTHING, NAN);
+ check_get_double("!invalid", NS_XSD "long", true, SERD_NOTHING, NAN);
+ check_get_double("D3AD", NS_XSD "hexBinary", true, SERD_NOTHING, NAN);
+ check_get_double("Zm9v", NS_XSD "base64Binary", true, SERD_NOTHING, NAN);
SERD_RESTORE_WARNINGS
}
@@ -214,7 +336,8 @@ 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 = serd_new_float(NULL, test_values[i]);
+ SerdNode* 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]));
@@ -225,24 +348,35 @@ test_float(void)
assert(datatype);
assert(!strcmp(serd_node_string(datatype), NS_XSD "float"));
- const float value = serd_get_float(node);
- assert(!memcmp(&value, &test_values[i], sizeof(value)));
+ const SerdValue value = serd_node_value(node);
+ assert(!memcmp(&value.data.as_float, &test_values[i], sizeof(float)));
serd_node_free(NULL, node);
}
}
static void
-check_get_float(const char* string,
- const char* datatype_uri,
- const float expected)
+check_get_float(const char* string,
+ const char* datatype_uri,
+ const bool lossy,
+ const SerdValueType value_type,
+ const float expected)
{
- SerdNode* const node = serd_new_literal(
- NULL, serd_string(string), SERD_HAS_DATATYPE, serd_string(datatype_uri));
+ SerdNode* const node = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri)));
assert(node);
- const float value = serd_get_float(node);
- assert(!memcmp(&value, &expected, sizeof(value)));
+ const SerdValue value = serd_node_value_as(node, SERD_FLOAT, lossy);
+
+ assert(value.type == value_type);
+
+ SERD_DISABLE_CONVERSION_WARNINGS
+
+ assert(value_type == SERD_NOTHING ||
+ ((isnan(value.data.as_float) && isnan(expected)) ||
+ !memcmp(&value.data.as_float, &expected, sizeof(float))));
+
+ SERD_RESTORE_WARNINGS
serd_node_free(NULL, node);
}
@@ -250,29 +384,20 @@ check_get_float(const char* string,
static void
test_get_float(void)
{
- check_get_float("1.2", NS_XSD "float", 1.2f);
- check_get_float("-.5", NS_XSD "float", -0.5f);
- check_get_float("-67", NS_XSD "long", -67.0f);
- check_get_float("1.5", NS_XSD "decimal", 1.5f);
- check_get_float("false", NS_XSD "boolean", 0.0f);
- check_get_float("true", NS_XSD "boolean", 1.0f);
+ check_get_float("1.2", NS_XSD "float", false, SERD_FLOAT, 1.2f);
+ check_get_float("-.5", NS_XSD "float", false, SERD_FLOAT, -0.5f);
+ check_get_float("-67", NS_XSD "long", false, SERD_FLOAT, -67.0f);
+ check_get_float("false", NS_XSD "boolean", false, SERD_FLOAT, 0.0f);
+ check_get_float("true", NS_XSD "boolean", false, SERD_FLOAT, 1.0f);
- SERD_DISABLE_CONVERSION_WARNINGS
-
- SerdNode* const nan = serd_new_string(NULL, serd_string("unknown"));
- assert(isnan(serd_get_float(nan)));
- serd_node_free(NULL, nan);
-
- SerdNode* const invalid = serd_new_literal(NULL,
- serd_string("!invalid"),
- SERD_HAS_DATATYPE,
- serd_string(NS_XSD "long"));
-
- assert(isnan(serd_get_double(invalid)));
+ check_get_float("1.5", NS_XSD "decimal", true, SERD_FLOAT, 1.5f);
+ SERD_DISABLE_CONVERSION_WARNINGS
+ check_get_float("str", NS_XSD "string", true, SERD_NOTHING, NAN);
+ check_get_float("!invalid", NS_XSD "long", true, SERD_NOTHING, NAN);
+ check_get_float("D3AD", NS_XSD "hexBinary", true, SERD_NOTHING, NAN);
+ check_get_float("Zm9v", NS_XSD "base64Binary", true, SERD_NOTHING, NAN);
SERD_RESTORE_WARNINGS
-
- serd_node_free(NULL, invalid);
}
static void
@@ -283,7 +408,7 @@ test_integer(void)
"0", "0", "-23", "23", "-12340", "1000", "-1000"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(double); ++i) {
- SerdNode* node = serd_new_integer(NULL, test_values[i]);
+ SerdNode* node = serd_node_new(NULL, serd_a_integer(test_values[i]));
const char* node_str = serd_node_string(node);
assert(!strcmp(node_str, test_strings[i]));
const size_t len = strlen(node_str);
@@ -293,21 +418,27 @@ test_integer(void)
assert(datatype);
assert(!strcmp(serd_node_string(datatype), NS_XSD "integer"));
- assert(serd_get_integer(node) == test_values[i]);
+ assert(serd_node_value(node).data.as_long == test_values[i]);
serd_node_free(NULL, node);
}
}
static void
-check_get_integer(const char* string,
- const char* datatype_uri,
- const int64_t expected)
+check_get_integer(const char* string,
+ const char* datatype_uri,
+ const bool lossy,
+ const SerdValueType value_type,
+ const int64_t expected)
{
- SerdNode* const node = serd_new_literal(
- NULL, serd_string(string), SERD_HAS_DATATYPE, serd_string(datatype_uri));
+ SerdNode* const node = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri)));
assert(node);
- assert(serd_get_integer(node) == expected);
+
+ const SerdValue value = serd_node_value_as(node, SERD_LONG, lossy);
+
+ assert(value.type == value_type);
+ assert(value_type == SERD_NOTHING || value.data.as_long == expected);
serd_node_free(NULL, node);
}
@@ -315,20 +446,66 @@ check_get_integer(const char* string,
static void
test_get_integer(void)
{
- check_get_integer("12", NS_XSD "long", 12);
- check_get_integer("-34", NS_XSD "long", -34);
- check_get_integer("56", NS_XSD "integer", 56);
- check_get_integer("false", NS_XSD "boolean", 0);
- check_get_integer("true", NS_XSD "boolean", 1);
- check_get_integer("78.0", NS_XSD "decimal", 78);
- check_get_integer("unknown", NS_XSD "string", 0);
- check_get_integer("!invalid", NS_XSD "long", 0);
+ check_get_integer("12", NS_XSD "long", false, SERD_LONG, 12);
+ check_get_integer("-34", NS_XSD "long", false, SERD_LONG, -34);
+ check_get_integer("56", NS_XSD "integer", false, SERD_LONG, 56);
+ check_get_integer("false", NS_XSD "boolean", false, SERD_LONG, 0);
+ check_get_integer("true", NS_XSD "boolean", false, SERD_LONG, 1);
+ check_get_integer("78.0", NS_XSD "decimal", false, SERD_LONG, 78);
+
+ check_get_integer("0", NS_XSD "nonPositiveInteger", false, SERD_LONG, 0);
+ check_get_integer("-1", NS_XSD "negativeInteger", false, SERD_LONG, -1);
+ check_get_integer("2", NS_XSD "nonNegativeInteger", false, SERD_LONG, 2);
+ check_get_integer("3", NS_XSD "positiveInteger", false, SERD_LONG, 3);
+
+ check_get_integer("78.5", NS_XSD "decimal", false, SERD_NOTHING, 0);
+ check_get_integer("78.5", NS_XSD "decimal", true, SERD_LONG, 78);
+
+ check_get_integer("unknown", NS_XSD "string", true, SERD_NOTHING, 0);
+ check_get_integer("!invalid", NS_XSD "long", true, SERD_NOTHING, 0);
+}
+
+static void
+test_hex(void)
+{
+ assert(!serd_node_new(NULL, serd_a_hex(0, &SERD_URI_NULL)));
+
+ // Test valid hex blobs with a range of sizes
+ for (size_t size = 1; size < 256; ++size) {
+ uint8_t* const data = (uint8_t*)malloc(size);
+ for (size_t i = 0; i < size; ++i) {
+ data[i] = (uint8_t)((size + i) % 256);
+ }
+
+ SerdNode* blob = serd_node_new(NULL, serd_a_hex(size, data));
+ const char* blob_str = serd_node_string(blob);
+ const size_t max_size = serd_node_decoded_size(blob);
+ uint8_t* out = (uint8_t*)calloc(1, max_size);
+
+ const SerdWriteResult r = serd_node_decode(blob, max_size, out);
+ assert(r.status == SERD_SUCCESS);
+ assert(r.count == size);
+ assert(r.count <= max_size);
+ assert(serd_node_length(blob) == strlen(blob_str));
+
+ for (size_t i = 0; i < size; ++i) {
+ assert(out[i] == data[i]);
+ }
+
+ const SerdNode* const datatype = serd_node_datatype(blob);
+ assert(datatype);
+ assert(!strcmp(serd_node_string(datatype), NS_XSD "hexBinary"));
+
+ serd_node_free(NULL, blob);
+ free(out);
+ free(data);
+ }
}
static void
test_base64(void)
{
- assert(!serd_new_base64(NULL, &SERD_URI_NULL, 0));
+ assert(!serd_node_new(NULL, serd_a_base64(0, &SERD_URI_NULL)));
// Test valid base64 blobs with a range of sizes
for (size_t size = 1; size < 256; ++size) {
@@ -337,12 +514,12 @@ test_base64(void)
data[i] = (uint8_t)((size + i) % 256);
}
- SerdNode* blob = serd_new_base64(NULL, data, size);
+ SerdNode* blob = serd_node_new(NULL, serd_a_base64(size, data));
const char* blob_str = serd_node_string(blob);
- const size_t max_size = serd_get_base64_size(blob);
+ const size_t max_size = serd_node_decoded_size(blob);
uint8_t* out = (uint8_t*)calloc(1, max_size);
- const SerdWriteResult r = serd_get_base64(blob, max_size, out);
+ const SerdWriteResult r = serd_node_decode(blob, max_size, out);
assert(r.status == SERD_SUCCESS);
assert(r.count == size);
assert(r.count <= max_size);
@@ -363,19 +540,17 @@ test_base64(void)
}
static void
-check_get_base64(const char* string,
- const char* datatype_uri,
- const char* expected)
+check_decode(const char* string, const char* datatype_uri, const char* expected)
{
- SerdNode* const node = serd_new_literal(
- NULL, serd_string(string), SERD_HAS_DATATYPE, serd_string(datatype_uri));
+ SerdNode* const node = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri)));
assert(node);
- const size_t max_size = serd_get_base64_size(node);
+ const size_t max_size = serd_node_decoded_size(node);
char* const decoded = (char*)calloc(1, max_size + 1);
- const SerdWriteResult r = serd_get_base64(node, max_size, decoded);
+ const SerdWriteResult r = serd_node_decode(node, max_size, decoded);
assert(!r.status);
assert(r.count <= max_size);
@@ -387,22 +562,53 @@ check_get_base64(const char* string,
}
static void
-test_get_base64(void)
+test_decode(void)
{
- check_get_base64("Zm9vYmFy", NS_XSD "base64Binary", "foobar");
- check_get_base64("Zm9vYg==", NS_XSD "base64Binary", "foob");
- check_get_base64(" \f\n\r\t\vZm9v \f\n\r\t\v", NS_XSD "base64Binary", "foo");
+ check_decode("666F6F626172", NS_XSD "hexBinary", "foobar");
+ check_decode("666F6F62", NS_XSD "hexBinary", "foob");
- SerdNode* const node = serd_new_literal(NULL,
- serd_string("Zm9v"),
- SERD_HAS_DATATYPE,
- serd_string(NS_XSD "base64Binary"));
+ check_decode("Zm9vYmFy", NS_XSD "base64Binary", "foobar");
+ check_decode("Zm9vYg==", NS_XSD "base64Binary", "foob");
+ check_decode(" \f\n\r\t\vZm9v \f\n\r\t\v", NS_XSD "base64Binary", "foo");
- char small[2] = {0};
- const SerdWriteResult r = serd_get_base64(node, sizeof(small), small);
+ char small[2] = {0};
- assert(r.status == SERD_OVERFLOW);
- serd_node_free(NULL, node);
+ {
+ SerdNode* const node =
+ serd_node_new(NULL,
+ serd_a_typed_literal(serd_string("Zm9v"),
+ serd_string(NS_XSD "base64Binary")));
+
+ const SerdWriteResult r = serd_node_decode(node, sizeof(small), small);
+
+ assert(r.status == SERD_OVERFLOW);
+ serd_node_free(NULL, node);
+ }
+ {
+ SerdNode* const string = serd_node_new(NULL, serd_a_string("string"));
+
+ assert(serd_node_decoded_size(string) == 0U);
+
+ const SerdWriteResult r = serd_node_decode(string, sizeof(small), small);
+
+ assert(r.status == SERD_BAD_ARG);
+ assert(r.count == 0U);
+ serd_node_free(NULL, string);
+ }
+ {
+ SerdNode* const unknown = serd_node_new(
+ NULL,
+ serd_a_typed_literal(serd_string("secret"),
+ serd_string("http://example.org/Datatype")));
+
+ assert(serd_node_decoded_size(unknown) == 0U);
+
+ const SerdWriteResult r = serd_node_decode(unknown, sizeof(small), small);
+
+ assert(r.status == SERD_BAD_ARG);
+ assert(r.count == 0U);
+ serd_node_free(NULL, unknown);
+ }
}
static void
@@ -413,8 +619,8 @@ test_node_equals(void)
static const SerdStringView replacement_char = {
(const char*)replacement_char_str, 3};
- SerdNode* lhs = serd_new_string(NULL, replacement_char);
- SerdNode* rhs = serd_new_string(NULL, serd_string("123"));
+ SerdNode* lhs = serd_node_new(NULL, serd_a_string_view(replacement_char));
+ SerdNode* rhs = serd_node_new(NULL, serd_a_string("123"));
assert(serd_node_equals(lhs, lhs));
assert(!serd_node_equals(lhs, rhs));
@@ -428,7 +634,7 @@ test_node_equals(void)
static void
test_node_from_string(void)
{
- SerdNode* const hello = serd_new_string(NULL, serd_string("hello\""));
+ 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));
@@ -436,7 +642,8 @@ test_node_from_string(void)
assert(serd_node_string_view(hello).length == 6);
serd_node_free(NULL, hello);
- SerdNode* const uri = serd_new_uri(NULL, serd_string("http://example.org/"));
+ SerdNode* const uri =
+ serd_node_new(NULL, serd_a_uri_string("http://example.org/"));
assert(serd_node_length(uri) == 19);
assert(!strcmp(serd_node_string(uri), "http://example.org/"));
assert(serd_node_uri_view(uri).authority.length == 11);
@@ -447,7 +654,8 @@ test_node_from_string(void)
static void
test_node_from_substring(void)
{
- SerdNode* const a_b = serd_new_string(NULL, serd_substring("a\"bc", 3));
+ 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);
@@ -471,48 +679,42 @@ test_literal(void)
const SerdStringView hello_str = serd_string("hello");
const SerdStringView empty_str = serd_empty_string();
- assert(!serd_new_literal(NULL,
- hello_str,
- SERD_HAS_DATATYPE | SERD_HAS_LANGUAGE,
- serd_string("whatever")));
-
- assert(!serd_new_literal(NULL, hello_str, SERD_HAS_DATATYPE, empty_str));
- assert(!serd_new_literal(NULL, hello_str, SERD_HAS_LANGUAGE, empty_str));
+ 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_new_literal(NULL, hello_str, SERD_HAS_DATATYPE, serd_string("Type")));
+ !serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("Type"))));
assert(
- !serd_new_literal(NULL, hello_str, SERD_HAS_DATATYPE, serd_string("de")));
+ !serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("de"))));
assert(
- !serd_new_literal(NULL, hello_str, SERD_HAS_LANGUAGE, serd_string("3n")));
+ !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("3n"))));
assert(
- !serd_new_literal(NULL, hello_str, SERD_HAS_LANGUAGE, serd_string("d3")));
+ !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("d3"))));
assert(
- !serd_new_literal(NULL, hello_str, SERD_HAS_LANGUAGE, serd_string("d3")));
+ !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("d3"))));
assert(
- !serd_new_literal(NULL, hello_str, SERD_HAS_LANGUAGE, serd_string("en-!")));
+ !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("en-!"))));
- SerdNode* hello2 = serd_new_string(NULL, serd_string("hello\""));
+ SerdNode* hello2 = serd_node_new(NULL, serd_a_string("hello\""));
assert(serd_node_length(hello2) == 6 &&
!strcmp(serd_node_string(hello2), "hello\""));
check_copy_equals(hello2);
- assert(!serd_new_literal(NULL,
- serd_string("plain"),
- SERD_HAS_DATATYPE,
- serd_string(NS_RDF "langString")));
+ assert(
+ !serd_node_new(NULL,
+ serd_a_typed_literal(serd_string("plain"),
+ serd_string(NS_RDF "langString"))));
serd_node_free(NULL, hello2);
const char* lang_lit_str = "\"Hello\"@en-ca";
SerdNode* sliced_lang_lit =
- serd_new_literal(NULL,
- serd_substring(lang_lit_str + 1, 5),
- SERD_HAS_LANGUAGE,
- serd_substring(lang_lit_str + 8, 5));
+ serd_node_new(NULL,
+ serd_a_plain_literal(serd_substring(lang_lit_str + 1, 5),
+ serd_substring(lang_lit_str + 8, 5)));
assert(!strcmp(serd_node_string(sliced_lang_lit), "Hello"));
@@ -524,10 +726,9 @@ test_literal(void)
const char* type_lit_str = "\"Hallo\"^^<http://example.org/Greeting>";
SerdNode* sliced_type_lit =
- serd_new_literal(NULL,
- serd_substring(type_lit_str + 1, 5),
- SERD_HAS_DATATYPE,
- serd_substring(type_lit_str + 10, 27));
+ serd_node_new(NULL,
+ serd_a_typed_literal(serd_substring(type_lit_str + 1, 5),
+ serd_substring(type_lit_str + 10, 27)));
assert(!strcmp(serd_node_string(sliced_type_lit), "Hallo"));
@@ -540,7 +741,7 @@ test_literal(void)
static void
test_blank(void)
{
- SerdNode* blank = serd_new_blank(NULL, serd_string("b0"));
+ SerdNode* blank = serd_node_new(NULL, serd_a_blank_string("b0"));
assert(serd_node_length(blank) == 2);
assert(serd_node_flags(blank) == 0);
assert(!strcmp(serd_node_string(blank), "b0"));
@@ -550,37 +751,34 @@ test_blank(void)
static void
test_compare(void)
{
- SerdNode* xsd_short =
- serd_new_uri(NULL, serd_string("http://www.w3.org/2001/XMLSchema#short"));
+ SerdNode* angst = serd_node_new(NULL, serd_a_string("angst"));
- SerdNode* angst = serd_new_string(NULL, serd_string("angst"));
-
- SerdNode* angst_de = serd_new_literal(
- NULL, serd_string("angst"), SERD_HAS_LANGUAGE, serd_string("de"));
+ SerdNode* angst_de = serd_node_new(
+ NULL, serd_a_plain_literal(serd_string("angst"), serd_string("de")));
assert(angst_de);
- SerdNode* angst_en = serd_new_literal(
- NULL, serd_string("angst"), SERD_HAS_LANGUAGE, serd_string("en"));
+ SerdNode* angst_en = serd_node_new(
+ NULL, serd_a_plain_literal(serd_string("angst"), serd_string("en")));
- SerdNode* hallo = serd_new_literal(
- NULL, serd_string("Hallo"), SERD_HAS_LANGUAGE, serd_string("de"));
+ SerdNode* hallo = serd_node_new(
+ NULL, serd_a_typed_literal(serd_string("Hallo"), serd_string("de")));
- SerdNode* hello = serd_new_string(NULL, serd_string("Hello"));
- SerdNode* universe = serd_new_string(NULL, serd_string("Universe"));
- SerdNode* integer = serd_new_integer(NULL, 4);
- SerdNode* blank = serd_new_blank(NULL, serd_string("b1"));
- SerdNode* uri = serd_new_uri(NULL, serd_string("http://example.org/"));
+ SerdNode* hello = serd_node_new(NULL, serd_a_string("Hello"));
+ SerdNode* universe = serd_node_new(NULL, serd_a_string("Universe"));
+ SerdNode* integer = serd_node_new(NULL, serd_a_integer(4));
+ SerdNode* short_int = serd_node_new(NULL, serd_a_primitive(serd_short(4)));
+ SerdNode* blank = serd_node_new(NULL, serd_a_blank_string("b1"));
+ SerdNode* uri = serd_node_new(NULL, serd_a_uri_string("http://example.org/"));
- SerdNode* aardvark =
- serd_new_literal(NULL,
- serd_string("alex"),
- SERD_HAS_DATATYPE,
- serd_string("http://example.org/Aardvark"));
+ SerdNode* aardvark = serd_node_new(
+ NULL,
+ serd_a_typed_literal(serd_string("alex"),
+ serd_string("http://example.org/Aardvark")));
- SerdNode* badger = serd_new_literal(NULL,
- serd_string("bobby"),
- SERD_HAS_DATATYPE,
- serd_string("http://example.org/Badger"));
+ SerdNode* badger = serd_node_new(
+ NULL,
+ serd_a_typed_literal(serd_string("bobby"),
+ serd_string("http://example.org/Badger")));
// Types are ordered according to their SerdNodeType (more or less arbitrary)
assert(serd_node_compare(integer, hello) < 0);
@@ -594,26 +792,29 @@ test_compare(void)
assert(serd_node_compare(angst, angst_de) < 0);
assert(serd_node_compare(angst_de, angst_en) < 0);
assert(serd_node_compare(aardvark, badger) < 0);
+ assert(serd_node_compare(integer, short_int) < 0);
+ serd_node_free(NULL, badger);
+ serd_node_free(NULL, aardvark);
serd_node_free(NULL, uri);
serd_node_free(NULL, blank);
+ serd_node_free(NULL, short_int);
serd_node_free(NULL, integer);
- serd_node_free(NULL, badger);
- serd_node_free(NULL, aardvark);
serd_node_free(NULL, universe);
serd_node_free(NULL, hello);
serd_node_free(NULL, hallo);
serd_node_free(NULL, angst_en);
serd_node_free(NULL, angst_de);
serd_node_free(NULL, angst);
- serd_node_free(NULL, xsd_short);
}
int
main(void)
{
+ test_new();
+ test_value();
test_boolean();
- test_get_boolean();
+ test_get_bool();
test_decimal();
test_double();
test_get_double();
@@ -621,8 +822,9 @@ main(void)
test_get_float();
test_integer();
test_get_integer();
+ test_hex();
test_base64();
- test_get_base64();
+ test_decode();
test_node_equals();
test_node_from_string();
test_node_from_substring();
diff --git a/test/test_overflow.c b/test/test_overflow.c
index 7b1693a8..8b47cd2b 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -29,7 +29,7 @@ test_size(SerdWorld* const world,
return SERD_BAD_STACK;
}
- SerdNode* string_name = serd_new_string(NULL, serd_string("string"));
+ SerdNode* string_name = serd_node_new(NULL, serd_a_string("string"));
const char* position = str;
SerdInputStream in = serd_open_input_string(&position);
serd_reader_start(reader, &in, string_name, 1);
diff --git a/test/test_reader.c b/test/test_reader.c
index a0eaee5c..54dbca9f 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -624,7 +624,7 @@ 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"));
+ SerdNode* const string_name = serd_node_new(NULL, serd_a_string("string"));
const char* position = string;
SerdInputStream in = serd_open_input_string(&position);
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index d6a2675d..aea0976d 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -154,7 +154,7 @@ test_writer(const char* const path)
serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
- SerdNode* lit = serd_new_string(NULL, serd_string("hello"));
+ SerdNode* lit = serd_node_new(NULL, serd_a_string("hello"));
const SerdSink* const iface = serd_writer_sink(writer);
assert(serd_sink_write_base(iface, lit));
@@ -164,9 +164,10 @@ test_writer(const char* const path)
static const uint8_t bad_buf[] = {0xEF, 0xBF, 0xBD, 0};
const SerdStringView bad_buf_view = {(const char*)bad_buf, 3};
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/pred"));
- SerdNode* bad = serd_new_string(NULL, bad_buf_view);
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org"));
+ SerdNode* p =
+ serd_node_new(NULL, serd_a_uri_string("http://example.org/pred"));
+ SerdNode* bad = serd_node_new(NULL, serd_a_string_view(bad_buf_view));
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][3] = {{s, bad, bad}, {bad, p, bad}, {s, bad, p}};
@@ -179,13 +180,13 @@ test_writer(const char* const path)
const SerdStringView urn_Type = serd_string("urn:Type");
const SerdStringView en = serd_string("en");
- SerdNode* const o = serd_new_string(NULL, serd_string("o"));
+ SerdNode* const o = serd_node_new(NULL, serd_a_string("o"));
SerdNode* const t =
- serd_new_literal(NULL, serd_string("t"), SERD_HAS_DATATYPE, urn_Type);
+ serd_node_new(NULL, serd_a_typed_literal(serd_string("t"), urn_Type));
SerdNode* const l =
- serd_new_literal(NULL, serd_string("l"), SERD_HAS_LANGUAGE, en);
+ serd_node_new(NULL, serd_a_plain_literal(serd_string("l"), en));
const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}};
@@ -200,15 +201,15 @@ test_writer(const char* const path)
static const char* const bad_uri_str = (const char*)bad_uri_buf;
// Write statements with bad UTF-8 (should be replaced)
- SerdNode* bad_lit = serd_new_string(NULL, serd_string(bad_lit_str));
- SerdNode* bad_uri = serd_new_uri(NULL, serd_string(bad_uri_str));
+ SerdNode* bad_lit = serd_node_new(NULL, serd_a_string(bad_lit_str));
+ SerdNode* bad_uri = serd_node_new(NULL, serd_a_uri_string(bad_uri_str));
assert(!serd_sink_write(iface, 0, s, p, bad_lit, 0));
assert(!serd_sink_write(iface, 0, s, p, bad_uri, 0));
serd_node_free(NULL, bad_uri);
serd_node_free(NULL, bad_lit);
// Write 1 valid statement
- SerdNode* const hello = serd_new_string(NULL, serd_string("hello"));
+ SerdNode* const hello = serd_node_new(NULL, serd_a_string("hello"));
assert(!serd_sink_write(iface, 0, s, p, hello, 0));
serd_node_free(NULL, hello);
@@ -223,7 +224,7 @@ test_writer(const char* const path)
// Test buffer sink
SerdBuffer buffer = {NULL, NULL, 0};
SerdNode* const base =
- serd_new_uri(NULL, serd_string("http://example.org/base"));
+ serd_node_new(NULL, serd_a_uri_string("http://example.org/base"));
output = serd_open_output_buffer(&buffer);
writer = serd_writer_new(world, SERD_TURTLE, 0, env, &output, 1U);
diff --git a/test/test_sink.c b/test/test_sink.c
index 9c7959de..72c45df6 100644
--- a/test/test_sink.c
+++ b/test/test_sink.c
@@ -11,7 +11,6 @@
#include "serd/sink.h"
#include "serd/statement.h"
#include "serd/status.h"
-#include "serd/string_view.h"
#include <assert.h>
#include <stddef.h>
@@ -111,10 +110,10 @@ test_failed_alloc(void)
static void
test_callbacks(void)
{
- SerdNode* const base = serd_new_uri(NULL, serd_string(NS_EG));
- SerdNode* const name = serd_new_string(NULL, serd_string("eg"));
- SerdNode* const uri = serd_new_uri(NULL, serd_string(NS_EG "uri"));
- SerdNode* const blank = serd_new_blank(NULL, serd_string("b1"));
+ SerdNode* const base = serd_node_new(NULL, serd_a_uri_string(NS_EG));
+ SerdNode* const name = serd_node_new(NULL, serd_a_string("eg"));
+ SerdNode* const uri = serd_node_new(NULL, serd_a_uri_string(NS_EG "uri"));
+ SerdNode* const blank = serd_node_new(NULL, serd_a_blank_string("b1"));
SerdEnv* env = serd_env_new(NULL, serd_node_string_view(base));
State state = {0, 0, 0, 0, 0, SERD_SUCCESS};
diff --git a/test/test_statement.c b/test/test_statement.c
index 0127b7bf..fe1ce818 100644
--- a/test/test_statement.c
+++ b/test/test_statement.c
@@ -6,7 +6,6 @@
#include "serd/caret.h"
#include "serd/node.h"
#include "serd/statement.h"
-#include "serd/string_view.h"
#include <assert.h>
#include <stddef.h>
@@ -16,9 +15,9 @@
static void
test_new(void)
{
- SerdNode* const u = serd_new_uri(NULL, serd_string(NS_EG "s"));
- SerdNode* const b = serd_new_blank(NULL, serd_string("b0"));
- SerdNode* const l = serd_new_string(NULL, serd_string("str"));
+ SerdNode* const u = serd_node_new(NULL, serd_a_uri_string(NS_EG "s"));
+ SerdNode* const b = serd_node_new(NULL, serd_a_blank_string("b0"));
+ SerdNode* const l = serd_node_new(NULL, serd_a_string("str"));
assert(!serd_statement_new(NULL, u, b, u, NULL, NULL));
assert(!serd_statement_new(NULL, l, u, u, NULL, NULL));
@@ -37,11 +36,11 @@ test_copy(void)
{
assert(!serd_statement_copy(NULL, NULL));
- SerdNode* const f = serd_new_string(NULL, serd_string("file"));
- SerdNode* const s = serd_new_uri(NULL, serd_string(NS_EG "s"));
- SerdNode* const p = serd_new_uri(NULL, serd_string(NS_EG "p"));
- SerdNode* const o = serd_new_uri(NULL, serd_string(NS_EG "o"));
- SerdNode* const g = serd_new_uri(NULL, serd_string(NS_EG "g"));
+ SerdNode* const f = serd_node_new(NULL, serd_a_string("file"));
+ SerdNode* const s = serd_node_new(NULL, serd_a_uri_string(NS_EG "s"));
+ SerdNode* const p = serd_node_new(NULL, serd_a_uri_string(NS_EG "p"));
+ SerdNode* const o = serd_node_new(NULL, serd_a_uri_string(NS_EG "o"));
+ SerdNode* const g = serd_node_new(NULL, serd_a_uri_string(NS_EG "g"));
SerdCaret* const caret = serd_caret_new(NULL, f, 1, 1);
SerdStatement* const statement = serd_statement_new(NULL, s, p, o, g, caret);
@@ -69,11 +68,11 @@ test_free(void)
static void
test_fields(void)
{
- SerdNode* const f = serd_new_string(NULL, serd_string("file"));
- SerdNode* const s = serd_new_uri(NULL, serd_string(NS_EG "s"));
- SerdNode* const p = serd_new_uri(NULL, serd_string(NS_EG "p"));
- SerdNode* const o = serd_new_uri(NULL, serd_string(NS_EG "o"));
- SerdNode* const g = serd_new_uri(NULL, serd_string(NS_EG "g"));
+ SerdNode* const f = serd_node_new(NULL, serd_a_string("file"));
+ SerdNode* const s = serd_node_new(NULL, serd_a_uri_string(NS_EG "s"));
+ SerdNode* const p = serd_node_new(NULL, serd_a_uri_string(NS_EG "p"));
+ SerdNode* const o = serd_node_new(NULL, serd_a_uri_string(NS_EG "o"));
+ SerdNode* const g = serd_node_new(NULL, serd_a_uri_string(NS_EG "g"));
SerdCaret* const caret = serd_caret_new(NULL, f, 1, 1);
SerdStatement* const statement = serd_statement_new(NULL, s, p, o, g, caret);
diff --git a/test/test_terse_write.c b/test/test_terse_write.c
index 0bdb0280..3fa08fbd 100644
--- a/test/test_terse_write.c
+++ b/test/test_terse_write.c
@@ -43,16 +43,16 @@ test(void)
SerdWorld* world = serd_world_new(NULL);
SerdEnv* env = serd_env_new(NULL, serd_empty_string());
- SerdNode* b1 = serd_new_blank(NULL, serd_string("b1"));
- SerdNode* l1 = serd_new_blank(NULL, serd_string("l1"));
- SerdNode* l2 = serd_new_blank(NULL, serd_string("l2"));
- SerdNode* s1 = serd_new_string(NULL, serd_string("s1"));
- SerdNode* s2 = serd_new_string(NULL, serd_string("s2"));
-
- SerdNode* rdf_first = serd_new_uri(NULL, serd_string(NS_RDF "first"));
- SerdNode* rdf_value = serd_new_uri(NULL, serd_string(NS_RDF "value"));
- SerdNode* rdf_rest = serd_new_uri(NULL, serd_string(NS_RDF "rest"));
- SerdNode* rdf_nil = serd_new_uri(NULL, serd_string(NS_RDF "nil"));
+ SerdNode* b1 = serd_node_new(NULL, serd_a_blank_string("b1"));
+ SerdNode* l1 = serd_node_new(NULL, serd_a_blank_string("l1"));
+ SerdNode* l2 = serd_node_new(NULL, serd_a_blank_string("l2"));
+ SerdNode* s1 = serd_node_new(NULL, serd_a_string("s1"));
+ SerdNode* s2 = serd_node_new(NULL, serd_a_string("s2"));
+
+ SerdNode* rdf_first = serd_node_new(NULL, serd_a_uri_string(NS_RDF "first"));
+ SerdNode* rdf_value = serd_node_new(NULL, serd_a_uri_string(NS_RDF "value"));
+ SerdNode* rdf_rest = serd_node_new(NULL, serd_a_uri_string(NS_RDF "rest"));
+ SerdNode* rdf_nil = serd_node_new(NULL, serd_a_uri_string(NS_RDF "nil"));
serd_env_set_prefix(env, serd_string("rdf"), serd_string(NS_RDF));
diff --git a/test/test_uri.c b/test/test_uri.c
index 79d3f73e..7a15ffb8 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -75,8 +75,8 @@ test_file_uri(const char* const hostname,
expected_path = path;
}
- SerdNode* node =
- serd_new_file_uri(NULL, serd_string(path), serd_string(hostname));
+ SerdNode* node = serd_node_new(
+ NULL, serd_a_file_uri(serd_string(path), serd_string(hostname)));
const char* node_str = serd_node_string(node);
char* out_hostname = NULL;
@@ -166,8 +166,8 @@ test_parse_uri(void)
const SerdURIView base_uri = serd_parse_uri(base.data);
const SerdURIView empty_uri = serd_parse_uri("");
- SerdNode* const nil =
- serd_new_parsed_uri(NULL, serd_resolve_uri(empty_uri, base_uri));
+ SerdNode* const nil = serd_node_new(
+ NULL, serd_a_parsed_uri(serd_resolve_uri(empty_uri, base_uri)));
assert(serd_node_type(nil) == SERD_URI);
assert(!strcmp(serd_node_string(nil), base.data));
@@ -227,21 +227,26 @@ check_relative_uri(const char* const uri_string,
assert(base_string);
assert(expected_string);
- SerdNode* const uri_node = serd_new_uri(NULL, serd_string(uri_string));
- const SerdURIView uri = serd_node_uri_view(uri_node);
- SerdNode* const base_node = serd_new_uri(NULL, serd_string(base_string));
- const SerdURIView base = serd_node_uri_view(base_node);
+ SerdNode* const uri_node = serd_node_new(NULL, serd_a_uri_string(uri_string));
+ const SerdURIView uri = serd_node_uri_view(uri_node);
+ SerdNode* const base_node =
+ serd_node_new(NULL, serd_a_uri_string(base_string));
+ const SerdURIView base = serd_node_uri_view(base_node);
SerdNode* result_node = NULL;
if (!root_string) {
- result_node = serd_new_parsed_uri(NULL, serd_relative_uri(uri, base));
+ result_node =
+ serd_node_new(NULL, serd_a_parsed_uri(serd_relative_uri(uri, base)));
} else {
- SerdNode* const root_node = serd_new_uri(NULL, serd_string(root_string));
- const SerdURIView root = serd_node_uri_view(root_node);
+ SerdNode* const root_node =
+ serd_node_new(NULL, serd_a_uri_string(root_string));
+ const SerdURIView root = serd_node_uri_view(root_node);
+
+ result_node =
+ serd_uri_is_within(uri, root)
+ ? serd_node_new(NULL, serd_a_parsed_uri(serd_relative_uri(uri, base)))
+ : serd_node_new(NULL, serd_a_uri_string(uri_string));
- result_node = serd_uri_is_within(uri, root)
- ? serd_new_parsed_uri(NULL, serd_relative_uri(uri, base))
- : serd_new_uri(NULL, serd_string(uri_string));
serd_node_free(NULL, root_node);
}
@@ -359,7 +364,7 @@ test_relative_uri(void)
static void
check_uri_string(const SerdURIView uri, const char* const expected)
{
- SerdNode* const node = serd_new_parsed_uri(NULL, uri);
+ SerdNode* const node = serd_node_new(NULL, serd_a_parsed_uri(uri));
assert(!strcmp(serd_node_string(node), expected));
serd_node_free(NULL, node);
}
diff --git a/test/test_writer.c b/test/test_writer.c
index 39bcd34a..8f4fef5c 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -78,13 +78,14 @@ test_write_failed_alloc(void)
SerdBuffer buffer = {&allocator.base, NULL, 0};
SerdOutputStream output = serd_open_output_buffer(&buffer);
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p1 = serd_new_uri(NULL, serd_string("http://example.org/p"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p1 = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
- SerdNode* p2 = serd_new_uri(
- NULL, serd_string("http://example.org/dramatically/longer/predicate"));
+ SerdNode* p2 = serd_node_new(
+ NULL,
+ serd_a_uri_string("http://example.org/dramatically/longer/predicate"));
- SerdNode* o = serd_new_token(NULL, SERD_BLANK, serd_string("o"));
+ SerdNode* o = serd_node_new(NULL, serd_a_blank_string("o"));
const size_t n_setup_allocs = allocator.n_allocations;
@@ -168,12 +169,13 @@ test_write_long_literal(void)
serd_writer_new(world, SERD_TURTLE, 0U, env, &output, 1U);
assert(writer);
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
- SerdNode* o = serd_new_literal(NULL,
- serd_string("hello \"\"\"world\"\"\"!"),
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
+ SerdNode* o =
+ serd_node_new(NULL,
+ serd_a_literal(serd_string("hello \"\"\"world\"\"\"!"),
SERD_IS_LONG,
- serd_empty_string());
+ serd_empty_string()));
assert(serd_node_flags(o) & SERD_IS_LONG);
assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL));
@@ -224,9 +226,9 @@ test_writer_cleanup(void)
const SerdSink* sink = serd_writer_sink(writer);
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
- SerdNode* o = serd_new_blank(NULL, serd_string("start"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
+ SerdNode* o = serd_node_new(NULL, serd_a_blank_string("start"));
st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL);
assert(!st);
@@ -236,7 +238,7 @@ test_writer_cleanup(void)
char buf[12] = {0};
snprintf(buf, sizeof(buf), "b%u", i);
- SerdNode* next_o = serd_new_blank(NULL, serd_string(buf));
+ SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf));
st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL);
@@ -248,7 +250,7 @@ test_writer_cleanup(void)
assert(!(st = serd_writer_finish(writer)));
// Set the base to an empty URI
- SerdNode* empty_uri = serd_new_uri(NULL, serd_string(""));
+ SerdNode* empty_uri = serd_node_new(NULL, serd_a_uri_string(""));
assert(!(st = serd_sink_write_base(sink, empty_uri)));
serd_node_free(NULL, empty_uri);
@@ -280,11 +282,12 @@ test_strict_write(void)
const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
- SerdNode* bad_lit = serd_new_string(NULL, serd_string((const char*)bad_str));
- SerdNode* bad_uri = serd_new_uri(NULL, serd_string((const char*)bad_str));
+ SerdNode* bad_lit = serd_node_new(NULL, serd_a_string((const char*)bad_str));
+ SerdNode* bad_uri =
+ serd_node_new(NULL, serd_a_uri_string((const char*)bad_str));
assert(serd_sink_write(sink, 0, s, p, bad_lit, NULL) == SERD_BAD_TEXT);
assert(serd_sink_write(sink, 0, s, p, bad_uri, NULL) == SERD_BAD_TEXT);
@@ -322,7 +325,7 @@ test_write_error(void)
SerdOutputStream out = serd_open_output_stream(error_sink, NULL, NULL, NULL);
SerdStatus st = SERD_SUCCESS;
- SerdNode* u = serd_new_uri(NULL, serd_string("http://example.com/u"));
+ SerdNode* u = serd_node_new(NULL, serd_a_uri_string("http://example.com/u"));
SerdWriter* const writer =
serd_writer_new(world, SERD_TURTLE, (SerdWriterFlags)0, env, &out, 1U);
@@ -353,10 +356,12 @@ test_writer_stack_overflow(void)
const SerdSink* sink = serd_writer_sink(writer);
- SerdNode* const s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* const p = serd_new_uri(NULL, serd_string("http://example.org/p"));
+ SerdNode* const s =
+ serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* const p =
+ serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
- SerdNode* o = serd_new_blank(NULL, serd_string("blank"));
+ SerdNode* o = serd_node_new(NULL, serd_a_blank_string("blank"));
SerdStatus st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL);
assert(!st);
@@ -365,7 +370,7 @@ test_writer_stack_overflow(void)
char buf[1024];
snprintf(buf, sizeof(buf), "b%u", i);
- SerdNode* next_o = serd_new_blank(NULL, serd_string(buf));
+ SerdNode* next_o = serd_node_new(NULL, serd_a_blank_string(buf));
st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL);
@@ -395,9 +400,9 @@ test_write_empty_syntax(void)
SerdWorld* world = serd_world_new(NULL);
SerdEnv* env = serd_env_new(NULL, serd_empty_string());
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
- SerdNode* o = serd_new_uri(NULL, serd_string("http://example.org/o"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
+ SerdNode* o = serd_node_new(NULL, serd_a_uri_string("http://example.org/o"));
SerdBuffer buffer = {NULL, NULL, 0};
SerdOutputStream output = serd_open_output_buffer(&buffer);
@@ -441,14 +446,14 @@ check_pname_escape(const char* const lname, const char* const expected)
serd_env_set_prefix(env, serd_string("eg"), serd_string(prefix));
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
char* const uri = (char*)calloc(1, prefix_len + strlen(lname) + 1);
memcpy(uri, prefix, prefix_len + 1);
memcpy(uri + prefix_len, lname, strlen(lname) + 1);
- SerdNode* node = serd_new_uri(NULL, serd_string(uri));
+ SerdNode* node = serd_node_new(NULL, serd_a_uri_string(uri));
assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, node, NULL));
serd_node_free(NULL, node);
@@ -503,9 +508,9 @@ test_write_bad_uri(void)
{
SerdWorld* world = serd_world_new(NULL);
SerdEnv* env = serd_env_new(NULL, serd_empty_string());
- SerdNode* s = serd_new_uri(NULL, serd_string("http://example.org/s"));
- SerdNode* p = serd_new_uri(NULL, serd_string("http://example.org/p"));
- SerdNode* rel = serd_new_uri(NULL, serd_string("rel"));
+ SerdNode* s = serd_node_new(NULL, serd_a_uri_string("http://example.org/s"));
+ SerdNode* p = serd_node_new(NULL, serd_a_uri_string("http://example.org/p"));
+ SerdNode* rel = serd_node_new(NULL, serd_a_uri_string("rel"));
SerdBuffer buffer = {NULL, NULL, 0};
SerdOutputStream output = serd_open_output_buffer(&buffer);