aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-04-28 19:41:47 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit65cc6abed4c9e8e424f919ba876dcf535a0677ec (patch)
treea99aca5302d5c31c7b7c3b79cd6ac0a5b545285e
parent44e792d8da5ef93a88dac76b7b191e588203c42b (diff)
downloadserd-65cc6abed4c9e8e424f919ba876dcf535a0677ec.tar.gz
serd-65cc6abed4c9e8e424f919ba876dcf535a0677ec.tar.bz2
serd-65cc6abed4c9e8e424f919ba876dcf535a0677ec.zip
Add test for failure while writing a list from a model
-rw-r--r--tests/model_test.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/model_test.c b/tests/model_test.c
index aa3af753..694fc119 100644
--- a/tests/model_test.c
+++ b/tests/model_test.c
@@ -29,6 +29,7 @@
#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
#define RDF_FIRST NS_RDF "first"
#define RDF_REST NS_RDF "rest"
+#define RDF_NIL NS_RDF "nil"
#define N_OBJECTS_PER 2U
@@ -751,6 +752,72 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads)
return 0;
}
+typedef struct {
+ size_t n_written;
+ size_t max_successes;
+} FailingWriteFuncState;
+
+/// Write function that fails after a certain number of writes
+static size_t
+failing_write_func(const void* buf, size_t size, size_t nmemb, void* stream)
+{
+ (void)buf;
+ (void)size;
+ (void)nmemb;
+
+ FailingWriteFuncState* state = (FailingWriteFuncState*)stream;
+
+ return (++state->n_written > state->max_successes) ? 0 : nmemb;
+}
+
+static int
+test_write_error_in_list(SerdWorld* world, const unsigned n_quads)
+{
+ (void)n_quads;
+
+ serd_world_set_log_func(world, expected_error, NULL);
+
+ SerdModel* model = serd_model_new(world, SERD_INDEX_SPO);
+ SerdNodes* nodes = serd_nodes_new();
+ const SerdNode* s = manage(world, serd_new_uri("urn:s"));
+ const SerdNode* p = manage(world, serd_new_uri("urn:p"));
+ const SerdNode* l1 = manage(world, serd_new_blank("l1"));
+ const SerdNode* one = manage(world, serd_new_integer(1, NULL));
+ const SerdNode* l2 = manage(world, serd_new_blank("l2"));
+ const SerdNode* two = manage(world, serd_new_integer(2, NULL));
+ const SerdNode* rdf_first = manage(world, serd_new_uri(RDF_FIRST));
+ const SerdNode* rdf_rest = manage(world, serd_new_uri(RDF_REST));
+ const SerdNode* rdf_nil = manage(world, serd_new_uri(RDF_NIL));
+
+ serd_model_add(model, s, p, l1, NULL);
+ serd_model_add(model, l1, rdf_first, one, NULL);
+ serd_model_add(model, l1, rdf_rest, l2, NULL);
+ serd_model_add(model, l2, rdf_first, two, NULL);
+ serd_model_add(model, l2, rdf_rest, rdf_nil, NULL);
+
+ SerdEnv* env = serd_env_new(NULL);
+
+ for (size_t max_successes = 0; max_successes < 21; ++max_successes) {
+ FailingWriteFuncState state = {0, max_successes};
+ SerdWriter* writer = serd_writer_new(
+ world, SERD_TURTLE, 0, env, failing_write_func, &state);
+
+ const SerdSink* const sink = serd_writer_get_sink(writer);
+ SerdRange* const all = serd_model_all(model);
+ const SerdStatus st = serd_range_serialise(all, sink, 0);
+ serd_range_free(all);
+
+ assert(st == SERD_ERR_BAD_WRITE);
+
+ serd_writer_free(writer);
+ }
+
+ serd_env_free(env);
+ serd_model_free(model);
+ serd_nodes_free(nodes);
+ return 0;
+}
+
int
main(void)
{
@@ -779,6 +846,7 @@ main(void)
test_remove_graph,
test_default_graph,
test_write_bad_list,
+ test_write_error_in_list,
NULL};
SerdWorld* world = serd_world_new();