Browse Source

Allow setting the base URI of an Env to NULL

zrythm_meson
David Robillard 2 years ago
parent
commit
dddc46b13f
  1. 8
      src/env.c
  2. 7
      test/test_env.c

8
src/env.c

@ -70,13 +70,17 @@ serd_env_get_base_uri(const SerdEnv* env, @@ -70,13 +70,17 @@ serd_env_get_base_uri(const SerdEnv* env,
return &env->base_uri_node;
}
// TODO: Make env nonnull in next major release
SerdStatus
serd_env_set_base_uri(SerdEnv* env,
const SerdNode* uri)
{
if (!env || !uri) {
if (!env || (uri && uri->type != SERD_URI)) {
return SERD_ERR_BAD_ARG;
} else if (!uri) {
serd_node_free(&env->base_uri_node);
env->base_uri_node = SERD_NODE_NULL;
env->base_uri = SERD_URI_NULL;
return SERD_SUCCESS;
}
// Resolve base URI and create a new node and URI for it

7
test/test_env.c

@ -43,7 +43,7 @@ test_env(void) @@ -43,7 +43,7 @@ test_env(void)
SerdEnv* env = serd_env_new(NULL);
serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
assert(serd_env_set_base_uri(env, NULL));
assert(!serd_env_set_base_uri(env, NULL));
assert(serd_env_set_base_uri(env, &SERD_NODE_NULL));
assert(serd_node_equals(serd_env_get_base_uri(env, NULL), &SERD_NODE_NULL));
@ -84,6 +84,11 @@ test_env(void) @@ -84,6 +84,11 @@ test_env(void)
SerdNode prefix_name;
assert(!serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix));
assert(!serd_env_set_base_uri(env, &u));
assert(serd_node_equals(serd_env_get_base_uri(env, NULL), &u));
assert(!serd_env_set_base_uri(env, NULL));
assert(!serd_env_get_base_uri(env, NULL)->buf);
serd_env_free(env);
}

Loading…
Cancel
Save