aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-16 16:21:20 -0400
committerDavid Robillard <d@drobilla.net>2018-11-25 09:21:03 +0100
commit5e60861c65b84ef7569a26920a7ff2401c1e14d0 (patch)
tree7db2d30adf9044bd56c245b13dc730d5e4005043 /tests
parentd70d76deeb5735f97bb90792d5200ee812fb50b0 (diff)
downloadserd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.tar.gz
serd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.tar.bz2
serd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.zip
Use char* for strings in public API
The constant casting just makes user code a mess, for no benefit.
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c127
1 files changed, 61 insertions, 66 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c
index c65e44b7..ad8d20fc 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -25,8 +25,6 @@
#include "test_utils.h"
-#define USTR(s) ((const uint8_t*)(s))
-
#ifndef INFINITY
# define INFINITY (DBL_MAX + DBL_MAX)
#endif
@@ -89,11 +87,9 @@ check_file_uri(const char* hostname,
expected_path = path;
}
- SerdNode node = serd_node_new_file_uri(
- USTR(path), USTR(hostname), 0, escape);
-
- uint8_t* out_hostname = NULL;
- uint8_t* out_path = serd_file_uri_parse(node.buf, &out_hostname);
+ SerdNode node = serd_node_new_file_uri(path, hostname, 0, escape);
+ char* out_hostname = NULL;
+ char* out_path = serd_file_uri_parse(node.buf, &out_hostname);
int ret = 0;
if (strcmp((const char*)node.buf, expected_uri)) {
ret = FAILF("Bad URI %s != %s\n", node.buf, expected_uri);
@@ -156,13 +152,13 @@ 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);
const bool pass = (node.buf && dbl_test_strs[i])
- ? !strcmp((const char*)node.buf, (const char*)dbl_test_strs[i])
- : ((const char*)node.buf == dbl_test_strs[i]);
+ ? !strcmp(node.buf, dbl_test_strs[i])
+ : (node.buf == dbl_test_strs[i]);
if (!pass) {
FAILF("Serialised `%s' != %s\n",
node.buf, dbl_test_strs[i]);
}
- const size_t len = node.buf ? strlen((const char*)node.buf) : 0;
+ const size_t len = node.buf ? strlen(node.buf) : 0;
if (node.n_bytes != len) {
FAILF("Length %zu != %zu\n",
node.n_bytes, len);
@@ -186,7 +182,7 @@ main(void)
FAILF("Serialised `%s' != %s\n",
node.buf, int_test_strs[i]);
}
- const size_t len = strlen((const char*)node.buf);
+ const size_t len = strlen(node.buf);
if (node.n_bytes != len) {
FAILF("Length %zu,%zu != %zu\n",
node.n_bytes, len);
@@ -231,20 +227,20 @@ main(void)
const uint8_t str[] = { '"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0 };
SerdNodeFlags flags;
- size_t n_bytes = serd_strlen(str, &flags);
+ size_t n_bytes = serd_strlen((const char*)str, &flags);
if (n_bytes != 7 || flags != (SERD_HAS_QUOTE|SERD_HAS_NEWLINE)) {
FAILF("Bad serd_strlen(%s) n_bytes=%zu flags=%u\n",
str, n_bytes, flags);
}
- if (serd_strlen(str, NULL) != 7) {
+ if (serd_strlen((const char*)str, NULL) != 7) {
FAILF("Bad serd_strlen(%s) no flags\n", str, n_bytes);
}
// Test serd_strerror
- const uint8_t* msg = NULL;
- if (strcmp((const char*)(msg = serd_strerror(SERD_SUCCESS)), "Success")) {
+ const char* msg = NULL;
+ if (strcmp((msg = serd_strerror(SERD_SUCCESS)), "Success")) {
FAILF("Bad message `%s' for SERD_SUCCESS\n", msg);
}
for (int i = SERD_FAILURE; i <= SERD_ERR_INTERNAL; ++i) {
@@ -257,36 +253,36 @@ main(void)
// Test serd_uri_to_path
- const uint8_t* uri = (const uint8_t*)"file:///home/user/foo.ttl";
- if (strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")) {
+ const char* uri = "file:///home/user/foo.ttl";
+ if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file://localhost/home/user/foo.ttl";
- if (strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")) {
+ uri = "file://localhost/home/user/foo.ttl";
+ if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:illegal/file/uri";
+ uri = "file:illegal/file/uri";
if (serd_uri_to_path(uri)) {
FAILF("Converted invalid URI `%s' to path `%s'\n",
uri, serd_uri_to_path(uri));
}
- uri = (const uint8_t*)"file:///c:/awful/system";
+ uri = "file:///c:/awful/system";
if (strcmp((const char*)serd_uri_to_path(uri), "c:/awful/system")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:///c:awful/system";
+ uri = "file:///c:awful/system";
if (strcmp((const char*)serd_uri_to_path(uri), "/c:awful/system")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:///0/1";
+ uri = "file:///0/1";
if (strcmp((const char*)serd_uri_to_path(uri), "/0/1")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"C:\\Windows\\Sucks";
+ uri = "C:\\Windows\\Sucks";
if (strcmp((const char*)serd_uri_to_path(uri), "C:\\Windows\\Sucks")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"C|/Windows/Sucks";
+ uri = "C|/Windows/Sucks";
if (strcmp((const char*)serd_uri_to_path(uri), "C|/Windows/Sucks")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
@@ -310,9 +306,8 @@ main(void)
}
// Test tolerance of parsing junk URI escapes
-
- uint8_t* out_path = serd_file_uri_parse(USTR("file:///foo/%0Xbar"), NULL);
- if (strcmp((const char*)out_path, "/foo/bar")) {
+ char* out_path = serd_file_uri_parse("file:///foo/%0Xbar", NULL);
+ if (strcmp(out_path, "/foo/bar")) {
FAILF("bad tolerance of junk escape: `%s'\n", out_path);
}
serd_free(out_path);
@@ -320,13 +315,13 @@ main(void)
// Test serd_node_equals
const uint8_t replacement_char_str[] = { 0xEF, 0xBF, 0xBD, 0 };
- SerdNode lhs = serd_node_from_string(SERD_LITERAL, replacement_char_str);
- SerdNode rhs = serd_node_from_string(SERD_LITERAL, USTR("123"));
+ SerdNode lhs = serd_node_from_string(SERD_LITERAL, (const char*)replacement_char_str);
+ SerdNode rhs = serd_node_from_string(SERD_LITERAL, "123");
if (serd_node_equals(&lhs, &rhs)) {
FAILF("%s == %s\n", lhs.buf, rhs.buf);
}
- SerdNode qnode = serd_node_from_string(SERD_CURIE, USTR("foo:bar"));
+ SerdNode qnode = serd_node_from_string(SERD_CURIE, "foo:bar");
if (serd_node_equals(&lhs, &qnode)) {
FAILF("%s == %s\n", lhs.buf, qnode.buf);
}
@@ -342,7 +337,7 @@ main(void)
// Test serd_node_from_string
- SerdNode node = serd_node_from_string(SERD_LITERAL, (const uint8_t*)"hello\"");
+ SerdNode node = serd_node_from_string(SERD_LITERAL, "hello\"");
if (node.n_bytes != 6 || node.flags != SERD_HAS_QUOTE
|| strcmp((const char*)node.buf, "hello\"")) {
FAILF("Bad node %s %zu %d %d\n",
@@ -361,14 +356,14 @@ main(void)
FAIL("Successfully created node from NULL substring\n");
}
- SerdNode a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 3);
+ SerdNode a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 3);
if (a_b.n_bytes != 3 || a_b.flags != SERD_HAS_QUOTE
|| strncmp((const char*)a_b.buf, "a\"b", 3)) {
FAILF("Bad node %s %zu %d %d\n",
a_b.buf, a_b.n_bytes, a_b.flags, a_b.type);
}
- a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 10);
+ a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 10);
if (a_b.n_bytes != 4 || a_b.flags != SERD_HAS_QUOTE
|| strncmp((const char*)a_b.buf, "a\"bc", 4)) {
FAILF("Bad node %s %zu %zu %d %d\n",
@@ -383,10 +378,10 @@ main(void)
}
SerdURI base_uri;
- SerdNode base = serd_node_new_uri_from_string(USTR("http://example.org/"),
+ SerdNode base = serd_node_new_uri_from_string("http://example.org/",
NULL, &base_uri);
SerdNode nil = serd_node_new_uri_from_string(NULL, &base_uri, NULL);
- SerdNode nil2 = serd_node_new_uri_from_string(USTR(""), &base_uri, NULL);
+ SerdNode nil2 = serd_node_new_uri_from_string("", &base_uri, NULL);
if (nil.type != SERD_URI || strcmp((const char*)nil.buf, (const char*)base.buf) ||
nil2.type != SERD_URI || strcmp((const char*)nil2.buf, (const char*)base.buf)) {
FAILF("URI %s != base %s\n", nil.buf, base.buf);
@@ -395,7 +390,7 @@ main(void)
serd_node_free(&nil2);
// Test serd_node_new_relative_uri
- SerdNode abs = serd_node_from_string(SERD_URI, USTR("http://example.org/foo/bar"));
+ SerdNode abs = serd_node_from_string(SERD_URI, "http://example.org/foo/bar");
SerdURI abs_uri;
serd_uri_parse(abs.buf, &abs_uri);
@@ -415,7 +410,7 @@ main(void)
FAILF("Bad relative URI %s (expected 'http://example.org/')\n", noup.buf);
}
- SerdNode x = serd_node_from_string(SERD_URI, USTR("http://example.org/foo/x"));
+ SerdNode x = serd_node_from_string(SERD_URI, "http://example.org/foo/x");
SerdURI x_uri;
serd_uri_parse(x.buf, &x_uri);
@@ -432,11 +427,11 @@ main(void)
// Test SerdEnv
- SerdNode u = serd_node_from_string(SERD_URI, USTR("http://example.org/foo"));
- SerdNode b = serd_node_from_string(SERD_CURIE, USTR("invalid"));
- SerdNode c = serd_node_from_string(SERD_CURIE, USTR("eg.2:b"));
+ SerdNode u = serd_node_from_string(SERD_URI, "http://example.org/foo");
+ SerdNode b = serd_node_from_string(SERD_CURIE, "invalid");
+ SerdNode c = serd_node_from_string(SERD_CURIE, "eg.2:b");
SerdEnv* env = serd_env_new(NULL);
- serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
if (!serd_env_set_base_uri(env, NULL)) {
FAIL("Successfully set NULL base URI\n");
@@ -466,7 +461,7 @@ main(void)
}
serd_node_free(&xu);
- SerdNode badpre = serd_node_from_string(SERD_CURIE, USTR("hm:what"));
+ SerdNode badpre = serd_node_from_string(SERD_CURIE, "hm:what");
SerdNode xbadpre = serd_env_expand_node(env, &badpre);
if (!serd_node_equals(&xbadpre, &SERD_NODE_NULL)) {
FAILF("Expanded invalid curie %s\n", badpre.buf);
@@ -482,19 +477,19 @@ main(void)
FAIL("Set NULL prefix\n");
}
- const SerdNode lit = serd_node_from_string(SERD_LITERAL, USTR("hello"));
+ const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello");
if (!serd_env_set_prefix(env, &b, &lit)) {
FAIL("Set prefix to literal\n");
}
int n_prefixes = 0;
- serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
serd_env_foreach(env, count_prefixes, &n_prefixes);
if (n_prefixes != 1) {
FAILF("Bad prefix count %d\n", n_prefixes);
}
- SerdNode shorter_uri = serd_node_from_string(SERD_URI, USTR("urn:foo"));
+ SerdNode shorter_uri = serd_node_from_string(SERD_URI, "urn:foo");
SerdNode prefix_name;
if (serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix)) {
FAILF("Qualified %s\n", shorter_uri.buf);
@@ -514,7 +509,7 @@ main(void)
FAIL("Failed to create writer\n");
}
- serd_writer_chop_blank_prefix(writer, USTR("tmp"));
+ serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
if (!serd_writer_set_base_uri(writer, &lit)) {
@@ -527,10 +522,10 @@ main(void)
FAIL("Writer has incorrect env\n");
}
- uint8_t buf[] = { 0x80, 0, 0, 0, 0 };
- SerdNode s = serd_node_from_string(SERD_URI, USTR(""));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/pred"));
- SerdNode o = serd_node_from_string(SERD_LITERAL, buf);
+ uint8_t buf[] = { 0xEF, 0xBF, 0xBD, 0 };
+ SerdNode s = serd_node_from_string(SERD_URI, "");
+ SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/pred");
+ SerdNode o = serd_node_from_string(SERD_LITERAL, (char*)buf);
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][5] = { { &s, &p, NULL, NULL, NULL },
@@ -551,8 +546,8 @@ main(void)
}
}
- const SerdNode t = serd_node_from_string(SERD_URI, USTR("urn:Type"));
- const SerdNode l = serd_node_from_string(SERD_LITERAL, USTR("en"));
+ const SerdNode t = serd_node_from_string(SERD_URI, "urn:Type");
+ const SerdNode l = serd_node_from_string(SERD_LITERAL, "en");
const SerdNode* good[][5] = { { &s, &p, &o, NULL, NULL },
{ &s, &p, &o, &SERD_NODE_NULL, &SERD_NODE_NULL },
{ &s, &p, &o, &t, NULL },
@@ -572,9 +567,9 @@ main(void)
}
// Write statements with bad UTF-8 (should be replaced)
- const uint8_t bad_str[] = { 0xFF, 0x90, 'h', 'i', 0 };
- SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
- SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
+ const char bad_str[] = { (char)0xFF, (char)0x90, 'h', 'i', 0 };
+ SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
+ SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
if (serd_writer_write_statement(writer, 0, NULL,
&s, &p, &bad_lit, NULL, NULL)) {
FAIL("Failed to write junk UTF-8 literal\n");
@@ -584,7 +579,7 @@ main(void)
}
// Write 1 valid statement
- o = serd_node_from_string(SERD_LITERAL, USTR("hello"));
+ o = serd_node_from_string(SERD_LITERAL, "hello");
if (serd_writer_write_statement(writer, 0, NULL,
&s, &p, &o, NULL, NULL)) {
FAIL("Failed to write valid statement\n");
@@ -597,13 +592,13 @@ main(void)
writer = serd_writer_new(
SERD_TURTLE, (SerdStyle)0, env, NULL, serd_buffer_sink, &buffer);
- o = serd_node_from_string(SERD_URI, USTR("http://example.org/base"));
+ o = serd_node_from_string(SERD_URI, "http://example.org/base");
if (serd_writer_set_base_uri(writer, &o)) {
FAIL("Failed to write to chunk sink\n");
}
serd_writer_free(writer);
- uint8_t* out = serd_buffer_sink_finish(&buffer);
+ char* out = serd_buffer_sink_finish(&buffer);
if (strcmp((const char*)out, "@base <http://example.org/base> .\n")) {
FAILF("Incorrect buffer output:\n%s\n", buffer.buf);
@@ -625,20 +620,20 @@ main(void)
FAIL("Corrupt reader handle\n");
}
- SerdNode g = serd_node_from_string(SERD_URI, USTR("http://example.org/"));
+ SerdNode g = serd_node_from_string(SERD_URI, "http://example.org/");
serd_reader_set_default_graph(reader, &g);
- serd_reader_add_blank_prefix(reader, USTR("tmp"));
+ serd_reader_add_blank_prefix(reader, "tmp");
serd_reader_add_blank_prefix(reader, NULL);
- if (!serd_reader_read_file(reader, USTR("http://notafile"))) {
+ if (!serd_reader_read_file(reader, "http://notafile")) {
FAIL("Apparently read an http URI\n");
- } else if (!serd_reader_read_file(reader, USTR("file:///better/not/exist"))) {
+ } else if (!serd_reader_read_file(reader, "file:///better/not/exist")) {
FAIL("Apparently read a non-existent file\n");
- } else if (!serd_reader_read_file(reader, USTR("file://"))) {
+ } else if (!serd_reader_read_file(reader, "file://")) {
FAIL("Apparently read a file with no path\n");
}
- const SerdStatus st = serd_reader_read_file(reader, USTR(path));
+ const SerdStatus st = serd_reader_read_file(reader, path);
if (st) {
FAILF("Error reading file (%s)\n", serd_strerror(st));
} else if (rt->n_statements != 13) {
@@ -648,7 +643,7 @@ main(void)
FAILF("Bad graph %p\n", rt->graph);
}
- if (!serd_reader_read_string(reader, USTR("This isn't Turtle at all."))) {
+ if (!serd_reader_read_string(reader, "This isn't Turtle at all.")) {
FAIL("Parsed invalid string successfully.\n");
}