data tree NEW opaque data node
Used for unknown anyxml/anydata nodes.
Some refactoring including making context
const for cases when only the dictionary
is modified or replacing unsigned int with
uint32_t.
diff --git a/tests/src/test_parser_xml.c b/tests/src/test_parser_xml.c
index b5c3f4c..247ff0a 100644
--- a/tests/src/test_parser_xml.c
+++ b/tests/src/test_parser_xml.c
@@ -12,6 +12,8 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
+#include "tests/config.h"
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -20,10 +22,9 @@
#include <stdio.h>
#include <string.h>
-#include "tests/config.h"
-
#include "../../src/context.h"
#include "../../src/tree_data_internal.h"
+#include "../../src/printer_data.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
@@ -161,19 +162,32 @@
{
*state = test_anydata;
- const char *data = "<any xmlns=\"urn:tests:a\">"
- "<element1><x:element2 x:attr2=\"test\" xmlns:x=\"urn:x\">x:data</x:element2></element1><element1a/>"
- "</any>";
+ const char *data;
+ char *str;
struct lyd_node *tree;
- struct lyd_node_any *any;
+ data =
+ "<any xmlns=\"urn:tests:a\">"
+ "<element1>"
+ "<x:element2 x:attr2=\"test\" xmlns:a=\"urn:tests:a\" xmlns:x=\"urn:x\">a:data</x:element2>"
+ "</element1>"
+ "<element1a/>"
+ "</any>";
assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_VALOPT_DATA_ONLY, &tree));
assert_non_null(tree);
assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
assert_string_equal("any", tree->schema->name);
- any = (struct lyd_node_any*)tree;
- assert_int_equal(LYD_ANYDATA_XML, any->value_type);
- assert_string_equal("<element1><x:element2 x:attr2=\"test\" xmlns:x=\"urn:x\">x:data</x:element2></element1><element1a/>", any->value.xml);
+
+ lyd_print_mem(&str, tree, LYD_XML, 0);
+ assert_string_equal(str,
+ "<any xmlns=\"urn:tests:a\">"
+ "<element1>"
+ "<element2 xmlns=\"urn:x\" xmlns:x=\"urn:x\" x:attr2=\"test\" xmlns:a=\"urn:tests:a\">a:data</element2>"
+ "</element1>"
+ "<element1a/>"
+ "</any>"
+ );
+ free(str);
lyd_free_all(tree);
*state = NULL;
diff --git a/tests/src/test_printer_xml.c b/tests/src/test_printer_xml.c
index 83e14dc..f6cca7b 100644
--- a/tests/src/test_printer_xml.c
+++ b/tests/src/test_printer_xml.c
@@ -206,6 +206,8 @@
assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, LYD_VALOPT_DATA_ONLY));
assert_true((len = lyd_print_mem(&printed, tree, LYD_XML, 0)) >= 0);
assert_int_equal(len, strlen(printed));
+ /* canonized */
+ data = "<any xmlns=\"urn:tests:types\"><somexml xmlns=\"example.com\"><x xmlns=\"url:x\"/></somexml></any>";
assert_string_equal(printed, data);
free(printed);
lyd_free_all(tree);
@@ -218,6 +220,38 @@
free(printed);
lyd_free_all(tree);
+ data =
+ "<any xmlns=\"urn:tests:types\">"
+ "<cont>"
+ "<defs:elem1 xmlns:defs=\"urn:tests:defs\">"
+ "<elem2 xmlns:defaults=\"urn:defaults\" defs:attr1=\"defaults:val\" attr2=\"/defaults:node/defs:node2\">"
+ "</elem2>"
+ "</defs:elem1>"
+ "</cont>"
+ "</any>";
+ assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, LYD_VALOPT_DATA_ONLY));
+ /* cont should be normally parsed */
+ assert_string_equal(tree->schema->name, "any");
+ assert_int_equal(((struct lyd_node_any *)tree)->value_type, LYD_ANYDATA_DATATREE);
+ assert_string_equal(((struct lyd_node_any *)tree)->value.tree->schema->name, "cont");
+ /* but its children not */
+ assert_null(((struct lyd_node_inner *)(((struct lyd_node_any *)tree)->value.tree))->child->schema);
+ assert_true((len = lyd_print_mem(&printed, tree, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ /* canonized */
+ data =
+ "<any xmlns=\"urn:tests:types\">"
+ "<cont>"
+ "<elem1 xmlns=\"urn:tests:defs\">"
+ "<elem2 xmlns=\"urn:tests:types\" xmlns:defs=\"urn:tests:defs\" xmlns:defaults=\"urn:defaults\""
+ " defs:attr1=\"defaults:val\" attr2=\"/defaults:node/defs:node2\"/>"
+ "</elem1>"
+ "</cont>"
+ "</any>";
+ assert_string_equal(printed, data);
+ free(printed);
+ lyd_free_all(tree);
+
s->func = NULL;
}
diff --git a/tests/src/test_set.c b/tests/src/test_set.c
index 3e288b5..a4e4332 100644
--- a/tests/src/test_set.c
+++ b/tests/src/test_set.c
@@ -113,8 +113,6 @@
assert_int_equal(-1, ly_set_add(NULL, NULL, 0));
assert_string_equal(logbuf, "Invalid argument set (ly_set_add()).");
- assert_int_equal(-1, ly_set_add(&set, NULL, 0));
- assert_string_equal(logbuf, "Invalid argument object (ly_set_add()).");
assert_int_equal(-1, ly_set_merge(NULL, NULL, 0, NULL));
assert_string_equal(logbuf, "Invalid argument trg (ly_set_merge()).");
diff --git a/tests/src/test_validation.c b/tests/src/test_validation.c
index d81ea74..4ba2e7c 100644
--- a/tests/src/test_validation.c
+++ b/tests/src/test_validation.c
@@ -12,6 +12,8 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
+#include "tests/config.h"
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -20,8 +22,6 @@
#include <stdio.h>
#include <string.h>
-#include "tests/config.h"
-
#include "../../src/context.h"
#include "../../src/tree_data_internal.h"
#include "../../src/printer_data.h"
@@ -966,13 +966,13 @@
"<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
- "<ll1 ncwd:default=\"true\">def1</ll1>"
- "<ll1 ncwd:default=\"true\">def2</ll1>"
- "<ll1 ncwd:default=\"true\">def3</ll1>"
- "<d ncwd:default=\"true\">15</d>"
- "<ll2 ncwd:default=\"true\">dflt1</ll2>"
- "<ll2 ncwd:default=\"true\">dflt2</ll2>"
+ "<cont xmlns=\"urn:tests:f\">"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
+ "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
"</cont>");
free(str);
@@ -988,13 +988,13 @@
"<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
"<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
- "<ll1 ncwd:default=\"true\">def1</ll1>"
- "<ll1 ncwd:default=\"true\">def2</ll1>"
- "<ll1 ncwd:default=\"true\">def3</ll1>"
- "<d ncwd:default=\"true\">15</d>"
- "<ll2 ncwd:default=\"true\">dflt1</ll2>"
- "<ll2 ncwd:default=\"true\">dflt2</ll2>"
+ "<cont xmlns=\"urn:tests:f\">"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
+ "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
"</cont>"
"<l xmlns=\"urn:tests:f\">value</l>");
free(str);
@@ -1011,13 +1011,13 @@
/* check data tree */
lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
assert_string_equal(str,
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
- "<ll1 ncwd:default=\"true\">def1</ll1>"
- "<ll1 ncwd:default=\"true\">def2</ll1>"
- "<ll1 ncwd:default=\"true\">def3</ll1>"
- "<d ncwd:default=\"true\">15</d>"
- "<ll2 ncwd:default=\"true\">dflt1</ll2>"
- "<ll2 ncwd:default=\"true\">dflt2</ll2>"
+ "<cont xmlns=\"urn:tests:f\">"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
+ "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
"</cont>"
"<l xmlns=\"urn:tests:f\">value</l>"
"<d xmlns=\"urn:tests:f\">15</d>"
@@ -1034,13 +1034,13 @@
/* check data tree */
lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
assert_string_equal(str,
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
- "<ll1 ncwd:default=\"true\">def1</ll1>"
- "<ll1 ncwd:default=\"true\">def2</ll1>"
- "<ll1 ncwd:default=\"true\">def3</ll1>"
- "<d ncwd:default=\"true\">15</d>"
- "<ll2 ncwd:default=\"true\">dflt1</ll2>"
- "<ll2 ncwd:default=\"true\">dflt2</ll2>"
+ "<cont xmlns=\"urn:tests:f\">"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
+ "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
"</cont>"
"<l xmlns=\"urn:tests:f\">value</l>"
"<d xmlns=\"urn:tests:f\">15</d>"
@@ -1056,13 +1056,13 @@
/* check data tree */
lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
assert_string_equal(str,
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
- "<ll1 ncwd:default=\"true\">def1</ll1>"
- "<ll1 ncwd:default=\"true\">def2</ll1>"
- "<ll1 ncwd:default=\"true\">def3</ll1>"
- "<d ncwd:default=\"true\">15</d>"
- "<ll2 ncwd:default=\"true\">dflt1</ll2>"
- "<ll2 ncwd:default=\"true\">dflt2</ll2>"
+ "<cont xmlns=\"urn:tests:f\">"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>"
+ "<ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>"
+ "<d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>"
+ "<ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>"
"</cont>"
"<l xmlns=\"urn:tests:f\">value</l>"
"<d xmlns=\"urn:tests:f\">15</d>"
@@ -1078,7 +1078,7 @@
/* check data tree */
lyd_print_mem(&str, tree, LYD_XML, LYDP_WITHSIBLINGS | LYDP_WD_IMPL_TAG);
assert_string_equal(str,
- "<cont xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">"
+ "<cont xmlns=\"urn:tests:f\">"
"<ll1>def3</ll1>"
"<d>5</d>"
"<ll2>non-dflt</ll2>"