libyang REFACTOR return values and options changes

Unified, all functions that return a variety
of errors return LY_ERR. Any options such as
NOSIBLINGS, WITHSIBLINGS and so on were replaced
by function variants with suffixes _single, _all,
_tree, and _siblings.
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
index 9a09dee..9cb43ff 100644
--- a/tests/utests/test_context.c
+++ b/tests/utests/test_context.c
@@ -285,7 +285,7 @@
     assert_int_equal(ctx->module_set_id, ly_ctx_get_module_set_id(ctx));
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
-    assert_null(lys_parse_mem_module(ctx, in, 4, 1, NULL, NULL));
+    assert_int_equal(LY_EINVAL, lys_parse_mem_module(ctx, in, 4, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
     logbuf_assert("Invalid schema input format.");
 
@@ -303,26 +303,23 @@
     /* name collision of module and submodule */
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}");
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;include y;}", &in));
-    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
-    assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", &in));
-    assert_non_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
-    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
-    assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1.");
 
     store = 1;
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to b {prefix b;}}");
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module b {namespace urn:b;prefix b;include y;}", &in));
-    assert_null(lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_EVALID, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
-    assert_int_equal(LY_EVALID, ly_errcode(ctx));
     logbuf_assert("Name collision between submodules of name \"y\". Line number 1.");
     store = -1;
 
@@ -330,24 +327,21 @@
     ly_ctx_reset_latests(ctx);
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}");
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
-    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, &mod2));
     ly_in_free(in, 0);
-    assert_non_null(mod2);
     assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date);
 
     /* reloading module in case only the compiled module resists in the context */
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module w {namespace urn:w;prefix w;revision 2018-10-24;}", &in));
-    mod1 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod1));
     ly_in_free(in, 0);
-    assert_non_null(mod1);
     assert_int_equal(LY_SUCCESS, lys_compile(&mod1, LYSC_OPT_FREE_SP));
     assert_non_null(mod1->compiled);
     assert_null(mod1->parsed);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
-    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
     ly_in_free(in, 0);
-    assert_non_null(mod2);
     /* mod1->parsed is necessary to compile mod2 because of possible groupings, typedefs, ... */
     ly_ctx_set_module_imp_clb(ctx, NULL, NULL);
     assert_int_equal(LY_ENOTFOUND, lys_compile(&mod2, 0));
@@ -355,9 +349,8 @@
     assert_null(mod2);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", &in));
-    mod2 = lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
     ly_in_free(in, 0);
-    assert_non_null(mod2);
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}");
     assert_int_equal(LY_SUCCESS, lys_compile(&mod2, 0));
     assert_non_null(mod2);
@@ -375,16 +368,18 @@
     *state = test_imports;
 
     struct ly_ctx *ctx;
-    struct lys_module *mod1, *mod2, *import;
+    const struct lys_module *mod1, *mod2, *import;
 
     /* import callback provides newer revision of module 'a' than present in context, so when importing 'a', the newer revision
      * from the callback should be loaded into the context and used as an import */
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
-    assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-16;}", LYS_IN_YANG));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-16;}",
+                                               LYS_IN_YANG, &mod1));
     assert_int_equal(1, mod1->latest_revision);
     assert_int_equal(1, mod1->implemented);
-    assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+                                               LYS_IN_YANG, &mod2));
     import = mod2->compiled->imports[0].module;
     assert_int_equal(2, import->latest_revision);
     assert_int_equal(0, mod1->latest_revision);
@@ -398,10 +393,12 @@
      * already present in the context should be selected and the callback's revision should not be loaded into the context */
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
     ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
-    assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-18;}", LYS_IN_YANG));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-18;}",
+                                               LYS_IN_YANG, &mod1));
     assert_int_equal(1, mod1->latest_revision);
     assert_int_equal(1, mod1->implemented);
-    assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+                                               LYS_IN_YANG, &mod2));
     import = mod2->compiled->imports[0].module;
     assert_ptr_equal(mod1, import);
     assert_int_equal(2, import->latest_revision);
@@ -420,7 +417,7 @@
     *state = test_get_models;
 
     struct ly_ctx *ctx;
-    const struct lys_module *mod, *mod2;
+    struct lys_module *mod, *mod2;
     const char *str0 = "module a {namespace urn:a;prefix a;}";
     const char *str1 = "module a {namespace urn:a;prefix a;revision 2018-10-23;}";
     const char *str2 = "module a {namespace urn:a;prefix a;revision 2018-10-23;revision 2018-10-24;}";
@@ -459,17 +456,16 @@
     assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
 
     /* select module by revision */
-    mod = lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, &mod));
     /* invalid attempts - implementing module of the same name and inserting the same module */
-    assert_null(lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_EDENIED, lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL, NULL));
     logbuf_assert("Module \"a\" is already implemented in the context.");
     ly_in_reset(in1);
-    assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL));
+    assert_int_equal(LY_EEXIST, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL, NULL));
     logbuf_assert("Module \"a\" of revision \"2018-10-23\" is already present in the context.");
     /* insert the second module only as imported, not implemented */
     ly_in_reset(in2);
-    mod2 = lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL);
-    assert_non_null(mod);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL, &mod2));
     assert_non_null(mod2);
     assert_ptr_not_equal(mod, mod2);
     mod = ly_ctx_get_module_latest(ctx, "a");
@@ -477,18 +473,17 @@
     mod2 = ly_ctx_get_module_latest_ns(ctx, mod->ns);
     assert_ptr_equal(mod, mod2);
     /* work with module with no revision */
-    mod = lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL);
-    assert_non_null(mod);
+    assert_int_equal(LY_SUCCESS, lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL, &mod));
     assert_ptr_equal(mod, ly_ctx_get_module(ctx, "a", NULL));
     assert_ptr_not_equal(mod, ly_ctx_get_module_latest(ctx, "a"));
 
     str1 = "submodule b {belongs-to a {prefix a;}}";
     ly_in_free(in1, 0);
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
-    assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL));
+    assert_int_equal(LY_EINVAL, lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, &mod));
     logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
 
-    while ((mod = ly_ctx_get_module_iter(ctx, &index))) {
+    while ((mod = (struct lys_module *)ly_ctx_get_module_iter(ctx, &index))) {
         assert_string_equal(names[index - 1], mod->name);
     }
     assert_int_equal(9, index);