diff options
author | David Robillard <d@drobilla.net> | 2018-02-04 15:33:36 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:24 -0500 |
commit | b2b4fa05b73c6eee51ee9db59726fc404198111a (patch) | |
tree | ce2c1b9f0d6e460dde8d439d684598a6ebe1e703 /test/test_env.c | |
parent | ecbc7584a09059ab5987dca95a998c88de8b479a (diff) | |
download | serd-b2b4fa05b73c6eee51ee9db59726fc404198111a.tar.gz serd-b2b4fa05b73c6eee51ee9db59726fc404198111a.tar.bz2 serd-b2b4fa05b73c6eee51ee9db59726fc404198111a.zip |
Make nodes opaque
Diffstat (limited to 'test/test_env.c')
-rw-r--r-- | test/test_env.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/test/test_env.c b/test/test_env.c index 336cbc55..99e16854 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -34,57 +34,62 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) static void test_env(void) { - SerdNode u = serd_node_from_string(SERD_URI, "http://example.org/foo"); - SerdNode b = serd_node_from_string(SERD_CURIE, "invalid"); - SerdNode c = serd_node_from_string(SERD_CURIE, "eg.2:b"); - SerdEnv* env = serd_env_new(NULL); + SerdNode* u = serd_new_string(SERD_URI, "http://example.org/foo"); + SerdNode* b = serd_new_string(SERD_CURIE, "invalid"); + SerdNode* c = serd_new_string(SERD_CURIE, "eg.2:b"); + SerdNode* s = serd_new_string(SERD_LITERAL, "hello"); + SerdEnv* env = serd_env_new(NULL); serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); - assert(!serd_env_set_base_uri(env, NULL)); - assert(serd_env_set_base_uri(env, &SERD_NODE_NULL)); - assert(serd_node_equals(serd_env_base_uri(env, NULL), &SERD_NODE_NULL)); - SerdStringView prefix; SerdStringView suffix; - assert(serd_env_expand(env, &b, &prefix, &suffix)); + assert(serd_env_expand(env, b, &prefix, &suffix)); - SerdNode xnode = serd_env_expand_node(env, &SERD_NODE_NULL); - assert(serd_node_equals(&xnode, &SERD_NODE_NULL)); + assert(!serd_env_expand_node(env, b)); + assert(!serd_env_expand_node(env, s)); - SerdNode xu = serd_env_expand_node(env, &u); - assert(!strcmp(xu.buf, "http://example.org/foo")); - serd_node_free(&xu); + assert(!serd_env_set_base_uri(env, NULL)); - SerdNode badpre = serd_node_from_string(SERD_CURIE, "hm:what"); - SerdNode xbadpre = serd_env_expand_node(env, &badpre); - assert(serd_node_equals(&xbadpre, &SERD_NODE_NULL)); + SerdNode* xu = serd_env_expand_node(env, u); + assert(!strcmp(serd_node_string(xu), "http://example.org/foo")); + serd_node_free(xu); - SerdNode xc = serd_env_expand_node(env, &c); - assert(!strcmp(xc.buf, "http://example.org/b")); - serd_node_free(&xc); + SerdNode* badpre = serd_new_string(SERD_CURIE, "hm:what"); + SerdNode* xbadpre = serd_env_expand_node(env, badpre); + assert(!xbadpre); - assert(serd_env_set_prefix(env, &SERD_NODE_NULL, &SERD_NODE_NULL)); + SerdNode* xc = serd_env_expand_node(env, c); + assert(!strcmp(serd_node_string(xc), "http://example.org/b")); + serd_node_free(xc); - const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello"); - assert(serd_env_set_prefix(env, &b, &lit)); + SerdNode* lit = serd_new_string(SERD_LITERAL, "hello"); + assert(serd_env_set_prefix(env, b, lit)); - const SerdNode blank = serd_node_from_string(SERD_BLANK, "b1"); - const SerdNode xblank = serd_env_expand_node(env, &blank); - assert(serd_node_equals(&xblank, &SERD_NODE_NULL)); + SerdNode* blank = serd_new_string(SERD_BLANK, "b1"); + assert(!serd_env_expand_node(env, blank)); + serd_node_free(blank); int n_prefixes = 0; serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); serd_env_foreach(env, count_prefixes, &n_prefixes); assert(n_prefixes == 1); - SerdNode shorter_uri = serd_node_from_string(SERD_URI, "urn:foo"); - SerdNode prefix_name; - assert(!serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix)); + SerdNode* shorter_uri = serd_new_string(SERD_URI, "urn:foo"); + const SerdNode* prefix_name = NULL; + assert(!serd_env_qualify(env, shorter_uri, &prefix_name, &suffix)); - assert(!serd_env_set_base_uri(env, &u)); - assert(serd_node_equals(serd_env_base_uri(env, NULL), &u)); + assert(!serd_env_set_base_uri(env, u)); + assert(serd_node_equals(serd_env_base_uri(env, NULL), u)); assert(!serd_env_set_base_uri(env, NULL)); - assert(!serd_env_base_uri(env, NULL)->buf); + assert(!serd_env_base_uri(env, NULL)); + + serd_node_free(shorter_uri); + serd_node_free(lit); + serd_node_free(badpre); + serd_node_free(s); + serd_node_free(c); + serd_node_free(b); + serd_node_free(u); serd_env_free(env); } |