aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_reader_writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-29 18:29:03 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit5c02da92038072f28408854e862fc2d4edf765d4 (patch)
tree34577415801279981b626b18c1dc69dc79afea7f /test/test_reader_writer.c
parent672e90382da08efa8f593fdc9081e31d0e548fa0 (diff)
downloadserd-5c02da92038072f28408854e862fc2d4edf765d4.tar.gz
serd-5c02da92038072f28408854e862fc2d4edf765d4.tar.bz2
serd-5c02da92038072f28408854e862fc2d4edf765d4.zip
Simplify node construction API
Diffstat (limited to 'test/test_reader_writer.c')
-rw-r--r--test/test_reader_writer.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 245f5328..b1121cbc 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -13,6 +13,7 @@
#include "serd/statement.h"
#include "serd/status.h"
#include "serd/stream.h"
+#include "serd/string_view.h"
#include "serd/syntax.h"
#include "serd/writer.h"
@@ -414,9 +415,9 @@ test_write_errors(void)
ctx.n_written = 0;
ctx.error_offset = o;
- SerdEnv* const env = serd_env_new(NULL);
+ SerdEnv* const env = serd_env_new(serd_empty_string());
SerdWriter* const writer =
- serd_writer_new(syntax, style, env, NULL, faulty_sink, &ctx);
+ serd_writer_new(syntax, style, env, faulty_sink, &ctx);
SerdReader* const reader =
serd_reader_new(SERD_TRIG,
@@ -444,27 +445,28 @@ static void
test_writer(const char* const path)
{
FILE* fd = fopen(path, "wb");
- SerdEnv* env = serd_env_new(NULL);
+ SerdEnv* env = serd_env_new(serd_empty_string());
assert(fd);
- SerdWriter* writer =
- serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_file_sink, fd);
+ SerdWriter* writer = serd_writer_new(SERD_TURTLE, 0, env, serd_file_sink, fd);
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
- SerdNode* lit = serd_new_string(SERD_LITERAL, "hello");
+ SerdNode* lit = serd_new_string(serd_string("hello"));
assert(serd_writer_set_base_uri(writer, lit));
assert(serd_writer_set_prefix(writer, lit, lit));
assert(serd_writer_end_anon(writer, NULL));
assert(serd_writer_env(writer) == env);
- uint8_t buf[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode* s = serd_new_string(SERD_URI, "");
- SerdNode* p = serd_new_string(SERD_URI, "http://example.org/pred");
- SerdNode* o = serd_new_string(SERD_LITERAL, (char*)buf);
+ static const uint8_t buf[] = {0xEF, 0xBF, 0xBD, 0};
+ const SerdStringView buf_view = {(const char*)buf, 3};
+
+ SerdNode* s = serd_new_uri(serd_empty_string());
+ SerdNode* p = serd_new_uri(serd_string("http://example.org/pred"));
+ SerdNode* o = serd_new_string(buf_view);
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][3] = {{s, o, o}, {o, p, o}, {s, o, p}};
@@ -473,26 +475,33 @@ test_writer(const char* const path)
writer, 0, NULL, junk[i][0], junk[i][1], junk[i][2]));
}
- SerdNode* t = serd_new_literal((char*)buf, "urn:Type", NULL);
- SerdNode* l = serd_new_literal((char*)buf, NULL, "en");
+ const SerdStringView empty = serd_empty_string();
+ const SerdStringView urn_Type = serd_string("urn:Type");
+ const SerdStringView en = serd_string("en");
+
+ SerdNode* const t = serd_new_literal(buf_view, urn_Type, empty);
+ SerdNode* const l = serd_new_literal(buf_view, empty, en);
const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}};
+
for (size_t i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 3); ++i) {
assert(!serd_writer_write_statement(
writer, 0, NULL, good[i][0], good[i][1], good[i][2]));
}
// Write statements with bad UTF-8 (should be replaced)
- const char bad_str[] = {(char)0xFF, (char)0x90, 'h', 'i', 0};
- SerdNode* bad_lit = serd_new_string(SERD_LITERAL, bad_str);
- SerdNode* bad_uri = serd_new_string(SERD_URI, bad_str);
+ const char bad_str[] = {(char)0xFF, (char)0x90, 'h', 'i', 0};
+ const SerdStringView bad_view = {(const char*)bad_str, 4};
+ SerdNode* bad_lit = serd_new_string(bad_view);
+ SerdNode* bad_uri = serd_new_uri(bad_view);
assert(!serd_writer_write_statement(writer, 0, NULL, s, p, bad_lit));
assert(!serd_writer_write_statement(writer, 0, NULL, s, p, bad_uri));
- serd_node_free(bad_lit);
+
serd_node_free(bad_uri);
+ serd_node_free(bad_lit);
// Write 1 valid statement
serd_node_free(o);
- o = serd_new_string(SERD_LITERAL, "hello");
+ o = serd_new_string(serd_string("hello"));
assert(!serd_writer_write_statement(writer, 0, NULL, s, p, o));
serd_writer_free(writer);
@@ -503,13 +512,13 @@ test_writer(const char* const path)
// Test buffer sink
SerdBuffer buffer = {NULL, 0};
- writer =
- serd_writer_new(SERD_TURTLE, 0, env, NULL, serd_buffer_sink, &buffer);
+ writer = serd_writer_new(SERD_TURTLE, 0, env, serd_buffer_sink, &buffer);
- o = serd_new_string(SERD_URI, "http://example.org/base");
- assert(!serd_writer_set_base_uri(writer, o));
+ SerdNode* const base = serd_new_uri(serd_string("http://example.org/base"));
- serd_node_free(o);
+ serd_writer_set_base_uri(writer, base);
+
+ serd_node_free(base);
serd_writer_free(writer);
char* out = serd_buffer_sink_finish(&buffer);
@@ -540,7 +549,7 @@ test_reader(const char* path)
assert(serd_reader_read_chunk(reader) == SERD_FAILURE);
- SerdNode* g = serd_new_string(SERD_URI, "http://example.org/");
+ SerdNode* g = serd_new_uri(serd_string("http://example.org/"));
serd_reader_set_default_graph(reader, g);
serd_reader_add_blank_prefix(reader, "tmp");