libyang REFACTOR parsed/printed bytes in in/out structs
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
index 5f14972..9a09dee 100644
--- a/tests/utests/test_context.c
+++ b/tests/utests/test_context.c
@@ -22,6 +22,7 @@
 
 #include "common.h"
 #include "context.h"
+#include "parser.h"
 #include "tests/config.h"
 #include "tree_schema_internal.h"
 
@@ -272,6 +273,7 @@
     *state = test_models;
 
     struct ly_ctx *ctx;
+    struct ly_in *in;
     const char *str;
     struct lys_module *mod1, *mod2;
 
@@ -282,7 +284,9 @@
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
     assert_int_equal(ctx->module_set_id, ly_ctx_get_module_set_id(ctx));
 
-    assert_null(lys_parse_mem_module(ctx, "module x {namespace urn:x;prefix x;}", 4, 1, NULL, NULL));
+    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));
+    ly_in_free(in, 0);
     logbuf_assert("Invalid schema input format.");
 
     /* import callback */
@@ -298,18 +302,26 @@
 
     /* 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_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;include y;}", LYS_IN_YANG, 1, NULL, NULL));
+    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));
+    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_non_null(lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", LYS_IN_YANG, 1, NULL, NULL));
-    assert_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;}", LYS_IN_YANG, 1, NULL, NULL));
+    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));
+    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));
+    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_null(lys_parse_mem_module(ctx, "module b {namespace urn:b;prefix b;include y;}", LYS_IN_YANG, 1, NULL, NULL));
+    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));
+    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;
@@ -317,18 +329,24 @@
     /* selecting correct revision of the submodules */
     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;}");
-    mod2 = lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", LYS_IN_YANG, 0, NULL, NULL);
+    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);
+    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 */
-    mod1 = lys_parse_mem_module(ctx, "module w {namespace urn:w;prefix w;revision 2018-10-24;}", LYS_IN_YANG, 1, NULL, NULL);
+    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);
+    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);
 
-    mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL);
+    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);
+    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);
@@ -336,7 +354,9 @@
     logbuf_assert("Unable to reload \"w\" module to import it into \"z\", source data not found.");
     assert_null(mod2);
 
-    mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL);
+    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);
+    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));
@@ -404,10 +424,14 @@
     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;}";
+    struct ly_in *in0, *in1, *in2;
 
     unsigned int index = 0;
     const char *names[] = {"ietf-yang-metadata", "yang", "ietf-inet-types", "ietf-yang-types", "ietf-datastores", "ietf-yang-library", "a", "a", "a"};
 
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str0, &in0));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str1, &in1));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(str2, &in2));
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
     /* invalid arguments */
@@ -435,14 +459,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, str1, LYS_IN_YANG, 1, NULL, NULL);
+    mod = lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL);
     /* invalid attempts - implementing module of the same name and inserting the same module */
-    assert_null(lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 1, NULL, NULL));
+    assert_null(lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL));
     logbuf_assert("Module \"a\" is already implemented in the context.");
-    assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 0, NULL, NULL));
+    ly_in_reset(in1);
+    assert_null(lys_parse_mem_module(ctx, in1, LYS_IN_YANG, 0, 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 */
-    mod2 = lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 0, NULL, NULL);
+    ly_in_reset(in2);
+    mod2 = lys_parse_mem_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL);
     assert_non_null(mod);
     assert_non_null(mod2);
     assert_ptr_not_equal(mod, mod2);
@@ -451,13 +477,15 @@
     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, str0, LYS_IN_YANG, 0, NULL, NULL);
+    mod = lys_parse_mem_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL);
     assert_non_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;}}";
-    assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 1, NULL, NULL));
+    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));
     logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
 
     while ((mod = ly_ctx_get_module_iter(ctx, &index))) {
@@ -467,6 +495,9 @@
 
     /* cleanup */
     *state = NULL;
+    ly_in_free(in0, 0);
+    ly_in_free(in1, 0);
+    ly_in_free(in2, 0);
     ly_ctx_destroy(ctx, NULL);
 }