aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_env.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_env.c')
-rw-r--r--test/test_env.c108
1 files changed, 54 insertions, 54 deletions
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);