dictionary REFACTOR unify functions pattern to return LY_ERR
Change API functions manipulating with libyang dictionary to return
LY_ERR value as a primary indicator of the result and the value from the
dictionary is returned via optional output parameter.
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index e5fa612..94df4f0 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -1630,9 +1630,10 @@
{
struct test_parser_yin_state *st = *state;
const char *data;
- const char *pat = lydict_insert(st->ctx, "\006pattern", 8);
+ const char *pat;
struct lysp_ext_instance *exts = NULL;
+ assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
assert_string_equal(pat, "\x015pattern");
@@ -1643,7 +1644,7 @@
exts = NULL;
FREE_STRING(st->ctx, pat);
- pat = lydict_insert(st->ctx, "\006pattern", 8);
+ assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1.");
diff --git a/tests/utests/test_hash_table.c b/tests/utests/test_hash_table.c
index c9943ba..bf40371 100644
--- a/tests/utests/test_hash_table.c
+++ b/tests/utests/test_hash_table.c
@@ -73,12 +73,12 @@
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
- assert_null(lydict_insert(NULL, NULL, 0));
+ assert_int_equal(LY_EINVAL, lydict_insert(NULL, NULL, 0, NULL));
logbuf_assert("Invalid argument ctx (lydict_insert()).");
- assert_null(lydict_insert_zc(NULL, NULL));
+ assert_int_equal(LY_EINVAL, lydict_insert_zc(NULL, NULL, NULL));
logbuf_assert("Invalid argument ctx (lydict_insert_zc()).");
- assert_null(lydict_insert_zc(ctx, NULL));
+ assert_int_equal(LY_EINVAL, lydict_insert_zc(ctx, NULL, NULL));
logbuf_assert("Invalid argument value (lydict_insert_zc()).");
ly_ctx_destroy(ctx, NULL);
@@ -89,19 +89,20 @@
{
(void) state; /* unused */
- const char *str1, *str2;
+ const char *str1, *str2, *str3;
struct ly_ctx *ctx;
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
/* insert 2 strings, one of them repeatedly */
- str1 = lydict_insert(ctx, "test1", 0);
+ assert_int_equal(LY_SUCCESS, lydict_insert(ctx, "test1", 0, &str1));
assert_non_null(str1);
/* via zerocopy we have to get the same pointer as provided */
assert_non_null(str2 = strdup("test2"));
- assert_true(str2 == lydict_insert_zc(ctx, (char *)str2));
+ assert_int_equal(LY_SUCCESS, lydict_insert_zc(ctx, (char *)str2, &str3));
+ assert_ptr_equal(str2, str3);
/* here we get the same pointer as in case the string was inserted first time */
- str2 = lydict_insert(ctx, "test1", 0);
+ assert_int_equal(LY_SUCCESS, lydict_insert(ctx, "test1", 0, &str2));
assert_non_null(str2);
assert_ptr_equal(str1, str2);