aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-04-28 16:36:02 +0200
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commit01daa5914169d57a6a6c4925d3f8d76db80a2bd8 (patch)
tree468a3371fe17adc082e93f7894147c5d67ed47fe /test
parent36e2f27502524155e6475a75ffcab4999fce166a (diff)
downloadserd-01daa5914169d57a6a6c4925d3f8d76db80a2bd8.tar.gz
serd-01daa5914169d57a6a6c4925d3f8d76db80a2bd8.tar.bz2
serd-01daa5914169d57a6a6c4925d3f8d76db80a2bd8.zip
Report writer errors and add strict write mode
Diffstat (limited to 'test')
-rw-r--r--test/test_reader_writer.c37
-rw-r--r--test/test_string.c2
2 files changed, 38 insertions, 1 deletions
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index 8cbce04e..fec09ff8 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -145,6 +145,42 @@ test_get_blank(void)
return 0;
}
+static int
+test_strict_write(void)
+{
+ SerdWorld* world = serd_world_new();
+ const char* path = "serd_strict_write_test.ttl";
+ FILE* fd = fopen(path, "wb");
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdWriter* writer = serd_writer_new(
+ world, SERD_TURTLE, SERD_WRITE_STRICT, env, (SerdWriteFunc)fwrite, fd);
+
+ assert(fd);
+ assert(writer);
+
+ const SerdSink* sink = serd_writer_sink(writer);
+ const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
+ const SerdStringView bad_view = {(const char*)bad_str, 4};
+
+ SerdNode* s = serd_new_uri(SERD_STATIC_STRING("http://example.org/s"));
+ SerdNode* p = serd_new_uri(SERD_STATIC_STRING("http://example.org/s"));
+ SerdNode* bad_lit = serd_new_string(bad_view);
+ SerdNode* bad_uri = serd_new_uri(bad_view);
+
+ assert(serd_sink_write(sink, 0, s, p, bad_lit, 0) == SERD_ERR_BAD_TEXT);
+ assert(serd_sink_write(sink, 0, s, p, bad_uri, 0) == SERD_ERR_BAD_TEXT);
+ serd_node_free(bad_uri);
+ serd_node_free(bad_lit);
+ serd_node_free(s);
+ serd_node_free(p);
+
+ serd_writer_free(writer);
+ serd_env_free(env);
+ fclose(fd);
+ serd_world_free(world);
+ return 0;
+}
+
static void
test_read_string(void)
{
@@ -361,6 +397,7 @@ main(void)
test_read_chunks();
test_read_string();
test_get_blank();
+ test_strict_write();
const char* const path = "serd_test.ttl";
test_writer(path);
diff --git a/test/test_string.c b/test/test_string.c
index 472b464a..2456e17a 100644
--- a/test/test_string.c
+++ b/test/test_string.c
@@ -39,7 +39,7 @@ test_strerror(void)
{
const char* msg = serd_strerror(SERD_SUCCESS);
assert(!strcmp(msg, "Success"));
- for (int i = SERD_FAILURE; i <= SERD_ERR_NO_DATA; ++i) {
+ for (int i = SERD_FAILURE; i <= SERD_ERR_BAD_WRITE; ++i) {
msg = serd_strerror((SerdStatus)i);
assert(strcmp(msg, "Success"));
}