diff options
author | David Robillard <d@drobilla.net> | 2023-08-30 20:43:05 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d (patch) | |
tree | d7be35c7b4b3d466049352f2975e2c88c298f4b8 /test | |
parent | b13ad41a4d65b577b4db67660a9edf3056bdf7af (diff) | |
download | serd-258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d.tar.gz serd-258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d.tar.bz2 serd-258ea2ff59bbd2127ea446cf4b9676ad3d7fe53d.zip |
Use ZixStringView directly
Diffstat (limited to 'test')
-rw-r--r-- | test/headers/.clang-tidy | 2 | ||||
-rw-r--r-- | test/test_canon.c | 17 | ||||
-rw-r--r-- | test/test_env.c | 108 | ||||
-rw-r--r-- | test/test_log.c | 4 | ||||
-rw-r--r-- | test/test_model.c | 73 | ||||
-rw-r--r-- | test/test_node.c | 86 | ||||
-rw-r--r-- | test/test_node_syntax.c | 27 | ||||
-rw-r--r-- | test/test_nodes.c | 51 | ||||
-rw-r--r-- | test/test_overflow.c | 5 | ||||
-rw-r--r-- | test/test_reader.c | 26 | ||||
-rw-r--r-- | test/test_reader_writer.c | 21 | ||||
-rw-r--r-- | test/test_terse_write.c | 6 | ||||
-rw-r--r-- | test/test_uri.c | 19 | ||||
-rw-r--r-- | test/test_writer.c | 39 |
14 files changed, 248 insertions, 236 deletions
diff --git a/test/headers/.clang-tidy b/test/headers/.clang-tidy index 2d823c5a..36e379b5 100644 --- a/test/headers/.clang-tidy +++ b/test/headers/.clang-tidy @@ -8,5 +8,5 @@ Checks: > -modernize-macro-to-enum, -readability-identifier-length, WarningsAsErrors: '*' -HeaderFilterRegex: '.*' +HeaderFilterRegex: '.*/serd/.*\.h' FormatStyle: file diff --git a/test/test_canon.c b/test/test_canon.c index 89d1312b..ce3cfc67 100644 --- a/test/test_canon.c +++ b/test/test_canon.c @@ -11,8 +11,8 @@ #include "serd/nodes.h" #include "serd/sink.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/world.h" +#include "zix/string_view.h" #include <assert.h> #include <stddef.h> @@ -56,11 +56,13 @@ test_new_failed_alloc(void) static void test_write_failed_alloc(void) { - const SerdStringView s_string = serd_string("http://example.org/s"); - const SerdStringView p_string = serd_string("http://example.org/p"); - const SerdStringView o_string = serd_string("012.340"); - const SerdStringView xsd_float = - serd_string("http://www.w3.org/2001/XMLSchema#float"); +#define NS_EG "http://example.org/s" +#define NS_XSD "http://www.w3.org/2001/XMLSchema#" + + static const ZixStringView s_string = ZIX_STATIC_STRING(NS_EG "s"); + static const ZixStringView p_string = ZIX_STATIC_STRING(NS_EG "p"); + static const ZixStringView o_string = ZIX_STATIC_STRING("012.340"); + static const ZixStringView xsd_float = ZIX_STATIC_STRING(NS_XSD "float"); SerdFailingAllocator allocator = serd_failing_allocator(); SerdWorld* const world = serd_world_new(&allocator.base); @@ -92,6 +94,9 @@ test_write_failed_alloc(void) serd_sink_free(target); serd_nodes_free(nodes); serd_world_free(world); + +#undef NS_XSD +#undef NS_EG } int diff --git a/test/test_env.c b/test/test_env.c index 5a4c95df..9539798d 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -11,7 +11,7 @@ #include "serd/nodes.h" #include "serd/sink.h" #include "serd/status.h" -#include "serd/string_view.h" +#include "zix/string_view.h" #include <assert.h> #include <stdio.h> @@ -25,14 +25,14 @@ test_new_failed_alloc(void) SerdFailingAllocator allocator = serd_failing_allocator(); // Successfully allocate a env to count the number of allocations - SerdEnv* const env = serd_env_new(&allocator.base, serd_empty_string()); + SerdEnv* const env = serd_env_new(&allocator.base, zix_empty_string()); assert(env); // Test that each allocation failing is handled gracefully const size_t n_new_allocs = allocator.n_allocations; for (size_t i = 0; i < n_new_allocs; ++i) { allocator.n_remaining = i; - assert(!serd_env_new(&allocator.base, serd_empty_string())); + assert(!serd_env_new(&allocator.base, zix_empty_string())); } serd_env_free(env); @@ -47,9 +47,9 @@ test_copy_failed_alloc(void) SerdFailingAllocator allocator = serd_failing_allocator(); // Create a simple env - SerdEnv* const env = serd_env_new(&allocator.base, serd_empty_string()); - assert(!serd_env_set_prefix(env, serd_string(name), serd_string(uri))); - assert(!serd_env_set_base_uri(env, serd_string(uri))); + SerdEnv* const env = serd_env_new(&allocator.base, zix_empty_string()); + assert(!serd_env_set_prefix(env, zix_string(name), zix_string(uri))); + assert(!serd_env_set_base_uri(env, zix_string(uri))); // Successfully copy the env to count the number of allocations const size_t n_setup_allocs = allocator.n_allocations; @@ -70,7 +70,8 @@ test_copy_failed_alloc(void) static void test_set_prefix_absolute_failed_alloc(void) { - const SerdStringView base_uri = serd_string("http://example.org/"); + static const ZixStringView base_uri = + ZIX_STATIC_STRING("http://example.org/"); SerdFailingAllocator allocator = serd_failing_allocator(); @@ -83,7 +84,7 @@ test_set_prefix_absolute_failed_alloc(void) const size_t n_setup_allocs = allocator.n_allocations; // Successfully set an absolute prefix to count the number of allocations - st = serd_env_set_prefix(env, serd_string(name), serd_string(uri)); + st = serd_env_set_prefix(env, zix_string(name), zix_string(uri)); assert(st == SERD_SUCCESS); // Test that each allocation failing is handled gracefully @@ -94,7 +95,7 @@ test_set_prefix_absolute_failed_alloc(void) snprintf(name, sizeof(name), "eg%zu", i); snprintf(uri, sizeof(name), "http://example.org/%zu", i); - st = serd_env_set_prefix(env, serd_string(name), serd_string(uri)); + st = serd_env_set_prefix(env, zix_string(name), zix_string(uri)); assert(st == SERD_BAD_ALLOC); } @@ -104,7 +105,8 @@ test_set_prefix_absolute_failed_alloc(void) static void test_set_prefix_relative_failed_alloc(void) { - const SerdStringView base_uri = serd_string("http://example.org/"); + static const ZixStringView base_uri = + ZIX_STATIC_STRING("http://example.org/"); SerdFailingAllocator allocator = serd_failing_allocator(); @@ -113,7 +115,7 @@ test_set_prefix_relative_failed_alloc(void) // Successfully set an absolute prefix to count the number of allocations SerdEnv* env = serd_env_new(&allocator.base, base_uri); - SerdStatus st = serd_env_set_prefix(env, serd_string(name), serd_string(uri)); + SerdStatus st = serd_env_set_prefix(env, zix_string(name), zix_string(uri)); assert(st == SERD_SUCCESS); serd_env_free(env); @@ -127,7 +129,7 @@ test_set_prefix_relative_failed_alloc(void) env = serd_env_new(&allocator.base, base_uri); if (env) { - st = serd_env_set_prefix(env, serd_string(name), serd_string(uri)); + st = serd_env_set_prefix(env, zix_string(name), zix_string(uri)); assert(st == SERD_BAD_ALLOC); } @@ -141,22 +143,21 @@ test_copy(void) assert(!serd_env_copy(NULL, NULL)); SerdEnv* const env = - serd_env_new(NULL, serd_string("http://example.org/base/")); + serd_env_new(NULL, zix_string("http://example.org/base/")); - serd_env_set_prefix( - env, serd_string("eg"), serd_string("http://example.org/")); + serd_env_set_prefix(env, zix_string("eg"), zix_string("http://example.org/")); SerdEnv* const env_copy = serd_env_copy(NULL, env); assert(serd_env_equals(env, env_copy)); serd_env_set_prefix( - env_copy, serd_string("test"), serd_string("http://example.org/test")); + env_copy, zix_string("test"), zix_string("http://example.org/test")); assert(!serd_env_equals(env, env_copy)); serd_env_set_prefix( - env, serd_string("test2"), serd_string("http://example.org/test2")); + env, zix_string("test2"), zix_string("http://example.org/test2")); assert(!serd_env_equals(env, env_copy)); @@ -167,7 +168,7 @@ test_copy(void) static void test_comparison(void) { - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(!serd_env_equals(env, NULL)); assert(!serd_env_equals(NULL, env)); @@ -203,16 +204,16 @@ static void test_base_uri(void) { SerdNodes* const nodes = serd_nodes_new(NULL); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); const SerdNode* const eg = serd_nodes_get(nodes, serd_a_uri_string(NS_EG)); // Test that invalid calls work as expected assert(!serd_env_base_uri(env)); - assert(!serd_env_set_base_uri(env, serd_empty_string())); + assert(!serd_env_set_base_uri(env, zix_empty_string())); assert(!serd_env_base_uri(env)); // Try setting a relative prefix with no base URI - assert(serd_env_set_prefix(env, serd_string("eg.3"), serd_string("rel")) == + assert(serd_env_set_prefix(env, zix_string("eg.3"), zix_string("rel")) == SERD_BAD_ARG); // Set a valid base URI @@ -220,7 +221,7 @@ test_base_uri(void) assert(serd_node_equals(serd_env_base_uri(env), eg)); // Reset the base URI - assert(!serd_env_set_base_uri(env, serd_empty_string())); + assert(!serd_env_set_base_uri(env, zix_empty_string())); assert(!serd_env_base_uri(env)); serd_env_free(env); @@ -230,13 +231,13 @@ test_base_uri(void) static void test_set_prefix(void) { - const SerdStringView eg = serd_string(NS_EG); - const SerdStringView name1 = serd_string("eg.1"); - const SerdStringView name2 = serd_string("eg.2"); - const SerdStringView rel = serd_string("rel"); - const SerdStringView base = serd_string("http://example.org/"); + static const ZixStringView eg = ZIX_STATIC_STRING(NS_EG); + static const ZixStringView name1 = ZIX_STATIC_STRING("eg.1"); + static const ZixStringView name2 = ZIX_STATIC_STRING("eg.2"); + static const ZixStringView rel = ZIX_STATIC_STRING("rel"); + static const ZixStringView base = ZIX_STATIC_STRING("http://example.org/"); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); // Set a valid prefix assert(!serd_env_set_prefix(env, name1, eg)); @@ -248,7 +249,7 @@ test_set_prefix(void) // Test setting a prefix from strings assert(!serd_env_set_prefix( - env, serd_string("eg.3"), serd_string("http://example.org/three"))); + env, zix_string("eg.3"), zix_string("http://example.org/three"))); size_t n_prefixes = 0; SerdSink* const count_prefixes_sink = @@ -266,7 +267,7 @@ test_expand_untyped_literal(void) { SerdNodes* const nodes = serd_nodes_new(NULL); const SerdNode* const untyped = serd_nodes_get(nodes, serd_a_string("data")); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(!serd_env_expand_node(env, untyped)); @@ -277,14 +278,14 @@ test_expand_untyped_literal(void) static void test_expand_bad_uri_datatype(void) { - const SerdStringView type = serd_string("Type"); + static const ZixStringView type = ZIX_STATIC_STRING("Type"); SerdNodes* const nodes = serd_nodes_new(NULL); const SerdNode* const typed = - serd_nodes_get(nodes, serd_a_typed_literal(serd_string("data"), type)); + serd_nodes_get(nodes, serd_a_typed_literal(zix_string("data"), type)); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(!serd_env_expand_node(env, typed)); @@ -295,7 +296,7 @@ test_expand_bad_uri_datatype(void) static void test_expand_uri(void) { - const SerdStringView base = serd_string("http://example.org/b/"); + static const ZixStringView base = ZIX_STATIC_STRING("http://example.org/b/"); SerdNodes* const nodes = serd_nodes_new(NULL); SerdEnv* const env = serd_env_new(NULL, base); @@ -317,7 +318,7 @@ test_expand_uri(void) static void test_expand_empty_uri_ref(void) { - const SerdStringView base = serd_string("http://example.org/b/"); + static const ZixStringView base = ZIX_STATIC_STRING("http://example.org/b/"); SerdNodes* const nodes = serd_nodes_new(NULL); SerdEnv* const env = serd_env_new(NULL, base); @@ -335,7 +336,7 @@ static void test_expand_bad_uri(void) { SerdNodes* const nodes = serd_nodes_new(NULL); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); const SerdNode* const bad_uri = serd_nodes_get(nodes, serd_a_uri_string("rel")); @@ -349,15 +350,14 @@ test_expand_bad_uri(void) static void test_expand_curie(void) { - const SerdStringView name = serd_string("eg.1"); - const SerdStringView eg = serd_string(NS_EG); + static const ZixStringView name = ZIX_STATIC_STRING("eg.1"); + static const ZixStringView eg = ZIX_STATIC_STRING(NS_EG); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(!serd_env_set_prefix(env, name, eg)); - SerdNode* const expanded = - serd_env_expand_curie(env, serd_string("eg.1:foo")); + SerdNode* const expanded = serd_env_expand_curie(env, zix_string("eg.1:foo")); assert(expanded); assert(!strcmp(serd_node_string(expanded), "http://example.org/foo")); @@ -369,12 +369,12 @@ test_expand_curie(void) static void test_expand_bad_curie(void) { - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); - assert(!serd_env_expand_curie(NULL, serd_empty_string())); - assert(!serd_env_expand_curie(NULL, serd_string("what:ever"))); - assert(!serd_env_expand_curie(env, serd_string("eg.1:foo"))); - assert(!serd_env_expand_curie(env, serd_string("nocolon"))); + assert(!serd_env_expand_curie(NULL, zix_empty_string())); + assert(!serd_env_expand_curie(NULL, zix_string("what:ever"))); + assert(!serd_env_expand_curie(env, zix_string("eg.1:foo"))); + assert(!serd_env_expand_curie(env, zix_string("nocolon"))); serd_env_free(env); } @@ -384,9 +384,9 @@ test_expand_blank(void) { SerdNodes* const nodes = serd_nodes_new(NULL); const SerdNode* const blank = - serd_nodes_get(nodes, serd_a_blank(serd_string("b1"))); + serd_nodes_get(nodes, serd_a_blank(zix_string("b1"))); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(!serd_env_expand_node(env, blank)); @@ -397,9 +397,9 @@ test_expand_blank(void) static void test_equals(void) { - const SerdStringView name1 = serd_string("n1"); - const SerdStringView base1 = serd_string(NS_EG "b1/"); - const SerdStringView base2 = serd_string(NS_EG "b2/"); + static const ZixStringView name1 = ZIX_STATIC_STRING("n1"); + static const ZixStringView base1 = ZIX_STATIC_STRING(NS_EG "b1/"); + static const ZixStringView base2 = ZIX_STATIC_STRING(NS_EG "b2/"); SerdEnv* const env1 = serd_env_new(NULL, base1); SerdEnv* const env2 = serd_env_new(NULL, base2); @@ -412,11 +412,11 @@ test_equals(void) serd_env_set_base_uri(env2, base1); assert(serd_env_equals(env1, env2)); - assert(!serd_env_set_prefix(env1, name1, serd_string(NS_EG "n1"))); + assert(!serd_env_set_prefix(env1, name1, zix_string(NS_EG "n1"))); assert(!serd_env_equals(env1, env2)); - assert(!serd_env_set_prefix(env2, name1, serd_string(NS_EG "othern1"))); + assert(!serd_env_set_prefix(env2, name1, zix_string(NS_EG "othern1"))); assert(!serd_env_equals(env1, env2)); - assert(!serd_env_set_prefix(env2, name1, serd_string(NS_EG "n1"))); + assert(!serd_env_set_prefix(env2, name1, zix_string(NS_EG "n1"))); assert(serd_env_equals(env1, env2)); serd_env_set_base_uri(env2, base2); diff --git a/test/test_log.c b/test/test_log.c index aba9fe23..ca4343a2 100644 --- a/test/test_log.c +++ b/test/test_log.c @@ -7,8 +7,8 @@ #include "serd/log.h" #include "serd/node.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/world.h" +#include "zix/string_view.h" #include <assert.h> #include <stdbool.h> @@ -19,7 +19,7 @@ custom_log_func(void* const handle, const SerdLogLevel level, const size_t n_fields, const SerdLogField* const fields, - const SerdStringView message) + const ZixStringView message) { (void)message; diff --git a/test/test_model.c b/test/test_model.c index feb35440..2e3a7847 100644 --- a/test/test_model.c +++ b/test/test_model.c @@ -20,11 +20,11 @@ #include "serd/sink.h" #include "serd/statement.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" #include "serd/writer.h" #include "zix/attributes.h" +#include "zix/string_view.h" #include <assert.h> #include <stdbool.h> @@ -88,19 +88,19 @@ generate(SerdWorld* world, const SerdNode* hello = serd_nodes_get(nodes, serd_a_string("hello")); const SerdNode* hello_gb = serd_nodes_get( - nodes, serd_a_plain_literal(serd_string("hello"), serd_string("en-gb"))); + nodes, serd_a_plain_literal(zix_string("hello"), zix_string("en-gb"))); const SerdNode* hello_us = serd_nodes_get( - nodes, serd_a_plain_literal(serd_string("hello"), serd_string("en-us"))); + nodes, serd_a_plain_literal(zix_string("hello"), zix_string("en-us"))); const SerdNode* hello_t4 = serd_nodes_get(nodes, - serd_a_typed_literal(serd_string("hello"), + serd_a_typed_literal(zix_string("hello"), serd_node_string_view(uri(world, 4)))); const SerdNode* hello_t5 = serd_nodes_get(nodes, - serd_a_typed_literal(serd_string("hello"), + serd_a_typed_literal(zix_string("hello"), serd_node_string_view(uri(world, 5)))); assert(!serd_model_add(model, uri(world, 98), uri(world, 4), hello, graph)); @@ -127,10 +127,10 @@ generate(SerdWorld* world, // (14 6 "bonjour"@fr) and (14 6 "salut"@fr) const SerdNode* const bonjour = serd_nodes_get( - nodes, serd_a_plain_literal(serd_string("bonjour"), serd_string("fr"))); + nodes, serd_a_plain_literal(zix_string("bonjour"), zix_string("fr"))); const SerdNode* const salut = serd_nodes_get( - nodes, serd_a_plain_literal(serd_string("salut"), serd_string("fr"))); + nodes, serd_a_plain_literal(zix_string("salut"), zix_string("fr"))); assert(!serd_model_add(model, uri(world, 14), uri(world, 6), bonjour, graph)); assert(!serd_model_add(model, uri(world, 14), uri(world, 6), salut, graph)); @@ -140,7 +140,7 @@ generate(SerdWorld* world, // Add a blank node subject const SerdNode* ablank = - serd_nodes_get(nodes, serd_a_blank(serd_string("ablank"))); + serd_nodes_get(nodes, serd_a_blank(zix_string("ablank"))); assert(!serd_model_add(model, ablank, uri(world, 6), salut, graph)); @@ -177,7 +177,7 @@ test_read(SerdWorld* world, assert(serd_cursor_advance(cursor) == SERD_BAD_CURSOR); serd_cursor_free(NULL, cursor); - const SerdStringView s = serd_string("hello"); + static const ZixStringView s = ZIX_STATIC_STRING("hello"); const SerdNode* plain_hello = serd_nodes_get(nodes, serd_a_string_view(s)); @@ -188,10 +188,10 @@ test_read(SerdWorld* world, nodes, serd_a_typed_literal(s, serd_node_string_view(uri(world, 5)))); const SerdNode* gb_hello = - serd_nodes_get(nodes, serd_a_plain_literal(s, serd_string("en-gb"))); + serd_nodes_get(nodes, serd_a_plain_literal(s, zix_string("en-gb"))); const SerdNode* us_hello = - serd_nodes_get(nodes, serd_a_plain_literal(s, serd_string("en-us"))); + serd_nodes_get(nodes, serd_a_plain_literal(s, zix_string("en-us"))); #define NUM_PATTERNS 18 @@ -265,7 +265,7 @@ test_read(SerdWorld* world, // Query blank node subject const SerdNode* ablank = - serd_nodes_get(nodes, serd_a_blank(serd_string("ablank"))); + serd_nodes_get(nodes, serd_a_blank(zix_string("ablank"))); Quad pat = {ablank, 0, 0}; int num_results = 0; @@ -328,7 +328,7 @@ expected_error(void* const handle, const SerdLogLevel level, const size_t n_fields, const SerdLogField* const fields, - const SerdStringView message) + const ZixStringView message) { (void)level; (void)n_fields; @@ -344,7 +344,7 @@ ignore_only_index_error(void* const handle, const SerdLogLevel level, const size_t n_fields, const SerdLogField* const fields, - const SerdStringView message) + const ZixStringView message) { (void)handle; (void)level; @@ -761,8 +761,7 @@ test_add_with_caret(SerdWorld* world, const unsigned n_quads) const SerdNode* lit = serd_nodes_get(nodes, serd_a_string("string")); const SerdNode* uri = serd_nodes_get(nodes, serd_a_uri_string("urn:uri")); - const SerdNode* blank = - serd_nodes_get(nodes, serd_a_blank(serd_string("b1"))); + const SerdNode* blank = serd_nodes_get(nodes, serd_a_blank(zix_string("b1"))); SerdModel* model = serd_model_new(world, SERD_ORDER_SPO, 0U); @@ -1097,8 +1096,8 @@ test_write_flat_range(SerdWorld* world, const unsigned n_quads) const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("urn:s")); const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p")); - const SerdNode* b1 = serd_nodes_get(nodes, serd_a_blank(serd_string("b1"))); - const SerdNode* b2 = serd_nodes_get(nodes, serd_a_blank(serd_string("b2"))); + const SerdNode* b1 = serd_nodes_get(nodes, serd_a_blank(zix_string("b1"))); + const SerdNode* b2 = serd_nodes_get(nodes, serd_a_blank(zix_string("b2"))); const SerdNode* o = serd_nodes_get(nodes, serd_a_uri_string("urn:o")); serd_model_add(model, s, p, b1, NULL); @@ -1107,7 +1106,7 @@ test_write_flat_range(SerdWorld* world, const unsigned n_quads) serd_model_add(model, b2, p, o, NULL); SerdBuffer buffer = {NULL, NULL, 0}; - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); SerdOutputStream out = serd_open_output_buffer(&buffer); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, &out, 1); @@ -1160,17 +1159,15 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads) const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("urn:s")); const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p")); - const SerdNode* list1 = - serd_nodes_get(nodes, serd_a_blank(serd_string("l1"))); + const SerdNode* list1 = serd_nodes_get(nodes, serd_a_blank(zix_string("l1"))); - const SerdNode* list2 = - serd_nodes_get(nodes, serd_a_blank(serd_string("l2"))); + const SerdNode* list2 = serd_nodes_get(nodes, serd_a_blank(zix_string("l2"))); const SerdNode* nofirst = - serd_nodes_get(nodes, serd_a_blank(serd_string("nof"))); + serd_nodes_get(nodes, serd_a_blank(zix_string("nof"))); const SerdNode* norest = - serd_nodes_get(nodes, serd_a_blank(serd_string("nor"))); + serd_nodes_get(nodes, serd_a_blank(zix_string("nor"))); const SerdNode* pfirst = serd_nodes_get(nodes, serd_a_uri_string(RDF_FIRST)); const SerdNode* prest = serd_nodes_get(nodes, serd_a_uri_string(RDF_REST)); @@ -1190,7 +1187,7 @@ test_write_bad_list(SerdWorld* world, const unsigned n_quads) serd_model_add(model, norest, pfirst, val2, NULL); SerdBuffer buffer = {NULL, NULL, 0}; - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); SerdOutputStream out = serd_open_output_buffer(&buffer); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, &out, 1); @@ -1239,11 +1236,9 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads) const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("urn:s")); const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p")); - const SerdNode* list1 = - serd_nodes_get(nodes, serd_a_blank(serd_string("l1"))); + const SerdNode* list1 = serd_nodes_get(nodes, serd_a_blank(zix_string("l1"))); - const SerdNode* list2 = - serd_nodes_get(nodes, serd_a_blank(serd_string("l2"))); + const SerdNode* list2 = serd_nodes_get(nodes, serd_a_blank(zix_string("l2"))); const SerdNode* pfirst = serd_nodes_get(nodes, serd_a_uri_string(RDF_FIRST)); const SerdNode* prest = serd_nodes_get(nodes, serd_a_uri_string(RDF_REST)); @@ -1258,7 +1253,7 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads) serd_model_add(model, list2, prest, list1, NULL); SerdBuffer buffer = {NULL, NULL, 0}; - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); SerdOutputStream out = serd_open_output_buffer(&buffer); SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, &out, 1); @@ -1266,8 +1261,8 @@ test_write_infinite_list(SerdWorld* world, const unsigned n_quads) serd_env_set_prefix( env, - serd_string("rdf"), - serd_string("http://www.w3.org/1999/02/22-rdf-syntax-ns#")); + zix_string("rdf"), + zix_string("http://www.w3.org/1999/02/22-rdf-syntax-ns#")); SerdCursor* all = serd_model_begin(NULL, model); serd_describe_range(NULL, all, serd_writer_sink(writer), 0); @@ -1333,9 +1328,9 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads) const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p")); const SerdNode* o = serd_nodes_get(nodes, serd_a_uri_string("urn:o")); - const SerdNode* l1 = serd_nodes_get(nodes, serd_a_blank(serd_string("l1"))); + const SerdNode* l1 = serd_nodes_get(nodes, serd_a_blank(zix_string("l1"))); const SerdNode* one = serd_nodes_get(nodes, serd_a_integer(1)); - const SerdNode* l2 = serd_nodes_get(nodes, serd_a_blank(serd_string("l2"))); + const SerdNode* l2 = serd_nodes_get(nodes, serd_a_blank(zix_string("l2"))); const SerdNode* two = serd_nodes_get(nodes, serd_a_integer(2)); const SerdNode* rdf_first = @@ -1351,7 +1346,7 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads) serd_model_add(model, l2, rdf_rest, rdf_nil, NULL); serd_model_add(model, l1, p, o, NULL); - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); for (size_t max_successes = 0; max_successes < 18; ++max_successes) { FailingWriteFuncState state = {0, max_successes}; @@ -1393,9 +1388,9 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads) const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("urn:s")); const SerdNode* p = serd_nodes_get(nodes, serd_a_uri_string("urn:p")); - const SerdNode* l1 = serd_nodes_get(nodes, serd_a_blank(serd_string("l1"))); + const SerdNode* l1 = serd_nodes_get(nodes, serd_a_blank(zix_string("l1"))); const SerdNode* one = serd_nodes_get(nodes, serd_a_integer(1)); - const SerdNode* l2 = serd_nodes_get(nodes, serd_a_blank(serd_string("l2"))); + const SerdNode* l2 = serd_nodes_get(nodes, serd_a_blank(zix_string("l2"))); const SerdNode* two = serd_nodes_get(nodes, serd_a_integer(2)); const SerdNode* rdf_first = @@ -1411,7 +1406,7 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads) serd_model_add(model, l2, rdf_first, two, NULL); serd_model_add(model, l2, rdf_rest, rdf_nil, NULL); - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); for (size_t max_successes = 0; max_successes < 21; ++max_successes) { FailingWriteFuncState state = {0, max_successes}; diff --git a/test/test_node.c b/test/test_node.c index 7ed6e3c5..10e0765c 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -5,10 +5,10 @@ #include "serd/node.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/uri.h" #include "serd/value.h" #include "serd/write_result.h" +#include "zix/string_view.h" #include <assert.h> #include <math.h> @@ -52,7 +52,7 @@ static void test_new(void) { const SerdNodeArgs bad_args = {(SerdNodeArgsType)-1, - {{(SerdNodeType)-1, {NULL, 0U}}}}; + {{SERD_LITERAL, zix_string("invalid")}}}; assert(!serd_node_new(NULL, bad_args)); } @@ -191,7 +191,7 @@ check_get_bool(const char* string, const bool expected) { SerdNode* const node = serd_node_new( - NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri))); + NULL, serd_a_typed_literal(zix_string(string), zix_string(datatype_uri))); assert(node); @@ -293,7 +293,7 @@ check_get_double(const char* string, const double expected) { SerdNode* const node = serd_node_new( - NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri))); + NULL, serd_a_typed_literal(zix_string(string), zix_string(datatype_uri))); assert(node); @@ -366,7 +366,7 @@ check_get_float(const char* string, const float expected) { SerdNode* const node = serd_node_new( - NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri))); + NULL, serd_a_typed_literal(zix_string(string), zix_string(datatype_uri))); assert(node); @@ -435,7 +435,7 @@ check_get_integer(const char* string, const int64_t expected) { SerdNode* const node = serd_node_new( - NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri))); + NULL, serd_a_typed_literal(zix_string(string), zix_string(datatype_uri))); assert(node); @@ -547,7 +547,7 @@ static void check_decode(const char* string, const char* datatype_uri, const char* expected) { SerdNode* const node = serd_node_new( - NULL, serd_a_typed_literal(serd_string(string), serd_string(datatype_uri))); + NULL, serd_a_typed_literal(zix_string(string), zix_string(datatype_uri))); assert(node); @@ -580,8 +580,8 @@ test_decode(void) { SerdNode* const node = serd_node_new(NULL, - serd_a_typed_literal(serd_string("Zm9v"), - serd_string(NS_XSD "base64Binary"))); + serd_a_typed_literal(zix_string("Zm9v"), + zix_string(NS_XSD "base64Binary"))); const SerdWriteResult r = serd_node_decode(node, sizeof(small), small); @@ -602,8 +602,8 @@ test_decode(void) { SerdNode* const unknown = serd_node_new( NULL, - serd_a_typed_literal(serd_string("secret"), - serd_string("http://example.org/Datatype"))); + serd_a_typed_literal(zix_string("secret"), + zix_string("http://example.org/Datatype"))); assert(serd_node_decoded_size(unknown) == 0U); @@ -620,7 +620,7 @@ test_node_equals(void) { static const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0}; - static const SerdStringView replacement_char = { + static const ZixStringView replacement_char = { (const char*)replacement_char_str, 3}; SerdNode* lhs = serd_node_new(NULL, serd_a_string_view(replacement_char)); @@ -660,7 +660,7 @@ static void test_node_from_substring(void) { SerdNode* const a_b = - serd_node_new(NULL, serd_a_string_view(serd_substring("a\"bc", 3))); + serd_node_new(NULL, serd_a_string_view(zix_substring("a\"bc", 3))); assert(serd_node_length(a_b) == 3); assert(!serd_node_flags(a_b)); @@ -682,17 +682,18 @@ check_copy_equals(const SerdNode* const node) static void test_uri(void) { - const SerdStringView base = serd_string("http://example.org/base/"); - const SerdStringView rel = serd_string("a/b"); - const SerdStringView abs = serd_string("http://example.org/base/a/b"); +#define NS_EG "http://example.org/" + + static const ZixStringView base = ZIX_STATIC_STRING(NS_EG "base/"); + static const ZixStringView rel = ZIX_STATIC_STRING("a/b"); + static const ZixStringView abs = ZIX_STATIC_STRING(NS_EG "base/a/b"); const SerdURIView base_uri = serd_parse_uri(base.data); const SerdURIView rel_uri = serd_parse_uri(rel.data); const SerdURIView abs_uri = serd_resolve_uri(rel_uri, base_uri); SerdNode* const from_string = serd_node_new(NULL, serd_a_uri(abs)); - - SerdNode* const from_uri = serd_node_new(NULL, serd_a_parsed_uri(abs_uri)); + SerdNode* const from_uri = serd_node_new(NULL, serd_a_parsed_uri(abs_uri)); assert(from_string); assert(from_uri); @@ -700,36 +701,38 @@ test_uri(void) serd_node_free(NULL, from_uri); serd_node_free(NULL, from_string); + +#undef NS_EG } static void test_literal(void) { - const SerdStringView hello_str = serd_string("hello"); - const SerdStringView empty_str = serd_empty_string(); + static const ZixStringView hello_str = ZIX_STATIC_STRING("hello"); + static const ZixStringView empty_str = ZIX_STATIC_STRING(""); assert(!serd_node_new(NULL, serd_a_literal(hello_str, SERD_HAS_DATATYPE | SERD_HAS_LANGUAGE, - serd_string("whatever")))); + zix_string("whatever")))); assert(!serd_node_new(NULL, serd_a_typed_literal(hello_str, empty_str))); assert(!serd_node_new(NULL, serd_a_plain_literal(hello_str, empty_str))); assert( - !serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("Type")))); + !serd_node_new(NULL, serd_a_typed_literal(hello_str, zix_string("Type")))); assert( - !serd_node_new(NULL, serd_a_typed_literal(hello_str, serd_string("de")))); + !serd_node_new(NULL, serd_a_typed_literal(hello_str, zix_string("de")))); assert( - !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("3n")))); + !serd_node_new(NULL, serd_a_plain_literal(hello_str, zix_string("3n")))); assert( - !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("d3")))); + !serd_node_new(NULL, serd_a_plain_literal(hello_str, zix_string("d3")))); assert( - !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("d3")))); + !serd_node_new(NULL, serd_a_plain_literal(hello_str, zix_string("d3")))); assert( - !serd_node_new(NULL, serd_a_plain_literal(hello_str, serd_string("en-!")))); + !serd_node_new(NULL, serd_a_plain_literal(hello_str, zix_string("en-!")))); SerdNode* hello2 = serd_node_new(NULL, serd_a_string("hello\"")); @@ -738,18 +741,17 @@ test_literal(void) check_copy_equals(hello2); - assert( - !serd_node_new(NULL, - serd_a_typed_literal(serd_string("plain"), - serd_string(NS_RDF "langString")))); + assert(!serd_node_new(NULL, + serd_a_typed_literal(zix_string("plain"), + zix_string(NS_RDF "langString")))); serd_node_free(NULL, hello2); const char* lang_lit_str = "\"Hello\"@en-ca"; SerdNode* sliced_lang_lit = serd_node_new(NULL, - serd_a_plain_literal(serd_substring(lang_lit_str + 1, 5), - serd_substring(lang_lit_str + 8, 5))); + serd_a_plain_literal(zix_substring(lang_lit_str + 1, 5), + zix_substring(lang_lit_str + 8, 5))); assert(!strcmp(serd_node_string(sliced_lang_lit), "Hello")); @@ -762,8 +764,8 @@ test_literal(void) const char* type_lit_str = "\"Hallo\"^^<http://example.org/Greeting>"; SerdNode* sliced_type_lit = serd_node_new(NULL, - serd_a_typed_literal(serd_substring(type_lit_str + 1, 5), - serd_substring(type_lit_str + 10, 27))); + serd_a_typed_literal(zix_substring(type_lit_str + 1, 5), + zix_substring(type_lit_str + 10, 27))); assert(!strcmp(serd_node_string(sliced_type_lit), "Hallo")); @@ -789,13 +791,13 @@ test_compare(void) SerdNode* angst = serd_node_new(NULL, serd_a_string("angst")); SerdNode* angst_de = serd_node_new( - NULL, serd_a_plain_literal(serd_string("angst"), serd_string("de"))); + NULL, serd_a_plain_literal(zix_string("angst"), zix_string("de"))); SerdNode* angst_en = serd_node_new( - NULL, serd_a_plain_literal(serd_string("angst"), serd_string("en"))); + NULL, serd_a_plain_literal(zix_string("angst"), zix_string("en"))); SerdNode* hallo = serd_node_new( - NULL, serd_a_plain_literal(serd_string("Hallo"), serd_string("de"))); + NULL, serd_a_plain_literal(zix_string("Hallo"), zix_string("de"))); SerdNode* hello = serd_node_new(NULL, serd_a_string("Hello")); SerdNode* universe = serd_node_new(NULL, serd_a_string("Universe")); @@ -806,13 +808,13 @@ test_compare(void) SerdNode* aardvark = serd_node_new( NULL, - serd_a_typed_literal(serd_string("alex"), - serd_string("http://example.org/Aardvark"))); + serd_a_typed_literal(zix_string("alex"), + zix_string("http://example.org/Aardvark"))); SerdNode* badger = serd_node_new( NULL, - serd_a_typed_literal(serd_string("bobby"), - serd_string("http://example.org/Badger"))); + serd_a_typed_literal(zix_string("bobby"), + zix_string("http://example.org/Badger"))); // Types are ordered according to their SerdNodeType (more or less arbitrary) assert(serd_node_compare(integer, hello) < 0); diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c index d1d913ec..5e106a94 100644 --- a/test/test_node_syntax.c +++ b/test/test_node_syntax.c @@ -10,9 +10,9 @@ #include "serd/node.h" #include "serd/node_syntax.h" #include "serd/nodes.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/value.h" +#include "zix/string_view.h" #include <assert.h> #include <stdbool.h> @@ -64,7 +64,7 @@ check(const SerdSyntax syntax, const char* const expected) { SerdEnv* const env = - serd_env_new(NULL, serd_string("http://example.org/base/")); + serd_env_new(NULL, zix_string("http://example.org/base/")); char* const str = serd_node_to_syntax(NULL, node, syntax, env); SerdNode* const copy = serd_node_from_syntax(NULL, str, syntax, env); @@ -82,33 +82,34 @@ test_common(const SerdSyntax syntax) { static const uint8_t data[] = {19U, 17U, 13U, 7U}; - const SerdStringView datatype = serd_string("http://example.org/Datatype"); + static const ZixStringView datatype = + ZIX_STATIC_STRING("http://example.org/Datatype"); SerdNodes* const nodes = serd_nodes_new(NULL); assert( check(syntax, serd_nodes_get(nodes, serd_a_string("node")), "\"node\"")); - assert(check( - syntax, - serd_nodes_get( - nodes, serd_a_plain_literal(serd_string("hallo"), serd_string("de"))), - "\"hallo\"@de")); + assert( + check(syntax, + serd_nodes_get( + nodes, serd_a_plain_literal(zix_string("hallo"), zix_string("de"))), + "\"hallo\"@de")); assert(check( syntax, - serd_nodes_get(nodes, serd_a_typed_literal(serd_string("X"), datatype)), + serd_nodes_get(nodes, serd_a_typed_literal(zix_string("X"), datatype)), "\"X\"^^<http://example.org/Datatype>")); assert(check(syntax, - serd_nodes_get(nodes, serd_a_blank(serd_string("blank"))), + serd_nodes_get(nodes, serd_a_blank(zix_string("blank"))), "_:blank")); assert(check( - syntax, serd_nodes_get(nodes, serd_a_blank(serd_string("b0"))), "_:b0")); + syntax, serd_nodes_get(nodes, serd_a_blank(zix_string("b0"))), "_:b0")); assert(check(syntax, - serd_nodes_get(nodes, serd_a_blank(serd_string("named1"))), + serd_nodes_get(nodes, serd_a_blank(zix_string("named1"))), "_:named1")); assert(check(syntax, @@ -151,7 +152,7 @@ test_ntriples(void) // If a relative URI can be expanded then all's well SerdEnv* const env = - serd_env_new(NULL, serd_string("http://example.org/base/")); + serd_env_new(NULL, zix_string("http://example.org/base/")); char* const str = serd_node_to_syntax(NULL, rel, SERD_NTRIPLES, env); assert(!strcmp(str, "<http://example.org/base/rel/uri>")); diff --git a/test/test_nodes.c b/test/test_nodes.c index 7c2c8508..b220f6d7 100644 --- a/test/test_nodes.c +++ b/test/test_nodes.c @@ -8,15 +8,16 @@ #include "serd/memory.h" #include "serd/node.h" #include "serd/nodes.h" -#include "serd/string_view.h" #include "serd/uri.h" #include "serd/value.h" +#include "zix/string_view.h" #include <assert.h> #include <stdbool.h> #include <stddef.h> #include <string.h> +#define NS_EG "http://example.org/" #define NS_XSD "http://www.w3.org/2001/XMLSchema#" static void @@ -98,7 +99,7 @@ test_intern(void) static void test_string(void) { - const SerdStringView string = serd_string("string"); + static const ZixStringView string = ZIX_STATIC_STRING("string"); SerdAllocator* const allocator = serd_default_allocator(); @@ -115,7 +116,7 @@ test_string(void) assert(!strcmp(serd_node_string(node), string.data)); const SerdNode* const long_node = serd_nodes_get( - nodes, serd_a_literal(string, SERD_IS_LONG, serd_empty_string())); + nodes, serd_a_literal(string, SERD_IS_LONG, zix_empty_string())); assert(long_node); assert(long_node != node); @@ -137,19 +138,19 @@ test_invalid_literal(void) SerdNodes* const nodes = serd_nodes_new(allocator); assert(!serd_nodes_get(nodes, - serd_a_literal(serd_string("double meta"), + serd_a_literal(zix_string("double meta"), SERD_HAS_LANGUAGE | SERD_HAS_DATATYPE, - serd_string("What am I?")))); + zix_string("What am I?")))); assert(!serd_nodes_get(nodes, - serd_a_literal(serd_string("empty language"), + serd_a_literal(zix_string("empty language"), SERD_HAS_LANGUAGE, - serd_empty_string()))); + zix_empty_string()))); assert(!serd_nodes_get(nodes, - serd_a_literal(serd_string("empty datatype"), + serd_a_literal(zix_string("empty datatype"), SERD_HAS_DATATYPE, - serd_empty_string()))); + zix_empty_string()))); serd_nodes_free(nodes); } @@ -157,8 +158,8 @@ test_invalid_literal(void) static void test_plain_literal(void) { - const SerdStringView string = serd_string("string"); - const SerdStringView language = serd_string("en"); + static const ZixStringView string = ZIX_STATIC_STRING("string"); + static const ZixStringView language = ZIX_STATIC_STRING("en"); SerdAllocator* const allocator = serd_default_allocator(); @@ -191,7 +192,7 @@ test_plain_literal(void) assert(long_version != node); const SerdNode* const other = - serd_nodes_get(nodes, serd_a_plain_literal(string, serd_string("de"))); + serd_nodes_get(nodes, serd_a_plain_literal(string, zix_string("de"))); assert(other != node); @@ -210,8 +211,8 @@ test_plain_literal(void) static void test_typed_literal(void) { - const SerdStringView string = serd_string("string"); - const SerdStringView datatype = serd_string("http://example.org/Type"); + static const ZixStringView string = ZIX_STATIC_STRING("string"); + static const ZixStringView datatype = ZIX_STATIC_STRING(NS_EG "Type"); SerdAllocator* const allocator = serd_default_allocator(); @@ -395,7 +396,7 @@ test_base64(void) static void test_uri(void) { - const SerdStringView string = serd_string("http://example.org/"); + static const ZixStringView string = ZIX_STATIC_STRING("http://example.org/"); SerdAllocator* const allocator = serd_default_allocator(); SerdNodes* const nodes = serd_nodes_new(allocator); @@ -416,7 +417,7 @@ test_uri(void) static void test_parsed_uri(void) { - const SerdStringView string = serd_string("http://example.org/"); + static const ZixStringView string = ZIX_STATIC_STRING("http://example.org/"); SerdAllocator* const allocator = serd_default_allocator(); @@ -436,8 +437,8 @@ test_parsed_uri(void) assert(alias == node); - const SerdNode* const other = serd_nodes_get( - nodes, serd_a_parsed_uri(serd_parse_uri("http://example.org/x"))); + const SerdNode* const other = + serd_nodes_get(nodes, serd_a_parsed_uri(serd_parse_uri(NS_EG "x"))); assert(other != node); @@ -449,17 +450,19 @@ test_file_uri(void) { SerdAllocator* const allocator = serd_default_allocator(); - const SerdStringView local_string = serd_string("file:///d/f.txt"); - const SerdStringView local_path = serd_string("/d/f.txt"); - const SerdStringView remote_host = serd_string("server"); - const SerdStringView remote_string = serd_string("file://server/d/f.txt"); + static const ZixStringView local_string = + ZIX_STATIC_STRING("file:///d/f.txt"); + static const ZixStringView local_path = ZIX_STATIC_STRING("/d/f.txt"); + static const ZixStringView remote_host = ZIX_STATIC_STRING("s"); + static const ZixStringView remote_string = + ZIX_STATIC_STRING("file://s/d/f.txt"); SerdNodes* const nodes = serd_nodes_new(allocator); const SerdNode* const local_uri = serd_nodes_get(nodes, serd_a_uri(local_string)); const SerdNode* const local_file_uri = - serd_nodes_get(nodes, serd_a_file_uri(local_path, serd_empty_string())); + serd_nodes_get(nodes, serd_a_file_uri(local_path, zix_empty_string())); assert(local_uri); assert(local_file_uri); @@ -492,7 +495,7 @@ test_file_uri(void) static void test_blank(void) { - const SerdStringView string = serd_string("b42"); + static const ZixStringView string = ZIX_STATIC_STRING("b42"); SerdAllocator* const allocator = serd_default_allocator(); diff --git a/test/test_overflow.c b/test/test_overflow.c index abc7d989..f2ff184b 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -4,6 +4,7 @@ #undef NDEBUG #include "serd/serd.h" +#include "zix/string_view.h" #include <assert.h> #include <stdio.h> @@ -24,8 +25,8 @@ test_size(SerdWorld* const world, SerdNodes* const nodes = serd_world_nodes(world); SerdAllocator* const alloc = serd_world_allocator(world); - SerdSink* sink = serd_sink_new(alloc, NULL, NULL, NULL); - SerdEnv* const env = serd_env_new(alloc, serd_empty_string()); + SerdSink* const sink = serd_sink_new(alloc, NULL, NULL, NULL); + SerdEnv* const env = serd_env_new(alloc, zix_empty_string()); SerdReader* const reader = serd_reader_new(world, syntax, flags, env, sink); if (!reader) { return SERD_BAD_STACK; diff --git a/test/test_reader.c b/test/test_reader.c index 3d59af8e..325f8c23 100644 --- a/test/test_reader.c +++ b/test/test_reader.c @@ -16,13 +16,13 @@ #include "serd/statement.h" #include "serd/status.h" #include "serd/stream.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" #include "zix/allocator.h" #include "zix/attributes.h" #include "zix/filesystem.h" #include "zix/path.h" +#include "zix/string_view.h" #ifdef _WIN32 # include <windows.h> @@ -69,7 +69,7 @@ test_new_failed_alloc(void) SerdFailingAllocator allocator = serd_failing_allocator(); SerdWorld* const world = serd_world_new(&allocator.base); - SerdEnv* const env = serd_env_new(&allocator.base, serd_empty_string()); + SerdEnv* const env = serd_env_new(&allocator.base, zix_empty_string()); size_t ignored = 0U; SerdSink* const sink = serd_sink_new(&allocator.base, &ignored, test_sink, NULL); @@ -105,7 +105,7 @@ test_start_failed_alloc(const char* const path) fseek(f, 0L, SEEK_SET); SerdWorld* world = serd_world_new(&allocator.base); - SerdEnv* env = serd_env_new(&allocator.base, serd_empty_string()); + SerdEnv* env = serd_env_new(&allocator.base, zix_empty_string()); size_t ignored = 0U; SerdSink* sink = serd_sink_new(&allocator.base, &ignored, test_sink, NULL); SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); @@ -175,8 +175,9 @@ test_prepare_error(const char* const path) SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0, env, sink); + assert(reader); SerdInputStream in = @@ -206,8 +207,9 @@ test_read_string(void) SerdSink* sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); + assert(reader); static const char* const string1 = @@ -307,7 +309,7 @@ test_read_eof_by_page(const char* const path) SerdWorld* const world = serd_world_new(NULL); ReaderTest rt = {0, 0, 0, 0}; SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); SerdInputStream in = @@ -335,7 +337,7 @@ test_read_eof_by_byte(void) SerdWorld* const world = serd_world_new(NULL); ReaderTest rt = {0, 0, 0, 0}; SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); size_t n_reads = 0U; @@ -387,7 +389,7 @@ test_read_nquads_chunks(const char* const path) SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(env); SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); @@ -473,7 +475,7 @@ test_read_turtle_chunks(const char* const path) SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(env); SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); @@ -562,7 +564,7 @@ test_read_empty(const char* const path) SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(env); SerdReader* const reader = @@ -617,8 +619,8 @@ test_error_cursor(void) SerdNodes* const nodes = serd_world_nodes(world); bool called = false; SerdSink* const sink = serd_sink_new(NULL, &called, check_cursor, NULL); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); - SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0U, env, sink); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); + SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, 0, env, sink); assert(sink); assert(reader); diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 7a57daed..1858d570 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -14,13 +14,13 @@ #include "serd/reader.h" #include "serd/sink.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" #include "serd/writer.h" #include "zix/allocator.h" #include "zix/filesystem.h" #include "zix/path.h" +#include "zix/string_view.h" #include <assert.h> #include <errno.h> @@ -110,7 +110,7 @@ test_write_errors(void) ctx.n_written = 0; ctx.error_offset = o; - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdOutputStream out = serd_open_output_stream(faulty_sink, NULL, NULL, &ctx); @@ -144,7 +144,7 @@ test_writer(const char* const path) { SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdOutputStream output = serd_open_output_file(path); @@ -161,7 +161,7 @@ test_writer(const char* const path) assert(serd_sink_write_end(iface, lit)); static const uint8_t bad_buf[] = {0xEF, 0xBF, 0xBD, 0}; - const SerdStringView bad_buf_view = {(const char*)bad_buf, 3}; + const ZixStringView bad_buf_view = {(const char*)bad_buf, 3}; const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("http://example.org")); @@ -177,15 +177,16 @@ test_writer(const char* const path) assert(serd_sink_write(iface, 0, junk[i][0], junk[i][1], junk[i][2], NULL)); } - const SerdStringView urn_Type = serd_string("urn:Type"); - const SerdStringView en = serd_string("en"); - const SerdNode* const o = serd_nodes_get(nodes, serd_a_string("o")); + static const ZixStringView urn_Type = ZIX_STATIC_STRING("urn:Type"); + static const ZixStringView en = ZIX_STATIC_STRING("en"); + + const SerdNode* const o = serd_nodes_get(nodes, serd_a_string("o")); const SerdNode* const t = - serd_nodes_get(nodes, serd_a_typed_literal(serd_string("t"), urn_Type)); + serd_nodes_get(nodes, serd_a_typed_literal(zix_string("t"), urn_Type)); const SerdNode* const l = - serd_nodes_get(nodes, serd_a_plain_literal(serd_string("l"), en)); + serd_nodes_get(nodes, serd_a_plain_literal(zix_string("l"), en)); const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}}; @@ -246,7 +247,7 @@ test_reader(const char* path) SerdSink* const sink = serd_sink_new(NULL, &rt, test_sink, NULL); assert(sink); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); assert(env); // Test that too little stack space fails gracefully diff --git a/test/test_terse_write.c b/test/test_terse_write.c index 2a516c04..0c55eb9d 100644 --- a/test/test_terse_write.c +++ b/test/test_terse_write.c @@ -11,10 +11,10 @@ #include "serd/output_stream.h" #include "serd/sink.h" #include "serd/statement.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" #include "serd/writer.h" +#include "zix/string_view.h" #include <assert.h> #include <stdio.h> @@ -43,7 +43,7 @@ test(void) SerdWorld* world = serd_world_new(NULL); SerdAllocator* alloc = serd_world_allocator(world); SerdBuffer buffer = {NULL, NULL, 0}; - SerdEnv* env = serd_env_new(alloc, serd_empty_string()); + SerdEnv* env = serd_env_new(alloc, zix_empty_string()); SerdNodes* nodes = serd_nodes_new(alloc); const SerdNode* b1 = serd_nodes_get(nodes, serd_a_blank_string("b1")); @@ -64,7 +64,7 @@ test(void) const SerdNode* rdf_nil = serd_nodes_get(nodes, serd_a_uri_string(NS_RDF "nil")); - serd_env_set_prefix(env, serd_string("rdf"), serd_string(NS_RDF)); + serd_env_set_prefix(env, zix_string("rdf"), zix_string(NS_RDF)); SerdOutputStream output = serd_open_output_buffer(&buffer); SerdWriter* const writer = diff --git a/test/test_uri.c b/test/test_uri.c index b1af8a02..bf4fa0f3 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -8,8 +8,8 @@ #include "serd/memory.h" #include "serd/node.h" #include "serd/nodes.h" -#include "serd/string_view.h" #include "serd/uri.h" +#include "zix/string_view.h" #include <assert.h> #include <stdbool.h> @@ -79,7 +79,7 @@ test_file_uri(const char* const hostname, SerdNodes* const nodes = serd_nodes_new(NULL); const SerdNode* node = serd_nodes_get( - nodes, serd_a_file_uri(serd_string(path), serd_string(hostname))); + nodes, serd_a_file_uri(zix_string(path), zix_string(hostname))); const char* node_str = serd_node_string(node); char* out_hostname = NULL; @@ -164,7 +164,8 @@ test_uri_parsing(void) static void test_parse_uri(void) { - const SerdStringView base = serd_string("http://example.org/a/b/c/"); + static const ZixStringView base = + ZIX_STATIC_STRING("http://example.org/a/b/c/"); const SerdURIView base_uri = serd_parse_uri(base.data); const SerdURIView empty_uri = serd_parse_uri(""); @@ -215,7 +216,7 @@ test_is_within(void) } static inline bool -chunk_equals(const SerdStringView* a, const SerdStringView* b) +chunk_equals(const ZixStringView* a, const ZixStringView* b) { return (!a->length && !b->length && !a->data && !b->data) || (a->length && b->length && a->data && b->data && @@ -374,11 +375,11 @@ check_uri_string(const SerdURIView uri, const char* const expected) static void test_uri_resolution(void) { - const SerdStringView top = serd_string("http://example.org/t/"); - const SerdStringView base = serd_string("http://example.org/t/b/"); - const SerdStringView sub = serd_string("http://example.org/t/b/s"); - const SerdStringView deep = serd_string("http://example.org/t/b/s/d"); - const SerdStringView other = serd_string("http://example.org/o"); + const ZixStringView top = ZIX_STATIC_STRING("http://example.org/t/"); + const ZixStringView base = ZIX_STATIC_STRING("http://example.org/t/b/"); + const ZixStringView sub = ZIX_STATIC_STRING("http://example.org/t/b/s"); + const ZixStringView deep = ZIX_STATIC_STRING("http://example.org/t/b/s/d"); + const ZixStringView other = ZIX_STATIC_STRING("http://example.org/o"); const SerdURIView top_uri = serd_parse_uri(top.data); const SerdURIView base_uri = serd_parse_uri(base.data); diff --git a/test/test_writer.c b/test/test_writer.c index 60f50308..17790527 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -15,10 +15,10 @@ #include "serd/sink.h" #include "serd/statement.h" #include "serd/status.h" -#include "serd/string_view.h" #include "serd/syntax.h" #include "serd/world.h" #include "serd/writer.h" +#include "zix/string_view.h" #include <assert.h> #include <stdint.h> @@ -30,7 +30,7 @@ static void test_writer_new(void) { SerdWorld* world = serd_world_new(NULL); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -46,7 +46,7 @@ test_new_failed_alloc(void) SerdFailingAllocator allocator = serd_failing_allocator(); SerdWorld* const world = serd_world_new(&allocator.base); - SerdEnv* env = serd_env_new(&allocator.base, serd_empty_string()); + SerdEnv* env = serd_env_new(&allocator.base, zix_empty_string()); SerdBuffer buffer = {&allocator.base, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); const size_t n_world_allocs = allocator.n_allocations; @@ -76,7 +76,7 @@ test_write_failed_alloc(void) SerdWorld* world = serd_world_new(&allocator.base); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdBuffer buffer = {&allocator.base, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -135,7 +135,7 @@ static void test_write_bad_event(void) { SerdWorld* world = serd_world_new(NULL); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -164,7 +164,7 @@ test_write_long_literal(void) { SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -180,9 +180,9 @@ test_write_long_literal(void) const SerdNode* o = serd_nodes_get(nodes, - serd_a_literal(serd_string("hello \"\"\"world\"\"\"!"), + serd_a_literal(zix_string("hello \"\"\"world\"\"\"!"), SERD_IS_LONG, - serd_empty_string())); + zix_empty_string())); assert(serd_node_flags(o) & SERD_IS_LONG); assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL)); @@ -222,7 +222,7 @@ test_writer_cleanup(void) SerdStatus st = SERD_SUCCESS; SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdOutputStream output = serd_open_output_stream(null_sink, NULL, NULL, NULL); @@ -237,7 +237,7 @@ test_writer_cleanup(void) const SerdNode* const p = serd_nodes_get(nodes, serd_a_uri_string("http://example.org/p")); - const SerdNode* o = serd_nodes_get(nodes, serd_a_blank(serd_string("start"))); + const SerdNode* o = serd_nodes_get(nodes, serd_a_blank(zix_string("start"))); st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL); assert(!st); @@ -275,7 +275,7 @@ test_strict_write(void) SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdOutputStream out = serd_open_output_stream(null_sink, NULL, NULL, fd); SerdWriter* const writer = serd_writer_new(world, SERD_TURTLE, 0U, env, &out, 1U); @@ -328,7 +328,7 @@ test_write_error(void) { SerdWorld* const world = serd_world_new(NULL); SerdNodes* const nodes = serd_world_nodes(world); - SerdEnv* const env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* const env = serd_env_new(NULL, zix_empty_string()); SerdOutputStream out = serd_open_output_stream(error_sink, NULL, NULL, NULL); SerdStatus st = SERD_SUCCESS; @@ -352,9 +352,10 @@ test_write_error(void) static void test_writer_stack_overflow(void) { - SerdWorld* world = serd_world_new(NULL); - SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdWorld* world = serd_world_new(NULL); + SerdNodes* nodes = serd_world_nodes(world); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); + SerdOutputStream output = serd_open_output_stream(null_sink, NULL, NULL, NULL); @@ -403,7 +404,7 @@ test_write_empty_syntax(void) { SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); @@ -441,7 +442,7 @@ check_pname_escape(const char* const lname, const char* const expected) { SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); SerdBuffer buffer = {NULL, NULL, 0}; SerdOutputStream output = serd_open_output_buffer(&buffer); @@ -452,7 +453,7 @@ check_pname_escape(const char* const lname, const char* const expected) static const char* const prefix = "http://example.org/"; const size_t prefix_len = strlen(prefix); - serd_env_set_prefix(env, serd_string("eg"), serd_string(prefix)); + serd_env_set_prefix(env, zix_string("eg"), zix_string(prefix)); const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); @@ -517,7 +518,7 @@ test_write_bad_uri(void) { SerdWorld* world = serd_world_new(NULL); SerdNodes* nodes = serd_world_nodes(world); - SerdEnv* env = serd_env_new(NULL, serd_empty_string()); + SerdEnv* env = serd_env_new(NULL, zix_empty_string()); const SerdNode* s = serd_nodes_get(nodes, serd_a_uri_string("http://example.org/s")); |