libyang REFACTOR parsed/printed bytes in in/out structs
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 20681b1..79c85f5 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -21,6 +21,7 @@
#include <string.h>
#include "context.h"
+#include "parser.h"
#include "parser_data.h"
#include "printer.h"
#include "printer_data.h"
@@ -126,7 +127,7 @@
struct lyd_node *tree;
struct lyd_node_term *leaf;
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("foo", tree->schema->name);
@@ -143,7 +144,7 @@
/* make foo2 explicit */
data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("foo2", tree->schema->name);
@@ -155,7 +156,7 @@
/* parse foo2 but make it implicit */
data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" wd:default=\"true\">default-val</foo2>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LEAF, tree->schema->nodetype);
assert_string_equal("foo2", tree->schema->name);
@@ -187,7 +188,7 @@
"</element1>"
"<element1a/>"
"</any>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
assert_string_equal("any", tree->schema->name);
@@ -220,7 +221,7 @@
struct lyd_node_term *leaf;
/* check hashes */
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LIST, tree->schema->nodetype);
assert_string_equal("l1", tree->schema->name);
@@ -232,25 +233,25 @@
/* missing keys */
data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("List instance is missing its key \"a\". /a:l1[b='b'][c='1']");
data = "<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("List instance is missing its key \"b\". /a:l1[a='a']");
data = "<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("List instance is missing its key \"c\". /a:l1[a='a'][b='b']");
/* key duplicate */
data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("Duplicate instance of \"c\". /a:l1[a='a'][b='b'][c='1'][c='1']/c");
/* keys order */
data = "<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LIST, tree->schema->nodetype);
assert_string_equal("l1", tree->schema->name);
@@ -267,7 +268,7 @@
lyd_free_all(tree);
data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a></l1>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_LIST, tree->schema->nodetype);
assert_string_equal("l1", tree->schema->name);
@@ -282,7 +283,7 @@
logbuf_clean();
lyd_free_all(tree);
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_PARSE_STRICT, 0, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, 0, &tree));
logbuf_assert("Invalid position of the key \"b\" in a list. Line number 1.");
*state = NULL;
@@ -297,7 +298,7 @@
struct lyd_node *tree;
struct lyd_node_inner *cont;
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
assert_string_equal("c", tree->schema->name);
@@ -306,7 +307,7 @@
lyd_free_all(tree);
data = "<cp xmlns=\"urn:tests:a\"/>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
assert_string_equal("cp", tree->schema->name);
@@ -331,12 +332,12 @@
/* invalid value, no flags */
data = "<foo3 xmlns=\"urn:tests:a\"/>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("Invalid empty uint32 value. /a:foo3");
assert_null(tree);
/* opaq flag */
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_null(tree->schema);
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "foo3");
@@ -349,12 +350,12 @@
/* missing key, no flags */
data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><d>val_d</d></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("List instance is missing its key \"c\". /a:l1[a='val_a'][b='val_b']");
assert_null(tree);
/* opaq flag */
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ , LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ , LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_null(tree->schema);
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
@@ -367,12 +368,12 @@
/* invalid key, no flags */
data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><c>val_c</c></l1>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
logbuf_assert("Invalid int16 value \"val_c\". /a:l1/c");
assert_null(tree);
/* opaq flag */
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_null(tree->schema);
assert_string_equal(((struct lyd_node_opaq *)tree)->name, "l1");
@@ -384,7 +385,8 @@
lyd_free_all(tree);
/* opaq flag and fail */
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, "<a xmlns=\"ns\"><b>x</b><c xml:id=\"D\">1</c></a>", LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, "<a xmlns=\"ns\"><b>x</b><c xml:id=\"D\">1</c></a>", LYD_XML,
+ LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
ly_out_free(out, NULL, 1);
@@ -398,6 +400,7 @@
*state = test_rpc;
const char *data;
+ struct ly_in *in;
char *str;
struct lyd_node *tree, *op;
const struct lyd_node *node;
@@ -423,7 +426,9 @@
"</config>"
"</edit-config>"
"</rpc>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &tree, &op));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+ ly_in_free(in, 0);
assert_non_null(op);
assert_string_equal(op->schema->name, "edit-config");
@@ -484,6 +489,7 @@
*state = test_action;
const char *data;
+ struct ly_in *in;
char *str;
struct lyd_node *tree, *op;
const struct lyd_node *node;
@@ -501,7 +507,9 @@
"</c>"
"</action>"
"</rpc>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &tree, &op));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+ ly_in_free(in, 0);
assert_non_null(op);
assert_string_equal(op->schema->name, "act");
@@ -543,6 +551,7 @@
*state = test_notification;
const char *data;
+ struct ly_in *in;
char *str;
struct lyd_node *tree, *ntf;
const struct lyd_node *node;
@@ -559,7 +568,9 @@
"</n1>"
"</c>"
"</notification>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_notif(ctx, data, &tree, &ntf));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+ ly_in_free(in, 0);
assert_non_null(ntf);
assert_string_equal(ntf->schema->name, "n1");
@@ -584,7 +595,9 @@
/* top-level notif without envelope */
data = "<n2 xmlns=\"urn:tests:a\"/>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_notif(ctx, data, &tree, &ntf));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+ ly_in_free(in, 0);
assert_non_null(ntf);
assert_string_equal(ntf->schema->name, "n2");
@@ -611,6 +624,7 @@
*state = test_reply;
const char *data;
+ struct ly_in *in;
char *str;
struct lyd_node *request, *tree, *op;
const struct lyd_node *node;
@@ -624,12 +638,17 @@
"<al>value</al>"
"</act>"
"</c>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
+ ly_in_free(in, 0);
+
data =
"<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\">"
"<al xmlns=\"urn:tests:a\">25</al>"
"</rpc-reply>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &tree, &op));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_reply(request, in, LYD_XML, &tree, &op));
+ ly_in_free(in, 0);
lyd_free_all(request);
assert_non_null(op);
diff --git a/tests/utests/data/test_printer_xml.c b/tests/utests/data/test_printer_xml.c
index e972808..7f44fb4 100644
--- a/tests/utests/data/test_printer_xml.c
+++ b/tests/utests/data/test_printer_xml.c
@@ -178,7 +178,6 @@
const char *data;
const char *result;
char *printed;
- ssize_t len;
struct ly_out *out;
s->func = test_leaf;
@@ -187,8 +186,8 @@
data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n </int8>";
result = "<int8 xmlns=\"urn:tests:types\">15</int8>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, result);
lyd_free_all(tree);
@@ -203,7 +202,6 @@
struct lyd_node *tree;
const char *data;
char *printed;
- ssize_t len;
struct ly_out *out;
s->func = test_anydata;
@@ -211,8 +209,8 @@
data = "<any xmlns=\"urn:tests:types\"><somexml xmlns:x=\"url:x\" xmlns=\"example.com\"><x:x/></somexml></any>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
/* canonized */
data = "<any xmlns=\"urn:tests:types\"><somexml xmlns=\"example.com\"><x xmlns=\"url:x\"/></somexml></any>";
assert_string_equal(printed, data);
@@ -221,8 +219,8 @@
data = "<any xmlns=\"urn:tests:types\"/>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, 0)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
lyd_free_all(tree);
@@ -243,8 +241,8 @@
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(out, tree, LYD_XML, 0)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, 0));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
/* canonized */
data =
"<any xmlns=\"urn:tests:types\">"
@@ -271,7 +269,6 @@
struct lyd_node *tree;
const char *data;
char *printed;
- ssize_t len;
struct ly_out *out;
s->func = test_defaults;
@@ -282,27 +279,27 @@
data = "<c xmlns=\"urn:defaults\">aa</c>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
" ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
" ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>";
@@ -315,23 +312,23 @@
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\">/d:b</a>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
assert_string_equal(printed, data);
ly_out_reset(out);
@@ -341,20 +338,20 @@
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_TRIM));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c>"
"<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
" ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>"
@@ -362,8 +359,8 @@
assert_string_equal(printed, data);
ly_out_reset(out);
- assert_true((len = lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG)) >= 0);
- assert_int_equal(len, strlen(printed));
+ assert_int_equal(LY_SUCCESS, lyd_print(out, tree, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_IMPL_TAG));
+ assert_int_equal(strlen(printed), ly_out_printed(out));
data = "<c xmlns=\"urn:defaults\">aa</c><a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b>";
assert_string_equal(printed, data);
ly_out_reset(out);
diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c
index f80ce9f..cd05191 100644
--- a/tests/utests/data/test_validation.c
+++ b/tests/utests/data/test_validation.c
@@ -21,6 +21,7 @@
#include <string.h>
#include "context.h"
+#include "parser.h"
#include "parser_data.h"
#include "printer.h"
#include "printer_data.h"
@@ -477,19 +478,19 @@
struct lyd_node *tree;
data = "<c xmlns=\"urn:tests:a\">hey</c>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("When condition \"/cont/b = 'val_b'\" not satisfied. /a:c");
data = "<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_string_equal("c", tree->next->schema->name);
assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
lyd_free_all(tree);
data = "<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
assert_string_equal("a", lyd_node_children(tree, 0)->schema->name);
assert_int_equal(LYD_WHEN_TRUE, lyd_node_children(tree, 0)->flags);
@@ -509,22 +510,22 @@
struct lyd_node *tree;
data = "<d xmlns=\"urn:tests:b\"/>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Mandatory node \"choic\" instance does not exist. /b:choic");
data = "<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
data = "<a xmlns=\"urn:tests:b\">string</a>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
data = "<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -540,14 +541,14 @@
struct lyd_node *tree;
data = "<d xmlns=\"urn:tests:c\"/>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
data =
"<l xmlns=\"urn:tests:c\">val1</l>"
"<l xmlns=\"urn:tests:c\">val2</l>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
@@ -555,7 +556,7 @@
"<l xmlns=\"urn:tests:c\">val1</l>"
"<l xmlns=\"urn:tests:c\">val2</l>"
"<l xmlns=\"urn:tests:c\">val3</l>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -568,7 +569,7 @@
"<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>"
"<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>"
"<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Too many \"lt\" instances. /c:lt");
@@ -591,7 +592,7 @@
"<lt xmlns=\"urn:tests:d\">"
"<k>val2</k>"
"</lt>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -604,7 +605,7 @@
"<k>val2</k>"
"<l1>not-same</l1>"
"</lt>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -617,7 +618,7 @@
"<k>val2</k>"
"<l1>same</l1>"
"</lt>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
@@ -655,7 +656,7 @@
"<k>val8</k>"
"<l1>8</l1>"
"</lt>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -689,7 +690,7 @@
"<lt xmlns=\"urn:tests:d\">"
"<k>val8</k>"
"</lt>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -723,7 +724,7 @@
"<k>val8</k>"
"<l1>8</l1>"
"</lt>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
@@ -795,7 +796,7 @@
"<l3>3</l3>"
"</lt3>"
"</lt2>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -856,7 +857,7 @@
"<l3>3</l3>"
"</lt3>"
"</lt2>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Unique data leaf(s) \"l3\" not satisfied in \"/d:lt2[k='val2']/lt3[kk='val3']\" and"
" \"/d:lt2[k='val2']/lt3[kk='val1']\". /d:lt2[k='val2']/lt3[kk='val1']");
@@ -897,7 +898,7 @@
"</cont>"
"<l4>5</l4>"
"</lt2>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Unique data leaf(s) \"cont/l2 l4\" not satisfied in \"/d:lt2[k='val4']\" and \"/d:lt2[k='val2']\". /d:lt2[k='val2']");
@@ -945,7 +946,7 @@
"<l5>3</l5>"
"<l6>3</l6>"
"</lt2>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Unique data leaf(s) \"l5 l6\" not satisfied in \"/d:lt2[k='val5']\" and \"/d:lt2[k='val3']\". /d:lt2[k='val3']");
@@ -961,51 +962,51 @@
struct lyd_node *tree;
data = "<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"d\". /e:d");
data = "<lt xmlns=\"urn:tests:e\"><k>A</k></lt><lt xmlns=\"urn:tests:e\"><k>B</k></lt><lt xmlns=\"urn:tests:e\"><k>A</k></lt>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"lt\". /e:lt[k='A']");
data = "<ll xmlns=\"urn:tests:e\">A</ll><ll xmlns=\"urn:tests:e\">B</ll><ll xmlns=\"urn:tests:e\">B</ll>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"ll\". /e:ll[.='B']");
data = "<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"cont\". /e:cont");
/* same tests again but using hashes */
data = "<cont xmlns=\"urn:tests:e\"><d>25</d><d>50</d><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll></cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"d\". /e:cont/d");
data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
"<lt><k>a</k></lt><lt><k>b</k></lt><lt><k>c</k></lt><lt><k>d</k></lt><lt><k>c</k></lt></cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"lt\". /e:cont/lt[k='c']");
data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
"<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"ll\". /e:cont/ll[.='d']");
/* cases */
data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><l xmlns=\"urn:tests:e\">b</l>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Duplicate instance of \"l\". /e:l[.='b']");
data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><a xmlns=\"urn:tests:e\">aa</a>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Data for both cases \"a\" and \"b\" exist. /e:choic");
@@ -1185,7 +1186,7 @@
"<cont xmlns=\"urn:tests:g\">"
"<d>51</d>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Data are disabled by \"cont\" schema node if-feature. /g:cont");
@@ -1204,7 +1205,7 @@
"<e>val</e>"
"</cont2>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Data are disabled by \"cont2\" schema node if-feature. /g:cont/cont2");
@@ -1212,14 +1213,14 @@
"<cont xmlns=\"urn:tests:g\">"
"<a>val</a>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Data are disabled by \"choic\" schema node if-feature. /g:cont/a");
/* enable f3 */
assert_int_equal(lys_feature_enable(mod, "f3"), LY_SUCCESS);
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -1228,14 +1229,14 @@
"<cont xmlns=\"urn:tests:g\">"
"<l>val</l>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Data are disabled by \"b\" schema node if-feature. /g:cont/l");
/* enable f2 */
assert_int_equal(lys_feature_enable(mod, "f2"), LY_SUCCESS);
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_siblings(tree);
@@ -1252,7 +1253,7 @@
"<e>val</e>"
"</cont2>"
"</cont>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
assert_non_null(tree);
assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT));
@@ -1286,15 +1287,15 @@
"<l>val</l>"
"</cont2>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &tree));
assert_null(tree);
logbuf_assert("Invalid state data node \"cont2\" found. Line number 1.");
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, &tree));
assert_null(tree);
logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
assert_non_null(tree);
assert_int_equal(LY_EVALID, lyd_validate(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE));
@@ -1318,7 +1319,7 @@
"<l>wrong</l>"
"<l2>val</l2>"
"</cont>";
- assert_int_equal(LY_EVALID, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_null(tree);
logbuf_assert("Must condition \"../l = 'right'\" not satisfied. /i:cont/l2");
@@ -1327,7 +1328,7 @@
"<l>right</l>"
"<l2>val</l2>"
"</cont>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, 0, LYD_VALIDATE_PRESENT, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
assert_non_null(tree);
lyd_free_tree(tree);
@@ -1340,6 +1341,7 @@
*state = test_action;
const char *data;
+ struct ly_in *in;
struct lyd_node *tree, *op_tree;
const struct lys_module *mod;
@@ -1352,20 +1354,22 @@
"</act>"
"</l1>"
"</cont>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &op_tree, NULL));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &op_tree, NULL));
assert_non_null(op_tree);
/* missing leafref */
assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_RPC));
logbuf_assert("Invalid leafref value \"target\" - no target instance \"/lf3\" with the same value."
" /j:cont/l1[k='val1']/act/lf2");
+ ly_in_free(in, 0);
data =
"<cont xmlns=\"urn:tests:j\">"
"<lf1>not true</lf1>"
"</cont>"
"<lf3 xmlns=\"urn:tests:j\">target</lf3>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
assert_non_null(tree);
/* disabled if-feature */
@@ -1386,7 +1390,7 @@
"<lf1>true</lf1>"
"</cont>"
"<lf3 xmlns=\"urn:tests:j\">target</lf3>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
assert_non_null(tree);
/* success */
@@ -1405,6 +1409,7 @@
*state = test_reply;
const char *data;
+ struct ly_in *in;
struct lyd_node *tree, *op_tree, *request;
const struct lys_module *mod;
@@ -1417,12 +1422,17 @@
"</act>"
"</l1>"
"</cont>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_rpc(ctx, data, &request, NULL));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
assert_non_null(request);
+ ly_in_free(in, 0);
+
data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_reply(request, data, &op_tree, NULL));
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_reply(request, in, LYD_XML, &op_tree, NULL));
lyd_free_all(request);
assert_non_null(op_tree);
+ ly_in_free(in, 0);
/* missing leafref */
assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_REPLY));
@@ -1434,7 +1444,7 @@
"<lf1>not true</lf1>"
"</cont>"
"<lf4 xmlns=\"urn:tests:j\">target</lf4>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
assert_non_null(tree);
/* disabled if-feature */
@@ -1455,7 +1465,7 @@
"<lf1>true2</lf1>"
"</cont>"
"<lf4 xmlns=\"urn:tests:j\">target</lf4>";
- assert_int_equal(LY_SUCCESS, lyd_parse_xml_data(ctx, data, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_TRUSTED, 0, &tree));
assert_non_null(tree);
/* success */