From bd24b8f6d558bafbbb16d9490ebe3478dbf130bd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 9 Sep 2021 13:57:43 -0400 Subject: Use more human-readable status codes --- test/test_env.c | 4 ++-- test/test_log.c | 2 +- test/test_model.c | 14 +++++++------- test/test_node.c | 2 +- test/test_overflow.c | 4 ++-- test/test_reader.c | 4 ++-- test/test_reader_writer.c | 4 ++-- test/test_sink.c | 4 ++-- test/test_string.c | 6 +++++- test/test_writer.c | 16 ++++++++-------- 10 files changed, 32 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/test_env.c b/test/test_env.c index 58455167..3b6e20c9 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -99,7 +99,7 @@ test_base_uri(void) // Try setting a relative prefix with no base URI assert(serd_env_set_prefix(env, SERD_STRING("eg.3"), SERD_STRING("rel")) == - SERD_ERR_BAD_ARG); + SERD_BAD_ARG); // Set a valid base URI assert(!serd_env_set_base_uri(env, serd_node_string_view(eg))); @@ -128,7 +128,7 @@ test_set_prefix(void) assert(!serd_env_set_prefix(env, name1, eg)); // Test setting a prefix from a relative URI - assert(serd_env_set_prefix(env, name2, rel) == SERD_ERR_BAD_ARG); + assert(serd_env_set_prefix(env, name2, rel) == SERD_BAD_ARG); assert(!serd_env_set_base_uri(env, base)); assert(!serd_env_set_prefix(env, name2, rel)); diff --git a/test/test_log.c b/test/test_log.c index 88d14dc6..707a00f2 100644 --- a/test/test_log.c +++ b/test/test_log.c @@ -52,7 +52,7 @@ test_bad_arg(void) serd_set_log_func(world, custom_log_func, &called); - assert(serd_logf(world, SERD_LOG_LEVEL_ERROR, "%s", "") == SERD_ERR_BAD_ARG); + assert(serd_logf(world, SERD_LOG_LEVEL_ERROR, "%s", "") == SERD_BAD_ARG); serd_world_free(world); } diff --git a/test/test_model.c b/test/test_model.c index 78372997..3e781c7e 100644 --- a/test/test_model.c +++ b/test/test_model.c @@ -164,7 +164,7 @@ test_read(SerdWorld* world, } // Attempt to increment past end - assert(serd_cursor_advance(cursor) == SERD_ERR_BAD_CURSOR); + assert(serd_cursor_advance(cursor) == SERD_BAD_CURSOR); serd_cursor_free(cursor); const SerdStringView s = SERD_STRING("hello"); @@ -453,7 +453,7 @@ test_add_with_iterator(SerdWorld* world, const unsigned n_quads) // Check that iterator has been invalidated assert(!serd_cursor_get(iter)); - assert(serd_cursor_advance(iter) == SERD_ERR_BAD_CURSOR); + assert(serd_cursor_advance(iter) == SERD_BAD_CURSOR); serd_cursor_free(iter); serd_model_free(model); @@ -543,7 +543,7 @@ test_remove_index(SerdWorld* world, const unsigned n_quads) const SerdNode* const o2 = uri(world, 3); // Try to remove default and non-existent indices - assert(serd_model_drop_index(model, SERD_ORDER_SPO) == SERD_ERR_BAD_CALL); + assert(serd_model_drop_index(model, SERD_ORDER_SPO) == SERD_BAD_CALL); assert(serd_model_drop_index(model, SERD_ORDER_PSO) == SERD_FAILURE); // Add a couple of statements so that dropping an index isn't trivial @@ -578,7 +578,7 @@ test_inserter(SerdWorld* world, const unsigned n_quads) serd_set_log_func(world, expected_error, NULL); - assert(serd_sink_write(inserter, 0, s, p, rel, NULL) == SERD_ERR_BAD_ARG); + assert(serd_sink_write(inserter, 0, s, p, rel, NULL) == SERD_BAD_ARG); serd_sink_free(inserter); serd_model_free(model); @@ -612,7 +612,7 @@ test_erase_with_iterator(SerdWorld* world, const unsigned n_quads) // Check that other iterator has been invalidated assert(!serd_cursor_get(iter2)); - assert(serd_cursor_advance(iter2) == SERD_ERR_BAD_CURSOR); + assert(serd_cursor_advance(iter2) == SERD_BAD_CURSOR); // Check that erasing the end iterator does nothing SerdCursor* const end = serd_cursor_copy(serd_model_end(model)); @@ -1290,7 +1290,7 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads) const SerdStatus st = serd_describe_range(all, sink, 0); serd_cursor_free(all); - assert(st == SERD_ERR_BAD_WRITE); + assert(st == SERD_BAD_WRITE); serd_writer_free(writer); serd_close_output(&out); @@ -1346,7 +1346,7 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads) const SerdStatus st = serd_describe_range(all, sink, 0); serd_cursor_free(all); - assert(st == SERD_ERR_BAD_WRITE); + assert(st == SERD_BAD_WRITE); serd_writer_free(writer); serd_close_output(&out); diff --git a/test/test_node.c b/test/test_node.c index 200791af..41ee6209 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -408,7 +408,7 @@ test_get_base64(void) char small[2] = {0}; const SerdWriteResult r = serd_get_base64(node, sizeof(small), small); - assert(r.status == SERD_ERR_OVERFLOW); + assert(r.status == SERD_OVERFLOW); serd_node_free(node); } diff --git a/test/test_overflow.c b/test/test_overflow.c index ca273b23..2aedc1bb 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -67,11 +67,11 @@ test_all_sizes(SerdWorld* const world, // Test with an increasingly smaller stack for (size_t size = max_stack_size; size > min_stack_size; --size) { if ((st = test_size(world, str, syntax, flags, size))) { - assert(st == SERD_ERR_OVERFLOW); + assert(st == SERD_BAD_STACK); } } - assert(st == SERD_ERR_OVERFLOW); + assert(st == SERD_BAD_STACK); } static void diff --git a/test/test_reader.c b/test/test_reader.c index 1c28e3da..37e645e3 100644 --- a/test/test_reader.c +++ b/test/test_reader.c @@ -74,12 +74,12 @@ test_prepare_error(void) SerdInputStream in = serd_open_input_stream(prepare_test_read, prepare_test_error, NULL, f); - assert(serd_reader_start(reader, &in, NULL, 0) == SERD_ERR_BAD_ARG); + assert(serd_reader_start(reader, &in, NULL, 0) == SERD_BAD_ARG); SerdStatus st = serd_reader_start(reader, &in, NULL, 1); assert(!st); - assert(serd_reader_read_document(reader) == SERD_ERR_UNKNOWN); + assert(serd_reader_read_document(reader) == SERD_BAD_READ); serd_close_input(&in); serd_reader_free(reader); diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 82af9f20..8bb76083 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -146,8 +146,8 @@ test_reader(const char* path) SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, env, sink, 4096); assert(reader); - assert(serd_reader_read_document(reader) == SERD_ERR_BAD_CALL); - assert(serd_reader_read_chunk(reader) == SERD_ERR_BAD_CALL); + assert(serd_reader_read_document(reader) == SERD_BAD_CALL); + assert(serd_reader_read_chunk(reader) == SERD_BAD_CALL); SerdInputStream in = serd_open_input_file(path); assert(!serd_reader_start(reader, &in, NULL, 4096)); diff --git a/test/test_sink.c b/test/test_sink.c index 29bb793f..8bbfbb2d 100644 --- a/test/test_sink.c +++ b/test/test_sink.c @@ -91,7 +91,7 @@ on_event(void* const handle, const SerdEvent* const event) return on_end(handle, event->end.node); } - return SERD_ERR_BAD_ARG; + return SERD_BAD_ARG; } static void @@ -157,7 +157,7 @@ test_callbacks(void) assert(serd_node_equals(state.last_end, blank)); const SerdEvent junk = {(SerdEventType)42}; - assert(serd_sink_write_event(sink, &junk) == SERD_ERR_BAD_ARG); + assert(serd_sink_write_event(sink, &junk) == SERD_BAD_ARG); serd_sink_free(sink); diff --git a/test/test_string.c b/test/test_string.c index f8534001..c91284bb 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -32,13 +32,17 @@ test_strerror(void) { const char* msg = serd_strerror(SERD_SUCCESS); assert(!strcmp(msg, "Success")); - for (int i = SERD_FAILURE; i <= SERD_ERR_INVALID; ++i) { + + for (int i = SERD_FAILURE; i <= SERD_BAD_WRITE; ++i) { msg = serd_strerror((SerdStatus)i); assert(strcmp(msg, "Success")); } msg = serd_strerror((SerdStatus)-1); assert(!strcmp(msg, "Unknown error")); + + msg = serd_strerror((SerdStatus)1000000); + assert(!strcmp(msg, "Unknown error")); } static void diff --git a/test/test_writer.c b/test/test_writer.c index 34eafbb2..c719642f 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -52,7 +52,7 @@ test_write_bad_event(void) const SerdEvent event = {(SerdEventType)42}; assert(serd_sink_write_event(serd_writer_sink(writer), &event) == - SERD_ERR_BAD_ARG); + SERD_BAD_ARG); assert(!serd_close_output(&output)); @@ -158,12 +158,12 @@ test_writer_stack_overflow(void) o = next_o; if (st) { - assert(st == SERD_ERR_OVERFLOW); + assert(st == SERD_BAD_STACK); break; } } - assert(st == SERD_ERR_OVERFLOW); + assert(st == SERD_BAD_STACK); serd_writer_free(writer); serd_close_output(&output); @@ -199,8 +199,8 @@ test_strict_write(void) const SerdNode* bad_lit = serd_nodes_string(nodes, bad_view); const SerdNode* bad_uri = serd_nodes_uri(nodes, 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); + assert(serd_sink_write(sink, 0, s, p, bad_lit, 0) == SERD_BAD_TEXT); + assert(serd_sink_write(sink, 0, s, p, bad_uri, 0) == SERD_BAD_TEXT); serd_writer_free(writer); serd_close_output(&output); @@ -250,7 +250,7 @@ test_write_error(void) assert(writer); SerdStatus st = serd_sink_write(serd_writer_sink(writer), 0u, s, p, o, NULL); - assert(st == SERD_ERR_BAD_WRITE); + assert(st == SERD_BAD_WRITE); serd_writer_free(writer); serd_close_output(&output); @@ -262,7 +262,7 @@ test_write_error(void) assert(writer); assert(serd_sink_write(serd_writer_sink(writer), 0u, s, p, o, NULL) == - SERD_ERR_BAD_WRITE); + SERD_BAD_WRITE); serd_writer_free(writer); serd_close_output(&output); @@ -337,7 +337,7 @@ test_write_bad_uri(void) serd_sink_write(serd_writer_sink(writer), 0u, s, p, rel, NULL); assert(st); - assert(st == SERD_ERR_BAD_ARG); + assert(st == SERD_BAD_ARG); serd_close_output(&output); serd_free(buffer.buf); -- cgit v1.2.1