schema CHANGE redesign Sized arrays to be usable in a more simple way
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index e6fec3c..db73f63 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -725,7 +725,7 @@
TEST_NODE(LYS_ANYXML, "anyxml test;}", "test");
/* augment */
TEST_GENERIC("augment /somepath;}", mod->augments,
- assert_string_equal("/somepath", LY_ARRAY_INDEX(mod->augments, 0, struct lysp_augment)->nodeid));
+ assert_string_equal("/somepath", mod->augments[0].nodeid));
/* choice */
TEST_NODE(LYS_CHOICE, "choice test;}", "test");
/* contact 0..1 */
@@ -738,22 +738,22 @@
assert_string_equal("some description", mod->dsc));
/* deviation */
TEST_GENERIC("deviation /somepath {deviate not-supported;}}", mod->deviations,
- assert_string_equal("/somepath", LY_ARRAY_INDEX(mod->deviations, 0, struct lysp_deviation)->nodeid));
+ assert_string_equal("/somepath", mod->deviations[0].nodeid));
/* extension */
TEST_GENERIC("extension test;}", mod->extensions,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->extensions, 0, struct lysp_ext)->name));
+ assert_string_equal("test", mod->extensions[0].name));
/* feature */
TEST_GENERIC("feature test;}", mod->features,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->features, 0, struct lysp_feature)->name));
+ assert_string_equal("test", mod->features[0].name));
/* grouping */
TEST_GENERIC("grouping grp;}", mod->groupings,
- assert_string_equal("grp", LY_ARRAY_INDEX(mod->groupings, 0, struct lysp_grp)->name));
+ assert_string_equal("grp", mod->groupings[0].name));
/* identity */
TEST_GENERIC("identity test;}", mod->identities,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->identities, 0, struct lysp_ident)->name));
+ assert_string_equal("test", mod->identities[0].name));
/* import */
TEST_GENERIC("import test {prefix z;}}", mod->imports,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->imports, 0, struct lysp_import)->name));
+ assert_string_equal("test", mod->imports[0].name));
/* import - prefix collision */
str = SCHEMA_BEGINNING "import test {prefix x;}}";
@@ -767,7 +767,7 @@
/* include */
TEST_GENERIC("include test;}", mod->includes,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->includes, 0, struct lysp_include)->name));
+ assert_string_equal("test", mod->includes[0].name));
/* leaf */
TEST_NODE(LYS_LEAF, "leaf test {type string;}}", "test");
/* leaf-list */
@@ -776,7 +776,7 @@
TEST_NODE(LYS_LIST, "list test {key a;leaf a {type string;}}}", "test");
/* notification */
TEST_GENERIC("notification test;}", mod->notifs,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->notifs, 0, struct lysp_notif)->name));
+ assert_string_equal("test", mod->notifs[0].name));
/* organization 0..1 */
TEST_GENERIC("organization \"CESNET a.l.e.\";}", mod->org,
assert_string_equal("CESNET a.l.e.", mod->org));
@@ -785,13 +785,13 @@
assert_string_equal("RFC7950", mod->ref));
/* revision */
TEST_GENERIC("revision 2018-10-12;}", mod->revs,
- assert_string_equal("2018-10-12", LY_ARRAY_INDEX(mod->revs, 0, struct lysp_revision)->rev));
+ assert_string_equal("2018-10-12", mod->revs[0].rev));
/* rpc */
TEST_GENERIC("rpc test;}", mod->rpcs,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->rpcs, 0, struct lysp_action)->name));
+ assert_string_equal("test", mod->rpcs[0].name));
/* typedef */
TEST_GENERIC("typedef test{type string;}}", mod->typedefs,
- assert_string_equal("test", LY_ARRAY_INDEX(mod->typedefs, 0, struct lysp_tpdf)->name));
+ assert_string_equal("test", mod->typedefs[0].name));
/* uses */
TEST_NODE(LYS_USES, "uses test;}", "test");
/* yang-version */
@@ -814,8 +814,8 @@
/* extensions */
TEST_GENERIC("prefix:test;}", mod->exts,
- assert_string_equal("prefix:test", LY_ARRAY_INDEX(mod->exts, 0, struct lysp_ext_instance)->name);
- assert_int_equal(LYEXT_SUBSTMT_SELF, LY_ARRAY_INDEX(mod->exts, 0, struct lysp_ext_instance)->insubstmt));
+ assert_string_equal("prefix:test", mod->exts[0].name);
+ assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
mod = mod_renew(&ctx, mod, 0);
/* invalid substatement */
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index 8e72276..79c7c42 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -94,14 +94,14 @@
/* features */
assert_non_null(mod.compiled->features);
assert_int_equal(2, LY_ARRAY_SIZE(mod.compiled->features));
- f = LY_ARRAY_INDEX(mod.compiled->features, 1);
+ f = &mod.compiled->features[1];
assert_non_null(f->iffeatures);
assert_int_equal(1, LY_ARRAY_SIZE(f->iffeatures));
- iff = LY_ARRAY_INDEX(f->iffeatures, 0);
+ iff = &f->iffeatures[0];
assert_non_null(iff->expr);
assert_non_null(iff->features);
assert_int_equal(1, LY_ARRAY_SIZE(iff->features));
- assert_ptr_equal(LY_ARRAY_INDEX(mod.compiled->features, 0), *LY_ARRAY_INDEX(iff->features, 0, struct lysc_feature*));
+ assert_ptr_equal(&mod.compiled->features[0], iff->features[0]);
lysc_module_free(mod.compiled, NULL);
@@ -153,17 +153,17 @@
}
/* enable f1 */
assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f1"));
- f1 = LY_ARRAY_INDEX(mod.compiled->features, 0);
+ f1 = &mod.compiled->features[0];
assert_int_equal(1, lysc_feature_value(f1));
/* enable f4 */
- f = LY_ARRAY_INDEX(mod.compiled->features, 3);
+ f = &mod.compiled->features[3];
assert_int_equal(0, lysc_feature_value(f));
assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f4"));
assert_int_equal(1, lysc_feature_value(f));
/* enable f5 - no possible since f2 is disabled */
- f = LY_ARRAY_INDEX(mod.compiled->features, 4);
+ f = &mod.compiled->features[4];
assert_int_equal(0, lysc_feature_value(f));
assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "f5"));
logbuf_assert("Feature \"f5\" cannot be enabled since it is disabled by its if-feature condition(s).");
@@ -175,7 +175,7 @@
assert_int_equal(1, lysc_feature_value(f));
/* f1 is enabled, so f6 cannot be enabled */
- f = LY_ARRAY_INDEX(mod.compiled->features, 5);
+ f = &mod.compiled->features[5];
assert_int_equal(0, lysc_feature_value(f));
assert_int_equal(LY_EDENIED, lys_feature_enable(&mod, "f6"));
logbuf_assert("Feature \"f6\" cannot be enabled since it is disabled by its if-feature condition(s).");
@@ -183,19 +183,17 @@
/* so disable f1 - f5 will became also disabled */
assert_int_equal(1, lysc_feature_value(f1));
- f = LY_ARRAY_INDEX(mod.compiled->features, 4);
assert_int_equal(LY_SUCCESS, lys_feature_disable(&mod, "f1"));
assert_int_equal(0, lysc_feature_value(f1));
- assert_int_equal(0, lysc_feature_value(f));
+ assert_int_equal(0, lysc_feature_value(&mod.compiled->features[4]));
/* while f4 is stille enabled */
- assert_int_equal(1, lysc_feature_value(LY_ARRAY_INDEX(mod.compiled->features, 3)));
+ assert_int_equal(1, lysc_feature_value(&mod.compiled->features[3]));
/* and finally f6 can be enabled */
- f = LY_ARRAY_INDEX(mod.compiled->features, 5);
assert_int_equal(LY_SUCCESS, lys_feature_enable(&mod, "f6"));
- assert_int_equal(1, lysc_feature_value(f));
+ assert_int_equal(1, lysc_feature_value(&mod.compiled->features[5]));
/* complex evaluation of f7: f1 and f3 are disabled, while f2 is enabled */
- assert_int_equal(1, lysc_iffeature_value(LY_ARRAY_INDEX(LY_ARRAY_INDEX(mod.compiled->features, 6, struct lysc_feature)->iffeatures, 0)));
+ assert_int_equal(1, lysc_iffeature_value(&mod.compiled->features[6].iffeatures[0]));
lysc_module_free(mod.compiled, NULL);
lysp_module_free(mod.parsed);
diff --git a/tests/src/test_tree_schema_helpers.c b/tests/src/test_tree_schema_helpers.c
index 67f4138..3dc7d7c 100644
--- a/tests/src/test_tree_schema_helpers.c
+++ b/tests/src/test_tree_schema_helpers.c
@@ -90,20 +90,20 @@
logbuf_assert("");
/* revisions are stored in wrong order - the newest is the last */
- LYSP_ARRAY_NEW_RET(NULL, revs, rev,);
+ LY_ARRAY_NEW_RET(NULL, revs, rev,);
strcpy(rev->rev, "2018-01-01");
- LYSP_ARRAY_NEW_RET(NULL, revs, rev,);
+ LY_ARRAY_NEW_RET(NULL, revs, rev,);
strcpy(rev->rev, "2018-12-31");
assert_int_equal(2, LY_ARRAY_SIZE(revs));
- assert_string_equal("2018-01-01", LY_ARRAY_INDEX(revs, 0));
- assert_string_equal("2018-12-31", LY_ARRAY_INDEX(revs, 1));
+ assert_string_equal("2018-01-01", &revs[0]);
+ assert_string_equal("2018-12-31", &revs[1]);
/* the order should be fixed, so the newest revision will be the first in the array */
lysp_sort_revisions(revs);
- assert_string_equal("2018-12-31", LY_ARRAY_INDEX(revs, 0));
- assert_string_equal("2018-01-01", LY_ARRAY_INDEX(revs, 1));
+ assert_string_equal("2018-12-31", &revs[0]);
+ assert_string_equal("2018-01-01", &revs[1]);
- free(revs);
+ LY_ARRAY_FREE(revs);
}
int main(void)