parser json FEATURE support for nested ext instances with data
... such as schema-mount.
diff --git a/tests/modules/yang/sm.yang b/tests/modules/yang/sm.yang
index 00e9595..3da9c9a 100644
--- a/tests/modules/yang/sm.yang
+++ b/tests/modules/yang/sm.yang
@@ -22,9 +22,7 @@
leaf name {
type string;
}
- container mnt-root {
- yangmnt:mount-point "mnt-root";
- }
+ yangmnt:mount-point "mnt-root";
}
}
leaf target {
diff --git a/tests/plugins/simple.c b/tests/plugins/simple.c
index ead70b0..f74147d 100644
--- a/tests/plugins/simple.c
+++ b/tests/plugins/simple.c
@@ -53,7 +53,9 @@
.plugin.id = "libyang 2 - simple test, version 1",
.plugin.compile = &hint_compile,
.plugin.sprinter = NULL,
- .plugin.free = NULL
+ .plugin.free = NULL,
+ .plugin.parse = NULL,
+ .plugin.validate = NULL
},
{0} /* terminating zeroed item */
};
diff --git a/tests/utests/basic/test_json.c b/tests/utests/basic/test_json.c
index a8d3af4..244e328 100644
--- a/tests/utests/basic/test_json.c
+++ b/tests/utests/basic/test_json.c
@@ -29,20 +29,20 @@
/* empty */
str = "";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
lyjson_ctx_free(jsonctx);
str = " \n\t \n";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
lyjson_ctx_free(jsonctx);
/* constant values */
str = "true";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_TRUE, lyjson_ctx_status(jsonctx, 0));
assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
@@ -50,7 +50,7 @@
str = "false";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_FALSE, lyjson_ctx_status(jsonctx, 0));
assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
@@ -58,7 +58,7 @@
str = "null";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NULL, lyjson_ctx_status(jsonctx, 0));
assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
@@ -77,7 +77,7 @@
/* simple value */
str = "11";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("11", jsonctx->value);
assert_int_equal(2, jsonctx->value_len);
@@ -87,7 +87,7 @@
/* fraction number */
str = "37.7668";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("37.7668", jsonctx->value);
assert_int_equal(7, jsonctx->value_len);
@@ -97,7 +97,7 @@
/* negative number */
str = "-122.3959";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-122.3959", jsonctx->value);
assert_int_equal(9, jsonctx->value_len);
@@ -107,7 +107,7 @@
/* integer, positive exponent */
str = "550E3";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("550000", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -116,7 +116,7 @@
str = "-550E3";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-550000", jsonctx->value);
assert_int_equal(7, jsonctx->value_len);
@@ -126,7 +126,7 @@
/* integer, negative exponent */
str = "1E-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.1", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -135,7 +135,7 @@
str = "15E-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("1.5", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -144,7 +144,7 @@
str = "-15E-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-1.5", jsonctx->value);
assert_int_equal(4, jsonctx->value_len);
@@ -153,7 +153,7 @@
str = "16E-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.16", jsonctx->value);
assert_int_equal(4, jsonctx->value_len);
@@ -162,7 +162,7 @@
str = "-16E-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-0.16", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -171,7 +171,7 @@
str = "17E-3";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.017", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -180,7 +180,7 @@
str = "-17E-3";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-0.017", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -189,7 +189,7 @@
str = "21000E-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("210", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -198,7 +198,7 @@
str = "21000E-4";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("2.1", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -207,7 +207,7 @@
str = "21000E-7";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.0021", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -217,7 +217,7 @@
/* decimal number, positive exponent */
str = "5.087E1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("50.87", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -226,7 +226,7 @@
str = "-5.087E1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-50.87", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -235,7 +235,7 @@
str = "5.087E5";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("508700", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -244,7 +244,7 @@
str = "59.1e+1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("591", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -253,7 +253,7 @@
str = "0.005087E1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.05087", jsonctx->value);
assert_int_equal(7, jsonctx->value_len);
@@ -262,7 +262,7 @@
str = "0.005087E2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.5087", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -271,7 +271,7 @@
str = "0.005087E6";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("5087", jsonctx->value);
assert_int_equal(4, jsonctx->value_len);
@@ -280,7 +280,7 @@
str = "0.05087E6";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("50870", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -289,7 +289,7 @@
str = "0.005087E8";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("508700", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -299,7 +299,7 @@
/* decimal number, negative exponent */
str = "35.94e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("3.594", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -308,7 +308,7 @@
str = "-35.94e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("-3.594", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -317,7 +317,7 @@
str = "35.94e-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.3594", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -326,7 +326,7 @@
str = "35.94e-3";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.03594", jsonctx->value);
assert_int_equal(7, jsonctx->value_len);
@@ -335,7 +335,7 @@
str = "0.3594e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.03594", jsonctx->value);
assert_int_equal(7, jsonctx->value_len);
@@ -344,7 +344,7 @@
str = "0.03594e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.003594", jsonctx->value);
assert_int_equal(8, jsonctx->value_len);
@@ -353,7 +353,7 @@
str = "0.003594e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.0003594", jsonctx->value);
assert_int_equal(9, jsonctx->value_len);
@@ -362,7 +362,7 @@
str = "0.3594e-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.003594", jsonctx->value);
assert_int_equal(8, jsonctx->value_len);
@@ -371,7 +371,7 @@
str = "0.03594e-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.0003594", jsonctx->value);
assert_int_equal(9, jsonctx->value_len);
@@ -380,7 +380,7 @@
str = "0.003594e-2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.00003594", jsonctx->value);
assert_int_equal(10, jsonctx->value_len);
@@ -390,7 +390,7 @@
/* zero */
str = "0";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_true(jsonctx->value[0] == '0');
assert_int_equal(1, jsonctx->value_len);
@@ -399,7 +399,7 @@
str = "-0";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_true(jsonctx->value[0] == '-');
assert_true(jsonctx->value[1] == '0');
@@ -409,7 +409,7 @@
str = "94E0";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_true(jsonctx->value[0] == '9');
assert_true(jsonctx->value[1] == '4');
@@ -419,7 +419,7 @@
str = "0E2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_true(jsonctx->value[0] == '0');
assert_int_equal(1, jsonctx->value_len);
@@ -428,7 +428,7 @@
str = "-0E2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_true(jsonctx->value[0] == '-');
assert_true(jsonctx->value[1] == '0');
@@ -438,7 +438,7 @@
str = "5.320e+2";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("532", jsonctx->value);
assert_int_equal(3, jsonctx->value_len);
@@ -447,7 +447,7 @@
str = "5.320e-1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("0.532", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -457,67 +457,67 @@
/* various invalid inputs */
str = "-x";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character in JSON Number value (\"x\").", "Line number 1.");
str = " -";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1.");
str = "--1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character in JSON Number value (\"-\").", "Line number 1.");
str = "+1";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character sequence \"+1\", expected a JSON value.", "Line number 1.");
str = " 1.x ";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character in JSON Number value (\"x\").", "Line number 1.");
str = "1.";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1.");
str = " 1eo ";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character in JSON Number value (\"o\").", "Line number 1.");
str = "1e";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1.");
str = "1E1000";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Number encoded as a string exceeded the LY_NUMBER_MAXLEN limit.", "Line number 1.");
str = "1e9999999999999999999";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1e9999999999999999999).", "Line number 1.");
str = "1.1e66000";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1.1e66000).", "Line number 1.");
str = "1.1e-66000";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Exponent out-of-bounds in a JSON Number value (1.1e-66000).", "Line number 1.");
str = "-2.1e0.";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Unexpected character \".\" after JSON number.", "Line number 1.");
ly_in_free(in, 0);
@@ -537,7 +537,7 @@
#if 0
/* simple string */
str = "\"hello\"";
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0));
assert_ptr_equal(&str[1], jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -547,7 +547,7 @@
/* 4-byte utf8 character */
str = "\"\\t𠜎\"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("\t𠜎", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -559,7 +559,7 @@
* the YANG string type's restrictions apply to the JSON escape sequences */
str = "\"\\\" \\\\ \\r \\/ \\n \\t \\u20ac\"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("\" \\ \r / \n \t €", jsonctx->value);
assert_int_equal(15, jsonctx->value_len);
@@ -569,31 +569,31 @@
/* backspace and form feed are valid JSON escape sequences, but the control characters they represents are not allowed values for YANG string type */
str = "\"\\b\"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character reference \"\\b\" (0x00000008).", "Line number 1.");
str = "\"\\f\"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character reference \"\\f\" (0x0000000c).", "Line number 1.");
#endif
/* unterminated string */
str = "\"unterminated string";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Missing quotation-mark at the end of a JSON string.", "Line number 1.");
#if 0
/* invalid escape sequence */
str = "\"char \\x \"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character escape sequence \\x.", "Line number 1.");
/* new line is allowed only as escaped character in JSON */
str = "\"\n\"";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character in JSON string \"\n\" (0x0000000a).", "Line number 1.");
#endif
@@ -610,7 +610,7 @@
/* empty */
str = " { } ";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_OBJECT_EMPTY, lyjson_ctx_status(jsonctx, 0));
assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
@@ -619,7 +619,7 @@
/* simple value */
str = "{\"name\" : \"Radek\"}";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0));
assert_ptr_equal(&str[2], jsonctx->value);
assert_int_equal(4, jsonctx->value_len);
@@ -640,7 +640,7 @@
/* two values */
str = "{\"smart\" : true,\"handsom\":false}";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("smart\" : true,\"handsom\":false}", jsonctx->value);
assert_int_equal(5, jsonctx->value_len);
@@ -667,7 +667,7 @@
/* inherited objects */
str = "{\"person\" : {\"name\":\"Radek\"}}";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_OBJECT, lyjson_ctx_status(jsonctx, 0));
assert_string_equal("person\" : {\"name\":\"Radek\"}}", jsonctx->value);
assert_int_equal(6, jsonctx->value_len);
@@ -697,7 +697,7 @@
/* new line is allowed only as escaped character in JSON */
str = "{ unquoted : \"data\"}";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
CHECK_LOG_CTX("Invalid character sequence \"unquoted : \"data\"}\", expected a JSON object's member.", "Line number 1.");
ly_in_free(in, 0);
@@ -713,7 +713,7 @@
/* empty */
str = " [ ] ";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_ARRAY_EMPTY, lyjson_ctx_status(jsonctx, 0));
assert_int_equal(LY_SUCCESS, lyjson_ctx_next(jsonctx, NULL));
assert_int_equal(LYJSON_END, lyjson_ctx_status(jsonctx, 0));
@@ -722,7 +722,7 @@
/* simple value */
str = "[ null]";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0));
assert_null(jsonctx->value);
assert_int_equal(0, jsonctx->value_len);
@@ -740,7 +740,7 @@
/* two values */
str = "[{\"a\":null},\"x\"]";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0));
assert_null(jsonctx->value);
assert_int_equal(0, jsonctx->value_len);
@@ -773,7 +773,7 @@
/* new line is allowed only as escaped character in JSON */
str = "[ , null]";
assert_non_null(ly_in_memory(in, str));
- assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+ assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, 0, &jsonctx));
assert_int_equal(LY_EVALID, lyjson_ctx_next(jsonctx, NULL));
CHECK_LOG_CTX("Invalid character sequence \", null]\", expected a JSON value.", "Line number 1.");
lyjson_ctx_free(jsonctx);
diff --git a/tests/utests/extensions/test_schema_mount.c b/tests/utests/extensions/test_schema_mount.c
index 4e3b650..5216274 100644
--- a/tests/utests/extensions/test_schema_mount.c
+++ b/tests/utests/extensions/test_schema_mount.c
@@ -31,7 +31,7 @@
"container root2 {yangmnt:mount-point \"root\";}"
"container root3 {"
" list ls { key name; leaf name {type string;}"
- " container mnt-root {yangmnt:mount-point \"mnt-root\";}"
+ " yangmnt:mount-point \"mnt-root\";"
" }"
"}"
"leaf target{type string;}"
@@ -178,9 +178,9 @@
}
static void
-test_parse_xml_invalid(void **state)
+test_parse_invalid(void **state)
{
- const char *xml;
+ const char *xml, *json;
struct lyd_node *data;
/* no callback set */
@@ -197,6 +197,23 @@
CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.",
NULL);
+ json =
+ "{"
+ " \"sm:root\": {"
+ " \"unknown:unknown\": {"
+ " \"interface\": ["
+ " {"
+ " \"name\": \"bu\","
+ " \"type\": \"iana-if-type:ethernetCsmacd\""
+ " }"
+ " ]"
+ " }"
+ " }"
+ "}";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_EINVAL, data);
+ CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": Failed to get extension data, no callback set.",
+ NULL);
+
/* unknown data */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb, NULL);
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
@@ -210,6 +227,17 @@
CHECK_LOG_CTX("No module with namespace \"unknown\" in the context.",
"Schema location /sm:root, data location /sm:root, line number 1.");
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ assert_string_equal(LYD_NAME(data), "root");
+ assert_null(lyd_child(data));
+ assert_non_null(data->next);
+ assert_true(data->next->flags & LYD_DEFAULT);
+ lyd_free_siblings(data);
+
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("No module named \"unknown\" in the context.",
+ "Schema location /sm:root, data location /sm:root, line number 1.");
+
/* missing required callback data */
xml =
"<root xmlns=\"urn:sm\">"
@@ -223,6 +251,22 @@
CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
"Schema location /sm:root, data location /sm:root, line number 1.");
+ json =
+ "{"
+ " \"sm:root\": {"
+ " \"ietf-interfaces:interfaces\": {"
+ " \"interface\": ["
+ " {"
+ " \"name\": \"bu\""
+ " }"
+ " ]"
+ " }"
+ " }"
+ "}";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.",
+ "Schema location /sm:root, data location /sm:root, line number 1.");
+
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
"<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
" xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
@@ -253,6 +297,8 @@
"</modules-state>");
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
/* missing module in yang-library data */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
@@ -292,6 +338,8 @@
"</schema-mounts>");
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("Node \"interfaces\" not found as a child of \"root\" node.", NULL);
/* callback data correct, invalid YANG data */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
@@ -358,10 +406,24 @@
CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
"Mandatory node \"type\" instance does not exist.",
"Schema location /ietf-interfaces:interfaces/interface/type.");
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
+ "Mandatory node \"type\" instance does not exist.",
+ "Schema location /ietf-interfaces:interfaces/interface/type.");
- /* validation fail */
+ /* same validation fail in separate validation */
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
+ CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
+ "Mandatory node \"type\" instance does not exist.",
+ "Schema location /ietf-interfaces:interfaces/interface/type.");
+ lyd_free_siblings(data);
+
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT | LYD_PARSE_ONLY, 0, LY_SUCCESS, data);
+ assert_int_equal(LY_EVALID, lyd_validate_all(&data, NULL, LYD_VALIDATE_PRESENT, NULL));
+ CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
+ "Mandatory node \"type\" instance does not exist.",
+ "Schema location /ietf-interfaces:interfaces/interface/type.");
lyd_free_siblings(data);
/* success */
@@ -377,14 +439,32 @@
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+
+ json =
+ "{\n"
+ " \"sm:root\": {\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
}
static void
-test_parse_xml_inline(void **state)
+test_parse_inline(void **state)
{
- const char *xml;
+ const char *xml, *json;
struct lyd_node *data;
+ /* valid */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
"<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
" xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
@@ -468,6 +548,35 @@
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+ json =
+ "{\n"
+ " \"sm:root\": {\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"ietf-interfaces:interfaces-state\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
+ " \"oper-status\": \"not-present\",\n"
+ " \"statistics\": {\n"
+ " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
+
/* different yang-lib data */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
"<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
@@ -537,12 +646,16 @@
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
}
static void
-test_parse_xml_shared(void **state)
+test_parse_shared(void **state)
{
- const char *xml;
+ const char *xml, *json;
struct lyd_node *data;
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
@@ -628,6 +741,35 @@
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+ json =
+ "{\n"
+ " \"sm:root\": {\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"ietf-interfaces:interfaces-state\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
+ " \"oper-status\": \"not-present\",\n"
+ " \"statistics\": {\n"
+ " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
+
/* different yang-lib data */
ly_ctx_set_ext_data_clb(UTEST_LYCTX, test_ext_data_clb,
"<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
@@ -819,12 +961,63 @@
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+
+ json =
+ "{\n"
+ " \"sm:root\": {\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"ietf-interfaces:interfaces-state\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
+ " \"oper-status\": \"not-present\",\n"
+ " \"statistics\": {\n"
+ " \"discontinuity-time\": \"2022-01-01T10:00:00-00:00\"\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " },\n"
+ " \"sm:root2\": {\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"fu\",\n"
+ " \"type\": \"iana-if-type:fddi\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"ietf-interfaces:interfaces-state\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"fu\",\n"
+ " \"type\": \"iana-if-type:fddi\",\n"
+ " \"oper-status\": \"down\",\n"
+ " \"statistics\": {\n"
+ " \"discontinuity-time\": \"2020-01-01T10:00:00-00:00\"\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
}
static void
-test_parse_xml_shared_parent_ref(void **state)
+test_parse_shared_parent_ref(void **state)
{
- const char *xml;
+ const char *xml, *json;
struct lyd_node *data;
/* wrong leafref value */
@@ -894,7 +1087,7 @@
" <module>sm</module>"
" <label>mnt-root</label>"
" <shared-schema>"
- " <parent-reference>/smp:target[. = current()/../smp:name]</parent-reference>"
+ " <parent-reference>/smp:target[. = current()/smp:name]</parent-reference>"
" </shared-schema>"
" </mount-point>"
"</schema-mounts>");
@@ -902,15 +1095,13 @@
"<root3 xmlns=\"urn:sm\">\n"
" <ls>\n"
" <name>target-value</name>\n"
- " <mnt-root>\n"
- " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
- " <interface>\n"
- " <name>bu</name>\n"
- " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
- " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
- " </interface>\n"
- " </interfaces>\n"
- " </mnt-root>\n"
+ " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
+ " <interface>\n"
+ " <name>bu</name>\n"
+ " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
+ " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
+ " </interface>\n"
+ " </interfaces>\n"
" </ls>\n"
"</root3>\n"
"<target xmlns=\"urn:sm\">wrong-target-value</target>\n";
@@ -920,30 +1111,78 @@
"Schema location /ietf-interfaces:interfaces/interface/sm:sm-name, "
"data location /ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name.");
+ json =
+ "{\n"
+ " \"sm:root3\": {\n"
+ " \"ls\": ["
+ " {\n"
+ " \"name\": \"target-value\",\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
+ " \"sm:sm-name\": \"target-value\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"sm:target\": \"wrong-target-value\"\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, data);
+ CHECK_LOG_CTX("Extension plugin \"libyang 2 - Schema Mount, version 1\": "
+ "Invalid leafref value \"target-value\" - no existing target instance \"/sm:target\".",
+ "Schema location /ietf-interfaces:interfaces/interface/sm:sm-name, "
+ "data location /ietf-interfaces:interfaces/interface[name='bu']/sm:sm-name.");
+
/* success */
xml =
"<root3 xmlns=\"urn:sm\">\n"
" <ls>\n"
" <name>target-value</name>\n"
- " <mnt-root>\n"
- " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
- " <interface>\n"
- " <name>bu</name>\n"
- " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
- " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
- " </interface>\n"
- " </interfaces>\n"
- " </mnt-root>\n"
+ " <interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
+ " <interface>\n"
+ " <name>bu</name>\n"
+ " <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n"
+ " <sm-name xmlns=\"urn:sm\">target-value</sm-name>\n"
+ " </interface>\n"
+ " </interfaces>\n"
" </ls>\n"
"</root3>\n"
"<target xmlns=\"urn:sm\">target-value</target>\n";
CHECK_PARSE_LYD_PARAM(xml, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
CHECK_LYD_STRING_PARAM(data, xml, LYD_XML, LYD_PRINT_WITHSIBLINGS);
lyd_free_siblings(data);
+
+ json =
+ "{\n"
+ " \"sm:root3\": {\n"
+ " \"ls\": [\n"
+ " {\n"
+ " \"name\": \"target-value\",\n"
+ " \"ietf-interfaces:interfaces\": {\n"
+ " \"interface\": [\n"
+ " {\n"
+ " \"name\": \"bu\",\n"
+ " \"type\": \"iana-if-type:ethernetCsmacd\",\n"
+ " \"sm:sm-name\": \"target-value\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"sm:target\": \"target-value\"\n"
+ "}\n";
+ CHECK_PARSE_LYD_PARAM(json, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, data);
+ CHECK_LYD_STRING_PARAM(data, json, LYD_JSON, LYD_PRINT_WITHSIBLINGS);
+ lyd_free_siblings(data);
}
static void
-test_parse_xml_config(void **state)
+test_parse_config(void **state)
{
const char *xml;
struct lyd_node *data;
@@ -1044,11 +1283,11 @@
{
const struct CMUnitTest tests[] = {
UTEST(test_schema),
- UTEST(test_parse_xml_invalid, setup),
- UTEST(test_parse_xml_inline, setup),
- UTEST(test_parse_xml_shared, setup),
- UTEST(test_parse_xml_shared_parent_ref, setup),
- UTEST(test_parse_xml_config, setup),
+ UTEST(test_parse_invalid, setup),
+ UTEST(test_parse_inline, setup),
+ UTEST(test_parse_shared, setup),
+ UTEST(test_parse_shared_parent_ref, setup),
+ UTEST(test_parse_config, setup),
};
return cmocka_run_group_tests(tests, NULL, NULL);