XML printer FEATURE support for actions and anydata
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 1e8de87..e236b69 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -362,7 +362,7 @@
size_t p_len, n_len;
/* skip children data and store them as a string */
- while (cur_element_index <= ctx->elements.count) {
+ while (ctx->status != LYXML_END && cur_element_index <= ctx->elements.count) {
switch (ctx->status) {
case LYXML_ELEMENT:
ret = lyxml_get_element((struct lyxml_context *)ctx, data, &p, &p_len, &n, &n_len);
@@ -379,18 +379,19 @@
}
break;
case LYXML_END:
- /* unexpected end of data */
+ /* end of data */
LOGINT(ctx->ctx);
ret = LY_EINT;
goto cleanup;
}
LY_CHECK_GOTO(ret, cleanup);
}
- /* data now points after the anydata's closing element tag, we need just end of its content */
- for (stop = *data - 1; *stop != '<'; --stop);
-
((struct lyd_node_any*)cur)->value_type = LYD_ANYDATA_XML;
- ((struct lyd_node_any*)cur)->value.xml = lydict_insert(ctx->ctx, start, stop - start);
+ if (start != *data) {
+ /* data now points after the anydata's closing element tag, we need just end of its content */
+ for (stop = *data - 1; *stop != '<'; --stop);
+ ((struct lyd_node_any*)cur)->value.xml = lydict_insert(ctx->ctx, start, stop - start);
+ }
}
/* calculate the hash and insert it into parent (list with keys is handled when its keys are inserted) */
@@ -431,10 +432,6 @@
/* init */
*result = NULL;
- if (!data || !data[0]) {
- goto no_data;
- }
-
if (options & LYD_OPT_RPCREPLY) {
/* prepare container for RPC reply, for which we need RPC
* - prepare *result as top-level node
@@ -442,7 +439,10 @@
const struct lyd_node *action;
for (action = trees[0]; action && action->schema->nodetype != LYS_ACTION; action = lyd_node_children(action)) {
/* skip list's keys */
- for ( ;action->schema->nodetype == LYS_LEAF; action = action->next);
+ for ( ;action && action->schema->nodetype == LYS_LEAF; action = action->next);
+ if (action && action->schema->nodetype == LYS_ACTION) {
+ break;
+ }
}
if (!action) {
LOGERR(ctx, LY_EINVAL, "Data parser invalid argument trees - the first item in the array must be the RPC/action request when parsing %s.",
@@ -454,6 +454,10 @@
for (*result = (struct lyd_node*)parent; (*result)->parent; *result = (struct lyd_node*)(*result)->parent);
}
+ if (!data || !data[0]) {
+ goto no_data;
+ }
+
ret = lydxml_nodes(&xmlctx, parent, &data, *result ? &parent->child : result);
if (ret) {
lyd_free_all(*result);
diff --git a/src/printer_data.h b/src/printer_data.h
index 197463c..245dbb4 100644
--- a/src/printer_data.h
+++ b/src/printer_data.h
@@ -63,7 +63,7 @@
* node of the data tree to print the specific subtree.
* @param[in] format Data output format.
* @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted.
- * @return Number of printed bytes in case of success.
+ * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
* @return Negative value failure (absolute value corresponds to LY_ERR values).
*/
ssize_t lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options);
@@ -76,7 +76,7 @@
* node of the data tree to print the specific subtree.
* @param[in] format Data output format.
* @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted.
- * @return Number of printed bytes in case of success.
+ * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
* @return Negative value failure (absolute value corresponds to LY_ERR values).
*/
ssize_t lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options);
@@ -89,7 +89,7 @@
* node of the data tree to print the specific subtree.
* @param[in] format Data output format.
* @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted.
- * @return Number of printed bytes in case of success.
+ * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
* @return Negative value failure (absolute value corresponds to LY_ERR values).
*/
ssize_t lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options);
@@ -102,7 +102,7 @@
* node of the data tree to print the specific subtree.
* @param[in] format Data output format.
* @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted.
- * @return Number of printed bytes in case of success.
+ * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
* @return Negative value failure (absolute value corresponds to LY_ERR values).
*/
ssize_t lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options);
@@ -116,7 +116,7 @@
* node of the data tree to print the specific subtree.
* @param[in] format Data output format.
* @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted.
- * @return Number of printed bytes in case of success.
+ * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
* @return Negative value failure (absolute value corresponds to LY_ERR values).
*/
ssize_t lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyd_node *root,
diff --git a/src/printer_xml.c b/src/printer_xml.c
index 8d2dd01..ecc6e75 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -121,10 +121,9 @@
break;
case LYS_CONTAINER:
case LYS_LIST:
-#if 0
- case LYS_RPC:
case LYS_ACTION:
case LYS_NOTIF:
+#if 0
if (options & (LYP_WD_ALL_TAG | LYP_WD_IMPL_TAG)) {
/* get with-defaults module and print its namespace */
wdmod = ly_ctx_get_module(node->schema->module->ctx, "ietf-netconf-with-defaults", NULL, 1);
@@ -419,91 +418,73 @@
return LY_SUCCESS;
}
-#if 0
-static int
-xml_print_anydata(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
+static LY_ERR
+xml_print_anydata(struct xmlpr_ctx *ctx, const struct lyd_node_any *node)
{
- char *buf;
- struct lyd_node_anydata *any = (struct lyd_node_anydata *)node;
+ struct lyd_node_any *any = (struct lyd_node_any *)node;
struct lyd_node *iter;
- const char *ns;
+ int options_backup;
- LY_PRINT_SET;
+ LY_CHECK_RET(xml_print_node_open(ctx, (struct lyd_node *)node));
- if (toplevel || !node->parent || nscmp(node, node->parent)) {
- /* print "namespace" */
- ns = lyd_node_module(node)->ns;
- ly_print(out, "%*s<%s xmlns=\"%s\"", INDENT, node->schema->name, ns);
- } else {
- ly_print(out, "%*s<%s", INDENT, node->schema->name);
- }
-
- if (toplevel) {
- xml_print_ns(out, node, options);
- }
- if (xml_print_attrs(out, node, options)) {
- return EXIT_FAILURE;
- }
- if (!(void*)any->value.tree || (any->value_type == LYD_ANYDATA_CONSTSTRING && !any->value.str[0])) {
+ if (!any->value.tree) {
/* no content */
- ly_print(out, "/>%s", level ? "\n" : "");
+no_content:
+ ly_print(ctx->out, "/>%s", LEVEL ? "\n" : "");
+ return LY_SUCCESS;
} else {
- if (any->value_type == LYD_ANYDATA_DATATREE) {
- /* print namespaces in the anydata data tree */
- LY_TREE_FOR(any->value.tree, iter) {
- xml_print_ns(out, iter, options);
- }
- }
- /* close opening tag ... */
- ly_print(out, ">");
- /* ... and print anydata content */
switch (any->value_type) {
- case LYD_ANYDATA_CONSTSTRING:
- lyxml_dump_text(out, any->value.str, LYXML_DATA_ELEM);
- break;
case LYD_ANYDATA_DATATREE:
- if (any->value.tree) {
- if (level) {
- ly_print(out, "\n");
- }
- LY_TREE_FOR(any->value.tree, iter) {
- if (xml_print_node(out, level ? level + 1 : 0, iter, 0, (options & ~(LYP_WITHSIBLINGS | LYP_NETCONF)))) {
- return EXIT_FAILURE;
- }
+ /* close opening tag and print data */
+ options_backup = ctx->options;
+ ctx->options &= ~(LYDP_WITHSIBLINGS | LYDP_NETCONF);
+ LEVEL_INC;
+
+ ly_print(ctx->out, ">%s", LEVEL ? "\n" : "");
+ LY_LIST_FOR(any->value.tree, iter) {
+ if (xml_print_node(ctx, iter)) {
+ return EXIT_FAILURE;
}
}
- break;
- case LYD_ANYDATA_XML:
- lyxml_print_mem(&buf, any->value.xml, (level ? LYXML_PRINT_FORMAT | LYXML_PRINT_NO_LAST_NEWLINE : 0)
- | LYXML_PRINT_SIBLINGS);
- ly_print(out, "%s%s", level ? "\n" : "", buf);
- free(buf);
- break;
- case LYD_ANYDATA_SXML:
- /* print without escaping special characters */
- ly_print(out, "%s", any->value.str);
- break;
- case LYD_ANYDATA_JSON:
- case LYD_ANYDATA_LYB:
- /* JSON and LYB format is not supported */
- LOGWRN(node->schema->module->ctx, "Unable to print anydata content (type %d) as XML.", any->value_type);
+
+ LEVEL_DEC;
+ ctx->options = options_backup;
break;
case LYD_ANYDATA_STRING:
- case LYD_ANYDATA_SXMLD:
- case LYD_ANYDATA_JSOND:
- case LYD_ANYDATA_LYBD:
- /* dynamic strings are used only as input parameters */
- assert(0);
+ /* escape XML-sensitive characters */
+ if (!any->value.str[0]) {
+ goto no_content;
+ }
+ /* close opening tag and print data */
+ ly_print(ctx->out, ">");
+ lyxml_dump_text(ctx->out, any->value.str, 0);
break;
+ case LYD_ANYDATA_XML:
+ /* print without escaping special characters */
+ if (!any->value.str[0]) {
+ goto no_content;
+ }
+ ly_print(ctx->out, ">%s", any->value.str);
+ break;
+ case LYD_ANYDATA_JSON:
+#if 0 /* TODO LYB format */
+ case LYD_ANYDATA_LYB:
+#endif
+ /* JSON and LYB format is not supported */
+ LOGWRN(node->schema->module->ctx, "Unable to print anydata content (type %d) as XML.", any->value_type);
+ goto no_content;
}
/* closing tag */
- ly_print(out, "</%s>%s", node->schema->name, level ? "\n" : "");
+ if (any->value_type == LYD_ANYDATA_DATATREE) {
+ ly_print(ctx->out, "%*s</%s>%s", INDENT, node->schema->name, LEVEL ? "\n" : "");
+ } else {
+ ly_print(ctx->out, "</%s>%s", node->schema->name, LEVEL ? "\n" : "");
+ }
}
- LY_PRINT_RET(node->schema->module->ctx);
+ return LY_SUCCESS;
}
-#endif
/**
* @brief Print XML element representing lyd_node.
@@ -525,24 +506,20 @@
#endif
switch (node->schema->nodetype) {
-#if 0
- case LYS_NOTIF:
- case LYS_ACTION:
-#endif
case LYS_CONTAINER:
case LYS_LIST:
+ case LYS_NOTIF:
+ case LYS_ACTION:
ret = xml_print_inner(ctx, (const struct lyd_node_inner*)node);
break;
case LYS_LEAF:
case LYS_LEAFLIST:
ret = xml_print_term(ctx, (const struct lyd_node_term*)node);
break;
-#if 0
case LYS_ANYXML:
case LYS_ANYDATA:
- ret = xml_print_anydata(ctx, node);
+ ret = xml_print_anydata(ctx, (const struct lyd_node_any*)node);
break;
-#endif
default:
LOGINT(node->schema->module->ctx);
ret = LY_EINT;
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index c85e1f5..66bf94f 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -29,6 +29,8 @@
switch (node->schema->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
+ case LYS_ACTION:
+ case LYS_NOTIF:
return &((struct lyd_node_inner*)node)->child;
default:
return NULL;
diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt
index 7c20ce4..c5ded11 100644
--- a/tests/src/CMakeLists.txt
+++ b/tests/src/CMakeLists.txt
@@ -10,7 +10,8 @@
src_tree_schema_helpers
src_printer_yang
src_tree_data
- src_parser_xml)
+ src_parser_xml
+ src_printer_xml)
set(local_tests_wraps
" "
"-Wl,--wrap=realloc"
@@ -23,6 +24,7 @@
" "
" "
" "
+ " "
" ")
set(tests ${tests} ${local_tests} PARENT_SCOPE)
set(tests_wraps ${tests_wraps} ${local_tests_wraps} PARENT_SCOPE)
diff --git a/tests/src/test_printer_xml.c b/tests/src/test_printer_xml.c
new file mode 100644
index 0000000..942f5b9
--- /dev/null
+++ b/tests/src/test_printer_xml.c
@@ -0,0 +1,289 @@
+/*
+ * @file test_printer_xml.c
+ * @author: Radek Krejci <rkrejci@cesnet.cz>
+ * @brief unit tests for functions from printer_yang.c
+ *
+ * Copyright (c) 2019 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "../../src/context.h"
+#include "../../src/printer_data.h"
+
+#define BUFSIZE 1024
+char logbuf[BUFSIZE] = {0};
+int store = -1; /* negative for infinite logging, positive for limited logging */
+
+struct state_s {
+ void *func;
+ struct ly_ctx *ctx;
+};
+
+/* set to 0 to printing error messages to stderr instead of checking them in code */
+#define ENABLE_LOGGER_CHECKING 1
+
+#if ENABLE_LOGGER_CHECKING
+static void
+logger(LY_LOG_LEVEL level, const char *msg, const char *path)
+{
+ (void) level; /* unused */
+ if (store) {
+ if (path && path[0]) {
+ snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
+ } else {
+ strncpy(logbuf, msg, BUFSIZE - 1);
+ }
+ if (store > 0) {
+ --store;
+ }
+ }
+}
+#endif
+
+static int
+setup(void **state)
+{
+ struct state_s *s;
+ const char *schema_a = "module defs {namespace urn:tests:defs;prefix d;yang-version 1.1;"
+ "identity crypto-alg; identity interface-type; identity ethernet {base interface-type;} identity fast-ethernet {base ethernet;}}";
+ const char *schema_b = "module types {namespace urn:tests:types;prefix t;yang-version 1.1; import defs {prefix defs;}"
+ "feature f; identity gigabit-ethernet { base defs:ethernet;}"
+ "container cont {leaf leaftarget {type empty;}"
+ "list listtarget {key id; max-elements 5;leaf id {type uint8;} leaf value {type string;}"
+ "action test {input {leaf a {type string;}} output {leaf b {type string;}}}}"
+ "leaf-list leaflisttarget {type uint8; max-elements 5;}}"
+ "list list {key id; leaf id {type string;} leaf value {type string;} leaf-list targets {type string;}}"
+ "list list2 {key \"id value\"; leaf id {type string;} leaf value {type string;}}"
+ "list list_inst {key id; leaf id {type instance-identifier {require-instance true;}} leaf value {type string;}}"
+ "list list_ident {key id; leaf id {type identityref {base defs:interface-type;}} leaf value {type string;}}"
+ "leaf-list leaflisttarget {type string;}"
+ "leaf binary {type binary {length 5 {error-message \"This base64 value must be of length 5.\";}}}"
+ "leaf binary-norestr {type binary;}"
+ "leaf int8 {type int8 {range 10..20;}}"
+ "leaf uint8 {type uint8 {range 150..200;}}"
+ "leaf int16 {type int16 {range -20..-10;}}"
+ "leaf uint16 {type uint16 {range 150..200;}}"
+ "leaf int32 {type int32;}"
+ "leaf uint32 {type uint32;}"
+ "leaf int64 {type int64;}"
+ "leaf uint64 {type uint64;}"
+ "leaf bits {type bits {bit zero; bit one {if-feature f;} bit two;}}"
+ "leaf enums {type enumeration {enum white; enum yellow {if-feature f;}}}"
+ "leaf dec64 {type decimal64 {fraction-digits 1; range 1.5..10;}}"
+ "leaf dec64-norestr {type decimal64 {fraction-digits 18;}}"
+ "leaf str {type string {length 8..10; pattern '[a-z ]*';}}"
+ "leaf str-norestr {type string;}"
+ "leaf bool {type boolean;}"
+ "leaf empty {type empty;}"
+ "leaf ident {type identityref {base defs:interface-type;}}"
+ "leaf inst {type instance-identifier {require-instance true;}}"
+ "leaf inst-noreq {type instance-identifier {require-instance false;}}"
+ "leaf lref {type leafref {path /leaflisttarget; require-instance true;}}"
+ "leaf lref2 {type leafref {path \"../list[id = current()/../str-norestr]/targets\"; require-instance true;}}"
+ "leaf un1 {type union {"
+ "type leafref {path /int8; require-instance true;}"
+ "type union { type identityref {base defs:interface-type;} type instance-identifier {require-instance true;} }"
+ "type string {length 1..20;}}}"
+ "anydata any;"
+ "rpc sum {input {leaf x {type uint8;} leaf y {type uint8;}} output {leaf result {type uint16;}}}}";
+
+ s = calloc(1, sizeof *s);
+ assert_non_null(s);
+
+#if ENABLE_LOGGER_CHECKING
+ ly_set_log_clb(logger, 1);
+#endif
+
+ assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &s->ctx));
+ assert_non_null(lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG));
+ assert_non_null(lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG));
+
+ *state = s;
+
+ return 0;
+}
+
+static int
+teardown(void **state)
+{
+ struct state_s *s = (struct state_s*)(*state);
+
+#if ENABLE_LOGGER_CHECKING
+ if (s->func) {
+ fprintf(stderr, "%s\n", logbuf);
+ }
+#endif
+
+ ly_ctx_destroy(s->ctx, NULL);
+ free(s);
+
+ return 0;
+}
+
+void
+logbuf_clean(void)
+{
+ logbuf[0] = '\0';
+}
+
+#if ENABLE_LOGGER_CHECKING
+# define logbuf_assert(str) assert_string_equal(logbuf, str)
+#else
+# define logbuf_assert(str)
+#endif
+
+static void
+test_leaf(void **state)
+{
+ struct state_s *s = (struct state_s*)(*state);
+ struct lyd_node *tree;
+ const char *data;
+ const char *result;
+ char *printed;
+ ssize_t len;
+
+ s->func = test_leaf;
+
+ data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n </int8>";
+ result = "<int8 xmlns=\"urn:tests:types\">15</int8>";
+ assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, LYD_OPT_DATA, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, result);
+ free(printed);
+ lyd_free_all(tree);
+
+ s->func = NULL;
+}
+
+static void
+test_anydata(void **state)
+{
+ struct state_s *s = (struct state_s*)(*state);
+ struct lyd_node *tree;
+ const char *data;
+ char *printed;
+ ssize_t len;
+
+ s->func = test_anydata;
+
+ data = "<any xmlns=\"urn:tests:types\"><somexml xmlns:x=\"url:x\" xmlns=\"example.com\"><x:x/></somexml></any>";
+ assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, LYD_OPT_DATA, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, data);
+ free(printed);
+ lyd_free_all(tree);
+
+ data = "<any xmlns=\"urn:tests:types\"/>";
+ assert_non_null(tree = lyd_parse_mem(s->ctx, data, LYD_XML, LYD_OPT_DATA, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, data);
+ free(printed);
+ lyd_free_all(tree);
+
+ s->func = NULL;
+}
+
+static void
+test_rpc(void **state)
+{
+ struct state_s *s = (struct state_s*)(*state);
+ struct lyd_node *tree1;
+ struct lyd_node *tree2;
+ const struct lyd_node **trees;
+ const char *request;
+ const char *reply, *result;
+ char *printed;
+ ssize_t len;
+
+ s->func = test_rpc;
+
+ request = "<sum xmlns=\"urn:tests:types\"><x>10</x><y>20</y></sum>";
+ reply = "<result xmlns=\"urn:tests:types\">30</result>";
+ result = "<sum xmlns=\"urn:tests:types\"><result>30</result></sum>";
+ assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree1, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, request);
+ free(printed);
+ assert_non_null(trees = lyd_trees_new(1, tree1));
+ assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
+ assert_true((len = lyd_print_mem(&printed, tree2, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, result);
+ free(printed);
+ lyd_trees_free(trees, 0);
+ lyd_free_all(tree1);
+ lyd_free_all(tree2);
+
+ /* no arguments */
+ request = "<sum xmlns=\"urn:tests:types\"/>";
+ reply = "";
+ result = "<sum xmlns=\"urn:tests:types\"/>";
+ assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree1, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, request);
+ free(printed);
+ assert_non_null(trees = lyd_trees_new(1, tree1));
+ assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
+ assert_true((len = lyd_print_mem(&printed, tree2, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, result);
+ free(printed);
+ lyd_trees_free(trees, 0);
+ lyd_free_all(tree1);
+ lyd_free_all(tree2);
+
+ /* action
+ * "container cont {leaf leaftarget {type empty;}"
+ "list listtarget {key id; max-elements 5;leaf id {type uint8;} leaf value {type string;}"
+ "action test {input {leaf a {type string;}} output {leaf b {type string;}}}}"
+ "leaf-list leaflisttarget {type uint8; max-elements 5;}}"
+ */
+ request = "<cont xmlns=\"urn:tests:types\"><listtarget><id>10</id><test><a>test</a></test></listtarget></cont>";
+ reply = "<b xmlns=\"urn:tests:types\">test-reply</b>";
+ result = "<cont xmlns=\"urn:tests:types\"><listtarget><id>10</id><test><b>test-reply</b></test></listtarget></cont>";;
+ assert_non_null(tree1 = lyd_parse_mem(s->ctx, request, LYD_XML, LYD_OPT_RPC, NULL));
+ assert_true((len = lyd_print_mem(&printed, tree1, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, request);
+ free(printed);
+ assert_non_null(trees = lyd_trees_new(1, tree1));
+ assert_non_null(tree2 = lyd_parse_mem(s->ctx, reply, LYD_XML, LYD_OPT_RPCREPLY, trees));
+ assert_true((len = lyd_print_mem(&printed, tree2, LYD_XML, 0)) >= 0);
+ assert_int_equal(len, strlen(printed));
+ assert_string_equal(printed, result);
+ free(printed);
+ lyd_trees_free(trees, 0);
+ lyd_free_all(tree1);
+ lyd_free_all(tree2);
+
+ s->func = NULL;
+}
+
+int main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(test_leaf, setup, teardown),
+ cmocka_unit_test_setup_teardown(test_anydata, setup, teardown),
+ cmocka_unit_test_setup_teardown(test_rpc, setup, teardown),
+ };
+
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}