aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-06-26 10:21:49 -0400
committerDavid Robillard <d@drobilla.net>2024-06-26 17:05:06 -0400
commit7d6ae82233b3a4351e2dfce7a8471d341e538e7c (patch)
tree8479c0e0ed57b71d7822aa6d980b41b6c0fc533e
parent6f97a18e538c3390252c9d51de3f2ae92aeff7ee (diff)
downloadserd-7d6ae82233b3a4351e2dfce7a8471d341e538e7c.tar.gz
serd-7d6ae82233b3a4351e2dfce7a8471d341e538e7c.tar.bz2
serd-7d6ae82233b3a4351e2dfce7a8471d341e538e7c.zip
Factor out URI prefix in some tests
-rw-r--r--test/test_env.c17
-rw-r--r--test/test_writer.c36
2 files changed, 28 insertions, 25 deletions
diff --git a/test/test_env.c b/test/test_env.c
index 9547042f..d51e0595 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <string.h>
+#define NS_EG "http://example.org/"
#define USTR(s) ((const uint8_t*)(s))
static SerdStatus
@@ -24,12 +25,11 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri)
static void
test_env(void)
{
- SerdNode u = serd_node_from_string(SERD_URI, USTR("http://example.org/foo"));
- SerdNode b = serd_node_from_string(SERD_CURIE, USTR("invalid"));
- SerdNode c = serd_node_from_string(SERD_CURIE, USTR("eg.2:b"));
+ SerdNode u = serd_node_from_string(SERD_URI, USTR(NS_EG "foo"));
+ SerdNode b = serd_node_from_string(SERD_CURIE, USTR("invalid"));
+ SerdNode c = serd_node_from_string(SERD_CURIE, USTR("eg.2:b"));
SerdEnv* env = serd_env_new(NULL);
- serd_env_set_prefix_from_strings(
- env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR(NS_EG ""));
assert(!serd_env_set_base_uri(env, NULL));
assert(serd_env_set_base_uri(env, &SERD_NODE_NULL));
@@ -49,7 +49,7 @@ test_env(void)
assert(serd_node_equals(&xnode, &SERD_NODE_NULL));
SerdNode xu = serd_env_expand_node(env, &u);
- assert(!strcmp((const char*)xu.buf, "http://example.org/foo"));
+ assert(!strcmp((const char*)xu.buf, NS_EG "foo"));
serd_node_free(&xu);
SerdNode badpre = serd_node_from_string(SERD_CURIE, USTR("hm:what"));
@@ -57,7 +57,7 @@ test_env(void)
assert(serd_node_equals(&xbadpre, &SERD_NODE_NULL));
SerdNode xc = serd_env_expand_node(env, &c);
- assert(!strcmp((const char*)xc.buf, "http://example.org/b"));
+ assert(!strcmp((const char*)xc.buf, NS_EG "b"));
serd_node_free(&xc);
assert(serd_env_set_prefix(env, &SERD_NODE_NULL, &SERD_NODE_NULL));
@@ -72,8 +72,7 @@ test_env(void)
assert(serd_node_equals(&xblank, &SERD_NODE_NULL));
int n_prefixes = 0;
- serd_env_set_prefix_from_strings(
- env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR(NS_EG));
serd_env_foreach(env, count_prefixes, &n_prefixes);
assert(n_prefixes == 1);
diff --git a/test/test_writer.c b/test/test_writer.c
index b478f052..6c765148 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -10,6 +10,8 @@
#include <stdio.h>
#include <string.h>
+#define NS_EG "http://example.org/"
+
#define USTR(s) ((const uint8_t*)(s))
static void
@@ -22,8 +24,8 @@ test_write_long_literal(void)
assert(writer);
- SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s"));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p"));
+ SerdNode s = serd_node_from_string(SERD_URI, USTR(NS_EG "s"));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_EG "p"));
SerdNode o =
serd_node_from_string(SERD_LITERAL, USTR("hello \"\"\"world\"\"\"!"));
@@ -52,16 +54,16 @@ test_write_nested_anon(void)
assert(writer);
- SerdNode s0 = serd_node_from_string(SERD_URI, USTR("http://example.org/s0"));
- SerdNode p0 = serd_node_from_string(SERD_URI, USTR("http://example.org/p0"));
+ SerdNode s0 = serd_node_from_string(SERD_URI, USTR(NS_EG "s0"));
+ SerdNode p0 = serd_node_from_string(SERD_URI, USTR(NS_EG "p0"));
SerdNode b0 = serd_node_from_string(SERD_BLANK, USTR("b0"));
- SerdNode p1 = serd_node_from_string(SERD_URI, USTR("http://example.org/p1"));
+ SerdNode p1 = serd_node_from_string(SERD_URI, USTR(NS_EG "p1"));
SerdNode b1 = serd_node_from_string(SERD_BLANK, USTR("b1"));
- SerdNode p2 = serd_node_from_string(SERD_URI, USTR("http://example.org/p2"));
- SerdNode o2 = serd_node_from_string(SERD_URI, USTR("http://example.org/o2"));
- SerdNode p3 = serd_node_from_string(SERD_URI, USTR("http://example.org/p3"));
- SerdNode p4 = serd_node_from_string(SERD_URI, USTR("http://example.org/p4"));
- SerdNode o4 = serd_node_from_string(SERD_URI, USTR("http://example.org/o4"));
+ SerdNode p2 = serd_node_from_string(SERD_URI, USTR(NS_EG "p2"));
+ SerdNode o2 = serd_node_from_string(SERD_URI, USTR(NS_EG "o2"));
+ SerdNode p3 = serd_node_from_string(SERD_URI, USTR(NS_EG "p3"));
+ SerdNode p4 = serd_node_from_string(SERD_URI, USTR(NS_EG "p4"));
+ SerdNode o4 = serd_node_from_string(SERD_URI, USTR(NS_EG "o4"));
SerdNode nil = serd_node_from_string(
SERD_URI, USTR("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"));
@@ -132,8 +134,8 @@ test_writer_cleanup(void)
SerdWriter* writer =
serd_writer_new(SERD_TURTLE, (SerdStyle)0U, env, NULL, null_sink, NULL);
- SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s"));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p"));
+ SerdNode s = serd_node_from_string(SERD_URI, USTR(NS_EG "s"));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_EG "p"));
char o_buf[12] = {'b', '0', '\0'};
SerdNode o = serd_node_from_string(SERD_BLANK, USTR(o_buf));
@@ -183,8 +185,8 @@ test_write_bad_anon_stack(void)
SerdWriter* writer =
serd_writer_new(SERD_TURTLE, (SerdStyle)0U, env, NULL, null_sink, NULL);
- SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s"));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p"));
+ SerdNode s = serd_node_from_string(SERD_URI, USTR(NS_EG "s"));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_EG "p"));
SerdNode b0 = serd_node_from_string(SERD_BLANK, USTR("b0"));
SerdNode b1 = serd_node_from_string(SERD_BLANK, USTR("b1"));
SerdNode b2 = serd_node_from_string(SERD_BLANK, USTR("b2"));
@@ -219,8 +221,8 @@ test_strict_write(void)
const uint8_t bad_str[] = {0xFF, 0x90, 'h', 'i', 0};
- SerdNode s = serd_node_from_string(SERD_URI, USTR("http://example.org/s"));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/p"));
+ SerdNode s = serd_node_from_string(SERD_URI, USTR(NS_EG "s"));
+ SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_EG "p"));
SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
@@ -278,3 +280,5 @@ main(void)
return 0;
}
+
+#undef NS_EG