aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c112
1 files changed, 60 insertions, 52 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 3475d08e..857dd89b 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -90,7 +90,7 @@ check_file_uri(const char* hostname,
expected_path = path;
}
- SerdNode* node = serd_node_new_file_uri(path, hostname, escape);
+ SerdNode* node = serd_new_file_uri(path, hostname, escape);
const char* node_str = serd_node_get_string(node);
char* out_hostname = NULL;
char* out_path = serd_file_uri_parse(node_str, &out_hostname);
@@ -118,7 +118,7 @@ check_rel_uri(const char* uri,
const SerdNode* root,
const char* expected)
{
- SerdNode* rel = serd_node_new_relative_uri(uri, base, root);
+ SerdNode* rel = serd_new_relative_uri(uri, base, root);
const int ret = strcmp(serd_node_get_string(rel), expected);
serd_node_free(rel);
if (ret) {
@@ -160,7 +160,7 @@ main(void)
}
}
- // Test serd_node_new_decimal
+ // Test serd_new_decimal
const double dbl_test_nums[] = {
0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001, NAN, INFINITY
@@ -171,7 +171,7 @@ main(void)
};
for (unsigned i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) {
- SerdNode* node = serd_node_new_decimal(dbl_test_nums[i], 8, NULL);
+ SerdNode* node = serd_new_decimal(dbl_test_nums[i], 8, NULL);
const char* node_str = serd_node_get_string(node);
const bool pass = (node_str && dbl_test_strs[i])
? !strcmp(node_str, dbl_test_strs[i])
@@ -190,7 +190,7 @@ main(void)
serd_node_free(node);
}
- // Test serd_node_new_integer
+ // Test serd_new_integer
const long int_test_nums[] = {
0, -0, -23, 23, -12340, 1000, -1000
@@ -201,7 +201,7 @@ main(void)
};
for (unsigned i = 0; i < sizeof(int_test_nums) / sizeof(double); ++i) {
- SerdNode* node = serd_node_new_integer(int_test_nums[i], NULL);
+ SerdNode* node = serd_new_integer(int_test_nums[i], NULL);
const char* node_str = serd_node_get_string(node);
if (strcmp(node_str, (const char*)int_test_strs[i])) {
FAILF("Serialised `%s' != %s\n", node_str, int_test_strs[i]);
@@ -216,7 +216,7 @@ main(void)
serd_node_free(node);
}
- // Test serd_node_new_blob
+ // Test serd_new_blob
for (size_t size = 1; size < 256; ++size) {
uint8_t* data = (uint8_t*)malloc(size);
for (size_t i = 0; i < size; ++i) {
@@ -224,7 +224,7 @@ main(void)
}
size_t out_size;
- SerdNode* blob = serd_node_new_blob(data, size, size % 5, NULL);
+ SerdNode* blob = serd_new_blob(data, size, size % 5, NULL);
const char* blob_str = serd_node_get_string(blob);
uint8_t* out = (uint8_t*)serd_base64_decode(
blob_str, serd_node_get_length(blob), &out_size);
@@ -309,14 +309,14 @@ main(void)
// Test serd_node_equals
const uint8_t replacement_char_str[] = { 0xEF, 0xBF, 0xBD, 0 };
- SerdNode* lhs = serd_node_new_string((const char*)replacement_char_str);
- SerdNode* rhs = serd_node_new_string("123");
+ SerdNode* lhs = serd_new_string((const char*)replacement_char_str);
+ SerdNode* rhs = serd_new_string("123");
if (serd_node_equals(lhs, rhs)) {
FAILF("%s == %s\n",
serd_node_get_string(lhs), serd_node_get_string(rhs));
}
- SerdNode* qnode = serd_node_new_curie("foo:bar");
+ SerdNode* qnode = serd_new_curie("foo:bar");
if (serd_node_equals(lhs, qnode)) {
FAILF("%s == %s\n",
serd_node_get_string(lhs), serd_node_get_string(qnode));
@@ -335,34 +335,43 @@ main(void)
serd_node_free(lhs);
serd_node_free(rhs);
- // Test serd_node_new_string
+ // Test serd_new_string
- SerdNode* hello = serd_node_new_string("hello\"");
+ SerdNode* hello = serd_new_string("hello\"");
if (serd_node_get_length(hello) != 6 ||
serd_node_get_flags(hello) != SERD_HAS_QUOTE ||
strcmp(serd_node_get_string(hello), "hello\"")) {
FAILF("Bad node %s\n", serd_node_get_string(hello));
}
- if (serd_node_new_string(NULL)) {
+ if (serd_new_string(NULL)) {
FAIL("Successfully created node from NULL string\n");
}
- // Test serd_node_new_literal
+ // Test serd_new_literal
- if (serd_node_new_literal(NULL, NULL, NULL)) {
- FAIL("Successfully created node from NULL string\n");
+ if (serd_new_plain_literal(NULL, NULL)) {
+ FAIL("Successfully created plain literal from NULL string\n");
+ } else if (serd_new_typed_literal(NULL, NULL)) {
+ FAIL("Successfully created typed literal from NULL string\n");
}
- SerdNode* hello2 = serd_node_new_literal("hello\"", NULL, NULL);
+ SerdNode* hello2 = serd_new_string("hello\"");
if (serd_node_get_length(hello2) != 6 ||
serd_node_get_flags(hello2) != SERD_HAS_QUOTE ||
strcmp(serd_node_get_string(hello2), "hello\"")) {
FAILF("Bad node %s\n", serd_node_get_string(hello2));
}
+
+ SerdNode* hello3 = serd_new_plain_literal("hello\"", NULL);
+ if (!serd_node_equals(hello2, hello3)) {
+ FAIL("Plain literal does not match equivalent string\n");
+ }
+
+ serd_node_free(hello3);
serd_node_free(hello2);
- SerdNode* hello_l = serd_node_new_literal("hello_l\"", NULL, "en");
+ SerdNode* hello_l = serd_new_plain_literal("hello_l\"", "en");
if (serd_node_get_length(hello_l) != 8 ||
strcmp(serd_node_get_string(hello_l), "hello_l\"") ||
serd_node_get_flags(hello_l) != (SERD_HAS_QUOTE | SERD_HAS_LANGUAGE) ||
@@ -371,11 +380,10 @@ main(void)
}
serd_node_free(hello_l);
- SerdNode* eg_Thing = serd_node_new_uri("http://example.org/Thing");
+ SerdNode* eg_Thing = serd_new_uri("http://example.org/Thing");
- SerdNode* hello_dt =
- serd_node_new_literal("hello_dt\"", eg_Thing, NULL);
- if (serd_node_get_length(hello_dt) != 9 ||
+ SerdNode* hello_dt = serd_new_typed_literal("hello_dt\"", eg_Thing);
+ if (serd_node_get_length(hello_dt) != 9 ||
strcmp(serd_node_get_string(hello_dt), "hello_dt\"") ||
serd_node_get_flags(hello_dt) != (SERD_HAS_QUOTE | SERD_HAS_DATATYPE) ||
strcmp(serd_node_get_string(serd_node_get_datatype(hello_dt)),
@@ -387,18 +395,18 @@ main(void)
// Test absolute URI creation
- if (serd_node_new_uri(NULL)) {
+ if (serd_new_uri(NULL)) {
FAIL("Successfully created NULL URI\n");
}
- SerdNode* not_a_uri = serd_node_new_string("hello");
- SerdNode* root = serd_node_new_uri("http://example.org/a/b/");
- SerdNode* base = serd_node_new_uri("http://example.org/a/b/c/");
- SerdNode* nil = serd_node_new_resolved_uri(NULL, base);
- SerdNode* nil2 = serd_node_new_resolved_uri("", base);
- if (serd_node_new_resolved_uri("", NULL)) {
+ SerdNode* not_a_uri = serd_new_string("hello");
+ SerdNode* root = serd_new_uri("http://example.org/a/b/");
+ SerdNode* base = serd_new_uri("http://example.org/a/b/c/");
+ SerdNode* nil = serd_new_resolved_uri(NULL, base);
+ SerdNode* nil2 = serd_new_resolved_uri("", base);
+ if (serd_new_resolved_uri("", NULL)) {
FAIL("Successfully created URI resolved against NULL\n");
- } else if (serd_node_new_resolved_uri("", not_a_uri)) {
+ } else if (serd_new_resolved_uri("", not_a_uri)) {
FAIL("Successfully created URI resolved against non-URI\n");
} else if (serd_node_get_type(nil) != SERD_URI ||
strcmp(serd_node_get_string(nil), serd_node_get_string(base)) ||
@@ -434,7 +442,7 @@ main(void)
FAIL("Successfully resolved against a non-URI\n");
}
- SerdNode* rel = serd_node_new_relative_uri(
+ SerdNode* rel = serd_new_relative_uri(
"http://example.org/a/b/c/foo", base, NULL);
SerdNode* resolved = serd_node_resolve(rel, base);
if (strcmp(serd_node_get_string(resolved),
@@ -451,13 +459,13 @@ main(void)
serd_node_free(base);
serd_node_free(root);
- // Test serd_node_new_blank
+ // Test serd_new_blank
- if (serd_node_new_blank(NULL)) {
+ if (serd_new_blank(NULL)) {
FAIL("Successfully created blank node from NULL string\n");
}
- SerdNode* blank = serd_node_new_blank("b0");
+ SerdNode* blank = serd_new_blank("b0");
if (serd_node_get_length(blank) != 2 ||
serd_node_get_flags(blank) != 0 ||
strcmp(serd_node_get_string(blank), "b0")) {
@@ -469,9 +477,9 @@ main(void)
SerdWorld* world = serd_world_new();
- SerdNode* u = serd_node_new_uri("http://example.org/foo");
- SerdNode* b = serd_node_new_curie("invalid");
- SerdNode* c = serd_node_new_curie("eg.2:b");
+ SerdNode* u = serd_new_uri("http://example.org/foo");
+ SerdNode* b = serd_new_curie("invalid");
+ SerdNode* c = serd_new_curie("eg.2:b");
SerdEnv* env = serd_env_new(NULL);
serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
@@ -509,7 +517,7 @@ main(void)
}
serd_node_free(xu);
- SerdNode* badpre = serd_node_new_curie("hm:what");
+ SerdNode* badpre = serd_new_curie("hm:what");
SerdNode* xbadpre = serd_env_expand_node(env, badpre);
if (xbadpre) {
FAILF("Expanded invalid curie %s\n", serd_node_get_string(badpre));
@@ -527,7 +535,7 @@ main(void)
FAIL("Set NULL prefix\n");
}
- SerdNode* lit = serd_node_new_string("hello");
+ SerdNode* lit = serd_new_string("hello");
if (!serd_env_set_prefix(env, b, lit)) {
FAIL("Set prefix to literal\n");
}
@@ -539,7 +547,7 @@ main(void)
FAILF("Bad prefix count %d\n", n_prefixes);
}
- SerdNode* shorter_uri = serd_node_new_uri("urn:foo");
+ SerdNode* shorter_uri = serd_new_uri("urn:foo");
const SerdNode* prefix_name;
if (serd_env_qualify(env, shorter_uri, &prefix_name, &suffix)) {
FAILF("Qualified %s\n", serd_node_get_string(shorter_uri));
@@ -583,9 +591,9 @@ main(void)
}
uint8_t buf[] = { 0xEF, 0xBF, 0xBD, 0 };
- SerdNode* s = serd_node_new_uri("");
- SerdNode* p = serd_node_new_uri("http://example.org/pred");
- SerdNode* o = serd_node_new_string((char*)buf);
+ SerdNode* s = serd_new_uri("");
+ SerdNode* p = serd_new_uri("http://example.org/pred");
+ SerdNode* o = serd_new_string((char*)buf);
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][5] = { { s, p, NULL },
@@ -605,10 +613,10 @@ main(void)
}
}
- SerdNode* urn_Type = serd_node_new_uri("urn:Type");
+ SerdNode* urn_Type = serd_new_uri("urn:Type");
- SerdNode* t = serd_node_new_literal((char*)buf, urn_Type, NULL);
- SerdNode* l = serd_node_new_literal((char*)buf, NULL, "en");
+ SerdNode* t = serd_new_typed_literal((char*)buf, urn_Type);
+ SerdNode* l = serd_new_plain_literal((char*)buf, "en");
const SerdNode* good[][5] = { { s, p, o },
{ s, p, o },
{ s, p, t },
@@ -628,8 +636,8 @@ main(void)
// Write statements with bad UTF-8 (should be replaced)
const char bad_str[] = { (char)0xFF, (char)0x90, 'h', 'i', 0 };
- SerdNode* bad_lit = serd_node_new_string(bad_str);
- SerdNode* bad_uri = serd_node_new_uri(bad_str);
+ SerdNode* bad_lit = serd_new_string(bad_str);
+ SerdNode* bad_uri = serd_new_uri(bad_str);
if (serd_sink_write_nodes(iface, 0, s, p, bad_lit, 0)) {
FAIL("Failed to write junk UTF-8 literal\n");
} else if (serd_sink_write_nodes(iface, 0, s, p, bad_uri, 0)) {
@@ -640,7 +648,7 @@ main(void)
// Write 1 valid statement
serd_node_free(o);
- o = serd_node_new_string("hello");
+ o = serd_new_string("hello");
if (serd_sink_write_nodes(iface, 0, s, p, o, 0)) {
FAIL("Failed to write valid statement\n");
}
@@ -659,7 +667,7 @@ main(void)
writer = serd_writer_new(
world, SERD_TURTLE, (SerdStyle)0, env, serd_buffer_sink, &buffer);
- o = serd_node_new_uri("http://example.org/base");
+ o = serd_new_uri("http://example.org/base");
if (serd_writer_set_base_uri(writer, o)) {
FAIL("Failed to write to chunk sink\n");
}
@@ -684,7 +692,7 @@ main(void)
FAIL("Failed to create reader\n");
}
- SerdNode* g = serd_node_new_uri("http://example.org/");
+ SerdNode* g = serd_new_uri("http://example.org/");
serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");
serd_reader_add_blank_prefix(reader, NULL);