types CHANGE redesign storing canonical values
Canonical values are not available for all the types and the type's
printer should be used to get string representation instead of trying to
get string value directly from the lyd_value. So, the canonical value is
now much more hidden in lyd_value structure. On the other hand, there is
newly available original string representation of the value (some of the
types already needed it), which is always present no matter of the
value's type.
diff --git a/tests/features/test_types.c b/tests/features/test_types.c
index 6fdf096..5d508d9 100644
--- a/tests/features/test_types.c
+++ b/tests/features/test_types.c
@@ -159,12 +159,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("int8", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("15", leaf->value.canonized);
+ assert_string_equal("15", leaf->value.canonical_cache);
assert_int_equal(15, leaf->value.int8);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_int_equal(15, value.int8);
value.realtype->plugin->free(s->ctx, &value);
memset(&value, 0, sizeof value);
@@ -216,12 +216,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("uint8", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("150", leaf->value.canonized);
+ assert_string_equal("150", leaf->value.canonical_cache);
assert_int_equal(150, leaf->value.uint8);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_int_equal(150, value.uint8);
value.realtype->plugin->free(s->ctx, &value);
memset(&value, 0, sizeof value);
@@ -273,12 +273,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("dec64", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("8.0", leaf->value.canonized);
+ assert_string_equal("8.0", leaf->value.canonical_cache);
assert_int_equal(80, leaf->value.dec64);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_int_equal(80, value.dec64);
value.realtype->plugin->free(s->ctx, &value);
memset(&value, 0, sizeof value);
@@ -289,7 +289,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("dec64", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("8.0", leaf->value.canonized);
+ assert_string_equal("8.0", leaf->value.canonical_cache);
assert_int_equal(80, leaf->value.dec64);
lyd_free_all(tree);
@@ -298,7 +298,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("dec64-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("-9.223372036854775808", leaf->value.canonized);
+ assert_string_equal("-9.223372036854775808", leaf->value.canonical_cache);
assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), leaf->value.dec64);
lyd_free_all(tree);
@@ -307,7 +307,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("dec64-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("9.223372036854775807", leaf->value.canonized);
+ assert_string_equal("9.223372036854775807", leaf->value.canonical_cache);
assert_int_equal(INT64_C(9223372036854775807), leaf->value.dec64);
lyd_free_all(tree);
@@ -360,7 +360,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("str", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("teststring", leaf->value.canonized);
+ assert_string_equal("teststring", leaf->value.canonical_cache);
lyd_free_all(tree);
/* multibyte characters (€ encodes as 3-byte UTF8 character, length restriction is 2-5) */
@@ -369,7 +369,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("str-utf8", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("€€", leaf->value.canonized);
+ assert_string_equal("€€", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<str-utf8 xmlns=\"urn:tests:types\">€</str-utf8>";
assert_null(lyd_parse_mem(s->ctx, data, LYD_XML, 0, NULL));
@@ -415,14 +415,14 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("bits", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("zero two", leaf->value.canonized);
+ assert_string_equal("zero two", leaf->value.canonical_cache);
assert_int_equal(2, LY_ARRAY_SIZE(leaf->value.bits_items));
assert_string_equal("zero", leaf->value.bits_items[0]->name);
assert_string_equal("two", leaf->value.bits_items[1]->name);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_int_equal(2, LY_ARRAY_SIZE(value.bits_items));
assert_string_equal("zero", value.bits_items[0]->name);
assert_string_equal("two", value.bits_items[1]->name);
@@ -435,7 +435,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("bits", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("zero two", leaf->value.canonized);
+ assert_string_equal("zero two", leaf->value.canonical_cache);
lyd_free_all(tree);
/* disabled feature */
@@ -449,13 +449,13 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("bits", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("one", leaf->value.canonized);
+ assert_string_equal("one", leaf->value.canonical_cache);
assert_int_equal(1, LY_ARRAY_SIZE(leaf->value.bits_items));
assert_string_equal("one", leaf->value.bits_items[0]->name);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_int_equal(1, LY_ARRAY_SIZE(value.bits_items));
assert_string_equal("one", value.bits_items[0]->name);
value.realtype->plugin->free(s->ctx, &value);
@@ -491,12 +491,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("enums", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("white", leaf->value.canonized);
+ assert_string_equal("white", leaf->value.canonical_cache);
assert_string_equal("white", leaf->value.enum_item->name);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
assert_string_equal("white", value.enum_item->name);
value.realtype->plugin->free(s->ctx, &value);
lyd_free_all(tree);
@@ -512,7 +512,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("enums", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("yellow", leaf->value.canonized);
+ assert_string_equal("yellow", leaf->value.canonical_cache);
lyd_free_all(tree);
/* leading/trailing whitespaces are not valid */
@@ -549,16 +549,16 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("binary", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("aGVs\nbG8=", leaf->value.canonized);
+ assert_string_equal("aGVs\nbG8=", leaf->value.canonical_cache);
assert_non_null(tree = tree->next);
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("binary-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("TQ==", leaf->value.canonized);
+ assert_string_equal("TQ==", leaf->value.canonical_cache);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal(leaf->value.canonized, value.canonized);
+ assert_string_equal(leaf->value.canonical_cache, value.canonical_cache);
value.realtype->plugin->free(s->ctx, &value);
memset(&value, 0, sizeof value);
lyd_free_all(tree);
@@ -569,21 +569,21 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("binary-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("", leaf->value.canonized);
+ assert_string_equal("", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<binary-norestr xmlns=\"urn:tests:types\"></binary-norestr>";
assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, 0, NULL));
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("binary-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("", leaf->value.canonized);
+ assert_string_equal("", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<binary-norestr xmlns=\"urn:tests:types\"/>";
assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, 0, NULL));
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("binary-norestr", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("", leaf->value.canonized);
+ assert_string_equal("", leaf->value.canonical_cache);
lyd_free_all(tree);
/* invalid base64 character */
@@ -626,7 +626,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("bool", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("true", leaf->value.canonized);
+ assert_string_equal("true", leaf->value.canonical_cache);
assert_int_equal(1, leaf->value.boolean);
lyd_free_all(tree);
@@ -635,7 +635,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("bool", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("false", leaf->value.canonized);
+ assert_string_equal("false", leaf->value.canonical_cache);
assert_int_equal(0, leaf->value.boolean);
lyd_free_all(tree);
@@ -667,7 +667,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("empty", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("", leaf->value.canonized);
+ assert_string_equal("", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<empty xmlns=\"urn:tests:types\"/>";
@@ -675,7 +675,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("empty", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("", leaf->value.canonized);
+ assert_string_equal("", leaf->value.canonical_cache);
lyd_free_all(tree);
/* invalid value */
@@ -727,13 +727,13 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("ident", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
assert_string_equal("gigabit-ethernet", leaf->value.ident->name);
test_printed_value(&leaf->value, "t:gigabit-ethernet", LYD_XML, "t");
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_null(value.canonized);
+ assert_null(value.canonical_cache);
assert_string_equal("gigabit-ethernet", value.ident->name);
value.realtype->plugin->free(s->ctx, &value);
lyd_free_all(tree);
@@ -743,7 +743,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("ident", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
test_printed_value(&leaf->value, "d:fast-ethernet", LYD_XML, "d");
lyd_free_all(tree);
@@ -798,7 +798,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
assert_int_equal(2, LY_ARRAY_SIZE(leaf->value.target));
assert_string_equal("cont", leaf->value.target[0].node->name);
assert_null(leaf->value.target[0].predicates);
@@ -807,7 +807,7 @@
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_null(value.canonized);
+ assert_null(value.canonical_cache);
assert_true(LY_ARRAY_SIZE(leaf->value.target) == LY_ARRAY_SIZE(value.target));
assert_true(leaf->value.target[0].node == value.target[0].node);
assert_true(leaf->value.target[0].predicates == value.target[0].predicates); /* NULL */
@@ -823,7 +823,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<leaflisttarget xmlns=\"urn:tests:types\">1</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">2</leaflisttarget>"
@@ -833,7 +833,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id><value>x</value></list>"
@@ -843,7 +843,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='a']</id><value>x</value></list_inst>"
@@ -855,7 +855,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
assert_int_equal(2, LY_ARRAY_SIZE(leaf->value.target));
assert_string_equal("list_inst", leaf->value.target[0].node->name);
assert_int_equal(1, LY_ARRAY_SIZE(leaf->value.target[0].predicates));
@@ -867,7 +867,7 @@
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_null(value.canonized);
+ assert_null(value.canonical_cache);
assert_true(LY_ARRAY_SIZE(leaf->value.target) == LY_ARRAY_SIZE(value.target));
assert_true(leaf->value.target[0].node == value.target[0].node);
assert_true(LY_ARRAY_SIZE(leaf->value.target[0].predicates) == LY_ARRAY_SIZE(value.target[0].predicates));
@@ -885,7 +885,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list_ident xmlns=\"urn:tests:types\"><id xmlns:dfs=\"urn:tests:defs\">dfs:ethernet</id><value>x</value></list_ident>"
@@ -896,7 +896,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list2 xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list2>"
@@ -907,7 +907,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list>"
@@ -918,7 +918,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list2 xmlns=\"urn:tests:types\"><id>a</id><value>a</value></list2>"
@@ -930,11 +930,11 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("inst", tree->schema->name);
leaf = (const struct lyd_node_term*)tree;
- assert_null(leaf->value.canonized);
+ assert_null(leaf->value.canonical_cache);
trees = lyd_trees_new(1, tree);
assert_non_null(leaf = lyd_target(leaf->value.target, trees));
- assert_string_equal("a", leaf->value.canonized);
- assert_string_equal("b", ((struct lyd_node_term*)leaf->next)->value.canonized);
+ assert_string_equal("a", leaf->value.canonical_cache);
+ assert_string_equal("b", ((struct lyd_node_term*)leaf->next)->value.canonical_cache);
lyd_trees_free(trees, 1);
/* invalid value */
@@ -1139,7 +1139,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("lref", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("y", leaf->value.canonized);
+ assert_string_equal("y", leaf->value.canonical_cache);
assert_int_equal(LY_TYPE_STRING, leaf->value.realtype->plugin->type);
lyd_free_all(tree);
@@ -1151,7 +1151,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("lref2", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("y", leaf->value.canonized);
+ assert_string_equal("y", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
@@ -1162,7 +1162,7 @@
leaf = (struct lyd_node_term*)(lyd_node_children(lyd_node_children(tree))->prev);
assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
assert_string_equal("lr1", leaf->schema->name);
- assert_string_equal("y", leaf->value.canonized);
+ assert_string_equal("y", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
@@ -1174,7 +1174,7 @@
leaf = (struct lyd_node_term*)(lyd_node_children(lyd_node_children(tree)->prev)->prev);
assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
assert_string_equal("lr2", leaf->schema->name);
- assert_string_equal("y", leaf->value.canonized);
+ assert_string_equal("y", leaf->value.canonical_cache);
lyd_free_all(tree);
data = "<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
@@ -1187,7 +1187,7 @@
leaf = (struct lyd_node_term*)(lyd_node_children(lyd_node_children(tree)->prev)->prev);
assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
assert_string_equal("lr3", leaf->schema->name);
- assert_string_equal("c", leaf->value.canonized);
+ assert_string_equal("c", leaf->value.canonical_cache);
lyd_free_all(tree);
/* invalid value */
@@ -1258,20 +1258,23 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("12", leaf->value.canonized);
+ assert_string_equal("12", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_INT8, leaf->value.subvalue->value->realtype->basetype);
+ assert_string_equal("12", leaf->value.subvalue->value->canonical_cache);
assert_int_equal(12, leaf->value.subvalue->value->int8);
test_printed_value(&leaf->value, "12", LYD_XML, NULL);
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal("12", value.canonized);
- assert_string_equal("12", value.subvalue->value->canonized);
+ assert_string_equal("12", value.original);
+ assert_null(value.canonical_cache);
assert_null(value.subvalue->prefixes);
assert_int_equal(LY_TYPE_INT8, value.subvalue->value->realtype->basetype);
+ assert_string_equal("12", value.subvalue->value->canonical_cache);
assert_int_equal(12, leaf->value.subvalue->value->int8);
value.realtype->plugin->free(s->ctx, &value);
lyd_free_all(tree);
@@ -1283,10 +1286,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("2", leaf->value.canonized);
+ assert_string_equal("2", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value->realtype->basetype);
+ assert_string_equal("2", leaf->value.subvalue->value->canonical_cache);
lyd_free_all(tree);
data = "<un1 xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:fast-ethernet</un1>";
@@ -1294,19 +1299,21 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("x:fast-ethernet", leaf->value.canonized);
+ assert_string_equal("x:fast-ethernet", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_non_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_IDENT, leaf->value.subvalue->value->realtype->basetype);
- assert_null(leaf->value.subvalue->value->canonized);
+ assert_null(leaf->value.subvalue->value->canonical_cache); /* identityref does not have canonical form */
test_printed_value(&leaf->value, "x:fast-ethernet", LYD_XML, "x");
test_printed_value(leaf->value.subvalue->value, "d:fast-ethernet", LYD_XML, "d");
value.realtype = leaf->value.realtype;
assert_int_equal(LY_SUCCESS, value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
- assert_string_equal("x:fast-ethernet", value.canonized);
- assert_null(value.subvalue->value->canonized);
+ assert_string_equal("x:fast-ethernet", value.original);
+ assert_null(value.canonical_cache);
+ assert_null(value.subvalue->value->canonical_cache);
assert_non_null(value.subvalue->prefixes);
assert_int_equal(LY_TYPE_IDENT, value.subvalue->value->realtype->basetype);
assert_string_equal("fast-ethernet", value.subvalue->value->ident->name);
@@ -1318,11 +1325,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("d:superfast-ethernet", leaf->value.canonized);
+ assert_string_equal("d:superfast-ethernet", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_non_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value->realtype->basetype);
- assert_string_equal("d:superfast-ethernet", leaf->value.subvalue->value->canonized);
+ assert_string_equal("d:superfast-ethernet", leaf->value.subvalue->value->canonical_cache);
lyd_free_all(tree);
data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
@@ -1332,11 +1340,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("/a:leaflisttarget[2]", leaf->value.canonized);
+ assert_string_equal("/a:leaflisttarget[2]", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_non_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_INST, leaf->value.subvalue->value->realtype->basetype);
- assert_null(leaf->value.subvalue->value->canonized);
+ assert_null(leaf->value.subvalue->value->canonical_cache); /* instance-identifier does not have canonical form */
lyd_free_all(tree);
data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
@@ -1346,11 +1355,12 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("un1", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("/a:leaflisttarget[3]", leaf->value.canonized);
+ assert_string_equal("/a:leaflisttarget[3]", leaf->value.original);
+ assert_null(leaf->value.canonical_cache);
assert_non_null(leaf->value.subvalue->prefixes);
assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value->realtype->basetype);
- assert_string_equal("/a:leaflisttarget[3]", leaf->value.subvalue->value->canonized);
+ assert_string_equal("/a:leaflisttarget[3]", leaf->value.subvalue->value->canonical_cache);
lyd_free_all(tree);
data = "<un1 xmlns=\"urn:tests:types\">123456789012345678901</un1>";
diff --git a/tests/src/test_parser_xml.c b/tests/src/test_parser_xml.c
index 39d5d5c..f5c7d31 100644
--- a/tests/src/test_parser_xml.c
+++ b/tests/src/test_parser_xml.c
@@ -115,7 +115,7 @@
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("foo", tree->schema->name);
leaf = (struct lyd_node_term*)tree;
- assert_string_equal("foo value", leaf->value.canonized);
+ assert_string_equal("foo value", leaf->value.original);
lyd_free_all(tree);
*state = NULL;
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index ea5608c..20b688b 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -578,7 +578,7 @@
assert_non_null(l = (struct lysc_node_leaf*)mod->compiled->data);
assert_string_equal("ref", l->name);
assert_non_null(l->dflt);
- assert_null(l->dflt->canonized);
+ assert_null(l->dflt->canonical_cache);
/* invalid */
assert_null(lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}", LYS_IN_YANG));
@@ -3149,6 +3149,7 @@
assert_int_equal(0, dynamic);
assert_int_equal(1, llist->dflts[0]->uint8);
+ /* instance-identifiers with NULL canonical_cach are changed to string types with a canonical_cache value equal to the original value */
assert_non_null(mod = lys_parse_mem(ctx, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
"leaf q {type instance-identifier; default \"/e:d2\";}"
"leaf-list ql {type instance-identifier; default \"/e:d\"; default \"/e:d2\";}}", LYS_IN_YANG));
@@ -3157,17 +3158,17 @@
"deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG));
assert_non_null(leaf = (struct lysc_node_leaf*)mod->compiled->data);
assert_int_equal(LY_TYPE_STRING, leaf->dflt->realtype->basetype);
- assert_non_null(leaf->dflt->canonized);
- assert_string_equal("/e:d2", leaf->dflt->canonized);
+ assert_non_null(leaf->dflt->canonical_cache);
+ assert_string_equal("/e:d2", leaf->dflt->canonical_cache);
assert_non_null(llist = (struct lysc_node_leaflist*)leaf->next);
assert_int_equal(2, LY_ARRAY_SIZE(llist->dflts));
assert_int_equal(2, LY_ARRAY_SIZE(llist->dflts_mods));
assert_ptr_equal(llist->dflts_mods[0], mod);
assert_int_equal(LY_TYPE_STRING, llist->dflts[0]->realtype->basetype);
- assert_string_equal("/e:d", llist->dflts[0]->canonized);
+ assert_string_equal("/e:d", llist->dflts[0]->canonical_cache);
assert_ptr_equal(llist->dflts_mods[1], mod);
assert_int_equal(LY_TYPE_STRING, llist->dflts[0]->realtype->basetype);
- assert_string_equal("/e:d2", llist->dflts[1]->canonized);
+ assert_string_equal("/e:d2", llist->dflts[1]->canonical_cache);
assert_non_null(mod = lys_parse_mem(ctx, "module r {yang-version 1.1; namespace urn:r;prefix r;"
"typedef mytype {type uint8; default 200;}"