utests data REFACTOR put repetitive commands into macros
diff --git a/tests/utests/CMakeLists.txt b/tests/utests/CMakeLists.txt
index ebf5c7e..59ba07d 100644
--- a/tests/utests/CMakeLists.txt
+++ b/tests/utests/CMakeLists.txt
@@ -3,29 +3,31 @@
 
 set(format_sources
     ${format_sources}
-    ${CMAKE_CURRENT_SOURCE_DIR}/*.c
     ${CMAKE_CURRENT_SOURCE_DIR}/*.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/basic/*.c
     ${CMAKE_CURRENT_SOURCE_DIR}/data/*.c
     ${CMAKE_CURRENT_SOURCE_DIR}/extensions/*.c
     ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.c
     ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.h
     PARENT_SCOPE)
 
-ly_add_utest(NAME common WRAP "-Wl,--wrap=realloc" SOURCES test_common.c)
-ly_add_utest(NAME set SOURCES test_set.c)
-ly_add_utest(NAME hash_table SOURCES test_hash_table.c)
-ly_add_utest(NAME inout SOURCES test_inout.c)
-ly_add_utest(NAME context SOURCES test_context.c)
-ly_add_utest(NAME xml SOURCES test_xml.c)
-ly_add_utest(NAME json SOURCES test_json.c)
-ly_add_utest(NAME xpath SOURCES test_xpath.c)
-ly_add_utest(NAME yanglib SOURCES test_yanglib.c)
+ly_add_utest(NAME common SOURCES basic/test_common.c)
+ly_add_utest(NAME set SOURCES basic/test_set.c)
+ly_add_utest(NAME hash_table SOURCES basic/test_hash_table.c)
+ly_add_utest(NAME inout SOURCES basic/test_inout.c)
+ly_add_utest(NAME context SOURCES basic/test_context.c)
+ly_add_utest(NAME xml SOURCES basic/test_xml.c)
+ly_add_utest(NAME json SOURCES basic/test_json.c)
+ly_add_utest(NAME xpath SOURCES basic/test_xpath.c)
+ly_add_utest(NAME yanglib SOURCES basic/test_yanglib.c)
+
 ly_add_utest(NAME schema SOURCES schema/test_schema.c schema/test_schema_common.c schema/test_schema_stmts.c)
 ly_add_utest(NAME parser_yang SOURCES schema/test_parser_yang.c)
 ly_add_utest(NAME parser_yin SOURCES schema/test_parser_yin.c)
 ly_add_utest(NAME tree_schema_compile SOURCES schema/test_tree_schema_compile.c)
 ly_add_utest(NAME printer_yang SOURCES schema/test_printer_yang.c)
 ly_add_utest(NAME printer_yin SOURCES schema/test_printer_yin.c)
+
 ly_add_utest(NAME tree_data SOURCES data/test_tree_data.c)
 ly_add_utest(NAME new SOURCES data/test_new.c)
 ly_add_utest(NAME parser_xml SOURCES data/test_parser_xml.c)
@@ -36,5 +38,6 @@
 ly_add_utest(NAME types SOURCES data/test_types.c)
 ly_add_utest(NAME merge SOURCES data/test_merge.c)
 ly_add_utest(NAME diff SOURCES data/test_diff.c)
+
 ly_add_utest(NAME metadata SOURCES extensions/test_metadata.c)
 ly_add_utest(NAME nacm SOURCES extensions/test_nacm.c)
diff --git a/tests/utests/test_common.c b/tests/utests/basic/test_common.c
similarity index 78%
rename from tests/utests/test_common.c
rename to tests/utests/basic/test_common.c
index 0c1012d..41a1a2f 100644
--- a/tests/utests/test_common.c
+++ b/tests/utests/basic/test_common.c
@@ -11,77 +11,14 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#include <stdlib.h>
-
-#include "common.h"
+#define _UTEST_MAIN_
 #include "utests.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-
-    ly_set_log_clb(logger, 0);
-
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+#include "common.h"
 
 static void
-test_utf8(void **state)
+test_utf8(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
     char buf[5] = {0};
     const char *str = buf;
     unsigned int c;
@@ -116,51 +53,9 @@
     assert_int_equal(LY_EINVAL, ly_getutf8(&str, &c, &len));
 }
 
-#ifndef __APPLE__
-void *__real_realloc(void *ptr, size_t size);
-void *
-__wrap_realloc(void *ptr, size_t size)
-{
-    int wrap = mock_type(int);
-
-    if (wrap) {
-        /* memory allocation failed */
-        return NULL;
-    } else {
-        return __real_realloc(ptr, size);
-    }
-}
-
 static void
-test_lyrealloc(void **state)
+test_parse_int(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
-    char *ptr;
-
-    ptr = malloc(1);
-    assert_non_null(ptr);
-
-    /* realloc */
-    will_return(__wrap_realloc, 0);
-    ptr = ly_realloc(ptr, 2048);
-    assert_non_null(ptr);
-    ptr[2047] = 0; /* test write */
-
-    /* realloc fails */
-    will_return(__wrap_realloc, 1);
-    ptr = ly_realloc(ptr, 2048);
-    assert_null(ptr);
-
-    /* ptr should be freed by ly_realloc() */
-}
-
-#endif /* not __APPLE__ */
-
-static void
-test_parse_int(void **state)
-{
-    *state = test_parse_int;
     const char *str;
     int64_t i = 500;
 
@@ -199,14 +94,11 @@
 
     str = "10  zero";
     assert_int_equal(LY_EVALID, ly_parse_int(str, strlen(str), -10, 10, 10, &i));
-
-    *state = NULL;
 }
 
 static void
-test_parse_uint(void **state)
+test_parse_uint(void **UNUSED(state))
 {
-    *state = test_parse_int;
     const char *str;
     uint64_t u = 500;
 
@@ -239,14 +131,11 @@
 
     str = "10  zero";
     assert_int_equal(LY_EVALID, ly_parse_uint(str, strlen(str), 10, 10, &u));
-
-    *state = NULL;
 }
 
 static void
-test_parse_nodeid(void **state)
+test_parse_nodeid(void **UNUSED(state))
 {
-    *state = test_parse_nodeid;
     const char *str;
     const char *prefix, *name;
     size_t prefix_len, name_len;
@@ -272,14 +161,11 @@
     assert_int_equal(3, name_len);
     assert_int_equal(0, strncmp("_b2", name, name_len));
     assert_string_equal(" xxx", str);
-
-    *state = NULL;
 }
 
 static void
-test_parse_instance_predicate(void **state)
+test_parse_instance_predicate(void **UNUSED(state))
 {
-    *state = test_parse_instance_predicate;
     const char *str, *errmsg;
     const char *prefix, *id, *value;
     size_t prefix_len, id_len, value_len;
@@ -371,22 +257,17 @@
     str = "[ex:node='value']";
     assert_int_equal(LY_EINVAL, ly_parse_instance_predicate(&str, strlen(str) - 1, LYD_XML, &prefix, &prefix_len, &id, &id_len, &value, &value_len, &errmsg));
     assert_string_equal(errmsg, "Predicate is incomplete.");
-
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_utf8, logger_setup, logger_teardown),
-#ifndef __APPLE__
-        cmocka_unit_test(test_lyrealloc),
-#endif
-        cmocka_unit_test_setup_teardown(test_parse_int, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_parse_uint, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_parse_nodeid, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_parse_instance_predicate, logger_setup, logger_teardown),
+        UTEST(test_utf8),
+        UTEST(test_parse_int),
+        UTEST(test_parse_uint),
+        UTEST(test_parse_nodeid),
+        UTEST(test_parse_instance_predicate),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/basic/test_context.c b/tests/utests/basic/test_context.c
new file mode 100644
index 0000000..de535f0
--- /dev/null
+++ b/tests/utests/basic/test_context.c
@@ -0,0 +1,450 @@
+/*
+ * @file set.c
+ * @author: Radek Krejci <rkrejci@cesnet.cz>
+ * @brief unit tests for functions from context.c
+ *
+ * Copyright (c) 2018 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     https://opensource.org/licenses/BSD-3-Clause
+ */
+#define _UTEST_MAIN_
+#include "utests.h"
+
+#include "common.h"
+#include "context.h"
+#include "in.h"
+#include "schema_compile.h"
+#include "tests/config.h"
+#include "tree_schema_internal.h"
+#include "utests.h"
+
+static void
+test_searchdirs(void **state)
+{
+    const char * const *list;
+
+    /* invalid arguments */
+    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(NULL, NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_set_searchdir()).", NULL);
+    assert_null(ly_ctx_get_searchdirs(NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_get_searchdirs()).", NULL);
+    assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdir(NULL, NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_unset_searchdir()).", NULL);
+
+    /* readable and executable, but not a directory */
+    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_BIN "/utest_context"));
+    CHECK_LOG_CTX("Given search directory \""TESTS_BIN "/utest_context\" is not a directory.", NULL);
+    /* not executable */
+    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(UTEST_LYCTX, __FILE__));
+    CHECK_LOG_CTX("Unable to fully access search directory \""__FILE__ "\" (Permission denied).", NULL);
+    /* not existing */
+    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(UTEST_LYCTX, "/nonexistingfile"));
+    CHECK_LOG_CTX("Unable to use search directory \"/nonexistingfile\" (No such file or directory).", NULL);
+
+    /* ly_set_add() fails */
+    /* no change */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, NULL));
+
+    /* correct path */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_BIN "/utests"));
+    assert_int_equal(1, UTEST_LYCTX->search_paths.count);
+    assert_string_equal(TESTS_BIN "/utests", UTEST_LYCTX->search_paths.objs[0]);
+
+    /* duplicated paths */
+    assert_int_equal(LY_EEXIST, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_BIN "/utests"));
+    assert_int_equal(1, UTEST_LYCTX->search_paths.count);
+    assert_string_equal(TESTS_BIN "/utests", UTEST_LYCTX->search_paths.objs[0]);
+
+    /* another paths - add 8 to fill the initial buffer of the searchpaths list */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_BIN "/CMakeFiles"));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_SRC "/../src"));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_SRC "/../CMakeModules"));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_SRC "/../doc"));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_SRC));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_BIN));
+    assert_int_equal(7, UTEST_LYCTX->search_paths.count);
+
+    /* get searchpaths */
+    list = ly_ctx_get_searchdirs(UTEST_LYCTX);
+    assert_non_null(list);
+    assert_string_equal(TESTS_BIN "/utests", list[0]);
+    assert_string_equal(TESTS_BIN "/CMakeFiles", list[1]);
+    assert_string_equal(TESTS_SRC, list[5]);
+    assert_string_equal(TESTS_BIN, list[6]);
+    assert_null(list[7]);
+
+    /* removing searchpaths */
+    /* nonexisting */
+    assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdir(UTEST_LYCTX, "/nonexistingfile"));
+    CHECK_LOG_CTX("Invalid argument value (ly_ctx_unset_searchdir()).", NULL);
+    /* first */
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(UTEST_LYCTX, TESTS_BIN "/utests"));
+    assert_string_not_equal(TESTS_BIN "/utests", list[0]);
+    assert_int_equal(6, UTEST_LYCTX->search_paths.count);
+    /* middle */
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(UTEST_LYCTX, TESTS_SRC));
+    assert_int_equal(5, UTEST_LYCTX->search_paths.count);
+    /* last */
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(UTEST_LYCTX, TESTS_BIN));
+    assert_int_equal(4, UTEST_LYCTX->search_paths.count);
+    /* all */
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(UTEST_LYCTX, NULL));
+    assert_int_equal(0, UTEST_LYCTX->search_paths.count);
+
+    /* again - no change */
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(UTEST_LYCTX, NULL));
+
+    /* cleanup */
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+
+    /* test searchdir list in ly_ctx_new() */
+    assert_int_equal(LY_EINVAL, ly_ctx_new("/nonexistingfile", 0, &UTEST_LYCTX));
+    CHECK_LOG("Unable to use search directory \"/nonexistingfile\" (No such file or directory).", NULL);
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_SRC ":"TESTS_BIN ":"TESTS_BIN ":"TESTS_SRC, LY_CTX_DISABLE_SEARCHDIRS, &UTEST_LYCTX));
+    assert_int_equal(2, UTEST_LYCTX->search_paths.count);
+    assert_string_equal(TESTS_SRC, UTEST_LYCTX->search_paths.objs[0]);
+    assert_string_equal(TESTS_BIN, UTEST_LYCTX->search_paths.objs[1]);
+}
+
+static void
+test_options(void **state)
+{
+    /* use own context with extra flags */
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0xffff, &UTEST_LYCTX));
+
+    /* invalid arguments */
+    assert_int_equal(0, ly_ctx_get_options(NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_get_options()).", NULL);
+
+    assert_int_equal(LY_EINVAL, ly_ctx_set_options(NULL, 0));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_set_options()).", NULL);
+    assert_int_equal(LY_EINVAL, ly_ctx_unset_options(NULL, 0));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_unset_options()).", NULL);
+
+    /* option not allowed to be changed */
+    assert_int_equal(LY_EINVAL, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_NO_YANGLIBRARY));
+    CHECK_LOG_CTX("Invalid argument option (ly_ctx_set_options()).", NULL);
+    assert_int_equal(LY_EINVAL, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_NO_YANGLIBRARY));
+    CHECK_LOG_CTX("Invalid argument option (ly_ctx_set_options()).", NULL);
+
+    /* unset */
+    /* LY_CTX_ALL_IMPLEMENTED */
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_ALL_IMPLEMENTED);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_ALL_IMPLEMENTED));
+    assert_int_equal(0, UTEST_LYCTX->flags & LY_CTX_ALL_IMPLEMENTED);
+
+    /* LY_CTX_REF_IMPLEMENTED */
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_REF_IMPLEMENTED);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED));
+    assert_int_equal(0, UTEST_LYCTX->flags & LY_CTX_REF_IMPLEMENTED);
+
+    /* LY_CTX_DISABLE_SEARCHDIRS */
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIRS);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIRS));
+    assert_int_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIRS);
+
+    /* LY_CTX_DISABLE_SEARCHDIR_CWD */
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIR_CWD));
+    assert_int_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
+
+    /* LY_CTX_PREFER_SEARCHDIRS */
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_PREFER_SEARCHDIRS);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_PREFER_SEARCHDIRS));
+    assert_int_equal(0, UTEST_LYCTX->flags & LY_CTX_PREFER_SEARCHDIRS);
+
+    assert_int_equal(UTEST_LYCTX->flags, ly_ctx_get_options(UTEST_LYCTX));
+
+    /* set back */
+    /* LY_CTX_ALL_IMPLEMENTED */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_ALL_IMPLEMENTED));
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_ALL_IMPLEMENTED);
+
+    /* LY_CTX_REF_IMPLEMENTED */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED));
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_REF_IMPLEMENTED);
+
+    /* LY_CTX_DISABLE_SEARCHDIRS */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIRS));
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIRS);
+
+    /* LY_CTX_DISABLE_SEARCHDIR_CWD */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIR_CWD));
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
+
+    /* LY_CTX_PREFER_SEARCHDIRS */
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_PREFER_SEARCHDIRS));
+    assert_int_not_equal(0, UTEST_LYCTX->flags & LY_CTX_PREFER_SEARCHDIRS);
+
+    assert_int_equal(UTEST_LYCTX->flags, ly_ctx_get_options(UTEST_LYCTX));
+}
+
+static LY_ERR
+test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
+        const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
+        const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
+{
+    *module_data = user_data;
+    *format = LYS_IN_YANG;
+    *free_module_data = NULL;
+    return LY_SUCCESS;
+}
+
+static void
+test_models(void **state)
+{
+    struct ly_in *in;
+    const char *str;
+    struct lys_module *mod1, *mod2;
+    struct lys_glob_unres unres = {0};
+
+    /* use own context with extra flags */
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+
+    /* invalid arguments */
+    assert_int_equal(0, ly_ctx_get_module_set_id(NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_get_module_set_id()).", NULL);
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &UTEST_LYCTX));
+    assert_int_equal(UTEST_LYCTX->module_set_id, ly_ctx_get_module_set_id(UTEST_LYCTX));
+
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
+    assert_int_equal(LY_EINVAL, lys_create_module(UTEST_LYCTX, in, 4, 1, NULL, NULL, NULL, &unres, &mod1));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    CHECK_LOG_CTX("Invalid schema input format.", NULL);
+
+    /* import callback */
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, (void *)(str = "test"));
+    assert_ptr_equal(test_imp_clb, UTEST_LYCTX->imp_clb);
+    assert_ptr_equal(str, UTEST_LYCTX->imp_clb_data);
+    assert_ptr_equal(test_imp_clb, ly_ctx_get_module_imp_clb(UTEST_LYCTX, (void **)&str));
+    assert_string_equal("test", str);
+
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, NULL, NULL);
+    assert_null(UTEST_LYCTX->imp_clb);
+    assert_null(UTEST_LYCTX->imp_clb_data);
+
+    /* name collision of module and submodule */
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, 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_int_equal(LY_EVALID, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    CHECK_LOG_CTX("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_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
+    assert_int_equal(LY_EVALID, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    CHECK_LOG_CTX("Name collision between module and submodule of name \"y\".", "Line number 1.");
+
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, 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_int_equal(LY_EVALID, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
+    lys_compile_unres_glob_revert(UTEST_LYCTX, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    CHECK_LOG_CTX("Including \"y\" submodule into \"b\" failed.", NULL,
+            "Name collision between submodules of name \"y\".", "Line number 1.");
+
+    /* selecting correct revision of the submodules */
+    ly_ctx_reset_latests(UTEST_LYCTX);
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, 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));
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod2));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    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));
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod1));
+    ly_in_free(in, 0);
+    mod1->implemented = 1;
+    assert_int_equal(LY_SUCCESS, lys_compile(mod1, 0, &unres));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    assert_non_null(mod1->compiled);
+    assert_non_null(mod1->parsed);
+
+#if 0
+    /* TODO in case we are able to remove the parsed schema, here we will test how it will handle missing import parsed schema */
+
+    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));
+    /* mod1->parsed is necessary to compile mod2 because of possible groupings, typedefs, ... */
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, NULL, NULL);
+    assert_int_equal(LY_ENOTFOUND, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
+    /*logbuf_assert("Unable to reload \"w\" module to import it into \"z\", source data not found.");*/
+    CHECK_LOG_CTX("Recompilation of module \"w\" failed.", NULL);
+    assert_null(mod2);
+    ly_in_free(in, 0);
+#endif
+
+    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));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}");
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod2));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_free(in, 0);
+    assert_non_null(mod2);
+    assert_non_null(mod1->parsed);
+    assert_string_equal("w", mod1->name);
+}
+
+static void
+test_imports(void **state)
+{
+    const struct lys_module *mod1, *mod2, *import;
+
+    /* use own context with extra flags */
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+
+    /* 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, &UTEST_LYCTX));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "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_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+            LYS_IN_YANG, &mod2));
+    import = mod2->parsed->imports[0].module;
+    assert_int_equal(2, import->latest_revision);
+    assert_int_equal(0, mod1->latest_revision);
+    assert_ptr_not_equal(mod1, import);
+    assert_string_equal("2019-09-17", import->revision);
+    assert_int_equal(0, import->implemented);
+    assert_non_null(ly_ctx_get_module(UTEST_LYCTX, "a", "2019-09-16"));
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+
+    /* import callback provides older revision of module 'a' than present in context, so when importing a, the newer revision
+     * 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, &UTEST_LYCTX));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "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_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}}",
+            LYS_IN_YANG, &mod2));
+    import = mod2->parsed->imports[0].module;
+    assert_ptr_equal(mod1, import);
+    assert_int_equal(2, import->latest_revision);
+    assert_int_equal(1, import->implemented);
+    assert_string_equal("2019-09-18", import->revision);
+    assert_null(ly_ctx_get_module(UTEST_LYCTX, "a", "2019-09-17"));
+}
+
+static void
+test_get_models(void **state)
+{
+    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;}";
+    struct ly_in *in0, *in1, *in2;
+    struct lys_glob_unres unres = {0};
+
+    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));
+
+    /* invalid arguments */
+    assert_ptr_equal(NULL, ly_ctx_get_module(NULL, NULL, NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_get_module()).", NULL);
+    assert_ptr_equal(NULL, ly_ctx_get_module(UTEST_LYCTX, NULL, NULL));
+    CHECK_LOG_CTX("Invalid argument name (ly_ctx_get_module()).", NULL);
+    assert_ptr_equal(NULL, ly_ctx_get_module_ns(NULL, NULL, NULL));
+    CHECK_LOG("Invalid argument ctx (ly_ctx_get_module_ns()).", NULL);
+    assert_ptr_equal(NULL, ly_ctx_get_module_ns(UTEST_LYCTX, NULL, NULL));
+    CHECK_LOG_CTX("Invalid argument ns (ly_ctx_get_module_ns()).", NULL);
+    assert_null(ly_ctx_get_module(UTEST_LYCTX, "nonsence", NULL));
+
+    /* internal modules */
+    assert_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "ietf-yang-types"));
+    mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "yang");
+    assert_non_null(mod);
+    assert_non_null(mod->parsed);
+    assert_string_equal("yang", mod->name);
+    mod2 = ly_ctx_get_module_implemented_ns(UTEST_LYCTX, mod->ns);
+    assert_ptr_equal(mod, mod2);
+    assert_non_null(ly_ctx_get_module(UTEST_LYCTX, "ietf-yang-metadata", "2016-08-05"));
+    assert_non_null(ly_ctx_get_module(UTEST_LYCTX, "ietf-yang-types", "2013-07-15"));
+    assert_non_null(ly_ctx_get_module(UTEST_LYCTX, "ietf-inet-types", "2013-07-15"));
+    assert_non_null(ly_ctx_get_module_ns(UTEST_LYCTX, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
+
+    /* select module by revision */
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in1, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    /* invalid attempts - implementing module of the same name and inserting the same module */
+    assert_int_equal(LY_EDENIED, lys_create_module(UTEST_LYCTX, in2, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
+    CHECK_LOG_CTX("Module \"a@2018-10-23\" is already implemented in the context.", NULL);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_reset(in1);
+    /* it is already there, fine */
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in1, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, NULL));
+    /* insert the second module only as imported, not implemented */
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    ly_in_reset(in2);
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in2, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod2));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    assert_non_null(mod2);
+    assert_ptr_not_equal(mod, mod2);
+    mod = ly_ctx_get_module_latest(UTEST_LYCTX, "a");
+    assert_ptr_equal(mod, mod2);
+    mod2 = ly_ctx_get_module_latest_ns(UTEST_LYCTX, mod->ns);
+    assert_ptr_equal(mod, mod2);
+    /* work with module with no revision */
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in0, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+    assert_ptr_equal(mod, ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
+    assert_ptr_not_equal(mod, ly_ctx_get_module_latest(UTEST_LYCTX, "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_int_equal(LY_EINVAL, lys_create_module(UTEST_LYCTX, in1, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
+    CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
+
+    while ((mod = (struct lys_module *)ly_ctx_get_module_iter(UTEST_LYCTX, &index))) {
+        assert_string_equal(names[index - 1], mod->name);
+    }
+    assert_int_equal(9, index);
+
+    /* cleanup */
+    ly_in_free(in0, 0);
+    ly_in_free(in1, 0);
+    ly_in_free(in2, 0);
+}
+
+int
+main(void)
+{
+    const struct CMUnitTest tests[] = {
+        UTEST(test_searchdirs),
+        UTEST(test_options),
+        UTEST(test_models),
+        UTEST(test_imports),
+        UTEST(test_get_models),
+    };
+
+    return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/tests/utests/test_hash_table.c b/tests/utests/basic/test_hash_table.c
similarity index 74%
rename from tests/utests/test_hash_table.c
rename to tests/utests/basic/test_hash_table.c
index bcc4985..aa6ac3d 100644
--- a/tests/utests/test_hash_table.c
+++ b/tests/utests/basic/test_hash_table.c
@@ -11,103 +11,53 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#define _GNU_SOURCE
-#define _POSIX_C_SOURCE 200809L /* strdup */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdlib.h>
 
 #include "common.h"
 #include "hash_table.h"
-#include "utests.h"
 
 struct ht_rec *lyht_get_rec(unsigned char *recs, uint16_t rec_size, uint32_t idx);
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    (void) path; /* unused */
-
-    strncpy(logbuf, msg, BUFSIZE - 1);
-}
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 0);
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_invalid_arguments(void **state)
 {
-    (void) state; /* unused */
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     assert_int_equal(LY_EINVAL, lydict_insert(NULL, NULL, 0, NULL));
-    logbuf_assert("Invalid argument ctx (lydict_insert()).");
+    CHECK_LOG("Invalid argument ctx (lydict_insert()).", NULL);
 
     assert_int_equal(LY_EINVAL, lydict_insert_zc(NULL, NULL, NULL));
-    logbuf_assert("Invalid argument ctx (lydict_insert_zc()).");
-    assert_int_equal(LY_EINVAL, lydict_insert_zc(ctx, NULL, NULL));
-    logbuf_assert("Invalid argument value (lydict_insert_zc()).");
-
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG("Invalid argument ctx (lydict_insert_zc()).", NULL);
+    assert_int_equal(LY_EINVAL, lydict_insert_zc(UTEST_LYCTX, NULL, NULL));
+    CHECK_LOG_CTX("Invalid argument value (lydict_insert_zc()).", NULL);
 }
 
 static void
 test_dict_hit(void **state)
 {
-    (void) state; /* unused */
-
     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 */
-    assert_int_equal(LY_SUCCESS, lydict_insert(ctx, "test1", 0, &str1));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "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_int_equal(LY_SUCCESS, lydict_insert_zc(ctx, (char *)str2, &str3));
+    assert_int_equal(LY_SUCCESS, lydict_insert_zc(UTEST_LYCTX, (char *)str2, &str3));
     assert_ptr_equal(str2, str3);
     /* here we get the same pointer as in case the string was inserted first time */
-    assert_int_equal(LY_SUCCESS, lydict_insert(ctx, "test1", 0, &str2));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "test1", 0, &str2));
     assert_non_null(str2);
     assert_ptr_equal(str1, str2);
 
     /* remove strings, but the repeatedly inserted only once */
-    lydict_remove(ctx, "test1");
-    lydict_remove(ctx, "test2");
+    lydict_remove(UTEST_LYCTX, "test1");
+    lydict_remove(UTEST_LYCTX, "test2");
 
     /* destroy dictionary - should raise warning about data presence */
-    ly_ctx_destroy(ctx, NULL);
-    logbuf_assert("String \"test1\" not freed from the dictionary, refcount 1");
+    ly_ctx_destroy(UTEST_LYCTX, NULL);
+    UTEST_LYCTX = NULL;
+    CHECK_LOG("String \"test1\" not freed from the dictionary, refcount 1", NULL);
 
 #ifndef NDEBUG
     /* cleanup */
@@ -132,8 +82,6 @@
 static void
 test_ht_basic(void **state)
 {
-    (void) state; /* unused */
-
     uint32_t i;
     struct hash_table *ht;
 
@@ -146,7 +94,7 @@
     assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i));
     assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL));
     assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i));
-    logbuf_assert("Invalid argument hash (lyht_remove_with_resize_cb()).");
+    CHECK_LOG("Invalid argument hash (lyht_remove_with_resize_cb()).", NULL);
 
     lyht_free(ht);
 }
@@ -154,8 +102,6 @@
 static void
 test_ht_resize(void **state)
 {
-    (void) state; /* unused */
-
     uint32_t i;
     struct ht_rec *rec;
     struct hash_table *ht;
@@ -186,9 +132,9 @@
 
     /* removing not present data should fail */
     for (i = 0; i < 2; ++i) {
-        logbuf_clean();
+        UTEST_LOG_CLEAN;
         assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i));
-        logbuf_assert("Invalid argument hash (lyht_remove_with_resize_cb()).");
+        CHECK_LOG("Invalid argument hash (lyht_remove_with_resize_cb()).", NULL);
     }
     /* removing present data, resize should happened
      * when we are below 25% of the table filled, so with 3 records left */
@@ -211,9 +157,8 @@
 }
 
 static void
-test_ht_collisions(void **state)
+test_ht_collisions(void **UNUSED(state))
 {
-    (void) state; /* unused */
 #define GET_REC_INT(rec) (*((uint32_t *)&(rec)->val))
 
     uint32_t i;
@@ -315,11 +260,11 @@
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup(test_invalid_arguments, logger_setup),
-        cmocka_unit_test_setup(test_dict_hit, logger_setup),
-        cmocka_unit_test_setup(test_ht_basic, logger_setup),
-        cmocka_unit_test_setup(test_ht_resize, logger_setup),
-        cmocka_unit_test_setup(test_ht_collisions, logger_setup),
+        UTEST(test_invalid_arguments),
+        UTEST(test_dict_hit),
+        UTEST(test_ht_basic),
+        UTEST(test_ht_resize),
+        UTEST(test_ht_collisions),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/test_inout.c b/tests/utests/basic/test_inout.c
similarity index 78%
rename from tests/utests/test_inout.c
rename to tests/utests/basic/test_inout.c
index 3fbda08..f0f7968 100644
--- a/tests/utests/test_inout.c
+++ b/tests/utests/basic/test_inout.c
@@ -11,8 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#define _POSIX_C_SOURCE 200112L
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -25,76 +25,13 @@
 #include "in.h"
 #include "log.h"
 #include "out.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-
-    ly_set_log_clb(logger, 0);
-
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
 
 static void
-test_input_mem(void **state)
+test_input_mem(void **UNUSED(state))
 {
     struct ly_in *in = NULL;
     char *str1 = "a", *str2 = "b";
 
-    *state = test_input_mem;
-
     assert_int_equal(LY_EINVAL, ly_in_new_memory(NULL, NULL));
     assert_int_equal(LY_EINVAL, ly_in_new_memory(str1, NULL));
     assert_null(ly_in_memory(NULL, NULL));
@@ -105,20 +42,15 @@
     assert_ptr_equal(str2, ly_in_memory(in, NULL));
     assert_ptr_equal(str2, ly_in_memory(in, NULL));
     ly_in_free(in, 0);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_input_fd(void **state)
+test_input_fd(void **UNUSED(state))
 {
     struct ly_in *in = NULL;
     int fd1, fd2;
     struct stat statbuf;
 
-    *state = test_input_fd;
-
     assert_int_equal(LY_EINVAL, ly_in_new_fd(-1, NULL));
     assert_int_equal(-1, ly_in_fd(NULL, -1));
 
@@ -140,19 +72,14 @@
     errno = 0;
     assert_int_equal(-1, fstat(fd2, &statbuf));
     assert_int_equal(errno, EBADF);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_input_file(void **state)
+test_input_file(void **UNUSED(state))
 {
     struct ly_in *in = NULL;
     FILE *f1 = NULL, *f2 = NULL;
 
-    *state = test_input_file;
-
     assert_int_equal(LY_EINVAL, ly_in_new_file(NULL, NULL));
     assert_null(ly_in_file(NULL, NULL));
 
@@ -171,19 +98,14 @@
     assert_int_not_equal(-1, fileno(f1));
     fclose(f1);
     /* but f2 was closed by ly_in_free() */
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_input_filepath(void **state)
+test_input_filepath(void **UNUSED(state))
 {
     struct ly_in *in = NULL;
     const char *path1 = __FILE__, *path2 = __FILE__;
 
-    *state = test_input_filepath;
-
     assert_int_equal(LY_EINVAL, ly_in_new_filepath(NULL, 0, NULL));
     assert_int_equal(LY_EINVAL, ly_in_new_filepath(path1, 0, NULL));
     assert_ptr_equal(((void *)-1), ly_in_filepath(NULL, NULL, 0));
@@ -193,19 +115,14 @@
     assert_ptr_equal(NULL, ly_in_filepath(in, path2, 0));
     assert_string_equal(path2, ly_in_filepath(in, NULL, 0));
     ly_in_free(in, 0);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_output_mem(void **state)
+test_output_mem(void **UNUSED(state))
 {
     struct ly_out *out = NULL;
     char *buf1 = NULL, *buf2 = NULL;
 
-    *state = test_output_mem;
-
     /* manipulate with the handler */
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&buf1, 0, &out));
     assert_int_equal(LY_OUT_MEMORY, ly_out_type(out));
@@ -229,21 +146,16 @@
     assert_int_equal(8, ly_out_printed(out));
     assert_string_equal("rewrite", buf1);
     ly_out_free(out, NULL, 1);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_output_fd(void **state)
+test_output_fd(void **UNUSED(state))
 {
     struct ly_out *out = NULL;
     int fd1, fd2;
     char buf[31] = {0};
     const char *filepath = "/tmp/libyang_test_output";
 
-    *state = test_output_fd;
-
     assert_int_not_equal(-1, fd1 = open(filepath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR));
     assert_int_not_equal(-1, fd2 = open(filepath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR));
 
@@ -281,21 +193,16 @@
 
     close(fd2);
     ly_out_free(out, NULL, 1);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_output_file(void **state)
+test_output_file(void **UNUSED(state))
 {
     struct ly_out *out = NULL;
     FILE *f1, *f2;
     char buf[31] = {0};
     const char *filepath = "/tmp/libyang_test_output";
 
-    *state = test_output_file;
-
     assert_int_not_equal(-1, f1 = fopen(filepath, "w"));
     assert_int_not_equal(-1, f2 = fopen(filepath, "w"));
 
@@ -331,13 +238,10 @@
 
     fclose(f2);
     ly_out_free(out, NULL, 1);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_output_filepath(void **state)
+test_output_filepath(void **UNUSED(state))
 {
     struct ly_out *out = NULL;
     FILE *f1;
@@ -345,8 +249,6 @@
     const char *fp1 = "/tmp/libyang_test_output";
     const char *fp2 = "/tmp/libyang_test_output2";
 
-    *state = test_output_filepath;
-
     /* manipulate with the handler */
     assert_int_equal(LY_SUCCESS, ly_out_new_filepath(fp1, &out));
     assert_int_equal(LY_OUT_FILEPATH, ly_out_type(out));
@@ -377,21 +279,16 @@
 
     fclose(f1);
     ly_out_free(out, NULL, 1);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 static void
-test_output_clb(void **state)
+test_output_clb(void **UNUSED(state))
 {
     struct ly_out *out = NULL;
     int fd1, fd2;
     char buf[31] = {0};
     const char *filepath = "/tmp/libyang_test_output";
 
-    *state = test_output_clb;
-
     assert_int_not_equal(-1, fd1 = open(filepath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR));
     assert_int_not_equal(-1, fd2 = open(filepath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR));
 
@@ -421,24 +318,21 @@
 
     close(fd2);
     ly_out_free(out, (void *)close, 0);
-
-    /* cleanup */
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_input_mem, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_input_fd, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_input_file, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_input_filepath, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_output_mem, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_output_fd, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_output_file, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_output_filepath, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_output_clb, logger_setup, logger_teardown),
+        UTEST(test_input_mem),
+        UTEST(test_input_fd),
+        UTEST(test_input_file),
+        UTEST(test_input_filepath),
+        UTEST(test_output_mem),
+        UTEST(test_output_fd),
+        UTEST(test_output_file),
+        UTEST(test_output_filepath),
+        UTEST(test_output_clb),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/test_json.c b/tests/utests/basic/test_json.c
similarity index 72%
rename from tests/utests/test_json.c
rename to tests/utests/basic/test_json.c
index e36a47a..cf47400 100644
--- a/tests/utests/test_json.c
+++ b/tests/utests/basic/test_json.c
@@ -11,86 +11,14 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#define _DEFAULT_SOURCE
-#define _GNU_SOURCE
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "context.h"
 #include "in_internal.h"
 #include "json.h"
 #include "utests.h"
 
-void *testfunc = NULL;
-
-static int
-setup(void **state)
-{
-    if (ly_ctx_new(NULL, 0, (struct ly_ctx **)state)) {
-        return 1;
-    }
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-    ly_ctx_destroy(*state, NULL);
-    return 0;
-}
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-
-    if (path) {
-        snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-    } else {
-        strncpy(logbuf, msg, BUFSIZE - 1);
-    }
-}
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (testfunc) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_general(void **state)
 {
@@ -98,25 +26,23 @@
     struct ly_in *in;
     const char *str;
 
-    testfunc = test_general;
-
     /* empty */
     str = "";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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));
@@ -124,7 +50,7 @@
 
     str = "false";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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));
@@ -132,14 +58,13 @@
 
     str = "null";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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));
     lyjson_ctx_free(jsonctx);
 
     ly_in_free(in, 0);
-    testfunc = NULL;
 }
 
 static void
@@ -149,12 +74,10 @@
     struct ly_in *in;
     const char *str;
 
-    testfunc = test_number;
-
     /* simple value */
     str = "11";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("11", jsonctx->value);
     assert_int_equal(2, jsonctx->value_len);
@@ -164,7 +87,7 @@
     /* fraction number */
     str = "37.7668";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -174,7 +97,7 @@
     /* negative number */
     str = "-122.3959";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -184,7 +107,7 @@
     /* exp number */
     str = "1E10";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("10000000000", jsonctx->value);
     assert_int_equal(11, jsonctx->value_len);
@@ -193,7 +116,7 @@
 
     str = "15E-1";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -202,7 +125,7 @@
 
     str = "15E-3";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("0.015", jsonctx->value);
     assert_int_equal(5, jsonctx->value_len);
@@ -212,7 +135,7 @@
     /* exp fraction number */
     str = "1.1e3";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("1100", jsonctx->value);
     assert_int_equal(4, jsonctx->value_len);
@@ -222,7 +145,7 @@
     /* negative exp fraction number */
     str = "1.1e-3";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("0.0011", jsonctx->value);
     assert_int_equal(6, jsonctx->value_len);
@@ -232,7 +155,7 @@
     /* exp negative fraction number */
     str = "-0.11e3";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("-110", jsonctx->value);
     assert_int_equal(4, jsonctx->value_len);
@@ -242,7 +165,7 @@
     /* negative exp negative fraction number */
     str = "-3.14e-3";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_NUMBER, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("-0.00314", jsonctx->value);
     assert_int_equal(8, jsonctx->value_len);
@@ -252,46 +175,45 @@
     /* various invalid inputs */
     str = "-x";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_EVALID, lyjson_ctx_new(*state, in, &jsonctx));
-    logbuf_assert("Invalid character in JSON Number value (\"x\"). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Unexpected end-of-input. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character in JSON Number value (\"-\"). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character sequence \"+1\", expected a JSON value. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character in JSON Number value (\"x\"). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Unexpected end-of-input. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character in JSON Number value (\"o\"). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Unexpected end-of-input. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+    CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 1.");
 
     ly_in_free(in, 0);
-    testfunc = NULL;
 }
 
 static void
@@ -301,12 +223,10 @@
     struct ly_in *in;
     const char *str;
 
-    testfunc = test_string;
-
     /* simple string */
     str = "\"hello\"";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -316,7 +236,7 @@
     /* 4-byte utf8 character */
     str = "\"\\t𠜎\"";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_STRING, lyjson_ctx_status(jsonctx, 0));
     assert_string_equal("\t𠜎", jsonctx->value);
     assert_int_equal(5, jsonctx->value_len);
@@ -328,7 +248,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(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -338,34 +258,33 @@
     /* 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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character reference \"\\b\" (0x00000008). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character reference \"\\f\" (0x0000000c). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+    CHECK_LOG_CTX("Invalid character reference \"\\f\" (0x0000000c).", "Line number 1.");
 
     /* unterminated string */
     str = "\"unterminated string";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_EVALID, lyjson_ctx_new(*state, in, &jsonctx));
-    logbuf_assert("Missing quotation-mark at the end of a JSON string. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+    CHECK_LOG_CTX("Missing quotation-mark at the end of a JSON string.", "Line number 1.");
 
     /* invalid escape sequence */
     str = "\"char \\x \"";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_EVALID, lyjson_ctx_new(*state, in, &jsonctx));
-    logbuf_assert("Invalid character escape sequence \\x. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character in JSON string \"\n\" (0x0000000a). Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+    CHECK_LOG_CTX("Invalid character in JSON string \"\n\" (0x0000000a).", "Line number 1.");
 
     ly_in_free(in, 0);
-    testfunc = NULL;
 }
 
 static void
@@ -375,12 +294,10 @@
     struct ly_in *in;
     const char *str;
 
-    testfunc = test_object;
-
     /* empty */
     str = "  { }  ";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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));
@@ -389,7 +306,7 @@
     /* simple value */
     str = "{\"name\" : \"Radek\"}";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -410,7 +327,7 @@
     /* two values */
     str = "{\"smart\" : true,\"handsom\":false}";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -437,7 +354,7 @@
     /* inherited objects */
     str = "{\"person\" : {\"name\":\"Radek\"}}";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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);
@@ -467,11 +384,10 @@
     /* 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(*state, in, &jsonctx));
-    logbuf_assert("Invalid character sequence \"unquoted : \"data\"}\", expected a JSON object's member. Line number 1.");
+    assert_int_equal(LY_EVALID, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
+    CHECK_LOG_CTX("Invalid character sequence \"unquoted : \"data\"}\", expected a JSON object's member.", "Line number 1.");
 
     ly_in_free(in, 0);
-    testfunc = NULL;
 }
 
 static void
@@ -481,12 +397,10 @@
     struct ly_in *in;
     const char *str;
 
-    testfunc = test_array;
-
     /* empty */
     str = "  [  ]  ";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &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));
@@ -495,7 +409,7 @@
     /* simple value */
     str = "[ null]";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0));
     assert_null(jsonctx->value);
     assert_int_equal(0, jsonctx->value_len);
@@ -513,7 +427,7 @@
     /* two values */
     str = "[{\"a\":null},\"x\"]";
     assert_non_null(ly_in_memory(in, str));
-    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LYJSON_ARRAY, lyjson_ctx_status(jsonctx, 0));
     assert_null(jsonctx->value);
     assert_int_equal(0, jsonctx->value_len);
@@ -546,25 +460,24 @@
     /* 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(*state, in, &jsonctx));
+    assert_int_equal(LY_SUCCESS, lyjson_ctx_new(UTEST_LYCTX, in, &jsonctx));
     assert_int_equal(LY_EVALID, lyjson_ctx_next(jsonctx, NULL));
-    logbuf_assert("Invalid character sequence \", null]\", expected a JSON value. Line number 1.");
+    CHECK_LOG_CTX("Invalid character sequence \", null]\", expected a JSON value.", "Line number 1.");
     lyjson_ctx_free(jsonctx);
 
     ly_in_free(in, 0);
-    testfunc = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_general, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_number, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_string, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_object, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_array, logger_setup, logger_teardown),
+        UTEST(test_general),
+        UTEST(test_number),
+        UTEST(test_string),
+        UTEST(test_object),
+        UTEST(test_array),
     };
 
-    return cmocka_run_group_tests(tests, setup, teardown);
+    return cmocka_run_group_tests(tests, NULL, NULL);
 }
diff --git a/tests/utests/test_set.c b/tests/utests/basic/test_set.c
similarity index 82%
rename from tests/utests/test_set.c
rename to tests/utests/basic/test_set.c
index d52ad6e..c4ef521 100644
--- a/tests/utests/test_set.c
+++ b/tests/utests/basic/test_set.c
@@ -11,44 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#define _GNU_SOURCE
 #define _POSIX_C_SOURCE 200809L /* strdup */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdlib.h>
 #include <string.h>
 
-#include "utests.h"
-
 #include "set.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
 static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
+test_basics(void **UNUSED(state))
 {
-    (void) level; /* unused */
-    (void) path; /* unused */
-
-    strncpy(logbuf, msg, BUFSIZE - 1);
-}
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-
-    ly_set_log_clb(logger, 0);
-
-    return 0;
-}
-
-static void
-test_basics(void **state)
-{
-    (void) state; /* unused */
-
     struct ly_set *set;
     char *str;
     unsigned int u;
@@ -103,42 +77,40 @@
     memset(&set, 0, sizeof set);
 
     ly_set_clean(NULL, NULL);
-    assert_string_equal(logbuf, "");
+    CHECK_LOG(NULL, NULL);
 
     ly_set_erase(NULL, NULL);
-    assert_string_equal(logbuf, "");
+    CHECK_LOG(NULL, NULL);
 
     ly_set_free(NULL, NULL);
-    assert_string_equal(logbuf, "");
+    CHECK_LOG(NULL, NULL);
 
     assert_int_equal(LY_EINVAL, ly_set_dup(NULL, NULL, NULL));
-    assert_string_equal(logbuf, "Invalid argument set (ly_set_dup()).");
+    CHECK_LOG("Invalid argument set (ly_set_dup()).", NULL);
 
     assert_int_equal(LY_EINVAL, ly_set_add(NULL, NULL, 0, NULL));
-    assert_string_equal(logbuf, "Invalid argument set (ly_set_add()).");
+    CHECK_LOG("Invalid argument set (ly_set_add()).", NULL);
 
     assert_int_equal(LY_EINVAL, ly_set_merge(NULL, NULL, 0, NULL));
-    assert_string_equal(logbuf, "Invalid argument trg (ly_set_merge()).");
+    CHECK_LOG("Invalid argument trg (ly_set_merge()).", NULL);
     assert_int_equal(LY_SUCCESS, ly_set_merge(&set, NULL, 0, NULL));
 
     assert_int_equal(LY_EINVAL, ly_set_rm_index(NULL, 0, NULL));
-    assert_string_equal(logbuf, "Invalid argument set (ly_set_rm_index()).");
+    CHECK_LOG("Invalid argument set (ly_set_rm_index()).", NULL);
     assert_int_equal(LY_EINVAL, ly_set_rm_index(&set, 1, NULL));
-    assert_string_equal(logbuf, "Invalid argument index (ly_set_rm_index()).");
+    CHECK_LOG("Invalid argument index (ly_set_rm_index()).", NULL);
 
     assert_int_equal(LY_EINVAL, ly_set_rm(NULL, NULL, NULL));
-    assert_string_equal(logbuf, "Invalid argument set (ly_set_rm()).");
+    CHECK_LOG("Invalid argument set (ly_set_rm()).", NULL);
     assert_int_equal(LY_EINVAL, ly_set_rm(&set, NULL, NULL));
-    assert_string_equal(logbuf, "Invalid argument object (ly_set_rm()).");
-    assert_int_equal(LY_EINVAL, ly_set_rm(&set, &state, NULL));
-    assert_string_equal(logbuf, "Invalid argument object (ly_set_rm()).");
+    CHECK_LOG("Invalid argument object (ly_set_rm()).", NULL);
+    assert_int_equal(LY_EINVAL, ly_set_rm(&set, &set, NULL));
+    CHECK_LOG("Invalid argument object (ly_set_rm()).", NULL);
 }
 
 static void
-test_duplication(void **state)
+test_duplication(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
     struct ly_set *orig, *new;
     char *str;
     uint32_t index;
@@ -175,10 +147,8 @@
 }
 
 static void
-test_add(void **state)
+test_add(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
     uint32_t u, index;
     char *str = "test string";
     struct ly_set set;
@@ -210,10 +180,8 @@
 }
 
 static void
-test_merge(void **state)
+test_merge(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
     char *str1, *str2;
     struct ly_set one, two;
 
@@ -254,10 +222,8 @@
 }
 
 static void
-test_rm(void **state)
+test_rm(void **UNUSED(state))
 {
-    (void) state; /* unused */
-
     char *str1, *str2, *str3;
     struct ly_set set;
 
@@ -309,12 +275,12 @@
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test(test_basics),
-        cmocka_unit_test(test_duplication),
-        cmocka_unit_test(test_add),
-        cmocka_unit_test(test_merge),
-        cmocka_unit_test(test_rm),
-        cmocka_unit_test_setup(test_inval, logger_setup),
+        UTEST(test_basics),
+        UTEST(test_duplication),
+        UTEST(test_add),
+        UTEST(test_merge),
+        UTEST(test_rm),
+        UTEST(test_inval),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/test_xml.c b/tests/utests/basic/test_xml.c
similarity index 79%
rename from tests/utests/test_xml.c
rename to tests/utests/basic/test_xml.c
index 4d04b63..abf0bf1 100644
--- a/tests/utests/test_xml.c
+++ b/tests/utests/basic/test_xml.c
@@ -11,15 +11,13 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
-#define _DEFAULT_SOURCE
-#define _GNU_SOURCE
 #define _POSIX_C_SOURCE 200809L /* strdup */
 
 #include <string.h>
 
-#include "utests.h"
-
 #include "context.h"
 #include "in_internal.h"
 #include "xml.h"
@@ -27,63 +25,6 @@
 LY_ERR lyxml_ns_add(struct lyxml_ctx *xmlctx, const char *prefix, size_t prefix_len, char *uri);
 LY_ERR lyxml_ns_rm(struct lyxml_ctx *xmlctx);
 
-static int
-setup(void **state)
-{
-    if (ly_ctx_new(NULL, 0, (struct ly_ctx **)state)) {
-        return 1;
-    }
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-    ly_ctx_destroy(*state, NULL);
-    return 0;
-}
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-
-    if (path) {
-        snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-    } else {
-        strncpy(logbuf, msg, BUFSIZE - 1);
-    }
-}
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_element(void **state)
 {
@@ -94,7 +35,7 @@
     /* empty */
     str = "";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_END, xmlctx->status);
     lyxml_ctx_free(xmlctx);
     ly_in_free(in, 0);
@@ -102,36 +43,36 @@
     /* end element */
     str = "</element>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Stray closing element tag (\"element\"). Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Stray closing element tag (\"element\").", "Line number 1.");
     ly_in_free(in, 0);
 
     /* no element */
-    // logbuf_clean();
+    UTEST_LOG_CLEAN;
     str = "no data present";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Invalid character sequence \"no data present\", expected element tag start ('<'). Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Invalid character sequence \"no data present\", expected element tag start ('<').", "Line number 1.");
     ly_in_free(in, 0);
 
     /* not supported DOCTYPE */
     str = "<!DOCTYPE greeting SYSTEM \"hello.dtd\"><greeting/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Document Type Declaration not supported. Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Document Type Declaration not supported.", "Line number 1.");
     ly_in_free(in, 0);
 
     /* invalid XML */
     str = "<!NONSENSE/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Unknown XML section \"<!NONSENSE/>\". Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Unknown XML section \"<!NONSENSE/>\".", "Line number 1.");
     ly_in_free(in, 0);
 
     /* unqualified element */
     str = "  <  element/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_null(xmlctx->prefix);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
@@ -152,7 +93,7 @@
     /* element with attribute */
     str = "  <  element attr=\'x\'/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -183,7 +124,7 @@
     /* headers and comments */
     str = "<?xml version=\"1.0\"?>  <!-- comment --> <![CDATA[<greeting>Hello, world!</greeting>]]> <?TEST xxx?> <element/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -203,7 +144,7 @@
     /* separate opening and closing tags, neamespaced parsed internally */
     str = "<element xmlns=\"urn\"></element>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -226,7 +167,7 @@
     /* qualified element */
     str = "  <  yin:element/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len));
@@ -245,7 +186,7 @@
     /* non-matching closing tag */
     str = "<yin:element xmlns=\"urn\"></element>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("element", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("yin", xmlctx->prefix, xmlctx->prefix_len));
@@ -256,24 +197,24 @@
     assert_int_equal(LYXML_ELEM_CONTENT, xmlctx->status);
 
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Opening (\"yin:element\") and closing (\"element\") elements tag mismatch. Line number 1.");
+    CHECK_LOG_CTX("Opening (\"yin:element\") and closing (\"element\") elements tag mismatch.", "Line number 1.");
     lyxml_ctx_free(xmlctx);
     ly_in_free(in, 0);
 
     /* invalid closing tag */
     str = "<yin:element xmlns=\"urn\"></yin:element/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character sequence \"/>\", expected element tag termination ('>'). Line number 1.");
+    CHECK_LOG_CTX("Invalid character sequence \"/>\", expected element tag termination ('>').", "Line number 1.");
     lyxml_ctx_free(xmlctx);
     ly_in_free(in, 0);
 
     /* UTF8 characters */
     str = "<𠜎€𠜎Øn:𠜎€𠜎Øn/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->name, xmlctx->name_len));
     assert_true(!strncmp("𠜎€𠜎Øn", xmlctx->prefix, xmlctx->prefix_len));
 
@@ -291,22 +232,22 @@
     /* invalid UTF-8 characters */
     str = "<¢:element>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Identifier \"¢:element>\" starts with an invalid character. Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Identifier \"¢:element>\" starts with an invalid character.", "Line number 1.");
     ly_in_free(in, 0);
 
     str = "<yin:c⁐element>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character sequence \"⁐element>\", expected element tag end ('>' or '/>') or an attribute. Line number 1.");
+    CHECK_LOG_CTX("Invalid character sequence \"⁐element>\", expected element tag end ('>' or '/>') or an attribute.", "Line number 1.");
     lyxml_ctx_free(xmlctx);
     ly_in_free(in, 0);
 
     /* mixed content */
     str = "<a>text <b>x</b></a>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -338,7 +279,7 @@
     /* tag mismatch */
     str = "<a>text</b>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_true(!strncmp("a", xmlctx->name, xmlctx->name_len));
     assert_null(xmlctx->prefix);
@@ -348,7 +289,7 @@
     assert_true(!strncmp("text", xmlctx->value, xmlctx->value_len));
 
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Opening (\"a\") and closing (\"b\") elements tag mismatch. Line number 1.");
+    CHECK_LOG_CTX("Opening (\"a\") and closing (\"b\") elements tag mismatch.", "Line number 1.");
     lyxml_ctx_free(xmlctx);
     ly_in_free(in, 0);
 }
@@ -364,26 +305,26 @@
     /* not an attribute */
     str = "<e unknown/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Invalid character sequence \"/>\", expected '='. Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Invalid character sequence \"/>\", expected '='.", "Line number 1.");
     ly_in_free(in, 0);
 
     str = "<e xxx=/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Invalid character sequence \"/>\", expected either single or double quotation mark. Line number 1.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Invalid character sequence \"/>\", expected either single or double quotation mark.", "Line number 1.");
     ly_in_free(in, 0);
 
     str = "<e xxx\n = yyy/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EVALID, lyxml_ctx_new(*state, in, &xmlctx));
-    logbuf_assert("Invalid character sequence \"yyy/>\", expected either single or double quotation mark. Line number 2.");
+    assert_int_equal(LY_EVALID, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
+    CHECK_LOG_CTX("Invalid character sequence \"yyy/>\", expected either single or double quotation mark.", "Line number 2.");
     ly_in_free(in, 0);
 
     /* valid attribute */
     str = "<e attr=\"val\"";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
@@ -401,7 +342,7 @@
     /* valid namespace with prefix */
     str = "<e xmlns:nc\n = \'urn\'/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(1, xmlctx->ns.count);
     ns = (struct lyxml_ns *)xmlctx->ns.objs[0];
@@ -421,7 +362,7 @@
     /* empty attribute value */
     str = "<e a=\"\"";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
     assert_int_equal(LYXML_ATTRIBUTE, xmlctx->status);
@@ -460,14 +401,14 @@
     xmlctx->in = in;
     xmlctx->status = LYXML_ELEM_CONTENT;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Unexpected end-of-input. Line number 2.");
+    CHECK_LOG_CTX("Unexpected end-of-input.", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("xxx", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ELEM_CONTENT;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character sequence \"xxx\", expected element tag start ('<'). Line number 2.");
+    CHECK_LOG_CTX("Invalid character sequence \"xxx\", expected element tag start ('<').", "Line number 2.");
     ly_in_free(in, 0);
 
     lyxml_ctx_free(xmlctx);
@@ -475,7 +416,7 @@
     /* valid strings */
     str = "<a>€𠜎Øn \n&lt;&amp;&quot;&apos;&gt; &#82;&#x4f;&#x4B;</a>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
 
     assert_int_equal(LY_SUCCESS, lyxml_ctx_next(xmlctx));
@@ -503,49 +444,49 @@
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character sequence \"'\", expected ;. Line number 2.");
+    CHECK_LOG_CTX("Invalid character sequence \"'\", expected ;.", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"&#82\"", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character sequence \"\"\", expected ;. Line number 2.");
+    CHECK_LOG_CTX("Invalid character sequence \"\"\", expected ;.", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\"&nonsense;\"", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Entity reference \"&nonsense;\" not supported, only predefined references allowed. Line number 2.");
+    CHECK_LOG_CTX("Entity reference \"&nonsense;\" not supported, only predefined references allowed.", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(">&#o122;", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ELEMENT;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character reference \"&#o122;\". Line number 2.");
+    CHECK_LOG_CTX("Invalid character reference \"&#o122;\".", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#x06;\'", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character reference \"&#x06;\'\" (0x00000006). Line number 2.");
+    CHECK_LOG_CTX("Invalid character reference \"&#x06;\'\" (0x00000006).", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#xfdd0;\'", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character reference \"&#xfdd0;\'\" (0x0000fdd0). Line number 2.");
+    CHECK_LOG_CTX("Invalid character reference \"&#xfdd0;\'\" (0x0000fdd0).", "Line number 2.");
     ly_in_free(in, 0);
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory("=\'&#xffff;\'", &in));
     xmlctx->in = in;
     xmlctx->status = LYXML_ATTRIBUTE;
     assert_int_equal(LY_EVALID, lyxml_ctx_next(xmlctx));
-    logbuf_assert("Invalid character reference \"&#xffff;\'\" (0x0000ffff). Line number 2.");
+    CHECK_LOG_CTX("Invalid character reference \"&#xffff;\'\" (0x0000ffff).", "Line number 2.");
     ly_in_free(in, 0);
 
     lyxml_ctx_free(xmlctx);
@@ -562,7 +503,7 @@
     /* opening element1 */
     str = "<element1/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
 
     /* processing namespace definitions */
     assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default")));
@@ -616,7 +557,7 @@
     /* opening element1 */
     str = "<element1/>";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
 
     /* default namespace defined in parent element1 */
     assert_int_equal(LY_SUCCESS, lyxml_ns_add(xmlctx, NULL, 0, strdup("urn:default")));
@@ -646,7 +587,7 @@
     const char *test_input = "<elem1 attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>";
 
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(test_input, &in));
-    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(*state, in, &xmlctx));
+    assert_int_equal(LY_SUCCESS, lyxml_ctx_new(UTEST_LYCTX, in, &xmlctx));
     assert_int_equal(LYXML_ELEMENT, xmlctx->status);
     assert_string_equal(xmlctx->in->current, "attr1=\"value\"> <elem2 attr2=\"value\" /> </elem1>");
 
@@ -698,13 +639,13 @@
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup(test_element, logger_setup),
-        cmocka_unit_test_setup(test_attribute, logger_setup),
-        cmocka_unit_test_setup(test_text, logger_setup),
-        cmocka_unit_test_setup(test_ns, logger_setup),
-        cmocka_unit_test_setup(test_ns2, logger_setup),
-        cmocka_unit_test_setup(test_simple_xml, logger_setup),
+        UTEST(test_element),
+        UTEST(test_attribute),
+        UTEST(test_text),
+        UTEST(test_ns),
+        UTEST(test_ns2),
+        UTEST(test_simple_xml),
     };
 
-    return cmocka_run_group_tests(tests, setup, teardown);
+    return cmocka_run_group_tests(tests, NULL, NULL);
 }
diff --git a/tests/utests/test_xpath.c b/tests/utests/basic/test_xpath.c
similarity index 67%
rename from tests/utests/test_xpath.c
rename to tests/utests/basic/test_xpath.c
index d655ac2..712b854 100644
--- a/tests/utests/test_xpath.c
+++ b/tests/utests/basic/test_xpath.c
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <string.h>
 
@@ -20,151 +22,69 @@
 #include "tests/config.h"
 #include "tree_data.h"
 #include "tree_schema.h"
-#include "utests.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
+const char *schema_a =
+        "module a {\n"
+        "    namespace urn:tests:a;\n"
+        "    prefix a;\n"
+        "    yang-version 1.1;\n"
+        "\n"
+        "    list l1 {\n"
+        "        key \"a b\";\n"
+        "        leaf a {\n"
+        "            type string;\n"
+        "        }\n"
+        "        leaf b {\n"
+        "            type string;\n"
+        "        }\n"
+        "        leaf c {\n"
+        "            type string;\n"
+        "        }\n"
+        "    }\n"
+        "    leaf foo {\n"
+        "        type string;\n"
+        "    }\n"
+        "    leaf foo2 {\n"
+        "        type uint8;\n"
+        "    }\n"
+        "    container c {\n"
+        "        leaf x {\n"
+        "            type string;\n"
+        "        }\n"
+        "        list ll {\n"
+        "            key \"a\";\n"
+        "            leaf a {\n"
+        "                type string;\n"
+        "            }\n"
+        "            list ll {\n"
+        "                key \"a\";\n"
+        "                leaf a {\n"
+        "                    type string;\n"
+        "                }\n"
+        "                leaf b {\n"
+        "                    type string;\n"
+        "                }\n"
+        "            }\n"
+        "        }\n"
+        "        leaf-list ll2 {\n"
+        "            type string;\n"
+        "        }\n"
+        "    }\n"
+        "}";
 
 static int
 setup(void **state)
 {
-    (void) state; /* unused */
+    UTEST_SETUP;
 
-    const char *schema_a =
-            "module a {\n"
-            "    namespace urn:tests:a;\n"
-            "    prefix a;\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    list l1 {\n"
-            "        key \"a b\";\n"
-            "        leaf a {\n"
-            "            type string;\n"
-            "        }\n"
-            "        leaf b {\n"
-            "            type string;\n"
-            "        }\n"
-            "        leaf c {\n"
-            "            type string;\n"
-            "        }\n"
-            "    }\n"
-            "    leaf foo {\n"
-            "        type string;\n"
-            "    }\n"
-            "    leaf foo2 {\n"
-            "        type uint8;\n"
-            "    }\n"
-            "    container c {\n"
-            "        leaf x {\n"
-            "            type string;\n"
-            "        }\n"
-            "        list ll {\n"
-            "            key \"a\";\n"
-            "            leaf a {\n"
-            "                type string;\n"
-            "            }\n"
-            "            list ll {\n"
-            "                key \"a\";\n"
-            "                leaf a {\n"
-            "                    type string;\n"
-            "                }\n"
-            "                leaf b {\n"
-            "                    type string;\n"
-            "                }\n"
-            "            }\n"
-            "        }\n"
-            "        leaf-list ll2 {\n"
-            "            type string;\n"
-            "        }\n"
-            "    }\n"
-            "}";
-    const char *schema_b =
-            "module b {\n"
-            "    namespace urn:tests:b;\n"
-            "    prefix b;\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    list l2 {\n"
-            "        key \"a\";\n"
-            "        leaf a {\n"
-            "            type uint16;\n"
-            "        }\n"
-            "        leaf b {\n"
-            "            type uint16;\n"
-            "        }\n"
-            "    }\n"
-            "}";
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
-    assert_int_equal(lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL), LY_SUCCESS);
-    assert_int_equal(lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL), LY_SUCCESS);
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, NULL);
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
-
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_hash(void **state)
 {
-    *state = test_hash;
-
     const char *data =
             "<l1 xmlns=\"urn:tests:a\">\n"
             "    <a>a1</a>\n"
@@ -220,7 +140,7 @@
     struct lyd_node *tree, *node;
     struct ly_set *set;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
 
     /* top-level, so hash table is not ultimately used but instances can be compared based on hashes */
@@ -279,14 +199,27 @@
     ly_set_free(set, NULL);
 
     lyd_free_all(tree);
-    *state = NULL;
 }
 
 static void
 test_toplevel(void **state)
 {
-    *state = test_toplevel;
-
+    const char *schema_b =
+            "module b {\n"
+            "    namespace urn:tests:b;\n"
+            "    prefix b;\n"
+            "    yang-version 1.1;\n"
+            "\n"
+            "    list l2 {\n"
+            "        key \"a\";\n"
+            "        leaf a {\n"
+            "            type uint16;\n"
+            "        }\n"
+            "        leaf b {\n"
+            "            type uint16;\n"
+            "        }\n"
+            "    }\n"
+            "}";
     const char *data =
             "<l1 xmlns=\"urn:tests:a\">\n"
             "    <a>a1</a>\n"
@@ -318,7 +251,9 @@
     struct lyd_node *tree;
     struct ly_set *set;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+    UTEST_ADD_MODULE(schema_b, LYS_IN_YANG, NULL, NULL);
+
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
 
     /* all top-level nodes from one module (default container as well) */
@@ -352,18 +287,16 @@
     ly_set_free(set, NULL);
 
     lyd_free_all(tree);
-    *state = NULL;
 }
 
 static void
 test_atomize(void **state)
 {
-    *state = test_atomize;
-
     struct ly_set *set;
     const struct lys_module *mod;
 
-    mod = ly_ctx_get_module_latest(ctx, "a");
+    mod = ly_ctx_get_module_latest(UTEST_LYCTX, "a");
+    assert_non_null(mod);
 
     /* some random paths just making sure the API function works */
     assert_int_equal(LY_SUCCESS, lys_find_xpath_atoms(mod->compiled->data, "/a:*", 0, &set));
@@ -387,14 +320,12 @@
 static void
 test_canonize(void **state)
 {
-    *state = test_canonize;
-
     const char *data =
             "<foo2 xmlns=\"urn:tests:a\">50</foo2>";
     struct lyd_node *tree;
     struct ly_set *set;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
     assert_non_null(tree);
 
     assert_int_equal(LY_SUCCESS, lyd_find_xpath(tree, "/a:foo2[.='050']", &set));
@@ -404,17 +335,16 @@
     /* TODO more use-cases once there are some type plugins that have canonical values */
 
     lyd_free_all(tree);
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_hash, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_toplevel, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_atomize, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_canonize, setup, teardown),
+        UTEST(test_hash, setup),
+        UTEST(test_toplevel, setup),
+        UTEST(test_atomize, setup),
+        UTEST(test_canonize, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/basic/test_yanglib.c b/tests/utests/basic/test_yanglib.c
new file mode 100644
index 0000000..563fbb3
--- /dev/null
+++ b/tests/utests/basic/test_yanglib.c
@@ -0,0 +1,138 @@
+/**
+ * @file test_yanglib.c
+ * @author: Michal Vasko <mvasko@cesnet.cz>
+ * @brief unit tests for ietf-yang-library data
+ *
+ * Copyright (c) 2020 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     https://opensource.org/licenses/BSD-3-Clause
+ */
+#define _UTEST_MAIN_
+#include "utests.h"
+
+#include <string.h>
+
+#include "context.h"
+#include "in.h"
+#include "log.h"
+#include "set.h"
+#include "tests/config.h"
+#include "tree_data.h"
+#include "tree_schema.h"
+
+const char *schema_a =
+        "module a {\n"
+        "  namespace urn:tests:a;\n"
+        "  prefix a;\n"
+        "  yang-version 1.1;\n"
+        "\n"
+        "  include a_sub;\n"
+        "\n"
+        "  list l2 {\n"
+        "    key \"a\";\n"
+        "    leaf a {\n"
+        "      type uint16;\n"
+        "    }\n"
+        "    leaf b {\n"
+        "      type uint16;\n"
+        "    }\n"
+        "  }\n"
+        "}";
+const char *schema_b =
+        "module b {\n"
+        "  namespace urn:tests:b;\n"
+        "  prefix b;\n"
+        "  yang-version 1.1;\n"
+        "\n"
+        "  import a {\n"
+        "    prefix a;\n"
+        "  }\n"
+        "\n"
+        "  deviation /a:l2 {\n"
+        "    deviate add {\n"
+        "      max-elements 40;\n"
+        "    }\n"
+        "  }\n"
+        "\n"
+        "  leaf foo {\n"
+        "    type string;\n"
+        "  }\n"
+        "}";
+
+static LY_ERR
+test_imp_clb(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data,
+        LYS_INFORMAT *format, const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
+{
+    const char *schema_a_sub =
+            "submodule a_sub {\n"
+            "    belongs-to a {\n"
+            "        prefix a;\n"
+            "    }\n"
+            "    yang-version 1.1;\n"
+            "\n"
+            "    feature feat1;\n"
+            "\n"
+            "    list l3 {\n"
+            "        key \"a\";\n"
+            "        leaf a {\n"
+            "            type uint16;\n"
+            "        }\n"
+            "        leaf b {\n"
+            "            type uint16;\n"
+            "        }\n"
+            "    }\n"
+            "}\n";
+
+    assert_string_equal(mod_name, "a");
+    assert_null(mod_rev);
+    if (!submod_name) {
+        return LY_ENOTFOUND;
+    }
+    assert_string_equal(submod_name, "a_sub");
+    assert_null(sub_rev);
+    assert_null(user_data);
+
+    *format = LYS_IN_YANG;
+    *module_data = schema_a_sub;
+    *free_module_data = NULL;
+    return LY_SUCCESS;
+}
+
+static void
+test_yanglib(void **state)
+{
+    const char *feats[] = {"feat1", NULL};
+    struct lyd_node *tree;
+    struct ly_set *set;
+    LY_ERR ret;
+
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, NULL);
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, feats, NULL);
+    UTEST_ADD_MODULE(schema_b, LYS_IN_YANG, NULL, NULL);
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_get_yanglib_data(UTEST_LYCTX, &tree));
+
+    /* make sure there is "a" with a submodule and deviation */
+    ret = lyd_find_xpath(tree, "/ietf-yang-library:yang-library/module-set/module[name='a'][submodule/name='a_sub']"
+            "[feature='feat1'][deviation='b']", &set);
+    assert_int_equal(ret, LY_SUCCESS);
+
+    assert_int_equal(set->count, 1);
+    ly_set_free(set, NULL);
+
+    lyd_free_all(tree);
+}
+
+int
+main(void)
+{
+    const struct CMUnitTest tests[] = {
+        UTEST(test_yanglib),
+    };
+
+    return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/tests/utests/data/test_diff.c b/tests/utests/data/test_diff.c
index 84b1ac1..6964764 100644
--- a/tests/utests/data/test_diff.c
+++ b/tests/utests/data/test_diff.c
@@ -12,238 +12,245 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#include "libyang.h"
-#include "tests/config.h"
+#define _UTEST_MAIN_
 #include "utests.h"
 
-struct state {
-    struct ly_ctx *ctx;
-    struct lyd_node *first;
-    struct lyd_node *second;
-    struct lyd_node *third;
-    struct lyd_node *diff1;
-    struct lyd_node *diff2;
-    char *xml;
-    char *xml1;
-    char *xml2;
-};
+#include "libyang.h"
+
+#define CHECK_PARSE_LYD(INPUT, MODEL) \
+                CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, MODEL)
+
+#define CHECK_LYD_STRING(IN_MODEL, TEXT) \
+                CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS)
+
+#define CHECK_PARSE_LYD_DIFF(INPUT_1, INPUT_2, OUT_MODEL) \
+                assert_int_equal(LY_SUCCESS, lyd_diff_siblings(INPUT_1, INPUT_2, 0, &OUT_MODEL));\
+                assert_non_null(OUT_MODEL)
+
+#define TEST_DIFF_3(XML_1, XML_2, XML_3, DIFF_1, DIFF_2, MERGE) \
+                { \
+    /*decladation*/\
+                    struct lyd_node *model_1;\
+                    struct lyd_node *model_2;\
+                    struct lyd_node *model_3;\
+    /*create*/\
+                    CHECK_PARSE_LYD(XML_1, model_1);\
+                    CHECK_PARSE_LYD(XML_2, model_2);\
+                    CHECK_PARSE_LYD(XML_3, model_3);\
+    /* diff1 */ \
+                    struct lyd_node * diff1;\
+                    CHECK_PARSE_LYD_DIFF(model_1, model_2, diff1); \
+                    CHECK_LYD_STRING(diff1, DIFF_1); \
+                    assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS); \
+                    CHECK_LYD(model_1, model_2); \
+    /* diff2 */ \
+                    struct lyd_node * diff2;\
+                    CHECK_PARSE_LYD_DIFF(model_2, model_3, diff2); \
+                    CHECK_LYD_STRING(diff2, DIFF_2); \
+                    assert_int_equal(lyd_diff_apply_all(&model_2, diff2), LY_SUCCESS);\
+                    CHECK_LYD(model_2, model_3);\
+    /* merge */ \
+                    assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);\
+                    CHECK_LYD_STRING(diff1, MERGE); \
+    /* CREAR ENV */ \
+                    lyd_free_all(model_1);\
+                    lyd_free_all(model_2);\
+                    lyd_free_all(model_3);\
+                    lyd_free_all(diff1);\
+                    lyd_free_all(diff2);\
+                }
+
+const char *schema =
+        "module defaults {\n"
+        "    yang-version 1.1;\n"
+        "    namespace \"urn:libyang:tests:defaults\";\n"
+        "    prefix df;\n"
+        "\n"
+        "    feature unhide;\n"
+        "\n"
+        "    typedef defint32 {\n"
+        "        type int32;\n"
+        "        default \"42\";\n"
+        "    }\n"
+        "\n"
+        "    leaf hiddenleaf {\n"
+        "        if-feature \"unhide\";\n"
+        "        type int32;\n"
+        "        default \"42\";\n"
+        "    }\n"
+        "\n"
+        "    container df {\n"
+        "        leaf foo {\n"
+        "            type defint32;\n"
+        "        }\n"
+        "\n"
+        "        leaf hiddenleaf {\n"
+        "            if-feature \"unhide\";\n"
+        "            type int32;\n"
+        "            default \"42\";\n"
+        "        }\n"
+        "\n"
+        "        container bar {\n"
+        "            presence \"\";\n"
+        "            leaf hi {\n"
+        "                type int32;\n"
+        "                default \"42\";\n"
+        "            }\n"
+        "\n"
+        "            leaf ho {\n"
+        "                type int32;\n"
+        "                mandatory true;\n"
+        "            }\n"
+        "        }\n"
+        "\n"
+        "        leaf-list llist {\n"
+        "            type defint32;\n"
+        "            ordered-by user;\n"
+        "        }\n"
+        "\n"
+        "        leaf-list dllist {\n"
+        "            type uint8;\n"
+        "            default \"1\";\n"
+        "            default \"2\";\n"
+        "            default \"3\";\n"
+        "        }\n"
+        "\n"
+        "        list list {\n"
+        "            key \"name\";\n"
+        "            leaf name {\n"
+        "                type string;\n"
+        "            }\n"
+        "\n"
+        "            leaf value {\n"
+        "                type int32;\n"
+        "                default \"42\";\n"
+        "            }\n"
+        "        }\n"
+        "\n"
+        "        choice select {\n"
+        "            default \"a\";\n"
+        "            case a {\n"
+        "                choice a {\n"
+        "                    leaf a1 {\n"
+        "                        type int32;\n"
+        "                        default \"42\";\n"
+        "                    }\n"
+        "\n"
+        "                    leaf a2 {\n"
+        "                        type int32;\n"
+        "                        default \"24\";\n"
+        "                    }\n"
+        "                }\n"
+        "            }\n"
+        "\n"
+        "            leaf b {\n"
+        "                type string;\n"
+        "            }\n"
+        "\n"
+        "            container c {\n"
+        "                presence \"\";\n"
+        "                leaf x {\n"
+        "                    type int32;\n"
+        "                    default \"42\";\n"
+        "                }\n"
+        "            }\n"
+        "        }\n"
+        "\n"
+        "        choice select2 {\n"
+        "            default \"s2b\";\n"
+        "            leaf s2a {\n"
+        "                type int32;\n"
+        "                default \"42\";\n"
+        "            }\n"
+        "\n"
+        "            case s2b {\n"
+        "                choice s2b {\n"
+        "                    default \"b1\";\n"
+        "                    case b1 {\n"
+        "                        leaf b1_1 {\n"
+        "                            type int32;\n"
+        "                            default \"42\";\n"
+        "                        }\n"
+        "\n"
+        "                        leaf b1_2 {\n"
+        "                            type string;\n"
+        "                        }\n"
+        "\n"
+        "                        leaf b1_status {\n"
+        "                            type int32;\n"
+        "                            default \"42\";\n"
+        "                            config false;\n"
+        "                        }\n"
+        "                    }\n"
+        "\n"
+        "                    leaf b2 {\n"
+        "                        type int32;\n"
+        "                        default \"42\";\n"
+        "                    }\n"
+        "                }\n"
+        "            }\n"
+        "        }\n"
+        "    }\n"
+        "\n"
+        "    container hidden {\n"
+        "        leaf foo {\n"
+        "            type int32;\n"
+        "            default \"42\";\n"
+        "        }\n"
+        "\n"
+        "        leaf baz {\n"
+        "            type int32;\n"
+        "            default \"42\";\n"
+        "        }\n"
+        "\n"
+        "        leaf papa {\n"
+        "            type int32;\n"
+        "            default \"42\";\n"
+        "            config false;\n"
+        "        }\n"
+        "    }\n"
+        "\n"
+        "    rpc rpc1 {\n"
+        "        input {\n"
+        "            leaf inleaf1 {\n"
+        "                type string;\n"
+        "            }\n"
+        "\n"
+        "            leaf inleaf2 {\n"
+        "                type string;\n"
+        "                default \"def1\";\n"
+        "            }\n"
+        "        }\n"
+        "\n"
+        "        output {\n"
+        "            leaf outleaf1 {\n"
+        "                type string;\n"
+        "                default \"def2\";\n"
+        "            }\n"
+        "\n"
+        "            leaf outleaf2 {\n"
+        "                type string;\n"
+        "            }\n"
+        "        }\n"
+        "    }\n"
+        "\n"
+        "    notification notif {\n"
+        "        leaf ntfleaf1 {\n"
+        "            type string;\n"
+        "            default \"def3\";\n"
+        "        }\n"
+        "\n"
+        "        leaf ntfleaf2 {\n"
+        "            type string;\n"
+        "        }\n"
+        "    }\n"
+        "}\n";
 
 static int
-setup_f(void **state)
+setup(void **state)
 {
-    struct state *st;
-    const char *schema =
-            "module defaults {\n"
-            "    yang-version 1.1;\n"
-            "    namespace \"urn:libyang:tests:defaults\";\n"
-            "    prefix df;\n"
-            "\n"
-            "    feature unhide;\n"
-            "\n"
-            "    typedef defint32 {\n"
-            "        type int32;\n"
-            "        default \"42\";\n"
-            "    }\n"
-            "\n"
-            "    leaf hiddenleaf {\n"
-            "        if-feature \"unhide\";\n"
-            "        type int32;\n"
-            "        default \"42\";\n"
-            "    }\n"
-            "\n"
-            "    container df {\n"
-            "        leaf foo {\n"
-            "            type defint32;\n"
-            "        }\n"
-            "\n"
-            "        leaf hiddenleaf {\n"
-            "            if-feature \"unhide\";\n"
-            "            type int32;\n"
-            "            default \"42\";\n"
-            "        }\n"
-            "\n"
-            "        container bar {\n"
-            "            presence \"\";\n"
-            "            leaf hi {\n"
-            "                type int32;\n"
-            "                default \"42\";\n"
-            "            }\n"
-            "\n"
-            "            leaf ho {\n"
-            "                type int32;\n"
-            "                mandatory true;\n"
-            "            }\n"
-            "        }\n"
-            "\n"
-            "        leaf-list llist {\n"
-            "            type defint32;\n"
-            "            ordered-by user;\n"
-            "        }\n"
-            "\n"
-            "        leaf-list dllist {\n"
-            "            type uint8;\n"
-            "            default \"1\";\n"
-            "            default \"2\";\n"
-            "            default \"3\";\n"
-            "        }\n"
-            "\n"
-            "        list list {\n"
-            "            key \"name\";\n"
-            "            leaf name {\n"
-            "                type string;\n"
-            "            }\n"
-            "\n"
-            "            leaf value {\n"
-            "                type int32;\n"
-            "                default \"42\";\n"
-            "            }\n"
-            "        }\n"
-            "\n"
-            "        choice select {\n"
-            "            default \"a\";\n"
-            "            case a {\n"
-            "                choice a {\n"
-            "                    leaf a1 {\n"
-            "                        type int32;\n"
-            "                        default \"42\";\n"
-            "                    }\n"
-            "\n"
-            "                    leaf a2 {\n"
-            "                        type int32;\n"
-            "                        default \"24\";\n"
-            "                    }\n"
-            "                }\n"
-            "            }\n"
-            "\n"
-            "            leaf b {\n"
-            "                type string;\n"
-            "            }\n"
-            "\n"
-            "            container c {\n"
-            "                presence \"\";\n"
-            "                leaf x {\n"
-            "                    type int32;\n"
-            "                    default \"42\";\n"
-            "                }\n"
-            "            }\n"
-            "        }\n"
-            "\n"
-            "        choice select2 {\n"
-            "            default \"s2b\";\n"
-            "            leaf s2a {\n"
-            "                type int32;\n"
-            "                default \"42\";\n"
-            "            }\n"
-            "\n"
-            "            case s2b {\n"
-            "                choice s2b {\n"
-            "                    default \"b1\";\n"
-            "                    case b1 {\n"
-            "                        leaf b1_1 {\n"
-            "                            type int32;\n"
-            "                            default \"42\";\n"
-            "                        }\n"
-            "\n"
-            "                        leaf b1_2 {\n"
-            "                            type string;\n"
-            "                        }\n"
-            "\n"
-            "                        leaf b1_status {\n"
-            "                            type int32;\n"
-            "                            default \"42\";\n"
-            "                            config false;\n"
-            "                        }\n"
-            "                    }\n"
-            "\n"
-            "                    leaf b2 {\n"
-            "                        type int32;\n"
-            "                        default \"42\";\n"
-            "                    }\n"
-            "                }\n"
-            "            }\n"
-            "        }\n"
-            "    }\n"
-            "\n"
-            "    container hidden {\n"
-            "        leaf foo {\n"
-            "            type int32;\n"
-            "            default \"42\";\n"
-            "        }\n"
-            "\n"
-            "        leaf baz {\n"
-            "            type int32;\n"
-            "            default \"42\";\n"
-            "        }\n"
-            "\n"
-            "        leaf papa {\n"
-            "            type int32;\n"
-            "            default \"42\";\n"
-            "            config false;\n"
-            "        }\n"
-            "    }\n"
-            "\n"
-            "    rpc rpc1 {\n"
-            "        input {\n"
-            "            leaf inleaf1 {\n"
-            "                type string;\n"
-            "            }\n"
-            "\n"
-            "            leaf inleaf2 {\n"
-            "                type string;\n"
-            "                default \"def1\";\n"
-            "            }\n"
-            "        }\n"
-            "\n"
-            "        output {\n"
-            "            leaf outleaf1 {\n"
-            "                type string;\n"
-            "                default \"def2\";\n"
-            "            }\n"
-            "\n"
-            "            leaf outleaf2 {\n"
-            "                type string;\n"
-            "            }\n"
-            "        }\n"
-            "    }\n"
-            "\n"
-            "    notification notif {\n"
-            "        leaf ntfleaf1 {\n"
-            "            type string;\n"
-            "            default \"def3\";\n"
-            "        }\n"
-            "\n"
-            "        leaf ntfleaf2 {\n"
-            "            type string;\n"
-            "        }\n"
-            "    }\n"
-            "}\n";
-
-    (*state) = st = calloc(1, sizeof *st);
-    assert_non_null(st);
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &st->ctx));
-    assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-acm", "2018-02-14", NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, schema, LYS_IN_YANG, NULL));
-
-    return 0;
-}
-
-static int
-teardown_f(void **state)
-{
-    struct state *st = (*state);
-
-    lyd_free_siblings(st->first);
-    lyd_free_siblings(st->second);
-    lyd_free_siblings(st->third);
-    lyd_free_siblings(st->diff1);
-    lyd_free_siblings(st->diff2);
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st->xml);
-    free(st->xml1);
-    free(st->xml2);
-    free(st);
-    (*state) = NULL;
+    UTEST_SETUP;
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
 
     return 0;
 }
@@ -251,22 +258,26 @@
 static void
 test_invalid(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    st->second = NULL;
+    struct lyd_node *model_1;
 
-    assert_int_equal(lyd_diff_siblings(st->first, lyd_child(st->first), 0, &st->diff1), LY_EINVAL);
+    CHECK_PARSE_LYD(xml, model_1);
 
+    struct lyd_node *diff = NULL;
+
+    assert_int_equal(lyd_diff_siblings(model_1, lyd_child(model_1), 0, &diff), LY_EINVAL);
     assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, NULL), LY_EINVAL);
+
+    lyd_free_all(model_1);
+    lyd_free_all(diff);
 }
 
 static void
 test_same(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml =
             "<nacm xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-acm\">\n"
             "  <enable-nacm>true</enable-nacm>\n"
@@ -279,25 +290,32 @@
             "</df><hidden xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>42</foo><baz>42</baz></hidden>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
+    struct lyd_node *model_1;
+    struct lyd_node *model_2;
 
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-    assert_null(st->diff1);
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-acm", "2018-02-14", NULL));
 
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
+    CHECK_PARSE_LYD(xml, model_1);
+    CHECK_PARSE_LYD(xml, model_2);
+
+    struct lyd_node *diff = NULL;
+
+    assert_int_equal(lyd_diff_siblings(model_1, model_2, 0, &diff), LY_SUCCESS);
+    assert_null(diff);
+    assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
+    CHECK_LYD(model_1, model_2);
+
+    lyd_free_all(model_1);
+    lyd_free_all(model_2);
+    lyd_free_all(diff);
 }
 
 static void
 test_empty1(void **state)
 {
-    struct state *st = (*state);
-    const char *xml =
+    (void) state;
+    const char *xml_in =
             "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>42</foo>\n"
             "  <b1_1>42</b1_1>\n"
@@ -307,15 +325,15 @@
             "  <baz>42</baz>\n"
             "</hidden>\n";
 
-    st->first = NULL;
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
+    struct lyd_node *model_1 = NULL;
+    struct lyd_node *model_2;
 
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+    CHECK_PARSE_LYD(xml_in, model_2);
 
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    struct lyd_node *diff;
+
+    CHECK_PARSE_LYD_DIFF(model_1, model_2, diff);
+    CHECK_LYD_STRING(diff,
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
             "  <foo>42</foo>\n"
             "  <b1_1>42</b1_1>\n"
@@ -324,16 +342,18 @@
             "  <foo>42</foo>\n"
             "  <baz>42</baz>\n"
             "</hidden>\n");
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
+    assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
+    CHECK_LYD(model_1, model_2);
+
+    lyd_free_all(model_1);
+    lyd_free_all(model_2);
+    lyd_free_all(diff);
 }
 
 static void
 test_empty2(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>42</foo>\n"
             "  <b1_1>42</b1_1>\n"
@@ -342,15 +362,14 @@
             "  <baz>42</baz>\n"
             "</hidden>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    st->second = NULL;
+    struct lyd_node *model_1;
 
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
+    CHECK_PARSE_LYD(xml, model_1);
 
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    struct lyd_node *diff;
+
+    CHECK_PARSE_LYD_DIFF(model_1, NULL, diff);
+    CHECK_LYD_STRING(diff,
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
             "  <foo>42</foo>\n"
             "  <b1_1>42</b1_1>\n"
@@ -360,47 +379,53 @@
             "  <baz>42</baz>\n"
             "</hidden>\n");
 
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    assert_ptr_equal(st->first, st->second);
+    assert_int_equal(lyd_diff_apply_all(&model_1, diff), LY_SUCCESS);
+    assert_ptr_equal(model_1, NULL);
+
+    lyd_free_all(diff);
+    lyd_free_all(model_1);
 }
 
 static void
 test_empty_nested(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml = "<df xmlns=\"urn:libyang:tests:defaults\"><foo>42</foo></df>";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    st->second = NULL;
+    struct lyd_node *model_1;
 
-    assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, &st->diff1), LY_SUCCESS);
-    assert_null(st->diff1);
+    CHECK_PARSE_LYD(xml, model_1);
 
-    assert_int_equal(lyd_diff_siblings(NULL, lyd_child(st->first), 0, &st->diff1), LY_SUCCESS);
+    struct lyd_node *diff = NULL;
 
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    assert_int_equal(lyd_diff_siblings(NULL, NULL, 0, &diff), LY_SUCCESS);
+    assert_null(diff);
+
+    struct lyd_node *diff1;
+
+    CHECK_PARSE_LYD_DIFF(NULL, lyd_child(model_1), diff1);
+    CHECK_LYD_STRING(diff1,
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"create\">42</foo>\n"
             "</df>\n");
 
-    free(st->xml);
-    assert_int_equal(lyd_diff_siblings(lyd_child(st->first), NULL, 0, &st->diff2), LY_SUCCESS);
+    struct lyd_node *diff2;
 
-    assert_non_null(st->diff2);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    CHECK_PARSE_LYD_DIFF(lyd_child(model_1), NULL, diff2);
+    CHECK_LYD_STRING(diff2,
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"delete\">42</foo>\n"
             "</df>\n");
+
+    lyd_free_all(model_1);
+    lyd_free_all(diff1);
+    lyd_free_all(diff2);
 }
 
 static void
 test_leaf(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml1 =
             "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>42</foo>\n"
@@ -421,20 +446,7 @@
             "<hidden xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>40</foo>\n"
             "</hidden>\n";
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml1, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, LYD_PARSE_ONLY, 0, &st->third));
-    assert_non_null(st->third);
-
-    /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_diff_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">41</foo>\n"
             "  <b1_1 yang:operation=\"create\">42</b1_1>\n"
@@ -442,54 +454,32 @@
             "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">\n"
             "  <foo>42</foo>\n"
             "  <baz>42</baz>\n"
-            "</hidden>\n");
+            "</hidden>\n";
 
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
-
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
-            "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
+    const char *out_diff_2 = "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">40</foo>\n"
             "  <b1_1 yang:operation=\"delete\">42</b1_1>\n"
             "</df>\n"
             "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
             "  <foo>40</foo>\n"
-            "</hidden>\n");
+            "</hidden>\n";
 
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
-
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_merge =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"42\">40</foo>\n"
             "</df>\n"
             "<hidden xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-value=\"42\" yang:orig-default=\"false\">40</foo>\n"
             "  <baz yang:operation=\"delete\">42</baz>\n"
-            "</hidden>\n");
+            "</hidden>\n";
+
+    TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
 }
 
 static void
 test_list(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml1 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <list>\n"
             "    <name>a</name>\n"
@@ -521,19 +511,7 @@
             "  </list>\n"
             "</df>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml1, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, LYD_PARSE_ONLY, 0, &st->third));
-    assert_non_null(st->third);
-
-    /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_diff_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <list yang:operation=\"delete\">\n"
             "    <name>a</name>\n"
@@ -547,19 +525,8 @@
             "    <name>c</name>\n"
             "    <value>3</value>\n"
             "  </list>\n"
-            "</df>\n");
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
-
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_diff_2 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <list yang:operation=\"delete\">\n"
             "    <name>c</name>\n"
@@ -569,20 +536,8 @@
             "    <name>a</name>\n"
             "    <value>2</value>\n"
             "  </list>\n"
-            "</df>\n");
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
-
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_merge =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <list yang:operation=\"none\">\n"
             "    <name>a</name>\n"
@@ -592,13 +547,15 @@
             "    <name>b</name>\n"
             "    <value yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\">-2</value>\n"
             "  </list>\n"
-            "</df>\n");
+            "</df>\n";
+
+    TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
 }
 
 static void
 test_userord_llist(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml1 =
             "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <llist>1</llist>\n"
@@ -623,66 +580,31 @@
             "  <llist>2</llist>\n"
             "</df>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml1, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, LYD_PARSE_ONLY, 0, &st->third));
-    assert_non_null(st->third);
-
-    /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_diff_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
-
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_diff_2 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"delete\" yang:orig-value=\"\">1</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\">5</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
-
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_merge =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"1\">4</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"4\">3</llist>\n"
             "  <llist yang:orig-value=\"\" yang:operation=\"delete\">1</llist>\n"
             "  <llist yang:orig-default=\"false\" yang:orig-value=\"2\" yang:value=\"\" yang:operation=\"replace\">5</llist>\n"
-            "</df>\n");
+            "</df>\n";
+
+    TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
 }
 
 static void
 test_userord_llist2(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml1 =
             "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <llist>1</llist>\n"
@@ -707,63 +629,28 @@
             "  <llist>3</llist>\n"
             "</df>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml1, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, LYD_PARSE_ONLY, 0, &st->third));
-    assert_non_null(st->third);
-
-    /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_diff_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"2\">4</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
-
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_diff_2 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">4</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
-
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_merge =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">4</llist>\n"
             "  <llist yang:orig-value=\"1\" yang:operation=\"delete\">2</llist>\n"
-            "</df>\n");
+            "</df>\n";
+
+    TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
 }
 
 static void
 test_userord_mix(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const char *xml1 =
             "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <llist>1</llist>\n"
@@ -782,66 +669,31 @@
             "  <llist>3</llist>\n"
             "</df>\n";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml1, LYD_XML, LYD_PARSE_ONLY, 0, &st->first));
-    assert_non_null(st->first);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, LYD_PARSE_ONLY, 0, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, LYD_PARSE_ONLY, 0, &st->third));
-    assert_non_null(st->third);
-
-    /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, 0, &st->diff1), LY_SUCCESS);
-
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+    const char *out_diff_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, 0, &st->diff2), LY_SUCCESS);
-
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_diff_2 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\">1</llist>\n"
             "  <llist yang:operation=\"create\" yang:value=\"1\">4</llist>\n"
-            "</df>\n");
-
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
-
-    /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
-
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml,
+            "</df>\n";
+    const char *out_merge =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <llist yang:operation=\"delete\" yang:orig-value=\"1\">2</llist>\n"
             "  <llist yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"1\" yang:value=\"\">3</llist>\n"
             "  <llist yang:orig-default=\"false\" yang:orig-value=\"3\" yang:value=\"\" yang:operation=\"replace\">1</llist>\n"
             "  <llist yang:value=\"1\" yang:operation=\"create\">4</llist>\n"
-            "</df>\n");
+            "</df>\n";
+
+    TEST_DIFF_3(xml1, xml2, xml3, out_diff_1, out_diff_2, out_merge);
 }
 
 static void
 test_wd(void **state)
 {
-    struct state *st = (*state);
+    (void) state;
     const struct lys_module *mod;
     const char *xml2 = "<df xmlns=\"urn:libyang:tests:defaults\">\n"
             "  <foo>41</foo>\n"
@@ -853,85 +705,89 @@
             "  <dllist>1</dllist>\n"
             "</df>\n";
 
-    mod = ly_ctx_get_module_implemented(st->ctx, "defaults");
+    mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "defaults");
     assert_non_null(mod);
 
-    st->first = NULL;
-    assert_int_equal(lyd_validate_module(&st->first, mod, 0, NULL), LY_SUCCESS);
-    assert_ptr_not_equal(st->first, NULL);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->second));
-    assert_non_null(st->second);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, xml3, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->third));
-    assert_non_null(st->third);
+    struct lyd_node *model_1 = NULL;
+
+    assert_int_equal(lyd_validate_module(&model_1, mod, 0, NULL), LY_SUCCESS);
+    assert_ptr_not_equal(model_1, NULL);
+
+    struct lyd_node *model_2;
+    struct lyd_node *model_3;
+
+    CHECK_PARSE_LYD_PARAM(xml2, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_2);
+    CHECK_PARSE_LYD_PARAM(xml3, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, model_3);
 
     /* diff1 */
-    assert_int_equal(lyd_diff_siblings(st->first, st->second, LYD_DIFF_DEFAULTS, &st->diff1), LY_SUCCESS);
+    struct lyd_node *diff1 = NULL;
 
-    assert_non_null(st->diff1);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
-    assert_string_equal(st->xml,
+    assert_int_equal(lyd_diff_siblings(model_1, model_2, LYD_DIFF_DEFAULTS, &diff1), LY_SUCCESS);
+    assert_non_null(diff1);
+
+    const char *diff1_out_1 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-default=\"true\" yang:orig-value=\"42\">41</foo>\n"
             "  <dllist yang:operation=\"delete\">1</dllist>\n"
             "  <dllist yang:operation=\"delete\">2</dllist>\n"
             "  <dllist yang:operation=\"delete\">3</dllist>\n"
             "  <dllist yang:operation=\"create\">4</dllist>\n"
-            "</df>\n");
+            "</df>\n";
 
-    assert_int_equal(lyd_diff_apply_all(&st->first, st->diff1), LY_SUCCESS);
-    lyd_print_mem(&st->xml1, st->first, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    lyd_print_mem(&st->xml2, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
+    CHECK_LYD_STRING_PARAM(diff1, diff1_out_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+    assert_int_equal(lyd_diff_apply_all(&model_1, diff1), LY_SUCCESS);
+    CHECK_LYD(model_1, model_2);
 
     /* diff2 */
-    assert_int_equal(lyd_diff_siblings(st->second, st->third, LYD_DIFF_DEFAULTS, &st->diff2), LY_SUCCESS);
+    struct lyd_node *diff2;
 
-    assert_non_null(st->diff2);
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
-    assert_string_equal(st->xml,
+    assert_int_equal(lyd_diff_siblings(model_2, model_3, LYD_DIFF_DEFAULTS, &diff2), LY_SUCCESS);
+    assert_non_null(diff2);
+    CHECK_LYD_STRING(diff2,
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"41\">42</foo>\n"
             "  <dllist yang:operation=\"create\">1</dllist>\n"
             "</df>\n");
 
-    assert_int_equal(lyd_diff_apply_all(&st->second, st->diff2), LY_SUCCESS);
-    free(st->xml1);
-    lyd_print_mem(&st->xml1, st->second, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    free(st->xml2);
-    lyd_print_mem(&st->xml2, st->third, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(st->xml1, st->xml2);
+    assert_int_equal(lyd_diff_apply_all(&model_2, diff2), LY_SUCCESS);
+    CHECK_LYD(model_2, model_3);
 
     /* merge */
-    assert_int_equal(lyd_diff_merge_all(&st->diff1, st->diff2, 0), LY_SUCCESS);
+    assert_int_equal(lyd_diff_merge_all(&diff1, diff2, 0), LY_SUCCESS);
 
-    free(st->xml);
-    lyd_print_mem(&st->xml, st->diff1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
-    assert_string_equal(st->xml,
+    const char *diff1_out_2 =
             "<df xmlns=\"urn:libyang:tests:defaults\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
             "  <foo yang:orig-default=\"true\" yang:operation=\"none\">42</foo>\n"
             "  <dllist yang:operation=\"none\" yang:orig-default=\"true\">1</dllist>\n"
             "  <dllist yang:operation=\"delete\">2</dllist>\n"
             "  <dllist yang:operation=\"delete\">3</dllist>\n"
             "  <dllist yang:operation=\"create\">4</dllist>\n"
-            "</df>\n");
+            "</df>\n";
+
+    CHECK_LYD_STRING_PARAM(diff1, diff1_out_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL);
+
+    lyd_free_all(model_1);
+    lyd_free_all(model_2);
+    lyd_free_all(model_3);
+    lyd_free_all(diff1);
+    lyd_free_all(diff2);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_invalid, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_same, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_empty1, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_empty2, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_empty_nested, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_list, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_userord_llist, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_userord_llist2, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_userord_mix, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_wd, setup_f, teardown_f),
+        UTEST(test_invalid, setup),
+        UTEST(test_same, setup),
+        UTEST(test_empty1, setup),
+        UTEST(test_empty2, setup),
+        UTEST(test_empty_nested, setup),
+        UTEST(test_leaf, setup),
+        UTEST(test_list, setup),
+        UTEST(test_userord_llist, setup),
+        UTEST(test_userord_llist2, setup),
+        UTEST(test_userord_mix, setup),
+        UTEST(test_wd, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_lyb.c b/tests/utests/data/test_lyb.c
index 7730381..59ab85c 100644
--- a/tests/utests/data/test_lyb.c
+++ b/tests/utests/data/test_lyb.c
@@ -11,220 +11,23 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "hash_table.h"
 #include "libyang.h"
-#include "tests/config.h"
-#include "utests.h"
 
-struct state {
-    struct ly_ctx *ctx;
-    struct lyd_node *dt1, *dt2;
-    char *mem;
-};
+#define CHECK_PARSE_LYD(INPUT, MODEL) \
+                CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0,LY_SUCCESS, MODEL)
 
-static void
-check_data_tree_next(struct lyd_node **start, struct lyd_node **next, struct lyd_node **elem)
-{
-    if (*elem) {
-        goto loop_next;
-    }
-
-loop_begin:
-    /* LYD_TREE_DFS_BEGIN */
-    for (*elem = *next = *start; *elem; *elem = *next) {
-        return;
-loop_next:
-        /* LYD_TREE_DFS_END */
-
-        /* select element for the next run - children first */
-        *next = lyd_child(*elem);
-        if (!*next) {
-            /* no children */
-            if (*elem == *start) {
-                /* we are done, (START) has no children */
-                break;
-            }
-            /* try siblings */
-            *next = (*elem)->next;
-        }
-        while (!*next) {
-            /* parent is already processed, go to its sibling */
-            *elem = (struct lyd_node *)(*elem)->parent;
-            /* no siblings, go back through parents */
-            if ((*elem)->parent == (*start)->parent) {
-                /* we are done, no next element to process */
-                break;
-            }
-            *next = (*elem)->next;
-        }
-    }
-
-    if (!*next) {
-        /* top-level siblings */
-        *start = (*start)->next;
-        if (!(*start)) {
-            *elem = NULL;
-            return;
-        }
-        goto loop_begin;
-    }
-
-    return;
-}
-
-static void
-check_data_tree(struct lyd_node *root1, struct lyd_node *root2)
-{
-    struct lyd_node *next1, *next2, *elem1 = NULL, *elem2 = NULL, *iter;
-    struct lyd_meta *meta1, *meta2;
-    struct lyd_node_inner *in1, *in2;
-    uint32_t i1, i2;
-
-    for (check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2);
-            elem1 && elem2;
-            check_data_tree_next(&root1, &next1, &elem1), check_data_tree_next(&root2, &next2, &elem2)) {
-
-        if (elem1->schema != elem2->schema) {
-            fprintf(stderr, "Schema mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, elem2->schema->name);
-            fail();
-        }
-
-        /* check common data node attributes */
-        if (elem1->flags != elem2->flags) {
-            fprintf(stderr, "\"%s\": flags mismatch (\"%u\" and \"%u\").\n", elem1->schema->name, elem1->flags, elem2->flags);
-            fail();
-        }
-
-        /* check data node attributes */
-        for (meta1 = elem1->meta, meta2 = elem2->meta; meta1 && meta2; meta1 = meta1->next, meta2 = meta2->next) {
-            if (meta1->annotation != meta2->annotation) {
-                fprintf(stderr, "\"%s\": meta annotation mismatch.\n", elem1->schema->name);
-                fail();
-            }
-            if (strcmp(meta1->name, meta2->name)) {
-                fprintf(stderr, "\"%s\": meta name mismatch (\"%s\" and \"%s\").\n", elem1->schema->name, meta1->name, meta2->name);
-                fail();
-            }
-            if (lyd_compare_meta(meta1, meta2)) {
-                fprintf(stderr, "\"%s\": meta value mismatch.\n", elem1->schema->name);
-                fail();
-            }
-        }
-        if (meta1) {
-            fprintf(stderr, "\"%s\": meta mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name, meta1->name);
-            fail();
-        }
-        if (meta2) {
-            fprintf(stderr, "\"%s\": meta mismatch (\"NULL\" and \"%s\").\n", elem1->schema->name, meta2->name);
-            fail();
-        }
-
-        /* check specific data node attributes */
-        switch (elem1->schema->nodetype) {
-        case LYS_CONTAINER:
-        case LYS_LIST:
-        case LYS_RPC:
-        case LYS_ACTION:
-        case LYS_NOTIF:
-            in1 = (struct lyd_node_inner *)elem1;
-            in2 = (struct lyd_node_inner *)elem2;
-
-            i1 = 0;
-            LY_LIST_FOR(in1->child, iter) {
-                ++i1;
-            }
-
-            i2 = 0;
-            LY_LIST_FOR(in2->child, iter) {
-                ++i2;
-            }
-
-            if (i1 != i2) {
-                fprintf(stderr, "\"%s\": child count mismatch (%u and %u).\n", elem1->schema->name, i1, i2);
-                fail();
-            }
-
-            if (i1 >= LYD_HT_MIN_ITEMS) {
-                if (!in1->children_ht || !in2->children_ht) {
-                    fprintf(stderr, "\"%s\": missing hash table (%p and %p).\n", elem1->schema->name, in1->children_ht,
-                            in2->children_ht);
-                    fail();
-                }
-
-                LY_LIST_FOR(in1->child, iter) {
-                    if (lyht_find(in1->children_ht, &iter, iter->hash, NULL)) {
-                        fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 1.\n", elem1->schema->name, iter->schema->name);
-                        fail();
-                    }
-                }
-                LY_LIST_FOR(in2->child, iter) {
-                    if (lyht_find(in2->children_ht, &iter, iter->hash, NULL)) {
-                        fprintf(stderr, "\"%s\": missing child \"%s\" in the hash table 2.\n", elem1->schema->name, iter->schema->name);
-                        fail();
-                    }
-                }
-            }
-            break;
-        case LYS_LEAF:
-        case LYS_LEAFLIST:
-        case LYS_ANYDATA:
-        case LYS_ANYXML:
-            if (lyd_compare_single(elem1, elem2, 0)) {
-                fprintf(stderr, "\"%s\": value mismatch.\n", elem1->schema->name);
-                fail();
-            }
-            break;
-        default:
-            fprintf(stderr, "Unexpected data node type.\n");
-            fail();
-        }
-
-        if (!elem1->hash) {
-            fprintf(stderr, "\"%s\": hash not calculated.\n", elem1->schema->name);
-            fail();
-        }
-        if (elem1->hash != elem2->hash) {
-            fprintf(stderr, "\"%s\": hashes do not match (%u and %u).\n", elem1->schema->name, elem1->hash, elem2->hash);
-            fail();
-        }
-    }
-
-    if (elem1) {
-        fprintf(stderr, "Schema mismatch (\"%s\" and \"NULL\").\n", elem1->schema->name);
-        fail();
-    }
-    if (elem2) {
-        fprintf(stderr, "Schema mismatch (\"NULL\" and \"%s\").\n", elem2->schema->name);
-        fail();
-    }
-}
+#define CHECK_LYD_STRING(MODEL, TEXT) \
+                CHECK_LYD_STRING_PARAM(MODEL, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)
 
 static int
-setup_f(void **state)
+setup(void **state)
 {
-    struct state *st;
-
-    (*state) = st = calloc(1, sizeof *st);
-    assert_non_null(st);
-
-    /* libyang context */
-    assert_int_equal(ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &st->ctx), LY_SUCCESS);
-
-    return 0;
-}
-
-static int
-teardown_f(void **state)
-{
-    struct state *st = (*state);
-
-    lyd_free_siblings(st->dt1);
-    lyd_free_siblings(st->dt2);
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st->mem);
-    free(st);
-    (*state) = NULL;
+    UTEST_SETUP;
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
 
     return 0;
 }
@@ -232,8 +35,6 @@
 static void
 test_ietf_interfaces(void **state)
 {
-    struct state *st = (*state);
-    int ret;
     const char *data_xml =
             "<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n"
             "    <interface>\n"
@@ -271,27 +72,32 @@
             "        <enabled>false</enabled>\n"
             "    </interface>\n"
             "</interfaces>\n";
+    struct lyd_node *tree_1;
+    struct lyd_node *tree_2;
+    char *xml_out; /* tree_2 */
 
-    assert_non_null(ly_ctx_load_module(st->ctx, "ietf-ip", NULL, NULL));
-    assert_non_null(ly_ctx_load_module(st->ctx, "iana-if-type", NULL, NULL));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-ip", NULL, NULL));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "iana-if-type", NULL, NULL));
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
-    assert_ptr_not_equal(st->dt1, NULL);
+    CHECK_PARSE_LYD(data_xml, tree_1);
 
-    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
-    assert_int_equal(ret, 0);
+    assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
-    assert_ptr_not_equal(st->dt2, NULL);
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, xml_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &tree_2));
+    assert_non_null(tree_2);
 
-    check_data_tree(st->dt1, st->dt2);
+    /* compare models */
+    CHECK_LYD(tree_1, tree_2);
+
+    /* clean */
+    free(xml_out);
+    lyd_free_all(tree_1);
+    lyd_free_all(tree_2);
 }
 
 static void
 test_origin(void **state)
 {
-    struct state *st = (*state);
-    int ret;
     const char *origin_yang =
             "module test-origin {"
             "   namespace \"urn:test-origin\";"
@@ -318,27 +124,32 @@
             "  <leaf2>value2</leaf2>\n"
             "  <leaf3 xmlns:or=\"urn:ietf:params:xml:ns:yang:ietf-origin\" or:origin=\"or:system\">125</leaf3>\n"
             "</cont>\n";
+    struct lyd_node *tree_1;
+    struct lyd_node *tree_2;
+    char *xml_out; /* tree_2 */
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, origin_yang, LYS_IN_YANG, NULL));
-    lys_set_implemented(ly_ctx_get_module_latest(st->ctx, "ietf-origin"), NULL);
+    UTEST_ADD_MODULE(origin_yang, LYS_IN_YANG, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, lys_set_implemented(ly_ctx_get_module_latest(UTEST_LYCTX, "ietf-origin"), NULL));
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
-    assert_ptr_not_equal(st->dt1, NULL);
+    CHECK_PARSE_LYD(data_xml, tree_1);
 
-    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
-    assert_int_equal(ret, 0);
+    assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
-    assert_ptr_not_equal(st->dt2, NULL);
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, xml_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &tree_2));
+    assert_non_null(tree_2);
 
-    check_data_tree(st->dt1, st->dt2);
+    /* compare models */
+    CHECK_LYD(tree_1, tree_2);
+
+    /* clean */
+    free(xml_out);
+    lyd_free_all(tree_1);
+    lyd_free_all(tree_2);
 }
 
 static void
 test_statements(void **state)
 {
-    struct state *st = (*state);
-    int ret;
     const char *links_yang =
             "module links {\n"
             "    yang-version 1.1;\n"
@@ -526,312 +337,324 @@
             "  <lref>reference leaf</lref>\n"
             "  <iref>random-identity</iref>\n"
             "</random>\n";
+    struct lyd_node *tree_1;
+    struct lyd_node *tree_2;
+    char *xml_out; /* tree_2 */
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, links_yang, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, statements_yang, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(links_yang, LYS_IN_YANG, NULL, NULL);
+    UTEST_ADD_MODULE(statements_yang, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, data_xml, LYD_XML, LYD_PARSE_ONLY, 0, &st->dt1));
+    CHECK_PARSE_LYD(data_xml, tree_1);
+
+    assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0);
+
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, xml_out, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &tree_2));
+    assert_non_null(tree_2);
+
+    /* compare models */
+    CHECK_LYD(tree_1, tree_2);
+
+    /* clean */
+    free(xml_out);
+    lyd_free_all(tree_1);
+    lyd_free_all(tree_2);
+}
+
+#if 0
+
+static void
+test_types(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "types", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/types.xml", LYD_XML, LYD_OPT_CONFIG);
     assert_ptr_not_equal(st->dt1, NULL);
 
-    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYD_PRINT_WITHSIBLINGS);
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
     assert_int_equal(ret, 0);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, st->mem, LYD_LYB, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &st->dt2));
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
     assert_ptr_not_equal(st->dt2, NULL);
 
     check_data_tree(st->dt1, st->dt2);
 }
 
-// static void
-// test_types(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "types", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/types.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_annotations(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/annotations.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_similar_annot_names(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/similar-annot-names.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_many_child_annot(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/many-childs-annot.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_union(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "union", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_union2(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "statements", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/union2.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_collisions(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/collisions.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_anydata(void **state)
-// {
-// struct state *st = (*state);
-// const struct lys_module *mod;
-// int ret;
-// const char *test_anydata =
-// "module test-anydata {"
-// "   namespace \"urn:test-anydata\";"
-// "   prefix ya;"
-// ""
-// "   container cont {"
-// "       anydata ntf;"
-// "   }"
-// "}";
-//
-// assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-notifications", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-/// * get notification in LYB format to set as anydata content */
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// lyd_free_withsiblings(st->dt1);
-// st->dt1 = NULL;
-//
-/// * now comes the real test, test anydata */
-// mod = lys_parse_mem(st->ctx, test_anydata, LYS_YANG);
-// assert_non_null(mod);
-//
-// st->dt1 = lyd_new(NULL, mod, "cont");
-// assert_non_null(st->dt1);
-//
-// assert_non_null(lyd_new_anydata(st->dt1, NULL, "ntf", st->mem, LYD_ANYDATA_LYBD));
-// st->mem = NULL;
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// ret = lyd_validate(&st->dt1, LYD_OPT_CONFIG, NULL);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-//
-/// * and also test the embedded notification itself */
-// free(st->mem);
-// ret = lyd_lyb_data_length(((struct lyd_node_anydata *)st->dt1->child)->value.mem);
-// st->mem = malloc(ret);
-// memcpy(st->mem, ((struct lyd_node_anydata *)st->dt1->child)->value.mem, ret);
-//
-// lyd_free_withsiblings(st->dt2);
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_NOTIF | LYD_OPT_STRICT | LYD_OPT_NOEXTDEPS, NULL);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-/// * parse the JSON again for this comparison */
-// lyd_free_withsiblings(st->dt1);
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_submodule_feature(void **state)
-// {
-// struct state *st = (*state);
-// const struct lys_module *mod;
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// mod = ly_ctx_load_module(st->ctx, "feature-submodule-main", NULL);
-// assert_non_null(mod);
-// assert_int_equal(lys_features_enable(mod, "test-submodule-feature"), 0);
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/test-submodule-feature.json", LYD_JSON, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_coliding_augments(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "augment-target", NULL));
-// assert_non_null(ly_ctx_load_module(st->ctx, "augment0", NULL));
-// assert_non_null(ly_ctx_load_module(st->ctx, "augment1", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/augment.xml", LYD_XML, LYD_OPT_CONFIG);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
-//
-// static void
-// test_leafrefs(void **state)
-// {
-// struct state *st = (*state);
-// int ret;
-//
-// ly_ctx_set_searchdir(st->ctx, TESTS_DIR"/data/files");
-// assert_non_null(ly_ctx_load_module(st->ctx, "leafrefs2", NULL));
-//
-// st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR"/data/files/leafrefs2.json", LYD_JSON, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt1, NULL);
-//
-// ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
-// assert_int_equal(ret, 0);
-//
-// st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
-// assert_ptr_not_equal(st->dt2, NULL);
-//
-// check_data_tree(st->dt1, st->dt2);
-// }
+static void
+test_annotations(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/annotations.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_similar_annot_names(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/similar-annot-names.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_many_child_annot(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/many-childs-annot.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_union(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "union", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/union.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_union2(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "statements", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/union2.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_collisions(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "annotations", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/collisions.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_anydata(void **state)
+{
+    struct state *st = (*state);
+    const struct lys_module *mod;
+    int ret;
+    const char *test_anydata =
+            "module test-anydata {"
+            "   namespace \"urn:test-anydata\";"
+            "   prefix ya;"
+            ""
+            "   container cont {"
+            "       anydata ntf;"
+            "   }"
+            "}";
+
+    assert_non_null(ly_ctx_load_module(st->ctx, "ietf-netconf-notifications", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    / *get notification in LYB format to set as anydata content * /
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    lyd_free_withsiblings(st->dt1);
+    st->dt1 = NULL;
+
+    / *now comes the real test, test anydata * /
+    mod = lys_parse_mem(st->ctx, test_anydata, LYS_YANG);
+    assert_non_null(mod);
+
+    st->dt1 = lyd_new(NULL, mod, "cont");
+    assert_non_null(st->dt1);
+
+    assert_non_null(lyd_new_anydata(st->dt1, NULL, "ntf", st->mem, LYD_ANYDATA_LYBD));
+    st->mem = NULL;
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    ret = lyd_validate(&st->dt1, LYD_OPT_CONFIG, NULL);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+
+    /* and also test the embedded notification itself */
+    free(st->mem);
+    ret = lyd_lyb_data_length(((struct lyd_node_anydata *)st->dt1->child)->value.mem);
+    st->mem = malloc(ret);
+    memcpy(st->mem, ((struct lyd_node_anydata *)st->dt1->child)->value.mem, ret);
+
+    lyd_free_withsiblings(st->dt2);
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_NOTIF | LYD_OPT_STRICT | LYD_OPT_NOEXTDEPS, NULL);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    /* parse the JSON again for this comparison */
+    lyd_free_withsiblings(st->dt1);
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/ietf-netconf-notifications.json", LYD_JSON, LYD_OPT_NOTIF | LYD_OPT_TRUSTED, NULL);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_submodule_feature(void **state)
+{
+    struct state *st = (*state);
+    const struct lys_module *mod;
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    mod = ly_ctx_load_module(st->ctx, "feature-submodule-main", NULL);
+    assert_non_null(mod);
+    assert_int_equal(lys_features_enable(mod, "test-submodule-feature"), 0);
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/test-submodule-feature.json", LYD_JSON, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_coliding_augments(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "augment-target", NULL));
+    assert_non_null(ly_ctx_load_module(st->ctx, "augment0", NULL));
+    assert_non_null(ly_ctx_load_module(st->ctx, "augment1", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/augment.xml", LYD_XML, LYD_OPT_CONFIG);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+static void
+test_leafrefs(void **state)
+{
+    struct state *st = (*state);
+    int ret;
+
+    ly_ctx_set_searchdir(st->ctx, TESTS_DIR "/data/files");
+    assert_non_null(ly_ctx_load_module(st->ctx, "leafrefs2", NULL));
+
+    st->dt1 = lyd_parse_path(st->ctx, TESTS_DIR "/data/files/leafrefs2.json", LYD_JSON, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt1, NULL);
+
+    ret = lyd_print_mem(&st->mem, st->dt1, LYD_LYB, LYP_WITHSIBLINGS);
+    assert_int_equal(ret, 0);
+
+    st->dt2 = lyd_parse_mem(st->ctx, st->mem, LYD_LYB, LYD_OPT_CONFIG | LYD_OPT_STRICT);
+    assert_ptr_not_equal(st->dt2, NULL);
+
+    check_data_tree(st->dt1, st->dt2);
+}
+
+#endif
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_ietf_interfaces, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_origin, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_statements, setup_f, teardown_f),
-        /*cmocka_unit_test_setup_teardown(test_types, setup_f, teardown_f),
+        UTEST(test_ietf_interfaces, setup),
+        UTEST(test_origin, setup),
+        UTEST(test_statements, setup),
+#if 0
+        cmocka_unit_test_setup_teardown(test_types, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_annotations, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_similar_annot_names, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_many_child_annot, setup_f, teardown_f),
@@ -841,7 +664,8 @@
         cmocka_unit_test_setup_teardown(test_anydata, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_submodule_feature, setup_f, teardown_f),
         cmocka_unit_test_setup_teardown(test_coliding_augments, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leafrefs, setup_f, teardown_f),*/
+        cmocka_unit_test_setup_teardown(test_leafrefs, setup_f, teardown_f),
+#endif
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_merge.c b/tests/utests/data/test_merge.c
index 20df92a..0c429a4 100644
--- a/tests/utests/data/test_merge.c
+++ b/tests/utests/data/test_merge.c
@@ -11,66 +11,23 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#include "libyang.h"
+#define _UTEST_MAIN_
 #include "utests.h"
 
-struct state {
-    struct ly_ctx *ctx;
-    struct lyd_node *source;
-    struct lyd_node *target;
-    struct lyd_node *result;
-};
+#include "libyang.h"
 
-static int
-setup_dflt(void **state)
-{
-    struct state *st;
+#define LYD_TREE_CREATE(INPUT, MODEL) \
+                CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)
 
-    (*state) = st = calloc(1, sizeof *st);
-    if (!st) {
-        fprintf(stderr, "Memory allocation error.\n");
-        return -1;
-    }
+#define CONTEXT_CREATE \
+                CONTEXT_CREATE_PATH(NULL)
 
-    /* libyang context */
-    if (ly_ctx_new(NULL, 0, &st->ctx)) {
-        fprintf(stderr, "Failed to create context.\n");
-        goto error;
-    }
-
-    return 0;
-
-error:
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st);
-    (*state) = NULL;
-
-    return -1;
-}
-
-static int
-teardown_dflt(void **state)
-{
-    struct state *st = (*state);
-
-    lyd_free_siblings(st->target);
-    lyd_free_siblings(st->source);
-    lyd_free_siblings(st->result);
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st);
-    (*state) = NULL;
-
-    return 0;
-}
+#define LYD_TREE_CHECK_CHAR(MODEL, TEXT, PARAMS) \
+                CHECK_LYD_STRING_PARAM(MODEL, TEXT, LYD_XML, LYD_PRINT_WITHSIBLINGS | PARAMS)
 
 static void
 test_batch(void **state)
 {
-    struct state *st = (*state);
-    uint32_t i;
-    char *str;
-
     const char *start =
             "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">\n"
             "  <module>\n"
@@ -215,32 +172,25 @@
             "    <conformance-type>implement</conformance-type>\n"
             "  </module>\n"
             "</modules-state>\n";
-    struct ly_in *in = NULL;
 
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(start, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data(st->ctx, in, LYD_XML, LYD_PARSE_ONLY, 0, &st->target));
-    assert_non_null(st->target);
+    struct lyd_node *target;
 
-    for (i = 0; i < 11; ++i) {
-        ly_in_memory(in, data[i]);
-        assert_int_equal(LY_SUCCESS, lyd_parse_data(st->ctx, in, LYD_XML, LYD_PARSE_ONLY, 0, &st->source));
-        assert_non_null(st->source);
+    CHECK_PARSE_LYD_PARAM(start, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, target);
 
-        assert_int_equal(LY_SUCCESS, lyd_merge_siblings(&st->target, st->source, LYD_MERGE_DESTRUCT));
-        st->source = NULL;
+    for (int32_t i = 0; i < 11; ++i) {
+        struct lyd_node *source;
+        CHECK_PARSE_LYD_PARAM(data[i], LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, source);
+        assert_int_equal(LY_SUCCESS, lyd_merge_siblings(&target, source, LYD_MERGE_DESTRUCT));
     }
 
-    lyd_print_mem(&str, st->target, LYD_XML, 0);
-    assert_string_equal(str, output_template);
+    LYD_TREE_CHECK_CHAR(target, output_template, 0);
 
-    ly_in_free(in, 0);
-    free(str);
+    lyd_free_all(target);
 }
 
 static void
 test_leaf(void **state)
 {
-    struct state *st = (*state);
     const char *sch = "module x {"
             "  namespace urn:x;"
             "  prefix x;"
@@ -254,30 +204,27 @@
     const char *trg = "<A xmlns=\"urn:x\"> <f1>block</f1> </A>";
     const char *src = "<A xmlns=\"urn:x\"> <f1>aa</f1> <B> <f2>bb</f2> </B> </A>";
     const char *result = "<A xmlns=\"urn:x\"><f1>aa</f1><B><f2>bb</f2></B></A>";
-    char *printed = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
     /* merge them */
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
     /* check the result */
-    lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK);
-    assert_string_equal(printed, result);
-    free(printed);
+    LYD_TREE_CHECK_CHAR(target, result, LYD_PRINT_SHRINK);
+
+    lyd_free_all(target);
+    lyd_free_all(source);
 }
 
 static void
 test_container(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module A {\n"
             "    namespace \"aa:A\";\n"
@@ -296,30 +243,28 @@
     const char *trg = "<A xmlns=\"aa:A\"> <B> <f2>aaa</f2> </B> </A>";
     const char *src = "<A xmlns=\"aa:A\"> <C> <f3>bbb</f3> </C> </A>";
     const char *result = "<A xmlns=\"aa:A\"><B><f2>aaa</f2></B><C><f3>bbb</f3></C></A>";
-    char *printed = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
     /* merge them */
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
     /* check the result */
-    lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK);
-    assert_string_equal(printed, result);
-    free(printed);
+    LYD_TREE_CHECK_CHAR(target, result, LYD_PRINT_SHRINK);
+
+    /* destroy */
+    lyd_free_all(source);
+    lyd_free_all(target);
 }
 
 static void
 test_list(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module merge {\n"
             "    namespace \"http://test/merge\";\n"
@@ -365,30 +310,27 @@
             "    <p3>true</p3>\n"
             "  </b-list1>\n"
             "</inner1>\n";
-    char *printed = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
     /* merge them */
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
     /* check the result */
-    lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(printed, result);
-    free(printed);
+    LYD_TREE_CHECK_CHAR(target, result, 0);
+
+    lyd_free_all(target);
+    lyd_free_all(source);
 }
 
 static void
 test_list2(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module merge {\n"
             "    namespace \"http://test/merge\";\n"
@@ -443,30 +385,27 @@
             "    </inner2>\n"
             "  </b-list1>\n"
             "</inner1>\n";
-    char *printed = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
     /* merge them */
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
     /* check the result */
-    lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(printed, result);
-    free(printed);
+    LYD_TREE_CHECK_CHAR(target, result, 0);
+
+    lyd_free_all(source);
+    lyd_free_all(target);
 }
 
 static void
 test_case(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module merge {\n"
             "    namespace \"http://test/merge\";\n"
@@ -501,30 +440,27 @@
             "<cont xmlns=\"http://test/merge\">\n"
             "  <p1>1</p1>\n"
             "</cont>\n";
-    char *printed = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
     /* merge them */
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&st->target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
     /* check the result */
-    lyd_print_mem(&printed, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS);
-    assert_string_equal(printed, result);
-    free(printed);
+    LYD_TREE_CHECK_CHAR(target, result, 0);
+
+    lyd_free_all(source);
+    lyd_free_all(target);
 }
 
 static void
 test_dflt(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module merge-dflt {\n"
             "    namespace \"urn:merge-dflt\";\n"
@@ -542,28 +478,32 @@
             "        }\n"
             "    }\n"
             "}\n";
+    struct lyd_node *target = NULL;
+    struct lyd_node *source = NULL;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0, &st->target), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(NULL, UTEST_LYCTX, "/merge-dflt:top/c", "c_dflt", 0, &target), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
-    assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0, &st->source), LY_SUCCESS);
-    assert_int_equal(lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(NULL, UTEST_LYCTX, "/merge-dflt:top/a", "a_val", 0, &source), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(source, UTEST_LYCTX, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&source, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, LYD_MERGE_DESTRUCT | LYD_MERGE_DEFAULTS), LY_SUCCESS);
-    st->source = NULL;
+    assert_int_equal(lyd_merge_siblings(&target, source, LYD_MERGE_DESTRUCT | LYD_MERGE_DEFAULTS), LY_SUCCESS);
+    source = NULL;
 
     /* c should be replaced and now be default */
-    assert_string_equal(lyd_child(st->target)->prev->schema->name, "c");
-    assert_true(lyd_child(st->target)->prev->flags & LYD_DEFAULT);
+    assert_string_equal(lyd_child(target)->prev->schema->name, "c");
+    assert_true(lyd_child(target)->prev->flags & LYD_DEFAULT);
+
+    lyd_free_all(target);
+    lyd_free_all(source);
 }
 
 static void
 test_dflt2(void **state)
 {
-    struct state *st = (*state);
     const char *sch =
             "module merge-dflt {\n"
             "    namespace \"urn:merge-dflt\";\n"
@@ -581,26 +521,30 @@
             "        }\n"
             "    }\n"
             "}\n";
+    struct lyd_node *target;
+    struct lyd_node *source;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/c", "c_dflt", 0, &st->target), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&(st->target), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(NULL, UTEST_LYCTX, "/merge-dflt:top/c", "c_dflt", 0, &target), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&target, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
-    assert_int_equal(lyd_new_path(NULL, st->ctx, "/merge-dflt:top/a", "a_val", 0, &st->source), LY_SUCCESS);
-    assert_int_equal(lyd_new_path(st->source, st->ctx, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&(st->source), NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(NULL, UTEST_LYCTX, "/merge-dflt:top/a", "a_val", 0, &source), LY_SUCCESS);
+    assert_int_equal(lyd_new_path(source, UTEST_LYCTX, "/merge-dflt:top/b", "b_val", 0, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&source, NULL, LYD_VALIDATE_PRESENT, NULL), LY_SUCCESS);
 
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
 
     /* c should not be replaced, so c remains not default */
-    assert_false(lyd_child(st->target)->flags & LYD_DEFAULT);
+    assert_false(lyd_child(target)->flags & LYD_DEFAULT);
+
+    lyd_free_all(target);
+    lyd_free_all(source);
 }
 
 static void
 test_leafrefs(void **state)
 {
-    struct state *st = (*state);
     const char *sch = "module x {"
             "  namespace urn:x;"
             "  prefix x;"
@@ -616,36 +560,34 @@
     const char *res = "<l xmlns=\"urn:x\"><n>a</n><t>*</t></l>"
             "<l xmlns=\"urn:x\"><n>b</n><r>a</r></l>"
             "<l xmlns=\"urn:x\"><n>c</n><r>a</r></l>";
-    char *prt = NULL;
+    struct lyd_node *source, *target;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(st->ctx, sch, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(sch, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, src, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->source));
-    assert_non_null(st->source);
+    LYD_TREE_CREATE(src, source);
+    LYD_TREE_CREATE(trg, target);
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(st->ctx, trg, LYD_XML, 0, LYD_VALIDATE_PRESENT, &st->target));
-    assert_non_null(st->target);
+    assert_int_equal(lyd_merge_siblings(&target, source, 0), LY_SUCCESS);
 
-    assert_int_equal(lyd_merge_siblings(&st->target, st->source, 0), LY_SUCCESS);
+    LYD_TREE_CHECK_CHAR(target, res, LYD_PRINT_SHRINK);
 
-    lyd_print_mem(&prt, st->target, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK);
-    assert_string_equal(prt, res);
-    free(prt);
+    lyd_free_all(source);
+    lyd_free_all(target);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_batch, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_leaf, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_container, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_list, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_list2, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_case, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_dflt, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_dflt2, setup_dflt, teardown_dflt),
-        cmocka_unit_test_setup_teardown(test_leafrefs, setup_dflt, teardown_dflt),
+        UTEST(test_batch),
+        UTEST(test_leaf),
+        UTEST(test_container),
+        UTEST(test_list),
+        UTEST(test_list2),
+        UTEST(test_case),
+        UTEST(test_dflt),
+        UTEST(test_dflt2),
+        UTEST(test_leafrefs),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_new.c b/tests/utests/data/test_new.c
index 58ccb1c..12155a6 100644
--- a/tests/utests/data/test_new.c
+++ b/tests/utests/data/test_new.c
@@ -11,118 +11,85 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
-#include "libyang.h"
+#define _UTEST_MAIN_
 #include "utests.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
+#include "libyang.h"
 
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-setup(void **state)
-{
-    (void) state; /* unused */
-
-    const char *schema_a = "module a {namespace urn:tests:a;prefix a;yang-version 1.1;"
-            "list l1 { key \"a b\"; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
-            "leaf foo { type uint16;}"
-            "leaf-list ll { type string;}"
-            "container c {leaf-list x {type string;}}"
-            "anydata any {config false;}"
-            "list l2 {config false; container c{leaf x {type string;}}}"
-            "rpc oper {input {leaf param {type string;}} output {leaf param {type int8;}}}}";
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
-
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+/* common module for the tests */
+const char *schema_a = "module a {\n"
+        "  namespace urn:tests:a;\n"
+        "  prefix a;yang-version 1.1;\n"
+        "  list l1 {\n"
+        "    key \"a b\";\n"
+        "    leaf a {\n"
+        "      type string;\n"
+        "    }\n"
+        "    leaf b {\n"
+        "      type string;\n"
+        "    }\n"
+        "    leaf c {\n"
+        "      type string;}\n"
+        "    }\n"
+        "    leaf foo {\n"
+        "      type uint16;\n"
+        "    }\n"
+        "    leaf-list ll {\n"
+        "      type string;\n"
+        "    }\n"
+        "    container c {\n"
+        "      leaf-list x {\n"
+        "    type string;\n"
+        "    }\n"
+        "  }"
+        "  anydata any {\n"
+        "    config false;\n"
+        "  }"
+        "  list l2 {\n"
+        "    config false;\n"
+        "    container c {\n"
+        "      leaf x {\n"
+        "        type string;\n"
+        "      }\n"
+        "    }\n"
+        "  }\n"
+        "  rpc oper {\n"
+        "    input {\n"
+        "      leaf param {\n"
+        "        type string;\n"
+        "      }\n"
+        "    }\n"
+        "    output {\n"
+        "      leaf param {\n"
+        "        type int8;\n"
+        "      }\n"
+        "    }\n"
+        "  }\n"
+        "}\n";
 
 static void
 test_top_level(void **state)
 {
-    *state = test_top_level;
-
     const struct lys_module *mod;
     struct lyd_node *node, *rpc;
 
-    /* we need the module first */
-    mod = ly_ctx_get_module_implemented(ctx, "a");
-    assert_non_null(mod);
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, &mod);
 
     /* list */
     assert_int_equal(lyd_new_list(NULL, mod, "l1", 0, &node, "val_a", "val_b"), LY_SUCCESS);
     lyd_free_tree(node);
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[]", 0, &node), LY_EVALID);
-    logbuf_assert("Unexpected XPath token \"]\" (\"]\").");
+    CHECK_LOG_CTX("Unexpected XPath token \"]\" (\"]\").", NULL);
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[key1='a'][key2='b']", 0, &node), LY_ENOTFOUND);
-    logbuf_assert("Not found node \"key1\" in path.");
+    CHECK_LOG_CTX("Not found node \"key1\" in path.", NULL);
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b'][c='c']", 0, &node), LY_EVALID);
-    logbuf_assert("Key expected instead of leaf \"c\" in path. /a:l1/c");
+    CHECK_LOG_CTX("Key expected instead of leaf \"c\" in path.", "/a:l1/c");
 
     assert_int_equal(lyd_new_list2(NULL, mod, "c", "[a='a'][b='b']", 0, &node), LY_ENOTFOUND);
-    logbuf_assert("List node \"c\" not found.");
+    CHECK_LOG_CTX("List node \"c\" not found.", NULL);
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l1", "[a='a'][b='b']", 0, &node), LY_SUCCESS);
     lyd_free_tree(node);
@@ -138,10 +105,10 @@
 
     /* leaf */
     assert_int_equal(lyd_new_term(NULL, mod, "foo", "[a='a'][b='b'][c='c']", 0, &node), LY_EVALID);
-    logbuf_assert("Invalid uint16 value \"[a='a'][b='b'][c='c']\". /a:foo");
+    CHECK_LOG_CTX("Invalid uint16 value \"[a='a'][b='b'][c='c']\".", "/a:foo");
 
     assert_int_equal(lyd_new_term(NULL, mod, "c", "value", 0, &node), LY_ENOTFOUND);
-    logbuf_assert("Term node \"c\" not found.");
+    CHECK_LOG_CTX("Term node \"c\" not found.", NULL);
 
     assert_int_equal(lyd_new_term(NULL, mod, "foo", "256", 0, &node), LY_SUCCESS);
     lyd_free_tree(node);
@@ -155,10 +122,10 @@
     lyd_free_tree(node);
 
     assert_int_equal(lyd_new_inner(NULL, mod, "l1", 0, &node), LY_ENOTFOUND);
-    logbuf_assert("Inner node (and not a list) \"l1\" not found.");
+    CHECK_LOG_CTX("Inner node (and not a list) \"l1\" not found.", NULL);
 
     assert_int_equal(lyd_new_inner(NULL, mod, "l2", 0, &node), LY_ENOTFOUND);
-    logbuf_assert("Inner node (and not a list) \"l2\" not found.");
+    CHECK_LOG_CTX("Inner node (and not a list) \"l2\" not found.", NULL);
 
     /* anydata */
     assert_int_equal(lyd_new_any(NULL, mod, "any", "some-value", LYD_ANYDATA_STRING, 0, &node), LY_SUCCESS);
@@ -166,7 +133,7 @@
 
     /* key-less list */
     assert_int_equal(lyd_new_list2(NULL, mod, "l2", "[a='a'][b='b']", 0, &node), LY_EVALID);
-    logbuf_assert("List predicate defined for keyless list \"l2\" in path.");
+    CHECK_LOG_CTX("List predicate defined for keyless list \"l2\" in path.", NULL);
 
     assert_int_equal(lyd_new_list2(NULL, mod, "l2", "", 0, &node), LY_SUCCESS);
     lyd_free_tree(node);
@@ -184,19 +151,17 @@
     assert_int_equal(lyd_new_term(rpc, mod, "param", "22", 1, &node), LY_SUCCESS);
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_node_leaf *)node->schema)->type->basetype);
     lyd_free_tree(rpc);
-
-    *state = NULL;
 }
 
 static void
 test_opaq(void **state)
 {
-    *state = test_opaq;
-
     struct lyd_node *root, *node;
     struct lyd_node_opaq *opq;
 
-    assert_int_equal(lyd_new_opaq(NULL, ctx, "node1", NULL, "my-module", &root), LY_SUCCESS);
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, NULL);
+
+    assert_int_equal(lyd_new_opaq(NULL, UTEST_LYCTX, "node1", NULL, "my-module", &root), LY_SUCCESS);
     assert_null(root->schema);
     opq = (struct lyd_node_opaq *)root;
     assert_string_equal(opq->name.name, "node1");
@@ -212,20 +177,18 @@
     assert_ptr_equal(opq->parent, root);
 
     lyd_free_tree(root);
-
-    *state = NULL;
 }
 
 static void
 test_path(void **state)
 {
-    *state = test_path;
-
     LY_ERR ret;
     struct lyd_node *root, *node, *parent;
 
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, NULL);
+
     /* create 2 nodes */
-    ret = lyd_new_path2(NULL, ctx, "/a:c/x[.='val']", "vvv", 0, 0, &root, &node);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:c/x[.='val']", "vvv", 0, 0, &root, &node);
     assert_int_equal(ret, LY_SUCCESS);
     assert_non_null(root);
     assert_string_equal(root->schema->name, "c");
@@ -250,22 +213,22 @@
     lyd_free_tree(root);
 
     /* try LYD_NEWOPT_OPAQ */
-    ret = lyd_new_path2(NULL, ctx, "/a:l1", NULL, 0, 0, NULL, NULL);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:l1", NULL, 0, 0, NULL, NULL);
     assert_int_equal(ret, LY_EINVAL);
-    logbuf_assert("Predicate missing for list \"l1\" in path.");
+    CHECK_LOG_CTX("Predicate missing for list \"l1\" in path.", NULL);
 
-    ret = lyd_new_path2(NULL, ctx, "/a:l1", NULL, 0, LYD_NEW_PATH_OPAQ, NULL, &root);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:l1", NULL, 0, LYD_NEW_PATH_OPAQ, NULL, &root);
     assert_int_equal(ret, LY_SUCCESS);
     assert_non_null(root);
     assert_null(root->schema);
 
     lyd_free_tree(root);
 
-    ret = lyd_new_path2(NULL, ctx, "/a:foo", NULL, 0, 0, NULL, NULL);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:foo", NULL, 0, 0, NULL, NULL);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Invalid empty uint16 value. /a:foo");
+    CHECK_LOG_CTX("Invalid empty uint16 value.", "/a:foo");
 
-    ret = lyd_new_path2(NULL, ctx, "/a:foo", NULL, 0, LYD_NEW_PATH_OPAQ, NULL, &root);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:foo", NULL, 0, LYD_NEW_PATH_OPAQ, NULL, &root);
     assert_int_equal(ret, LY_SUCCESS);
     assert_non_null(root);
     assert_null(root->schema);
@@ -273,7 +236,7 @@
     lyd_free_tree(root);
 
     /* try LYD_NEWOPT_UPDATE */
-    ret = lyd_new_path2(NULL, ctx, "/a:l2[1]/c/x", "val", 0, 0, &root, &node);
+    ret = lyd_new_path2(NULL, UTEST_LYCTX, "/a:l2[1]/c/x", "val", 0, 0, &root, &node);
     assert_int_equal(ret, LY_SUCCESS);
     assert_non_null(root);
     assert_string_equal(node->schema->name, "x");
@@ -293,17 +256,15 @@
     assert_string_equal("val2", LYD_CANON_VALUE(node));
 
     lyd_free_tree(root);
-
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_top_level, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_opaq, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_path, setup, teardown),
+        UTEST(test_top_level),
+        UTEST(test_opaq),
+        UTEST(test_path),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_parser_json.c b/tests/utests/data/test_parser_json.c
index 12a5d87..77c8677 100644
--- a/tests/utests/data/test_parser_json.c
+++ b/tests/utests/data/test_parser_json.c
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "context.h"
 #include "in.h"
@@ -20,42 +22,11 @@
 #include "tests/config.h"
 #include "tree_data_internal.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
 
 static int
 setup(void **state)
 {
-    (void) state; /* unused */
-
-    const char *schema_a = "module a {namespace urn:tests:a;prefix a;yang-version 1.1; import ietf-yang-metadata {prefix md;}"
+    const char *schema = "module a {namespace urn:tests:a;prefix a;yang-version 1.1; import ietf-yang-metadata {prefix md;}"
             "md:annotation hint { type int8;}"
             "list l1 { key \"a b c\"; leaf a {type string;} leaf b {type string;} leaf c {type int16;} leaf d {type string;}}"
             "leaf foo { type string;}"
@@ -70,107 +41,74 @@
             "leaf foo2 { type string; default \"default-val\"; }"
             "leaf foo3 { type uint32; }"
             "notification n2;}";
-    const struct lys_module *mod;
-    const char *feats[] = {"writable-running", NULL};
 
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_SETUP;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
-    assert_non_null((mod = ly_ctx_load_module(ctx, "ietf-netconf", "2011-06-01", feats)));
-    assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
+#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
+    CHECK_PARSE_LYD_PARAM(INPUT, LYD_JSON, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
 
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
+#define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH) \
+    assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_JSON, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\
+    CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH);\
+    assert_null(MODEL)
 
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+#define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \
+    CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_JSON, PRINT_OPTION)
 
 static void
 test_leaf(void **state)
 {
-    *state = test_leaf;
-
-    const char *data = "{\"a:foo\":\"foo value\"}";
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
+    const char *data;
 
-    char *printed;
-    struct ly_out *out;
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
 
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo", tree->schema->name);
+    data = "{\"a:foo\":\"foo value\"}";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("foo value", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "foo value");
 
-    assert_int_equal(LYS_LEAF, tree->next->next->schema->nodetype);
-    assert_string_equal("foo2", tree->next->next->schema->name);
+    CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree->next->next;
-    assert_string_equal("default-val", leaf->value.canonical);
+
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_true(leaf->flags & LYD_DEFAULT);
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* make foo2 explicit */
     data = "{\"a:foo2\":\"default-val\"}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo2", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("default-val", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_false(leaf->flags & LYD_DEFAULT);
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* parse foo2 but make it implicit */
     data = "{\"a:foo2\":\"default-val\",\"@a:foo2\":{\"ietf-netconf-with-defaults:default\":true}}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo2", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("default-val", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_true(leaf->flags & LYD_DEFAULT);
 
     /* TODO default values
@@ -182,461 +120,315 @@
 
     /* multiple meatadata hint and unknown metadata xxx supposed to be skipped since it is from missing schema */
     data = "{\"@a:foo\":{\"a:hint\":1,\"a:hint\":2,\"x:xxx\":{\"value\":\"/x:no/x:yes\"}},\"a:foo\":\"xxx\"}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo", tree->schema->name);
-    assert_non_null(tree->meta);
-    assert_string_equal("hint", tree->meta->name);
-    assert_int_equal(LY_TYPE_INT8, tree->meta->value.realtype->basetype);
-    assert_string_equal("1", tree->meta->value.canonical);
-    assert_int_equal(1, tree->meta->value.int8);
-    assert_ptr_equal(tree, tree->meta->parent);
-    assert_non_null(tree->meta->next);
-    assert_string_equal("hint", tree->meta->next->name);
-    assert_int_equal(LY_TYPE_INT8, tree->meta->next->value.realtype->basetype);
-    assert_string_equal("2", tree->meta->next->value.canonical);
-    assert_int_equal(2, tree->meta->next->value.int8);
-    assert_ptr_equal(tree, tree->meta->next->parent);
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
+    CHECK_LYD_META(tree->meta, 1, "hint", 1, 1,  INT8, "1", 1);
+    CHECK_LYD_META(tree->meta->next, 1, "hint", 0, 1,  INT8, "2", 2);
     assert_null(tree->meta->next->next);
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, "{\"a:foo\":\"xxx\",\"@a:foo\":{\"a:hint\":1,\"a:hint\":2}}");
-    ly_out_free(out, NULL, 1);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
+            "{\"a:foo\":\"xxx\",\"@a:foo\":{\"a:hint\":1,\"a:hint\":2}}");
     lyd_free_all(tree);
 
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Unknown (or not implemented) YANG module \"x\" for metadata \"x:xxx\". /a:foo");
+    PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Unknown (or not implemented) YANG module \"x\" for metadata \"x:xxx\".", "/a:foo");
 
     /* missing referenced metadata node */
-    data = "{\"@a:foo\" : { \"a:hint\" : 1 }}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Missing JSON data instance to be coupled with @a:foo metadata. /");
+    PARSER_CHECK_ERROR("{\"@a:foo\" : { \"a:hint\" : 1 }}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Missing JSON data instance to be coupled with @a:foo metadata.", "/");
 
     /* missing namespace for meatadata*/
-    data = "{\"a:foo\" : \"value\", \"@a:foo\" : { \"hint\" : 1 }}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Metadata in JSON must be namespace-qualified, missing prefix for \"hint\". /a:foo");
-
-    *state = NULL;
+    PARSER_CHECK_ERROR("{\"a:foo\" : \"value\", \"@a:foo\" : { \"hint\" : 1 }}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Metadata in JSON must be namespace-qualified, missing prefix for \"hint\".", "/a:foo");
 }
 
 static void
 test_leaflist(void **state)
 {
-    *state = test_leaflist;
-
-    const char *data = "{\"a:ll1\":[10,11]}";
+    const char *data;
     struct lyd_node *tree;
     struct lyd_node_term *ll;
 
-    char *printed;
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    data = "{\"a:ll1\":[10,11]}";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAFLIST, tree->schema->nodetype);
-    assert_string_equal("ll1", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree;
-    assert_string_equal("10", ll->value.canonical);
+    CHECK_LYD_VALUE(ll->value, UINT8, "10", 10);
 
     assert_non_null(tree->next);
-    assert_int_equal(LYS_LEAFLIST, tree->next->schema->nodetype);
-    assert_string_equal("ll1", tree->next->schema->name);
+    CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree->next;
-    assert_string_equal("11", ll->value.canonical);
+    CHECK_LYD_VALUE(ll->value, UINT8, "11", 11);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* simple metadata */
     data = "{\"a:ll1\":[10,11],\"@a:ll1\":[null,{\"a:hint\":2}]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAFLIST, tree->schema->nodetype);
-    assert_string_equal("ll1", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree;
-    assert_string_equal("10", ll->value.canonical);
+    CHECK_LYD_VALUE(ll->value, UINT8, "10", 10);
     assert_null(ll->meta);
 
     assert_non_null(tree->next);
-    assert_int_equal(LYS_LEAFLIST, tree->next->schema->nodetype);
-    assert_string_equal("ll1", tree->next->schema->name);
+    CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree->next;
-    assert_string_equal("11", ll->value.canonical);
-    assert_non_null(ll->meta);
-    assert_string_equal("2", ll->meta->value.canonical);
+    CHECK_LYD_VALUE(ll->value, UINT8, "11", 11);
+    CHECK_LYD_META(ll->meta, 1, "hint", 0, 1,  INT8, "2", 2);
     assert_null(ll->meta->next);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* multiple meatadata hint and unknown metadata xxx supposed to be skipped since it is from missing schema */
-    data = "{\"@a:ll1\" : [{\"a:hint\" : 1, \"x:xxx\" :  { \"value\" : \"/x:no/x:yes\" }, \"a:hint\" : 10},null,{\"a:hint\" : 3}], \"a:ll1\" : [1,2,3]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    data = "{\"@a:ll1\" : [{\"a:hint\" : 1, \"x:xxx\" :  { \"value\" : \"/x:no/x:yes\" }, "
+            "\"a:hint\" : 10},null,{\"a:hint\" : 3}], \"a:ll1\" : [1,2,3]}";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAFLIST, tree->schema->nodetype);
-    assert_string_equal("ll1", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree;
-    assert_string_equal("1", ll->value.canonical);
-    assert_non_null(ll->meta);
-    assert_string_equal("hint", ll->meta->name);
-    assert_int_equal(LY_TYPE_INT8, ll->meta->value.realtype->basetype);
-    assert_string_equal("1", ll->meta->value.canonical);
-    assert_int_equal(1, ll->meta->value.int8);
-    assert_ptr_equal(ll, ll->meta->parent);
-    assert_non_null(ll->meta->next);
-    assert_string_equal("hint", ll->meta->next->name);
-    assert_int_equal(LY_TYPE_INT8, ll->meta->next->value.realtype->basetype);
-    assert_string_equal("10", ll->meta->next->value.canonical);
-    assert_int_equal(10, ll->meta->next->value.int8);
-    assert_ptr_equal(ll, ll->meta->next->parent);
-    assert_null(ll->meta->next->next);
+    CHECK_LYD_VALUE(ll->value, UINT8, "1", 1);
+    CHECK_LYD_META(ll->meta, 1, "hint", 1, 1,  INT8, "1", 1);
+    CHECK_LYD_META(ll->meta->next, 1, "hint", 0, 1,  INT8, "10", 10);
 
     assert_non_null(tree->next);
-    assert_int_equal(LYS_LEAFLIST, tree->next->schema->nodetype);
-    assert_string_equal("ll1", tree->next->schema->name);
+    CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree->next;
-    assert_string_equal("2", ll->value.canonical);
+    CHECK_LYD_VALUE(ll->value, UINT8, "2", 2);
     assert_null(ll->meta);
 
     assert_non_null(tree->next->next);
-    assert_int_equal(LYS_LEAFLIST, tree->next->next->schema->nodetype);
-    assert_string_equal("ll1", tree->next->next->schema->name);
+    CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "ll1",
+            1, LYS_LEAFLIST, 0, 0, NULL, 0);
     ll = (struct lyd_node_term *)tree->next->next;
-    assert_string_equal("3", ll->value.canonical);
-    assert_non_null(ll->meta);
-    assert_string_equal("hint", ll->meta->name);
-    assert_int_equal(LY_TYPE_INT8, ll->meta->value.realtype->basetype);
-    assert_string_equal("3", ll->meta->value.canonical);
-    assert_int_equal(3, ll->meta->value.int8);
-    assert_ptr_equal(ll, ll->meta->parent);
+    CHECK_LYD_VALUE(ll->value, UINT8, "3", 3);
+    CHECK_LYD_META(ll->meta, 1, "hint", 0, 1,  INT8, "3", 3);
     assert_null(ll->meta->next);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, "{\"a:ll1\":[1,2,3],\"@a:ll1\":[{\"a:hint\":1,\"a:hint\":10},null,{\"a:hint\":3}]}");
-    ly_out_free(out, NULL, 1);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
+            "{\"a:ll1\":[1,2,3],\"@a:ll1\":[{\"a:hint\":1,\"a:hint\":10},null,{\"a:hint\":3}]}");
     lyd_free_all(tree);
 
     /* missing referenced metadata node */
-    data = "{\"@a:ll1\":[{\"a:hint\":1}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Missing JSON data instance to be coupled with @a:ll1 metadata. /");
+    PARSER_CHECK_ERROR("{\"@a:ll1\":[{\"a:hint\":1}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Missing JSON data instance to be coupled with @a:ll1 metadata.", "/");
 
-    data = "{\"a:ll1\":[1],\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Missing JSON data instance no. 2 of a:ll1 to be coupled with metadata. /");
+    PARSER_CHECK_ERROR("{\"a:ll1\":[1],\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Missing JSON data instance no. 2 of a:ll1 to be coupled with metadata.", "/");
 
-    data = "{\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2},{\"a:hint\":3}],\"a:ll1\" : [1, 2]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Missing 3rd JSON data instance to be coupled with @a:ll1 metadata. /");
-
-    *state = NULL;
+    PARSER_CHECK_ERROR("{\"@a:ll1\":[{\"a:hint\":1},{\"a:hint\":2},{\"a:hint\":3}],\"a:ll1\" : [1, 2]}", 0, LYD_VALIDATE_PRESENT,
+            tree, LY_EVALID, "Missing 3rd JSON data instance to be coupled with @a:ll1 metadata.", "/");
 }
 
 static void
 test_anydata(void **state)
 {
-    *state = test_anydata;
-
     const char *data;
-    char *str;
     struct lyd_node *tree;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     data = "{\"a:any\":{\"x:element1\":{\"element2\":\"/a:some/a:path\",\"list\":[{},{\"key\":\"a\"}]}}}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
-    assert_string_equal("any", tree->schema->name);
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
-
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_SET_ENUM | LYS_CONFIG_R | LYS_YIN_ARGUMENT, 1, "any",
+            1, LYS_ANYDATA, 0, 0, NULL, 0);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_list(void **state)
 {
-    *state = test_list;
-
-    const char *data = "{\"a:l1\":[{\"a\":\"one\",\"b\":\"one\",\"c\":1}]}";
+    const char *data;
     struct lyd_node *tree, *iter;
     struct lyd_node_inner *list;
     struct lyd_node_term *leaf;
 
-    char *printed;
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-
     /* check hashes */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    data = "{\"a:l1\":[{\"a\":\"one\",\"b\":\"one\",\"c\":1}]}";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
+            1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     LY_LIST_FOR(list->child, iter) {
         assert_int_not_equal(0, iter->hash);
     }
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* missing keys */
-    data = "{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\"}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"a\". /a:l1[b='b'][c='1']");
+    PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"a\".", "/a:l1[b='b'][c='1']");
 
-    data = "{ \"a:l1\": [ {\"a\" : \"a\"}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"b\". /a:l1[a='a']");
+    PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"a\" : \"a\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"b\".", "/a:l1[a='a']");
 
-    data = "{ \"a:l1\": [ {\"b\" : \"b\", \"a\" : \"a\"}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"c\". /a:l1[a='a'][b='b']");
+    PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"b\" : \"b\", \"a\" : \"a\"}]}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"c\".", "/a:l1[a='a'][b='b']");
 
     /* key duplicate */
-    data = "{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\", \"a\" : \"a\", \"c\" : 1}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Duplicate instance of \"c\". /a:l1[a='a'][b='b'][c='1'][c='1']/c");
+    PARSER_CHECK_ERROR("{ \"a:l1\": [ {\"c\" : 1, \"b\" : \"b\", \"a\" : \"a\", \"c\" : 1}]}", 0, LYD_VALIDATE_PRESENT,
+            tree, LY_EVALID, "Duplicate instance of \"c\".", "/a:l1[a='a'][b='b'][c='1'][c='1']/c");
 
     /* keys order, in contrast to XML, JSON accepts keys in any order even in strict mode */
-    logbuf_clean();
-    data = "{ \"a:l1\": [ {\"d\" : \"d\", \"a\" : \"a\", \"c\" : 1, \"b\" : \"b\"}]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    CHECK_PARSE_LYD("{ \"a:l1\": [ {\"d\" : \"d\", \"a\" : \"a\", \"c\" : 1, \"b\" : \"b\"}]}", 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
+            1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     assert_non_null(leaf = (struct lyd_node_term *)list->child);
-    assert_string_equal("a", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("b", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("c", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("d", leaf->schema->name);
-    logbuf_assert("");
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "d", 0, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LOG_CTX(NULL, NULL);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1,\"d\":\"d\"}]}");
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
+            "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1,\"d\":\"d\"}]}");
     lyd_free_all(tree);
 
     /*  */
-    data = "{\"a:l1\":[{\"c\":1,\"b\":\"b\",\"a\":\"a\"}]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    CHECK_PARSE_LYD("{\"a:l1\":[{\"c\":1,\"b\":\"b\",\"a\":\"a\"}]}", LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
+            1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     assert_non_null(leaf = (struct lyd_node_term *)list->child);
-    assert_string_equal("a", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a",
+            1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("b", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b",
+            1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("c", leaf->schema->name);
-    logbuf_assert("");
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c",
+            1, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LOG_CTX(NULL, NULL);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1}]}");
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS,
+            "{\"a:l1\":[{\"a\":\"a\",\"b\":\"b\",\"c\":1}]}");
     lyd_free_all(tree);
 
     data = "{\"a:cp\":{\"@\":{\"a:hint\":1}}}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
-    assert_string_equal("cp", tree->schema->name);
-    assert_non_null(tree->meta);
-    assert_string_equal("hint", tree->meta->name);
-    assert_string_equal("1", tree->meta->value.canonical);
-    assert_ptr_equal(tree, tree->meta->parent);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
+    CHECK_LYD_META(tree->meta, 1, "hint", 0, 1,  INT8, "1", 1);
     assert_null(tree->meta->next);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_free(out, NULL, 1);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 static void
 test_container(void **state)
 {
-    *state = test_container;
-
-    const char *data = "{\"a:c\":{}}";
+    const char *data;
     struct lyd_node *tree;
     struct lyd_node_inner *cont;
 
-    char *printed;
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
-    assert_string_equal("c", tree->schema->name);
+    CHECK_PARSE_LYD("{\"a:c\":{}}", 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
     cont = (struct lyd_node_inner *)tree;
     assert_true(cont->flags & LYD_DEFAULT);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, "{}");
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{}");
     lyd_free_all(tree);
 
     data = "{\"a:cp\":{}}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
-    assert_string_equal("cp", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
     cont = (struct lyd_node_inner *)tree;
     assert_false(cont->flags & LYD_DEFAULT);
 
-    lyd_print_all(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(printed, data);
-    ly_out_free(out, NULL, 1);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 static void
 test_opaq(void **state)
 {
-    *state = test_opaq;
-
     const char *data;
-    char *str;
     struct lyd_node *tree;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     /* invalid value, no flags */
     data = "{\"a:foo3\":[null]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Invalid non-number-encoded uint32 value \"\". /a:foo3");
-    assert_null(tree);
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Invalid non-number-encoded uint32 value \"\".", "/a:foo3");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "foo3");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_PREF_JSON, "foo3", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* missing key, no flags */
     data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"d\":\"val_d\"}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"c\". /a:l1[a='val_a'][b='val_b']");
-    assert_null(tree);
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"c\".", "/a:l1[a='val_a'][b='val_b']");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* invalid key, no flags */
     data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":\"val_c\"}]}";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_JSON, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Invalid non-number-encoded int16 value \"val_c\". /a:l1/c");
-    assert_null(tree);
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Invalid non-number-encoded int16 value \"val_c\".", "/a:l1/c");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\",\"c\":{\"val\":\"val_c\"}}]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     data = "{\"a:l1\":[{\"a\":\"val_a\",\"b\":\"val_b\"}]}";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_JSON, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_rpc(void **state)
 {
-    *state = test_rpc;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
+    const char *dsc = "The <edit-config> operation loads all or part of a specified\n"
+            "configuration to the specified target configuration.";
+    const char *ref = "RFC 6241, Section 7.2";
+    const char *feats[] = {"writable-running", NULL};
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
+    assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
 
     data = "{\"ietf-netconf:rpc\":{\"edit-config\":{"
             "\"target\":{\"running\":[null]},"
@@ -644,177 +436,129 @@
             "\"a:l1\":[{\"@\":{\"ietf-netconf:operation\":\"replace\"},\"a\":\"val_a\",\"b\":\"val_b\",\"c\":\"val_c\"}]}"
             "}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_JSON, &tree, &op));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_JSON, &tree, &op));
     ly_in_free(in, 0);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "edit-config");
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc");
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, dsc, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "edit-config", LYS_RPC,
+            0, 0, 0, 0, 0, ref, 0);
+
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "rpc", 0, 0, NULL,  0,  "");
     /* TODO support generic attributes in JSON ?
     assert_non_null(((struct lyd_node_opaq *)tree)->attr);
     */
+
     node = lyd_child(tree);
-    assert_string_equal(node->schema->name, "edit-config");
+    CHECK_LYSC_ACTION((struct lysc_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "edit-config", LYS_RPC,
+            0, 0, 0, 0, 0, ref, 0);
     node = lyd_child(node)->next;
-    assert_string_equal(node->schema->name, "config");
+    CHECK_LYSC_NODE(node->schema, "Inline Config content.", 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "config",
+            0, LYS_ANYXML, 1, 0, NULL, 0);
 
     node = ((struct lyd_node_any *)node)->value.tree;
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "cp");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
     node = lyd_child(node);
     /* z has no value */
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "z");
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_PREF_JSON, "z", 0, 0, NULL,  0,  "");
     node = node->parent->next;
     /* l1 key c has invalid value so it is at the end */
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "l1");
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_PREF_JSON, "l1", 0, 0, NULL,  0,  "");
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_action(void **state)
 {
-    *state = test_action;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     data = "{\"ietf-netconf:rpc\":{\"yang:action\":{\"a:c\":{\"act\":{\"al\":\"value\"}}}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_JSON, &tree, &op));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_JSON, &tree, &op));
     ly_in_free(in, 0);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "act");
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "act", LYS_ACTION,
+            1, 0, 0, 1, 0, NULL, 0);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc");
-    assert_null(((struct lyd_node_opaq *)tree)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "rpc", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "action");
-    assert_null(((struct lyd_node_opaq *)node)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0, 0x1, LY_PREF_JSON, "action", 0, 0, NULL,  0,  "");
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_notification(void **state)
 {
-    *state = test_notification;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *ntf;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     data = "{\"ietf-restconf:notification\":{\"eventTime\":\"2037-07-08T00:01:00Z\",\"a:c\":{\"n1\":{\"nl\":\"value\"}}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_JSON, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(UTEST_LYCTX, in, LYD_JSON, &tree, &ntf));
     ly_in_free(in, 0);
 
     assert_non_null(ntf);
-    assert_string_equal(ntf->schema->name, "n1");
+    CHECK_LYSC_NOTIF((struct lysc_notif *)ntf->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "notification");
-    assert_null(((struct lyd_node_opaq *)tree)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "notification", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "eventTime");
-    assert_string_equal(((struct lyd_node_opaq *)node)->value, "2037-07-08T00:01:00Z");
-    assert_null(((struct lyd_node_opaq *)node)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0, 0, LY_PREF_JSON, "eventTime", 0, 0, NULL,  0,  "2037-07-08T00:01:00Z");
     node = node->next;
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "c");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* top-level notif without envelope */
     data = "{\"a:n2\":{}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_JSON, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(UTEST_LYCTX, in, LYD_JSON, &tree, &ntf));
     ly_in_free(in, 0);
 
     assert_non_null(ntf);
-    assert_string_equal(ntf->schema->name, "n2");
+    CHECK_LYSC_NOTIF((struct lysc_notif *)ntf->schema, 0, NULL, 0, 0x4, 1, 0, "n2", 0, 0, NULL, 0);
 
     assert_non_null(tree);
     assert_ptr_equal(ntf, tree);
 
-    lyd_print_tree(out, tree, LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_reply(void **state)
 {
-    *state = test_reply;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *request, *tree, *op;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     data = "{\"a:c\":{\"act\":{\"al\":\"value\"}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_JSON, &request, NULL));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_JSON, &request, NULL));
     ly_in_free(in, 0);
 
     data = "{\"ietf-netconf:rpc-reply\":{\"a:al\":25}}";
@@ -824,50 +568,39 @@
     lyd_free_all(request);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "act");
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "act", LYS_ACTION,
+            1, 0, 0, 1, 0, NULL, 0);
     node = lyd_child(op);
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "al");
-    assert_true(node->schema->flags & LYS_CONFIG_R);
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "al", 0, LYS_LEAF, 1, 0, NULL, 0);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc-reply");
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_JSON, "rpc-reply", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "c");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
 
     /* TODO print only rpc-reply node and then output subtree */
-    lyd_print_tree(out, lyd_child(op), LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, "{\"a:al\":25}");
-    ly_out_reset(out);
-    lyd_print_tree(out, lyd_child(tree), LYD_JSON, LYD_PRINT_SHRINK);
-    assert_string_equal(str, "{\"a:c\":{\"act\":{\"al\":25}}}");
-    ly_out_reset(out);
+    CHECK_LYD_STRING(lyd_child(op), LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:al\":25}");
+    CHECK_LYD_STRING(lyd_child(tree), LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{\"a:c\":{\"act\":{\"al\":25}}}");
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_leaf, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_leaflist, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_anydata, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_list, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_container, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_opaq, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_rpc, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_action, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_notification, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_reply, setup, teardown),
+        UTEST(test_leaf, setup),
+        UTEST(test_leaflist, setup),
+        UTEST(test_anydata, setup),
+        UTEST(test_list, setup),
+        UTEST(test_container, setup),
+        UTEST(test_opaq, setup),
+        UTEST(test_rpc, setup),
+        UTEST(test_action, setup),
+        UTEST(test_notification, setup),
+        UTEST(test_reply, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 2fe71c6..ba06db6 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from parser_xml.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,51 +11,21 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "context.h"
 #include "in.h"
 #include "out.h"
 #include "parser_data.h"
 #include "printer_data.h"
-#include "tests/config.h"
 #include "tree_data_internal.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
 
 static int
 setup(void **state)
 {
-    (void) state; /* unused */
-
-    const char *schema_a =
+    const char *schema =
             "module a {\n"
             "    namespace urn:tests:a;\n"
             "    prefix a;\n"
@@ -76,160 +46,119 @@
             "    leaf foo2 { type string; default \"default-val\"; }\n"
             "    leaf foo3 { type uint32; }\n"
             "    notification n2;}";
-    const struct lys_module *mod;
-    const char *feats[] = {"writable-running", NULL};
 
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_SETUP;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
-    assert_non_null((mod = ly_ctx_load_module(ctx, "ietf-netconf", "2011-06-01", feats)));
-    assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
+#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
+    CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
 
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
+#define PARSER_CHECK_ERROR(INPUT, PARSE_OPTION, VALIDATE_OPTION, MODEL, RET_VAL, ERR_MESSAGE, ERR_PATH) \
+    assert_int_equal(RET_VAL, lyd_parse_data_mem(UTEST_LYCTX, INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, &MODEL));\
+    CHECK_LOG_CTX(ERR_MESSAGE, ERR_PATH);\
+    assert_null(MODEL)
 
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+#define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \
+    CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, PRINT_OPTION)
 
 static void
 test_leaf(void **state)
 {
-    *state = test_leaf;
-
     const char *data = "<foo xmlns=\"urn:tests:a\">foo value</foo>";
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("foo value", leaf->value.canonical);
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
 
-    assert_int_equal(LYS_LEAF, tree->next->next->schema->nodetype);
-    assert_string_equal("foo2", tree->next->next->schema->name);
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "foo", 1, LYS_LEAF, 0, 0, NULL, 0);
+    leaf = (struct lyd_node_term *)tree;
+    CHECK_LYD_VALUE(leaf->value, STRING, "foo value");
+
+    CHECK_LYSC_NODE(tree->next->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree->next->next;
-    assert_string_equal("default-val", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_true(leaf->flags & LYD_DEFAULT);
 
     lyd_free_all(tree);
 
     /* make foo2 explicit */
     data = "<foo2 xmlns=\"urn:tests:a\">default-val</foo2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo2", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("default-val", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_false(leaf->flags & LYD_DEFAULT);
 
     lyd_free_all(tree);
 
     /* parse foo2 but make it implicit, skip metadata xxx from missing schema */
-    data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" wd:default=\"true\" xmlns:x=\"urn:x\" x:xxx=\"false\">default-val</foo2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    data = "<foo2 xmlns=\"urn:tests:a\" xmlns:wd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" "
+            "wd:default=\"true\" xmlns:x=\"urn:x\" x:xxx=\"false\">default-val</foo2>";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("foo2", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_SET_DFLT, 1, "foo2",
+            1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("default-val", leaf->value.canonical);
+    CHECK_LYD_VALUE(leaf->value, STRING, "default-val");
     assert_true(leaf->flags & LYD_DEFAULT);
 
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 static void
 test_anydata(void **state)
 {
-    *state = test_anydata;
-
     const char *data;
-    char *str;
     struct lyd_node *tree;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
-    data =
-            "<any xmlns=\"urn:tests:a\">\n"
+    data = "<any xmlns=\"urn:tests:a\">\n"
             "  <element1>\n"
             "    <x:element2 x:attr2=\"test\" xmlns:a=\"urn:tests:a\" xmlns:x=\"urn:x\">a:data</x:element2>\n"
             "  </element1>\n"
             "  <element1a/>\n"
             "</any>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_ANYDATA, tree->schema->nodetype);
-    assert_string_equal("any", tree->schema->name);
-
-    lyd_print_tree(out, tree, LYD_XML, 0);
-    assert_string_equal(str,
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_SET_CONFIG, 1, "any",
+            1, LYS_ANYDATA, 0, 0, NULL, 0);
+    const char *data_expected =
             "<any xmlns=\"urn:tests:a\">\n"
             "  <element1>\n"
             "    <element2 xmlns=\"urn:x\" xmlns:x=\"urn:x\" x:attr2=\"test\" xmlns:a=\"urn:tests:a\">a:data</element2>\n"
             "  </element1>\n"
             "  <element1a/>\n"
-            "</any>\n");
-    ly_out_reset(out);
+            "</any>\n";
+
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data_expected);
 
     lyd_free_all(tree);
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_list(void **state)
 {
-    *state = test_list;
-
-    const char *data = "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>1</c></l1>";
+    const char *data;
     struct lyd_node *tree, *iter;
     struct lyd_node_inner *list;
     struct lyd_node_term *leaf;
 
     /* check hashes */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    data = "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>1</c></l1>";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
+            1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     LY_LIST_FOR(list->child, iter) {
         assert_int_not_equal(0, iter->hash);
@@ -237,187 +166,146 @@
     lyd_free_all(tree);
 
     /* missing keys */
-    data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"a\". /a:l1[b='b'][c='1']");
+    PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"a\".", "/a:l1[b='b'][c='1']");
 
-    data = "<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"b\". /a:l1[a='a']");
+    PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"b\".", "/a:l1[a='a']");
 
-    data = "<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"c\". /a:l1[a='a'][b='b']");
+    PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><b>b</b><a>a</a></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"c\".", "/a:l1[a='a'][b='b']");
 
     /* key duplicate */
-    data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Duplicate instance of \"c\". /a:l1[a='a'][b='b'][c='1'][c='1']/c");
+    PARSER_CHECK_ERROR("<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a><c>1</c></l1>", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Duplicate instance of \"c\".", "/a:l1[a='a'][b='b'][c='1'][c='1']/c");
 
     /* keys order */
-    data = "<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    CHECK_PARSE_LYD("<l1 xmlns=\"urn:tests:a\"><d>d</d><a>a</a><c>1</c><b>b</b></l1>", 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1",
+            1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     assert_non_null(leaf = (struct lyd_node_term *)list->child);
-    assert_string_equal("a", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("b", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("c", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("d", leaf->schema->name);
-    logbuf_assert("Invalid position of the key \"b\" in a list.");
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "d", 0, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LOG_CTX("Invalid position of the key \"b\" in a list.", NULL);
     lyd_free_all(tree);
 
     data = "<l1 xmlns=\"urn:tests:a\"><c>1</c><b>b</b><a>a</a></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_LIST, tree->schema->nodetype);
-    assert_string_equal("l1", tree->schema->name);
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM, 1, "l1", 1, LYS_LIST, 0, 0, NULL, 0);
     list = (struct lyd_node_inner *)tree;
     assert_non_null(leaf = (struct lyd_node_term *)list->child);
-    assert_string_equal("a", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("b", leaf->schema->name);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "b", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = (struct lyd_node_term *)leaf->next);
-    assert_string_equal("c", leaf->schema->name);
-    logbuf_assert("Invalid position of the key \"a\" in a list.");
-    logbuf_clean();
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_KEY, 1, "c", 1, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LOG_CTX("Invalid position of the key \"a\" in a list.", NULL);
     lyd_free_all(tree);
 
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, 0, &tree));
-    logbuf_assert("Invalid position of the key \"b\" in a list. Line number 1.");
-
-    *state = NULL;
+    PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Invalid position of the key \"b\" in a list.", "Line number 1.");
 }
 
 static void
 test_container(void **state)
 {
-    *state = test_container;
-
-    const char *data = "<c xmlns=\"urn:tests:a\"/>";
     struct lyd_node *tree;
     struct lyd_node_inner *cont;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
-    assert_string_equal("c", tree->schema->name);
+    CHECK_PARSE_LYD("<c xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
     cont = (struct lyd_node_inner *)tree;
     assert_true(cont->flags & LYD_DEFAULT);
     lyd_free_all(tree);
 
-    data = "<cp xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD("<cp xmlns=\"urn:tests:a\"/>", 0, LYD_VALIDATE_PRESENT, tree);
     assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
-    assert_string_equal("cp", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
     cont = (struct lyd_node_inner *)tree;
     assert_false(cont->flags & LYD_DEFAULT);
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 static void
 test_opaq(void **state)
 {
-    *state = test_opaq;
-
     const char *data;
-    char *str;
     struct lyd_node *tree;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     /* invalid value, no flags */
     data = "<foo3 xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Invalid empty uint32 value. /a:foo3");
-    assert_null(tree);
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Invalid empty uint32 value.", "/a:foo3");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "foo3");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_XML, LYD_PRINT_SHRINK);
-    assert_string_equal(str, "<foo3 xmlns=\"urn:tests:a\"/>");
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0, LY_PREF_XML, "foo3", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, "<foo3 xmlns=\"urn:tests:a\"/>\n");
     lyd_free_all(tree);
 
     /* missing key, no flags */
-    data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><d>val_d</d></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("List instance is missing its key \"c\". /a:l1[a='val_a'][b='val_b']");
-    assert_null(tree);
+    data = "<l1 xmlns=\"urn:tests:a\">\n"
+            "  <a>val_a</a>\n"
+            "  <b>val_b</b>\n"
+            "  <d>val_d</d>\n"
+            "</l1>\n";
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "List instance is missing its key \"c\".", "/a:l1[a='val_a'][b='val_b']");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_XML, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_XML, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* invalid key, no flags */
-    data = "<l1 xmlns=\"urn:tests:a\"><a>val_a</a><b>val_b</b><c>val_c</c></l1>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Invalid int16 value \"val_c\". /a:l1/c");
-    assert_null(tree);
+    data = "<l1 xmlns=\"urn:tests:a\">\n"
+            "  <a>val_a</a>\n"
+            "  <b>val_b</b>\n"
+            "  <c>val_c</c>\n"
+            "</l1>\n";
+    PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+            "Invalid int16 value \"val_c\".", "/a:l1/c");
 
     /* opaq flag */
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "l1");
-    assert_string_equal(((struct lyd_node_opaq *)tree)->value, "");
-
-    lyd_print_tree(out, tree, LYD_XML, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, LYD_PARSE_OPAQ | LYD_PARSE_ONLY, 0, tree);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_PREF_XML, "l1", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* opaq flag and fail */
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, "<a xmlns=\"ns\"><b>x</b><c xml:id=\"D\">1</c></a>", LYD_XML,
-            LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
-    logbuf_assert("Unknown XML prefix \"xml\". Line number 1.");
-    assert_null(tree);
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
+    assert_int_equal(LY_EVALID, lyd_parse_data_mem(UTEST_LYCTX,
+            "<a xmlns=\"ns\">\n"
+            "  <b>x</b>\n"
+            "  <c xml:id=\"D\">1</c>\n"
+            "</a>\n",
+            LYD_XML, LYD_PARSE_OPAQ, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_LOG_CTX("Unknown XML prefix \"xml\".", "Line number 3.");
 }
 
 static void
 test_rpc(void **state)
 {
-    *state = test_rpc;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
+    const char *dsc = "The <edit-config> operation loads all or part of a specified\n"
+            "configuration to the specified target configuration.";
+    const char *ref = "RFC 6241, Section 7.2";
+    const char *feats[] = {"writable-running", NULL};
 
-    struct ly_out *out;
+    assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
 
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
-    data =
-            "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
+    data = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
             "  <edit-config>\n"
             "    <target>\n"
             "      <running/>\n"
@@ -435,35 +323,39 @@
             "  </edit-config>\n"
             "</rpc>\n";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_XML, &tree, &op));
     ly_in_free(in, 0);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "edit-config");
+
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, dsc, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "edit-config", LYS_RPC,
+            0, 0, 0, 0, 0, ref, 0);
 
     assert_non_null(tree);
     assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc");
-    assert_non_null(((struct lyd_node_opaq *)tree)->attr);
+
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0x1, 0x1, LY_PREF_XML, "rpc", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_string_equal(node->schema->name, "edit-config");
+    CHECK_LYSC_ACTION((struct lysc_action *)node->schema, dsc, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "edit-config", LYS_RPC,
+            0, 0, 0, 0, 0, ref, 0);
     node = lyd_child(node)->next;
-    assert_string_equal(node->schema->name, "config");
+    dsc = "Inline Config content.";
+    CHECK_LYSC_NODE(node->schema, dsc, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "config", 0, LYS_ANYXML, 1, 0, NULL, 0);
 
     node = ((struct lyd_node_any *)node)->value.tree;
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "cp");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_PRESENCE, 1, "cp",
+            1, LYS_CONTAINER, 0, 0, NULL, 0);
+
     node = lyd_child(node);
     /* z has no value */
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "z");
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0, LY_PREF_XML, "z", 0, 0, NULL,  0,  "");
     node = node->parent->next;
     /* l1 key c has invalid value so it is at the end */
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "l1");
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x1, 0x1, LY_PREF_XML, "l1", 0, 0, NULL,  0,  "");
 
-    lyd_print_tree(out, tree, LYD_XML, 0);
-    assert_string_equal(str,
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
             "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
             "  <edit-config>\n"
             "    <target>\n"
@@ -481,34 +373,22 @@
             "    </config>\n"
             "  </edit-config>\n"
             "</rpc>\n");
-    ly_out_reset(out);
+
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_action(void **state)
 {
-    *state = test_action;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *op;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
-    data =
-            "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
+    data = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
             "  <action xmlns=\"urn:ietf:params:xml:ns:yang:1\">\n"
             "    <c xmlns=\"urn:tests:a\">\n"
             "      <act>\n"
@@ -518,23 +398,18 @@
             "  </action>\n"
             "</rpc>\n";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &tree, &op));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_XML, &tree, &op));
     ly_in_free(in, 0);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "act");
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "act", LYS_ACTION,
+            1, 0, 0, 1, 0, NULL, 0);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc");
-    assert_non_null(((struct lyd_node_opaq *)tree)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0x1, 0x1, LY_PREF_XML, "rpc", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "action");
-    assert_null(((struct lyd_node_opaq *)node)->attr);
-
-    lyd_print_tree(out, tree, LYD_XML, 0);
-    assert_string_equal(str,
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x0, 0x1, LY_PREF_XML, "action", 0, 0, NULL,  0,  "");
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
             "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" msgid=\"25\" custom-attr=\"val\">\n"
             "  <action xmlns=\"urn:ietf:params:xml:ns:yang:1\">\n"
             "    <c xmlns=\"urn:tests:a\">\n"
@@ -544,34 +419,22 @@
             "    </c>\n"
             "  </action>\n"
             "</rpc>\n");
-    ly_out_reset(out);
+
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_notification(void **state)
 {
-    *state = test_notification;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *tree, *ntf;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
-    data =
-            "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
+    data = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
             "  <eventTime>2037-07-08T00:01:00Z</eventTime>\n"
             "  <c xmlns=\"urn:tests:a\">\n"
             "    <n1>\n"
@@ -580,70 +443,48 @@
             "  </c>\n"
             "</notification>\n";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(UTEST_LYCTX, in, LYD_XML, &tree, &ntf));
     ly_in_free(in, 0);
 
     assert_non_null(ntf);
-    assert_string_equal(ntf->schema->name, "n1");
+    CHECK_LYSC_NOTIF((struct lysc_notif *)ntf->schema, 1, NULL, 0, 0x4, 1, 0, "n1", 1, 0, NULL, 0);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "notification");
-    assert_null(((struct lyd_node_opaq *)tree)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0x0, 0x1, LY_PREF_XML, "notification", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_null(node->schema);
-    assert_string_equal(((struct lyd_node_opaq *)node)->name.name, "eventTime");
-    assert_string_equal(((struct lyd_node_opaq *)node)->value, "2037-07-08T00:01:00Z");
-    assert_null(((struct lyd_node_opaq *)node)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)node, 0x0, 0, LY_PREF_XML, "eventTime", 0, 0, NULL,  0,  "2037-07-08T00:01:00Z");
     node = node->next;
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "c");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
 
-    lyd_print_tree(out, tree, LYD_XML, 0);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* top-level notif without envelope */
-    data = "<n2 xmlns=\"urn:tests:a\"/>";
+    data = "<n2 xmlns=\"urn:tests:a\"/>\n";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_notif(ctx, in, LYD_XML, &tree, &ntf));
+    assert_int_equal(LY_SUCCESS, lyd_parse_notif(UTEST_LYCTX, in, LYD_XML, &tree, &ntf));
     ly_in_free(in, 0);
 
     assert_non_null(ntf);
-    assert_string_equal(ntf->schema->name, "n2");
+    CHECK_LYSC_NOTIF((struct lysc_notif *)ntf->schema, 0, NULL, 0, 0x4, 1, 0, "n2", 0, 0, NULL, 0);
 
     assert_non_null(tree);
     assert_ptr_equal(ntf, tree);
 
-    lyd_print_tree(out, tree, LYD_XML, LYD_PRINT_SHRINK);
-    assert_string_equal(str, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 static void
 test_reply(void **state)
 {
-    *state = test_reply;
-
     const char *data;
     struct ly_in *in;
-    char *str;
     struct lyd_node *request, *tree, *op;
     const struct lyd_node *node;
 
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
     data =
             "<c xmlns=\"urn:tests:a\">\n"
             "  <act>\n"
@@ -651,7 +492,7 @@
             "  </act>\n"
             "</c>\n";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_XML, &request, NULL));
     ly_in_free(in, 0);
 
     data =
@@ -664,47 +505,39 @@
     lyd_free_all(request);
 
     assert_non_null(op);
-    assert_string_equal(op->schema->name, "act");
+
+    CHECK_LYSC_ACTION((struct lysc_action *)op->schema, NULL, 0, LYS_STATUS_CURR,
+            1, 0, 0, 1, "act", LYS_ACTION,
+            1, 0, 0, 1, 0, NULL, 0);
     node = lyd_child(op);
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "al");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "al", 0, LYS_LEAF, 1, 0, NULL, 0);
     assert_true(node->schema->flags & LYS_CONFIG_R);
 
-    assert_non_null(tree);
-    assert_null(tree->schema);
-    assert_string_equal(((struct lyd_node_opaq *)tree)->name.name, "rpc-reply");
-    assert_non_null(((struct lyd_node_opaq *)tree)->attr);
+    CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0x1, 0x1, LY_PREF_XML, "rpc-reply", 0, 0, NULL,  0,  "");
     node = lyd_child(tree);
-    assert_non_null(node->schema);
-    assert_string_equal(node->schema->name, "c");
+    CHECK_LYSC_NODE(node->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 1, LYS_CONTAINER, 0, 0, NULL, 0);
 
     /* TODO print only rpc-reply node and then output subtree */
-    lyd_print_tree(out, lyd_child(op), LYD_XML, LYD_PRINT_SHRINK);
-    assert_string_equal(str, "<al xmlns=\"urn:tests:a\">25</al>");
-    ly_out_reset(out);
+    CHECK_LYD_STRING(lyd_child(op), LYD_PRINT_WITHSIBLINGS, "<al xmlns=\"urn:tests:a\">25</al>\n");
     lyd_free_all(tree);
 
     /* wrong namespace, element name, whatever... */
     /* TODO */
-
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_leaf, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_anydata, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_list, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_container, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_opaq, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_rpc, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_action, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_notification, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_reply, setup, teardown),
+        UTEST(test_leaf, setup),
+        UTEST(test_anydata, setup),
+        UTEST(test_list, setup),
+        UTEST(test_container, setup),
+        UTEST(test_opaq, setup),
+        UTEST(test_rpc, setup),
+        UTEST(test_action, setup),
+        UTEST(test_notification, setup),
+        UTEST(test_reply, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_printer_xml.c b/tests/utests/data/test_printer_xml.c
index 7a4af1a..521f0d6 100644
--- a/tests/utests/data/test_printer_xml.c
+++ b/tests/utests/data/test_printer_xml.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from printer_yang.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <string.h>
 
@@ -20,46 +22,13 @@
 #include "printer_data.h"
 #include "tests/config.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct state_s {
-    void *func;
-    struct ly_ctx *ctx;
-};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
 
 static int
 setup(void **state)
 {
-    struct state_s *s;
-    const char *schema_a = "module defs {namespace urn:tests:defs;prefix d;yang-version 1.1;"
+    const char *schema_defs = "module defs {namespace urn:tests:defs;prefix d;yang-version 1.1;"
             "identity crypto-alg; identity interface-type; identity ethernet {base interface-type;} identity fast-ethernet {base ethernet;}}";
-    const char *schema_b = "module types {namespace urn:tests:types;prefix t;yang-version 1.1; import defs {prefix defs;}"
+    const char *schema_types = "module types {namespace urn:tests:types;prefix t;yang-version 1.1; import defs {prefix defs;}"
             "feature f; identity gigabit-ethernet { base defs:ethernet;}"
             "container cont {leaf leaftarget {type empty;}"
             "    list listtarget {key id; max-elements 5;leaf id {type uint8;} leaf value {type string;}"
@@ -99,7 +68,7 @@
             "    type string {length 1..20;}}}"
             "anydata any;"
             "rpc sum {input {leaf x {type uint8;} leaf y {type uint8;}} output {leaf result {type uint16;}}}}";
-    const char *schema_c =
+    const char *schema_defaults =
             "module defaults {\n"
             "    namespace \"urn:defaults\";\n"
             "    prefix d;\n"
@@ -118,110 +87,53 @@
             "    }\n"
             "}";
 
-    s = calloc(1, sizeof *s);
-    assert_non_null(s);
+    UTEST_SETUP;
 
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &s->ctx));
-    assert_non_null(ly_ctx_load_module(s->ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_c, LYS_IN_YANG, NULL));
-
-    *state = s;
+    UTEST_ADD_MODULE(schema_defs, LYS_IN_YANG, NULL, NULL);
+    UTEST_ADD_MODULE(schema_types, LYS_IN_YANG, NULL, NULL);
+    UTEST_ADD_MODULE(schema_defaults, LYS_IN_YANG, NULL, NULL);
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-    struct state_s *s = (struct state_s *)(*state);
+#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
+    CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
 
-#if ENABLE_LOGGER_CHECKING
-    if (s->func) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-
-    ly_ctx_destroy(s->ctx, NULL);
-    free(s);
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+#define CHECK_LYD_STRING(IN_MODEL, PRINT_OPTION, TEXT) \
+    CHECK_LYD_STRING_PARAM(IN_MODEL, TEXT, LYD_XML, PRINT_OPTION)
 
 static void
 test_leaf(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
     struct lyd_node *tree;
-    const char *data;
-    const char *result;
-    char *printed;
-    struct ly_out *out;
-
-    s->func = test_leaf;
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
+    const char *data, *result;
 
     data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n  </int8>";
     result = "<int8 xmlns=\"urn:tests:types\">15</int8>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree->next, LYD_XML, LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, result);
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, result);
     lyd_free_all(tree);
-
-    ly_out_free(out, NULL, 1);
-    s->func = NULL;
 }
 
 static void
 test_anydata(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
     struct lyd_node *tree;
     const char *data;
-    char *printed;
-    struct ly_out *out;
-
-    s->func = test_anydata;
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
 
     data = "<any xmlns=\"urn:tests:types\"><somexml xmlns:x=\"url:x\" xmlns=\"example.com\"><x:x/></somexml></any>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree->next, LYD_XML, LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
     /* canonized */
     data = "<any xmlns=\"urn:tests:types\"><somexml xmlns=\"example.com\"><x xmlns=\"url:x\"/></somexml></any>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     data = "<any xmlns=\"urn:tests:types\"/>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree->next, LYD_XML, LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
-    data =
-            "<any xmlns=\"urn:tests:types\">\n"
+    data = "<any xmlns=\"urn:tests:types\">\n"
             "  <cont>\n"
             "    <defs:elem1 xmlns:defs=\"urn:tests:defs\">\n"
             "      <elem2 xmlns:defaults=\"urn:defaults\" defs:attr1=\"defaults:val\" attr2=\"/defaults:node/defs:node2\">\n"
@@ -229,16 +141,17 @@
             "    </defs:elem1>\n"
             "  </cont>\n"
             "</any>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    /* cont should be normally parsed */
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_string_equal(tree->schema->name, "any");
-    assert_int_equal(((struct lyd_node_any *)tree)->value_type, LYD_ANYDATA_DATATREE);
-    assert_string_equal(((struct lyd_node_any *)tree)->value.tree->schema->name, "cont");
+    /* cont should be normally parsed */
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "any", 0, LYS_ANYDATA, 0, 0, NULL, 0);
+    CHECK_LYD_NODE_ANY((struct lyd_node_any *)tree, 0, 0, 0, LYD_ANYDATA_DATATREE);
+    struct lyd_node *tree_tmp = ((struct lyd_node_any *)tree)->value.tree;
+
+    CHECK_LYSC_NODE(tree_tmp->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "cont", 1, LYS_CONTAINER, 0, 0, NULL, 0);
     /* but its children not */
-    assert_null(((struct lyd_node_inner *)(((struct lyd_node_any *)tree)->value.tree))->child->schema);
-    assert_int_equal(LY_SUCCESS, lyd_print_tree(out, tree, LYD_XML, 0));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
+    assert_null(((struct lyd_node_inner *)tree_tmp)->child->schema);
     /* canonized */
     data =
             "<any xmlns=\"urn:tests:types\">\n"
@@ -249,122 +162,68 @@
             "    </elem1>\n"
             "  </cont>\n"
             "</any>\n";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
 
     lyd_free_all(tree);
-
-    ly_out_free(out, NULL, 1);
-    s->func = NULL;
 }
 
 static void
 test_defaults(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
     struct lyd_node *tree;
     const char *data;
-    char *printed;
-    struct ly_out *out;
+    const char *data_trim;
+    const char *data_all;
+    const char *data_all_tag;
+    const char *data_impl_tag;
 
-    s->func = test_defaults;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
 
     /* standard default value */
     data = "<c xmlns=\"urn:defaults\">aa</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
 
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
 
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
             " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>"
             "<c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
 
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
     data = "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
             " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>"
             "<c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* string value equal to the default but default is an unresolved instance-identifier, so they are not considered equal */
     data = "<a xmlns=\"urn:defaults\">/d:b</a><c xmlns=\"urn:defaults\">aa</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
 
     /* instance-identifier value equal to the default, should be considered equal */
     data = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(s->ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    data = "<b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    data = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    data = "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
+    data_trim = "<b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
+    data_all = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
+    data_all_tag = "<a xmlns=\"urn:defaults\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
             " ncwd:default=\"true\" xmlns:d=\"urn:defaults\">/d:b</a>"
             "<b xmlns=\"urn:defaults\">val</b>"
             "<c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
+    data_impl_tag = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
 
-    assert_int_equal(LY_SUCCESS, lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK));
-    assert_int_equal(strlen(printed), ly_out_printed(out));
-    data = "<a xmlns=\"urn:defaults\" xmlns:d=\"urn:defaults\">/d:b</a><b xmlns=\"urn:defaults\">val</b><c xmlns=\"urn:defaults\">aa</c>";
-    assert_string_equal(printed, data);
-    ly_out_reset(out);
-
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_TRIM | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data_trim);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data_all);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_ALL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data_all_tag);
+    CHECK_LYD_STRING(tree, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data_impl_tag);
     lyd_free_all(tree);
-    ly_out_free(out, NULL, 1);
-
-    s->func = NULL;
 }
 
 #if 0
@@ -456,9 +315,9 @@
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_leaf, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_anydata, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_defaults, setup, teardown),
+        UTEST(test_leaf, setup),
+        UTEST(test_anydata, setup),
+        UTEST(test_defaults, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_tree_data.c b/tests/utests/data/test_tree_data.c
index e1507f4..1aab6fc 100644
--- a/tests/utests/data/test_tree_data.c
+++ b/tests/utests/data/test_tree_data.c
@@ -11,47 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "libyang.h"
 #include "path.h"
-#include "utests.h"
 #include "xpath.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
 static int
 setup(void **state)
 {
-    (void) state; /* unused */
-
-    const char *schema_a = "module a {namespace urn:tests:a;prefix a;yang-version 1.1;"
+    const char *schema = "module a {namespace urn:tests:a;prefix a;yang-version 1.1;"
             "leaf bar {type string;}"
             "list l1 { key \"a b\"; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
             "leaf foo { type string;}"
@@ -62,59 +33,29 @@
             "    container c{leaf x {type string;} leaf-list d {type string;}}"
             "}}";
 
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_SETUP;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
-
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+#define CHECK_PARSE_LYD(INPUT, PARSE_OPTION, VALIDATE_OPTION, TREE) \
+    CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, PARSE_OPTION, VALIDATE_OPTION, LY_SUCCESS, TREE)
 
 static void
 test_compare(void **state)
 {
-    *state = test_compare;
-
     struct lyd_node *tree1, *tree2;
-
-    const char *data1 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
-    const char *data2 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>y</c></l1>";
+    const char *data1;
+    const char *data2;
 
     assert_int_equal(LY_SUCCESS, lyd_compare_single(NULL, NULL, 0));
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    data1 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
+    data2 = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>y</c></l1>";
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0));
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     assert_int_equal(LY_ENOT, lyd_compare_single(((struct lyd_node_inner *)tree1)->child, tree2, 0));
@@ -123,8 +64,8 @@
 
     data1 = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
     data2 = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, 0));
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next->next, tree2->next, 0));
     lyd_free_all(tree1);
@@ -132,8 +73,8 @@
 
     data1 = "<ll xmlns=\"urn:tests:a\">a</ll><ll xmlns=\"urn:tests:a\">b</ll>";
     data2 = "<ll xmlns=\"urn:tests:a\">b</ll>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, 0));
     assert_int_equal(LY_ENOT, lyd_compare_single(NULL, tree2, 0));
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1, NULL, 0));
@@ -143,8 +84,8 @@
 
     data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>";
     data2 = "<c xmlns=\"urn:tests:a\"><x>y</x></c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0));
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
@@ -152,8 +93,8 @@
 
     data1 = "<c xmlns=\"urn:tests:a\"><x>x</x></c>";
     data2 = "<c xmlns=\"urn:tests:a\"><x>x</x><x>y</x></c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0));
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
@@ -161,29 +102,26 @@
 
     data1 = "<any xmlns=\"urn:tests:a\"><x>x</x></any>";
     data2 = "<any xmlns=\"urn:tests:a\"><x>x</x><x>y</x></any>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data2, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree2));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
+    CHECK_PARSE_LYD(data2, 0, LYD_VALIDATE_PRESENT, tree2);
     assert_int_equal(LY_ENOT, lyd_compare_single(tree1->next, tree2->next, 0));
     lyd_free_all(tree1);
     data1 = "<any xmlns=\"urn:tests:a\"><x>x</x><x>y</x></any>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data1, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data1, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, 0));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
-
-    *state = NULL;
 }
 
 static void
 test_dup(void **state)
 {
-    *state = test_dup;
-
     struct lyd_node *tree1, *tree2;
     const char *result;
-    const char *data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
+    const char *data;
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, LYD_DUP_RECURSIVE, &tree2));
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
@@ -191,64 +129,65 @@
 
     data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>x</c></l1>";
     result = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
     lyd_free_all(tree1);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
 
     data = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
     result = "<l2 xmlns=\"urn:tests:a\"><c><x>a</x></c></l2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_siblings(tree1, NULL, LYD_DUP_RECURSIVE, &tree2));
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2->next, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree2);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, LYD_DUP_RECURSIVE, &tree2));
     lyd_free_all(tree1);
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(result, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree2);
 
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2));
     lyd_free_all(tree1);
     result = "<l2 xmlns=\"urn:tests:a\"/>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, result, LYD_XML, LYD_PARSE_ONLY, 0, &tree1));
+    CHECK_PARSE_LYD_PARAM(result, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree1);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
 
     data = "<any xmlns=\"urn:tests:a\"><c><a>a</a></c></any>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1, NULL, 0, &tree2));
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, tree2, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
 
     data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child, NULL,
             LYD_DUP_WITH_PARENTS, &tree2));
-    assert_string_equal("x", tree2->schema->name);
-    assert_non_null(tree2->parent);
+    int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM;
+
+    CHECK_LYSC_NODE(tree2->schema, NULL, 0, flag, 1, "x", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1->next, (struct lyd_node *)tree2->parent->parent,
             LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
 
     data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev, NULL,
             LYD_DUP_WITH_PARENTS, &tree2));
-    assert_string_equal("c", tree2->schema->name);
-    assert_non_null(tree2->parent);
+    flag = LYS_CONFIG_W | LYS_SET_ENUM;
+    CHECK_LYSC_NODE(tree2->schema, NULL, 0, flag, 1, "c", 0, LYS_LEAF, 1, 0, NULL, 0);
     assert_int_equal(LY_SUCCESS, lyd_compare_single(tree1, (struct lyd_node *)tree2->parent, LYD_COMPARE_FULL_RECURSION));
     lyd_free_all(tree1);
     lyd_free_all(tree2);
 
     data = "<l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_SUCCESS, lyd_dup_single(tree1->next, NULL, 0, &tree2));
     assert_int_equal(LY_SUCCESS, lyd_dup_single(((struct lyd_node_inner *)((struct lyd_node_inner *)tree1->next)->child)->child,
             (struct lyd_node_inner *)tree2, LYD_DUP_WITH_PARENTS, NULL));
@@ -258,19 +197,15 @@
 
     /* invalid */
     data = "<l1 xmlns=\"urn:tests:a\"><a>a</a><b>b</b><c>c</c></l1><l2 xmlns=\"urn:tests:a\"><c><x>b</x></c></l2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree1));
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree1);
     assert_int_equal(LY_EINVAL, lyd_dup_single(((struct lyd_node_inner *)tree1)->child->prev,
             (struct lyd_node_inner *)tree1->next, LYD_DUP_WITH_PARENTS, NULL));
     lyd_free_all(tree1);
-
-    *state = NULL;
 }
 
 static void
 test_target(void **state)
 {
-    *state = test_target;
-
     const struct lyd_node_term *term;
     struct lyd_node *tree;
     struct lyxp_expr *exp;
@@ -289,29 +224,27 @@
             "<l2 xmlns=\"urn:tests:a\"><c>"
             "</c></l2>";
 
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_int_equal(LY_SUCCESS, ly_path_parse(ctx, NULL, path_str, strlen(path_str), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_FALSE,
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path_str, strlen(path_str), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_FALSE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_SIMPLE, &exp));
-    assert_int_equal(LY_SUCCESS, ly_path_compile(ctx, NULL, NULL, exp, LY_PATH_LREF_FALSE, LY_PATH_OPER_INPUT,
+    assert_int_equal(LY_SUCCESS, ly_path_compile(UTEST_LYCTX, NULL, NULL, exp, LY_PATH_LREF_FALSE, LY_PATH_OPER_INPUT,
             LY_PATH_TARGET_SINGLE, LY_PREF_JSON, NULL, NULL, &path));
     term = lyd_target(path, tree);
 
-    assert_string_equal(term->schema->name, "d");
+    const int unsigned flag = LYS_CONFIG_R | LYS_SET_ENUM | LYS_ORDBY_SYSTEM;
+
+    CHECK_LYSC_NODE(term->schema, NULL, 0, flag, 1, "d", 0, LYS_LEAFLIST, 1, 0, NULL, 0);
     assert_string_equal(LYD_CANON_VALUE(term), "b");
     assert_string_equal(LYD_CANON_VALUE(term->prev), "b");
 
     lyd_free_all(tree);
-    ly_path_free(ctx, path);
-    lyxp_expr_free(ctx, exp);
-
-    *state = NULL;
+    ly_path_free(UTEST_LYCTX, path);
+    lyxp_expr_free(UTEST_LYCTX, exp);
 }
 
 static void
 test_list_pos(void **state)
 {
-    *state = test_list_pos;
-
     const char *data;
     struct lyd_node *tree;
 
@@ -319,7 +252,7 @@
             "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b></l1>"
             "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>"
             "<foo xmlns=\"urn:tests:a\">test</foo>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_int_equal(0, lyd_list_pos(tree));
     assert_int_equal(1, lyd_list_pos(tree->next));
     assert_int_equal(2, lyd_list_pos(tree->next->next));
@@ -329,7 +262,7 @@
     data = "<ll xmlns=\"urn:tests:a\">one</ll>"
             "<ll xmlns=\"urn:tests:a\">two</ll>"
             "<ll xmlns=\"urn:tests:a\">three</ll>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_int_equal(1, lyd_list_pos(tree));
     assert_int_equal(2, lyd_list_pos(tree->next));
     assert_int_equal(3, lyd_list_pos(tree->next->next));
@@ -341,7 +274,7 @@
             "<l1 xmlns=\"urn:tests:a\"><a>two</a><b>two</b></l1>"
             "<ll xmlns=\"urn:tests:a\">three</ll>"
             "<l1 xmlns=\"urn:tests:a\"><a>three</a><b>three</b></l1>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_string_equal("l1", tree->schema->name);
     assert_int_equal(1, lyd_list_pos(tree));
     assert_int_equal(2, lyd_list_pos(tree->next));
@@ -351,15 +284,11 @@
     assert_int_equal(2, lyd_list_pos(tree->next->next->next->next));
     assert_int_equal(3, lyd_list_pos(tree->next->next->next->next->next));
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 static void
 test_first_sibling(void **state)
 {
-    *state = test_first_sibling;
-
     const char *data;
     struct lyd_node *tree;
     struct lyd_node_inner *parent;
@@ -367,7 +296,7 @@
     data = "<bar xmlns=\"urn:tests:a\">test</bar>"
             "<l1 xmlns=\"urn:tests:a\"><a>one</a><b>one</b><c>one</c></l1>"
             "<foo xmlns=\"urn:tests:a\">test</foo>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
     assert_ptr_equal(tree, lyd_first_sibling(tree->next));
     assert_ptr_equal(tree, lyd_first_sibling(tree));
     assert_ptr_equal(tree, lyd_first_sibling(tree->prev));
@@ -377,19 +306,17 @@
     assert_ptr_equal(parent->child, lyd_first_sibling(parent->child));
     assert_ptr_equal(parent->child, lyd_first_sibling(parent->child->prev));
     lyd_free_all(tree);
-
-    *state = NULL;
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_compare, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_dup, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_target, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_list_pos, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_first_sibling, setup, teardown),
+        UTEST(test_compare, setup),
+        UTEST(test_dup, setup),
+        UTEST(test_target, setup),
+        UTEST(test_list_pos, setup),
+        UTEST(test_first_sibling, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_types.c b/tests/utests/data/test_types.c
index f8316c6..a711c16 100644
--- a/tests/utests/data/test_types.c
+++ b/tests/utests/data/test_types.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for support of YANG data types
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,684 +11,484 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
+
+#include <stdio.h>
+#include <string.h>
 
 #include "libyang.h"
 #include "path.h"
 #include "plugins_types.h"
-#include "utests.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct state_s {
-    void *func;
-    struct ly_ctx *ctx;
-    const struct lys_module *mod_types;
-    const struct lys_module *mod_defs;
-};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
+const char *schema_a = "module defs {namespace urn:tests:defs;prefix d;yang-version 1.1;"
+        "identity crypto-alg; identity interface-type; identity ethernet {base interface-type;} identity fast-ethernet {base ethernet;}"
+        "typedef iref {type identityref {base interface-type;}}}";
+const char *schema_b = "module types {namespace urn:tests:types;prefix t;yang-version 1.1; import defs {prefix defs;}"
+        "feature f; identity gigabit-ethernet { base defs:ethernet;}"
+        "typedef tboolean {type boolean;}"
+        "typedef tempty {type empty;}"
+        "container cont {leaf leaftarget {type empty;}"
+        "    list listtarget {key id; max-elements 5;leaf id {type uint8;} leaf value {type string;}}"
+        "    leaf-list leaflisttarget {type uint8; max-elements 5;}}"
+        "list list {key id; leaf id {type string;} leaf value {type string;} leaf-list targets {type string;}}"
+        "list list2 {key \"id value\"; leaf id {type string;} leaf value {type string;}}"
+        "list list_inst {key id; leaf id {type instance-identifier {require-instance true;}} leaf value {type string;}}"
+        "list list_ident {key id; leaf id {type identityref {base defs:interface-type;}} leaf value {type string;}}"
+        "list list_keyless {config \"false\"; leaf id {type string;} leaf value {type string;}}"
+        "leaf-list leaflisttarget {type string;}"
+        "leaf binary {type binary {length 5 {error-message \"This base64 value must be of length 5.\";}}}"
+        "leaf binary-norestr {type binary;}"
+        "leaf int8 {type int8 {range 10..20;}}"
+        "leaf uint8 {type uint8 {range 150..200;}}"
+        "leaf int16 {type int16 {range -20..-10;}}"
+        "leaf uint16 {type uint16 {range 150..200;}}"
+        "leaf int32 {type int32;}"
+        "leaf uint32 {type uint32;}"
+        "leaf int64 {type int64;}"
+        "leaf uint64 {type uint64;}"
+        "leaf bits {type bits {bit zero; bit one {if-feature f;} bit two;}}"
+        "leaf enums {type enumeration {enum white; enum yellow {if-feature f;}}}"
+        "leaf dec64 {type decimal64 {fraction-digits 1; range 1.5..10;}}"
+        "leaf dec64-norestr {type decimal64 {fraction-digits 18;}}"
+        "leaf str {type string {length 8..10; pattern '[a-z ]*';}}"
+        "leaf str-norestr {type string;}"
+        "leaf str-utf8 {type string{length 2..5; pattern '€*';}}"
+        "leaf bool {type boolean;}"
+        "leaf tbool {type tboolean;}"
+        "leaf empty {type empty;}"
+        "leaf tempty {type tempty;}"
+        "leaf ident {type identityref {base defs:interface-type;}}"
+        "leaf iref {type defs:iref;}"
+        "leaf inst {type instance-identifier {require-instance true;}}"
+        "leaf inst-noreq {type instance-identifier {require-instance false;}}"
+        "leaf lref {type leafref {path /leaflisttarget; require-instance true;}}"
+        "leaf lref2 {type leafref {path \"../list[id = current()/../str-norestr]/targets\"; require-instance true;}}"
+        "leaf un1 {type union {"
+        "    type leafref {path /int8; require-instance true;}"
+        "    type union { type identityref {base defs:interface-type;} type instance-identifier {require-instance true;} }"
+        "    type string {length 1..20;}}}}";
 
 static int
 setup(void **state)
 {
-    struct state_s *s;
-    const char *schema_a = "module defs {namespace urn:tests:defs;prefix d;yang-version 1.1;"
-            "identity crypto-alg; identity interface-type; identity ethernet {base interface-type;} identity fast-ethernet {base ethernet;}"
-            "typedef iref {type identityref {base interface-type;}}}";
-    const char *schema_b = "module types {namespace urn:tests:types;prefix t;yang-version 1.1; import defs {prefix defs;}"
-            "feature f; identity gigabit-ethernet { base defs:ethernet;}"
-            "typedef tboolean {type boolean;}"
-            "typedef tempty {type empty;}"
-            "container cont {leaf leaftarget {type empty;}"
-            "    list listtarget {key id; max-elements 5;leaf id {type uint8;} leaf value {type string;}}"
-            "    leaf-list leaflisttarget {type uint8; max-elements 5;}}"
-            "list list {key id; leaf id {type string;} leaf value {type string;} leaf-list targets {type string;}}"
-            "list list2 {key \"id value\"; leaf id {type string;} leaf value {type string;}}"
-            "list list_inst {key id; leaf id {type instance-identifier {require-instance true;}} leaf value {type string;}}"
-            "list list_ident {key id; leaf id {type identityref {base defs:interface-type;}} leaf value {type string;}}"
-            "list list_keyless {config \"false\"; leaf id {type string;} leaf value {type string;}}"
-            "leaf-list leaflisttarget {type string;}"
-            "leaf binary {type binary {length 5 {error-message \"This base64 value must be of length 5.\";}}}"
-            "leaf binary-norestr {type binary;}"
-            "leaf int8 {type int8 {range 10..20;}}"
-            "leaf uint8 {type uint8 {range 150..200;}}"
-            "leaf int16 {type int16 {range -20..-10;}}"
-            "leaf uint16 {type uint16 {range 150..200;}}"
-            "leaf int32 {type int32;}"
-            "leaf uint32 {type uint32;}"
-            "leaf int64 {type int64;}"
-            "leaf uint64 {type uint64;}"
-            "leaf bits {type bits {bit zero; bit one {if-feature f;} bit two;}}"
-            "leaf enums {type enumeration {enum white; enum yellow {if-feature f;}}}"
-            "leaf dec64 {type decimal64 {fraction-digits 1; range 1.5..10;}}"
-            "leaf dec64-norestr {type decimal64 {fraction-digits 18;}}"
-            "leaf str {type string {length 8..10; pattern '[a-z ]*';}}"
-            "leaf str-norestr {type string;}"
-            "leaf str-utf8 {type string{length 2..5; pattern '€*';}}"
-            "leaf bool {type boolean;}"
-            "leaf tbool {type tboolean;}"
-            "leaf empty {type empty;}"
-            "leaf tempty {type tempty;}"
-            "leaf ident {type identityref {base defs:interface-type;}}"
-            "leaf iref {type defs:iref;}"
-            "leaf inst {type instance-identifier {require-instance true;}}"
-            "leaf inst-noreq {type instance-identifier {require-instance false;}}"
-            "leaf lref {type leafref {path /leaflisttarget; require-instance true;}}"
-            "leaf lref2 {type leafref {path \"../list[id = current()/../str-norestr]/targets\"; require-instance true;}}"
-            "leaf un1 {type union {"
-            "    type leafref {path /int8; require-instance true;}"
-            "    type union { type identityref {base defs:interface-type;} type instance-identifier {require-instance true;} }"
-            "    type string {length 1..20;}}}}";
-
-    s = calloc(1, sizeof *s);
-    assert_non_null(s);
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &s->ctx));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_a, LYS_IN_YANG, &s->mod_defs));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema_b, LYS_IN_YANG, &s->mod_types));
-
-    *state = s;
+    UTEST_SETUP;
+    UTEST_ADD_MODULE(schema_a, LYS_IN_YANG, NULL, NULL);
+    UTEST_ADD_MODULE(schema_b, LYS_IN_YANG, NULL, NULL);
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-    struct state_s *s = (struct state_s *)(*state);
+#define CHECK_PARSE_LYD(INPUT, MODEL) \
+    CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)
 
-#if ENABLE_LOGGER_CHECKING
-    if (s->func) {
-        fprintf(stderr, "%s\n", logbuf);
+#define TEST_PATTERN_1(INPUT, SCHEMA_NAME, SCHEMA_NEXT, VALUE_TYPE, ...) \
+    { \
+        struct lyd_node_term *leaf; \
+        struct lyd_value value = {0}; \
+    /* create model */ \
+        CHECK_LYSC_NODE((INPUT)->schema, NULL, 0, 0x5, 1, SCHEMA_NAME, SCHEMA_NEXT, LYS_LEAF, 0, 0, NULL, 0); \
+    /* CHECK_LYSC_NODE((INPUT)->schema, LYS_LEAF, SCHEMA_NAME); */ \
+        leaf = (struct lyd_node_term*)(INPUT); \
+        CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 0, 1, VALUE_TYPE, ## __VA_ARGS__); \
+    /* copy value */ \
+        assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(UTEST_LYCTX, &leaf->value, &value)); \
+        CHECK_LYD_VALUE(value, VALUE_TYPE, ## __VA_ARGS__); \
+        if (LY_TYPE_INST == LY_TYPE_ ## VALUE_TYPE) { \
+            for (LY_ARRAY_COUNT_TYPE it = 0; it < LY_ARRAY_COUNT(leaf->value.target); it++) { \
+                assert_ptr_equal(value.target[it].node, leaf->value.target[it].node); \
+                LY_ARRAY_COUNT_TYPE arr_size_predicates = 0; \
+                if (value.target[it].pred_type == LY_PATH_PREDTYPE_NONE) { \
+                    assert_null(value.target[it].predicates); \
+                } else { \
+                    assert_non_null(value.target[it].predicates); \
+                    arr_size_predicates =  LY_ARRAY_COUNT(value.target[it].predicates); \
+                    assert_int_equal(LY_ARRAY_COUNT(value.target[it].predicates), LY_ARRAY_COUNT(leaf->value.target[it].predicates)); \
+                } \
+                for (LY_ARRAY_COUNT_TYPE jt = 0; jt < arr_size_predicates; jt++) { \
+                    if (value.target[it].pred_type == LY_PATH_PREDTYPE_POSITION) { \
+                        assert_int_equal(value.target[it].predicates[jt].position, leaf->value.target[it].predicates[jt].position); \
+                    } else { \
+                        assert_true(LY_SUCCESS == value.realtype->plugin->compare(&value, &leaf->value)); \
+                    } \
+                } \
+            } \
+        } \
+        value.realtype->plugin->free(UTEST_LYCTX, &value); \
     }
-#endif
 
-    ly_ctx_destroy(s->ctx, NULL);
-    free(s);
+#define TEST_TYPE_ERROR(TYPE, VALUE, ERROR_MSG) \
+    { \
+        const char *data = "<" TYPE " xmlns=\"urn:tests:types\">" VALUE "</" TYPE">"; \
+        CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree); \
+        CHECK_LOG_CTX(ERROR_MSG, "/types:"TYPE); \
+    }
 
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-#define TEST_DATA(DATA, RETCODE, ERRMSG) \
-    logbuf_clean(); \
-    if (!in) { \
-        assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &in)); \
-    } else { \
-        ly_in_memory(in, DATA); \
-    } \
-    assert_int_equal(RETCODE, lyd_parse_data(s->ctx, in, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); \
-    if (!RETCODE) { \
-        logbuf_assert(ERRMSG); \
+#define TEST_PRINTED_VALUE(VALUE, EXPECTED, FORMAT, PREFIX_DATA) \
+    { \
+        const char *_str; \
+        uint8_t _dynamic; \
+        assert_non_null(_str = (VALUE)->realtype->plugin->print(VALUE, FORMAT, (void *)PREFIX_DATA, &_dynamic)); \
+        assert_string_equal(EXPECTED, _str); \
+        if (_dynamic) { \
+            free((char *)_str); \
+        } \
     }
 
 static void
 test_int(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_int;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
+    const char *data;
+    char *error_msg;
 
     /* valid data */
-    TEST_DATA("<int8 xmlns=\"urn:tests:types\">\n 15 \t\n  </int8>", LY_SUCCESS, "");
+    data = "<int8 xmlns=\"urn:tests:types\">\n 15 \t\n  </int8>";
+    CHECK_PARSE_LYD(data, tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("int8", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("15", leaf->value.canonical);
-    assert_int_equal(15, leaf->value.int8);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_int_equal(15, value.int8);
-    value.realtype->plugin->free(s->ctx, &value);
-    memset(&value, 0, sizeof value);
+    TEST_PATTERN_1(tree, "int8", 1, INT8, "15", 15);
     lyd_free_all(tree);
 
     /* invalid range */
-    TEST_DATA("<int8 xmlns=\"urn:tests:types\">1</int8>", LY_EVALID, "Value \"1\" does not satisfy the range constraint. /types:int8");
-    TEST_DATA("<int16 xmlns=\"urn:tests:types\">100</int16>", LY_EVALID, "Value \"100\" does not satisfy the range constraint. /types:int16");
+    error_msg = "Value \"1\" does not satisfy the range constraint.";
+    TEST_TYPE_ERROR("int8", "1", error_msg);
+    error_msg = "Value \"100\" does not satisfy the range constraint.";
+    TEST_TYPE_ERROR("int16", "100", error_msg);
 
     /* invalid value */
-    TEST_DATA("<int32 xmlns=\"urn:tests:types\">0x01</int32>", LY_EVALID, "Invalid int32 value \"0x01\". /types:int32");
-    TEST_DATA("<int64 xmlns=\"urn:tests:types\"></int64>", LY_EVALID, "Invalid empty int64 value. /types:int64");
-    TEST_DATA("<int64 xmlns=\"urn:tests:types\">   </int64>", LY_EVALID, "Invalid empty int64 value. /types:int64");
-    TEST_DATA("<int64 xmlns=\"urn:tests:types\">-10  xxx</int64>", LY_EVALID, "Invalid int64 value \"-10  xxx\". /types:int64");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    error_msg = "Invalid int32 value \"0x01\".";
+    TEST_TYPE_ERROR("int32", "0x01", error_msg);
+    error_msg = "Invalid empty int64 value.";
+    TEST_TYPE_ERROR("int64", "", error_msg);
+    error_msg = "Invalid empty int64 value.";
+    TEST_TYPE_ERROR("int64", "   ", error_msg);
+    error_msg = "Invalid int64 value \"-10  xxx\".";
+    TEST_TYPE_ERROR("int64", "-10  xxx", error_msg);
 }
 
 static void
 test_uint(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_uint;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
 
     /* valid data */
-    TEST_DATA("<uint8 xmlns=\"urn:tests:types\">\n 150 \t\n  </uint8>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<uint8 xmlns=\"urn:tests:types\">\n 150 \t\n  </uint8>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("uint8", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("150", leaf->value.canonical);
-    assert_int_equal(150, leaf->value.uint8);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_int_equal(150, value.uint8);
-    value.realtype->plugin->free(s->ctx, &value);
-    memset(&value, 0, sizeof value);
+    TEST_PATTERN_1(tree, "uint8", 1, UINT8, "150", 150);
     lyd_free_all(tree);
 
     /* invalid range */
-    TEST_DATA("<uint8 xmlns=\"urn:tests:types\">\n 15 \t\n  </uint8>", LY_EVALID, "Value \"15\" does not satisfy the range constraint. /types:uint8");
-    TEST_DATA("<uint16 xmlns=\"urn:tests:types\">\n 1500 \t\n  </uint16>", LY_EVALID, "Value \"1500\" does not satisfy the range constraint. /types:uint16");
+    TEST_TYPE_ERROR("uint8", "\n 15 \t\n  ",
+            "Value \"15\" does not satisfy the range constraint.");
+    TEST_TYPE_ERROR("uint16", "\n 1500 \t\n  ",
+            "Value \"1500\" does not satisfy the range constraint.");
 
     /* invalid value */
-    TEST_DATA("<uint32 xmlns=\"urn:tests:types\">-10</uint32>", LY_EVALID, "Value \"-10\" is out of uint32's min/max bounds. /types:uint32");
-    TEST_DATA("<uint64 xmlns=\"urn:tests:types\"/>", LY_EVALID, "Invalid empty uint64 value. /types:uint64");
-    TEST_DATA("<uint64 xmlns=\"urn:tests:types\">   </uint64>", LY_EVALID, "Invalid empty uint64 value. /types:uint64");
-    TEST_DATA("<uint64 xmlns=\"urn:tests:types\">10  xxx</uint64>", LY_EVALID, "Invalid uint64 value \"10  xxx\". /types:uint64");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("uint32", "-10",
+            "Value \"-10\" is out of uint32's min/max bounds.");
+    CHECK_PARSE_LYD_PARAM("<uint64 xmlns=\"urn:tests:types\"/>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid empty uint64 value.", "/types:uint64");
+    TEST_TYPE_ERROR("uint64", "   ", "Invalid empty uint64 value.");
+    TEST_TYPE_ERROR("uint64", "10  xxx", "Invalid uint64 value \"10  xxx\".");
 }
 
 static void
 test_dec64(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_dec64;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
 
     /* valid data */
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">\n +8 \t\n  </dec64>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<dec64 xmlns=\"urn:tests:types\">\n +8 \t\n  </dec64>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("dec64", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("8.0", leaf->value.canonical);
-    assert_int_equal(80, leaf->value.dec64);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_int_equal(80, value.dec64);
-    value.realtype->plugin->free(s->ctx, &value);
-    memset(&value, 0, sizeof value);
+    TEST_PATTERN_1(tree, "dec64", 1, DEC64, "8.0", 80);
     lyd_free_all(tree);
 
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">8.00</dec64>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<dec64 xmlns=\"urn:tests:types\">8.00</dec64>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("dec64", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("8.0", leaf->value.canonical);
-    assert_int_equal(80, leaf->value.dec64);
+    TEST_PATTERN_1(tree, "dec64", 1, DEC64, "8.0", 80);
     lyd_free_all(tree);
 
-    TEST_DATA("<dec64-norestr xmlns=\"urn:tests:types\">-9.223372036854775808</dec64-norestr>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<dec64-norestr xmlns=\"urn:tests:types\">-9.223372036854775808</dec64-norestr>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("dec64-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("-9.223372036854775808", leaf->value.canonical);
-    assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), leaf->value.dec64);
+    TEST_PATTERN_1(tree, "dec64-norestr", 1, DEC64, "-9.223372036854775808", INT64_C(-9223372036854775807) - INT64_C(1));
     lyd_free_all(tree);
 
-    TEST_DATA("<dec64-norestr xmlns=\"urn:tests:types\">9.223372036854775807</dec64-norestr>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<dec64-norestr xmlns=\"urn:tests:types\">9.223372036854775807</dec64-norestr>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("dec64-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("9.223372036854775807", leaf->value.canonical);
-    assert_int_equal(INT64_C(9223372036854775807), leaf->value.dec64);
+    TEST_PATTERN_1(tree, "dec64-norestr", 1, DEC64, "9.223372036854775807", INT64_C(9223372036854775807));
     lyd_free_all(tree);
 
     /* invalid range */
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">\n 15 \t\n  </dec64>", LY_EVALID, "Value \"15.0\" does not satisfy the range constraint. /types:dec64");
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">\n 0 \t\n  </dec64>", LY_EVALID, "Value \"0.0\" does not satisfy the range constraint. /types:dec64");
+    TEST_TYPE_ERROR("dec64", "\n 15 \t\n  ", "Value \"15.0\" does not satisfy the range constraint.");
+    TEST_TYPE_ERROR("dec64", "\n 0 \t\n  ", "Value \"0.0\" does not satisfy the range constraint.");
 
     /* invalid value */
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">xxx</dec64>", LY_EVALID, "Invalid 1. character of decimal64 value \"xxx\". /types:dec64");
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\"/>", LY_EVALID, "Invalid empty decimal64 value. /types:dec64");
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">   </dec64>", LY_EVALID, "Invalid empty decimal64 value. /types:dec64");
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">8.5  xxx</dec64>", LY_EVALID, "Invalid 6. character of decimal64 value \"8.5  xxx\". /types:dec64");
-    TEST_DATA("<dec64 xmlns=\"urn:tests:types\">8.55  xxx</dec64>", LY_EVALID, "Value \"8.55\" of decimal64 type exceeds defined number (1) of fraction digits. /types:dec64");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("dec64", "xxx", "Invalid 1. character of decimal64 value \"xxx\".");
+    CHECK_PARSE_LYD_PARAM("<dec64 xmlns=\"urn:tests:types\"/>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid empty decimal64 value.", "/types:dec64");
+    TEST_TYPE_ERROR("dec64", "   ", "Invalid empty decimal64 value.");
+    TEST_TYPE_ERROR("dec64", "8.5  xxx", "Invalid 6. character of decimal64 value \"8.5  xxx\".");
+    TEST_TYPE_ERROR("dec64", "8.55  xxx", "Value \"8.55\" of decimal64 type exceeds defined number (1) of fraction digits.");
 }
 
 static void
 test_string(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_string;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
 
     /* valid data */
-    TEST_DATA("<str xmlns=\"urn:tests:types\">teststring</str>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<str xmlns=\"urn:tests:types\">teststring</str>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("str", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("teststring", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "str", 1, STRING, "teststring");
     lyd_free_all(tree);
 
     /* multibyte characters (€ encodes as 3-byte UTF8 character, length restriction is 2-5) */
-    TEST_DATA("<str-utf8 xmlns=\"urn:tests:types\">€€</str-utf8>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<str-utf8 xmlns=\"urn:tests:types\">€€</str-utf8>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("str-utf8", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("€€", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "str-utf8", 1, STRING, "€€");
     lyd_free_all(tree);
-    TEST_DATA("<str-utf8 xmlns=\"urn:tests:types\">€</str-utf8>", LY_EVALID, "Length \"1\" does not satisfy the length constraint. /types:str-utf8");
-    TEST_DATA("<str-utf8 xmlns=\"urn:tests:types\">€€€€€€</str-utf8>", LY_EVALID, "Length \"6\" does not satisfy the length constraint. /types:str-utf8");
-    TEST_DATA("<str-utf8 xmlns=\"urn:tests:types\">€€x</str-utf8>", LY_EVALID, "String \"€€x\" does not conform to the pattern \"€*\". /types:str-utf8");
+
+    /*error */
+    TEST_TYPE_ERROR("str-utf8", "€",
+            "Length \"1\" does not satisfy the length constraint.");
+    TEST_TYPE_ERROR("str-utf8", "€€€€€€",
+            "Length \"6\" does not satisfy the length constraint.");
+    TEST_TYPE_ERROR("str-utf8", "€€x",
+            "String \"€€x\" does not conform to the pattern \"€*\".");
 
     /* invalid length */
-    TEST_DATA("<str xmlns=\"urn:tests:types\">short</str>", LY_EVALID, "Length \"5\" does not satisfy the length constraint. /types:str");
-    TEST_DATA("<str xmlns=\"urn:tests:types\">tooooo long</str>", LY_EVALID, "Length \"11\" does not satisfy the length constraint. /types:str");
+    TEST_TYPE_ERROR("str", "short",
+            "Length \"5\" does not satisfy the length constraint.");
+    TEST_TYPE_ERROR("str", "tooooo long",
+            "Length \"11\" does not satisfy the length constraint.");
 
     /* invalid pattern */
-    TEST_DATA("<str xmlns=\"urn:tests:types\">string15</str>", LY_EVALID, "String \"string15\" does not conform to the pattern \"[a-z ]*\". /types:str");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("str", "string15", "String \"string15\" does not conform to the pattern \"[a-z ]*\".");
 }
 
 static void
 test_bits(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_bits;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
 
     /* valid data */
-    TEST_DATA("<bits xmlns=\"urn:tests:types\">\n two    \t\nzero\n  </bits>", LY_SUCCESS, "");
-    tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("bits", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("zero two", leaf->value.canonical);
-    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.bits_items));
-    assert_string_equal("zero", leaf->value.bits_items[0]->name);
-    assert_string_equal("two", leaf->value.bits_items[1]->name);
+    const char *bits_array[] = {"zero", "two"};
 
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_int_equal(2, LY_ARRAY_COUNT(value.bits_items));
-    assert_string_equal("zero", value.bits_items[0]->name);
-    assert_string_equal("two", value.bits_items[1]->name);
-    value.realtype->plugin->free(s->ctx, &value);
-    memset(&value, 0, sizeof value);
+    CHECK_PARSE_LYD("<bits xmlns=\"urn:tests:types\">\n two    \t\nzero\n  </bits>", tree);
+    assert_non_null(tree);
+    tree = tree->next;
+    TEST_PATTERN_1(tree, "bits", 1, BITS, "zero two", bits_array);
     lyd_free_all(tree);
 
-    TEST_DATA("<bits xmlns=\"urn:tests:types\">zero  two</bits>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<bits xmlns=\"urn:tests:types\">zero  two</bits>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("bits", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("zero two", leaf->value.canonical);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_int_equal(2, LY_ARRAY_COUNT(value.bits_items));
-    assert_string_equal("zero", value.bits_items[0]->name);
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PATTERN_1(tree, "bits", 1, BITS, "zero two", bits_array);
     lyd_free_all(tree);
 
     /* disabled feature */
-    TEST_DATA("<bits xmlns=\"urn:tests:types\"> \t one \n\t </bits>", LY_EVALID, "Bit \"one\" is disabled by its 1. if-feature condition. /types:bits");
+    TEST_TYPE_ERROR("bits", " \t one \n\t ", "Invalid bit value \"one\".");
+
+    /* disabled feature */
+    TEST_TYPE_ERROR("bits",  "\t one \n\t", "Invalid bit value \"one\".");
 
     /* multiple instances of the bit */
-    TEST_DATA("<bits xmlns=\"urn:tests:types\">one zero one</bits>", LY_EVALID, "Bit \"one\" used multiple times. /types:bits");
+    TEST_TYPE_ERROR("bits", "one zero one", "Invalid bit value \"one\".");
 
     /* invalid bit value */
-    TEST_DATA("<bits xmlns=\"urn:tests:types\">one xero one</bits>", LY_EVALID, "Invalid bit value \"xero\". /types:bits");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("bits", "one xero one", "Invalid bit value \"one\".");
 }
 
 static void
 test_enums(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_enums;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
 
     /* valid data */
-    TEST_DATA("<enums xmlns=\"urn:tests:types\">white</enums>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<enums xmlns=\"urn:tests:types\">white</enums>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("enums", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("white", leaf->value.canonical);
-    assert_string_equal("white", leaf->value.enum_item->name);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    assert_string_equal("white", value.enum_item->name);
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PATTERN_1(tree, "enums", 1, ENUM, "white", "white");
     lyd_free_all(tree);
 
     /* disabled feature */
-    TEST_DATA("<enums xmlns=\"urn:tests:types\">yellow</enums>", LY_EVALID,
-            "Enumeration \"yellow\" is disabled by its 1. if-feature condition. /types:enums");
+    TEST_TYPE_ERROR("enums", "yellow", "Invalid enumeration value \"yellow\".");
 
     /* leading/trailing whitespaces are not valid */
-    TEST_DATA("<enums xmlns=\"urn:tests:types\"> white</enums>", LY_EVALID, "Invalid enumeration value \" white\". /types:enums");
-    TEST_DATA("<enums xmlns=\"urn:tests:types\">white\n</enums>", LY_EVALID, "Invalid enumeration value \"white\n\". /types:enums");
+    TEST_TYPE_ERROR("enums", " white", "Invalid enumeration value \" white\".");
+    TEST_TYPE_ERROR("enums", "white\n", "Invalid enumeration value \"white\n\".");
 
     /* invalid enumeration value */
-    TEST_DATA("<enums xmlns=\"urn:tests:types\">black</enums>", LY_EVALID, "Invalid enumeration value \"black\". /types:enums");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("enums", "black", "Invalid enumeration value \"black\".");
 }
 
 static void
 test_binary(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_binary;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
 
     /* valid data (hello) */
-    TEST_DATA("<binary xmlns=\"urn:tests:types\">\n   aGVs\nbG8=  \t\n  </binary><binary-norestr xmlns=\"urn:tests:types\">TQ==</binary-norestr>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<binary xmlns=\"urn:tests:types\">\n   aGVs\nbG8=  \t\n  </binary>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("binary", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("aGVs\nbG8=", leaf->value.canonical);
-    assert_non_null(tree = tree->next);
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("binary-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("TQ==", leaf->value.canonical);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal(leaf->value.canonical, value.canonical);
-    value.realtype->plugin->free(s->ctx, &value);
-    memset(&value, 0, sizeof value);
+    TEST_PATTERN_1(tree, "binary", 1, BINARY, "aGVs\nbG8=");
+    lyd_free_all(tree);
+    CHECK_PARSE_LYD("<binary-norestr xmlns=\"urn:tests:types\">TQ==</binary-norestr>", tree);
+    assert_non_null(tree);
+    tree = tree->next;
+    assert_non_null(tree);
+    TEST_PATTERN_1(tree, "binary-norestr", 1, BINARY, "TQ==");
     lyd_free_all(tree);
 
     /* no data */
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\">\n    \t\n  </binary-norestr>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<binary-norestr xmlns=\"urn:tests:types\">\n    \t\n  </binary-norestr>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("binary-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("</binary-norestr>", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "binary-norestr", 1, BINARY, "</binary-norestr>");
     lyd_free_all(tree);
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\"></binary-norestr>", LY_SUCCESS, "");
+
+    CHECK_PARSE_LYD("<binary-norestr xmlns=\"urn:tests:types\"></binary-norestr>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("binary-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "binary-norestr", 1, BINARY, "");
     lyd_free_all(tree);
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\"/>", LY_SUCCESS, "");
+
+    CHECK_PARSE_LYD("<binary-norestr xmlns=\"urn:tests:types\"/>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("binary-norestr", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "binary-norestr", 1, BINARY, "");
     lyd_free_all(tree);
 
     /* invalid base64 character */
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\">a@bcd=</binary-norestr>", LY_EVALID,
-            "Invalid Base64 character (@). /types:binary-norestr");
+    TEST_TYPE_ERROR("binary-norestr", "a@bcd=", "Invalid Base64 character (@).");
 
     /* missing data */
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\">aGVsbG8</binary-norestr>", LY_EVALID,
-            "Base64 encoded value length must be divisible by 4. /types:binary-norestr");
-    TEST_DATA("<binary-norestr xmlns=\"urn:tests:types\">VsbG8=</binary-norestr>", LY_EVALID,
-            "Base64 encoded value length must be divisible by 4. /types:binary-norestr");
+    TEST_TYPE_ERROR("binary-norestr", "aGVsbG8", "Base64 encoded value length must be divisible by 4.");
+
+    TEST_TYPE_ERROR("binary-norestr", "VsbG8=", "Base64 encoded value length must be divisible by 4.");
 
     /* invalid binary length */
     /* helloworld */
-    TEST_DATA("<binary xmlns=\"urn:tests:types\">aGVsbG93b3JsZA==</binary>", LY_EVALID,
-            "This base64 value must be of length 5. /types:binary");
-    /* M */
-    TEST_DATA("<binary xmlns=\"urn:tests:types\">TQ==</binary>", LY_EVALID,
-            "This base64 value must be of length 5. /types:binary");
+    TEST_TYPE_ERROR("binary", "aGVsbG93b3JsZA==", "This base64 value must be of length 5.");
 
-    ly_in_free(in, 0);
-    s->func = NULL;
+    /* M */
+    TEST_TYPE_ERROR("binary", "TQ==", "This base64 value must be of length 5.");
 }
 
 static void
 test_boolean(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_boolean;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
 
     /* valid data */
-    TEST_DATA("<bool xmlns=\"urn:tests:types\">true</bool>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<bool xmlns=\"urn:tests:types\">true</bool>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("bool", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("true", leaf->value.canonical);
-    assert_int_equal(1, leaf->value.boolean);
+    TEST_PATTERN_1(tree, "bool", 1, BOOL, "true", 1);
     lyd_free_all(tree);
 
-    TEST_DATA("<bool xmlns=\"urn:tests:types\">false</bool>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<bool xmlns=\"urn:tests:types\">false</bool>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("bool", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("false", leaf->value.canonical);
-    assert_int_equal(0, leaf->value.boolean);
+    TEST_PATTERN_1(tree, "bool", 1, BOOL, "false", 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<tbool xmlns=\"urn:tests:types\">false</tbool>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<tbool xmlns=\"urn:tests:types\">false</tbool>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("tbool", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("false", leaf->value.canonical);
-    assert_int_equal(0, leaf->value.boolean);
+    TEST_PATTERN_1(tree, "tbool", 1, BOOL, "false", 0);
     lyd_free_all(tree);
 
     /* invalid value */
-    TEST_DATA("<bool xmlns=\"urn:tests:types\">unsure</bool>", LY_EVALID, "Invalid boolean value \"unsure\". /types:bool");
-    TEST_DATA("<bool xmlns=\"urn:tests:types\"> true</bool>", LY_EVALID, "Invalid boolean value \" true\". /types:bool");
+    TEST_TYPE_ERROR("bool", "unsure", "Invalid boolean value \"unsure\".");
 
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("bool", " true", "Invalid boolean value \" true\".");
 }
 
 static void
 test_empty(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_empty;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
-    struct lyd_node_term *leaf;
 
     /* valid data */
-
-    TEST_DATA("<empty xmlns=\"urn:tests:types\"></empty>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<empty xmlns=\"urn:tests:types\"></empty>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("empty", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "empty", 1, EMPTY, "");
     lyd_free_all(tree);
 
-    TEST_DATA("<empty xmlns=\"urn:tests:types\"/>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<empty xmlns=\"urn:tests:types\"/>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("empty", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "empty", 1, EMPTY, "");
     lyd_free_all(tree);
 
-    TEST_DATA("<tempty xmlns=\"urn:tests:types\"/>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<tempty xmlns=\"urn:tests:types\"/>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("tempty", tree->schema->name);
-    leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("", leaf->value.canonical);
+    TEST_PATTERN_1(tree, "tempty", 1, EMPTY, "");
     lyd_free_all(tree);
 
     /* invalid value */
-    TEST_DATA("<empty xmlns=\"urn:tests:types\">x</empty>", LY_EVALID, "Invalid empty value \"x\". /types:empty");
-    TEST_DATA("<empty xmlns=\"urn:tests:types\"> </empty>", LY_EVALID, "Invalid empty value \" \". /types:empty");
+    TEST_TYPE_ERROR("empty", "x", "Invalid empty value \"x\".");
 
-    ly_in_free(in, 0);
-    s->func = NULL;
-}
-
-static void
-test_printed_value(const struct lyd_value *value, const char *expected_value, LY_PREFIX_FORMAT format,
-        const void *prefix_data)
-{
-    const char *str;
-    uint8_t dynamic;
-
-    assert_non_null(str = value->realtype->plugin->print(value, format, (void *)prefix_data, &dynamic));
-    assert_string_equal(expected_value, str);
-    if (dynamic) {
-        free((char *)str);
-    }
+    TEST_TYPE_ERROR("empty", " ", "Invalid empty value \" \".");
 }
 
 static void
 test_identityref(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_identityref;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
+    const struct lys_module *mod_types;
+    const struct lys_module *mod_defs;
+
+    assert_non_null(mod_types = ly_ctx_get_module_implemented(UTEST_LYCTX, "types"));
+    assert_non_null(mod_defs = ly_ctx_get_module_implemented(UTEST_LYCTX, "defs"));
 
     /* valid data */
-    TEST_DATA("<ident xmlns=\"urn:tests:types\">gigabit-ethernet</ident>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<ident xmlns=\"urn:tests:types\">gigabit-ethernet</ident>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("ident", tree->schema->name);
+    TEST_PATTERN_1(tree, "ident", 1, IDENT, "types:gigabit-ethernet", "gigabit-ethernet");
     leaf = (struct lyd_node_term *)tree;
-    assert_non_null(leaf->value.canonical);
-    assert_string_equal("types:gigabit-ethernet", leaf->value.canonical);
-    assert_string_equal("gigabit-ethernet", leaf->value.ident->name);
-    test_printed_value(&leaf->value, "t:gigabit-ethernet", LY_PREF_SCHEMA, s->mod_types->parsed);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal("types:gigabit-ethernet", value.canonical);
-    assert_string_equal("gigabit-ethernet", value.ident->name);
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PRINTED_VALUE(&leaf->value, "t:gigabit-ethernet", LY_PREF_SCHEMA, mod_types->parsed);
     lyd_free_all(tree);
 
-    TEST_DATA("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:fast-ethernet</ident>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:fast-ethernet</ident>", tree);
+    assert_non_null(tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("ident", tree->schema->name);
+    TEST_PATTERN_1(tree, "ident", 1, IDENT, "defs:fast-ethernet", "fast-ethernet");
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("defs:fast-ethernet", leaf->value.canonical);
-    test_printed_value(&leaf->value, "d:fast-ethernet", LY_PREF_SCHEMA, s->mod_defs->parsed);
+    TEST_PRINTED_VALUE(&leaf->value, "d:fast-ethernet", LY_PREF_SCHEMA, mod_defs->parsed);
     lyd_free_all(tree);
 
     /* invalid value */
-    TEST_DATA("<ident xmlns=\"urn:tests:types\">fast-ethernet</ident>", LY_EVALID,
-            "Invalid identityref \"fast-ethernet\" value - identity not found. /types:ident");
-    TEST_DATA("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:slow-ethernet</ident>", LY_EVALID,
-            "Invalid identityref \"x:slow-ethernet\" value - identity not found. /types:ident");
-    TEST_DATA("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:crypto-alg</ident>", LY_EVALID,
-            "Invalid identityref \"x:crypto-alg\" value - identity not accepted by the type specification. /types:ident");
-    TEST_DATA("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:unknown\">x:fast-ethernet</ident>", LY_EVALID,
-            "Invalid identityref \"x:fast-ethernet\" value - unable to map prefix to YANG schema. /types:ident");
+    TEST_TYPE_ERROR("ident", "fast-ethernet",
+            "Invalid identityref \"fast-ethernet\" value - identity not found in module \"types\".");
 
-    ly_in_free(in, 0);
-    s->func = NULL;
+    CHECK_PARSE_LYD_PARAM("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:slow-ethernet</ident>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid identityref \"x:slow-ethernet\" value - identity not found in module \"defs\".",
+            "/types:ident");
+
+    CHECK_PARSE_LYD_PARAM("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:crypto-alg</ident>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid identityref \"x:crypto-alg\" value - identity not derived from the base \"defs:interface-type\".",
+            "/types:ident");
+
+    CHECK_PARSE_LYD_PARAM("<ident xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:unknown\">x:fast-ethernet</ident>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid identityref \"x:fast-ethernet\" value - unable to map prefix to YANG schema.",
+            "/types:ident");
 }
 
 /* dummy get_prefix callback for test_instanceid() */
@@ -705,281 +505,323 @@
 static void
 test_instanceid(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_instanceid;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
     const struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
+    const struct lys_module *mod_types;
     const char *data;
 
+    assert_non_null(mod_types = ly_ctx_get_module_implemented(UTEST_LYCTX, "types"));
+
     /* valid data */
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaftarget/></cont>"
-            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:cont/xdf:leaftarget</xdf:inst>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<cont xmlns=\"urn:tests:types\"><leaftarget/></cont>"
+            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:cont/xdf:leaftarget</xdf:inst>", tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:cont/leaftarget", leaf->value.canonical);
+    const enum ly_path_pred_type result_1[] = {LY_PATH_PREDTYPE_NONE, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:cont/leaftarget", result_1);
+    leaf = (struct lyd_node_term *)tree;
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x5, 1, "cont", 1, LYS_CONTAINER, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0, 0x5, 1, "leaftarget", 1, LYS_LEAF, 1, 0, NULL, 0);
+    lyd_free_all(tree);
+
+    CHECK_PARSE_LYD("<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id></list>"
+            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[xdf:id='b']/xdf:id</xdf:inst>", tree);
+    tree = tree->prev;
+    const enum ly_path_pred_type result_2[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list[id='b']/id", result_2);
+    leaf = (struct lyd_node_term *)tree;
     assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
-    assert_string_equal("cont", leaf->value.target[0].node->name);
-    assert_null(leaf->value.target[0].predicates);
-    assert_string_equal("leaftarget", leaf->value.target[1].node->name);
-    assert_null(leaf->value.target[1].predicates);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal("/types:cont/leaftarget", value.canonical);
-    assert_true(LY_ARRAY_COUNT(leaf->value.target) == LY_ARRAY_COUNT(value.target));
-    assert_true(leaf->value.target[0].node == value.target[0].node);
-    assert_true(leaf->value.target[0].predicates == value.target[0].predicates); /* NULL */
-    assert_true(leaf->value.target[1].node == value.target[1].node);
-    assert_true(leaf->value.target[1].predicates == value.target[1].predicates); /* NULL */
-    value.realtype->plugin->free(s->ctx, &value);
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0,  0x85, 1, "list", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0, 0x105, 1,   "id", 1, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id></list>"
-            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[xdf:id='b']/xdf:id</xdf:inst>", LY_SUCCESS, "");
+    CHECK_PARSE_LYD("<leaflisttarget xmlns=\"urn:tests:types\">1</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">2</leaflisttarget>"
+            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:leaflisttarget[.='1']</xdf:inst>", tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:list[id='b']/id", leaf->value.canonical);
+    const enum ly_path_pred_type result_3[] = {LY_PATH_PREDTYPE_LEAFLIST};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:leaflisttarget[.='1']", result_3);
+    leaf = (struct lyd_node_term *)tree;
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "leaflisttarget", 1, LYS_LEAFLIST, 0, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">1</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">2</leaflisttarget>"
-            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:leaflisttarget[.='1']</xdf:inst>", LY_SUCCESS, "");
-    tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:leaflisttarget[.='1']", leaf->value.canonical);
-    lyd_free_all(tree);
-
-    TEST_DATA("<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='a']</id><value>x</value></list_inst>"
+    data = "<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='a']</id><value>x</value></list_inst>"
             "<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='b']</id><value>y</value></list_inst>"
             "<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list_inst[a:id=\"/a:leaflisttarget[.='b']\"]/a:value</a:inst>", LY_SUCCESS, "");
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list_inst[a:id=\"/a:leaflisttarget[.='b']\"]/a:value</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:list_inst[id=\"/types:leaflisttarget[.='b']\"]/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_4[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list_inst[id=\"/types:leaflisttarget[.='b']\"]/value", result_4);
+    leaf = (struct lyd_node_term *)tree;
     assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
-    assert_string_equal("list_inst", leaf->value.target[0].node->name);
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list_inst", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0,  0x5, 1, "value",     0, LYS_LEAF, 1, 0, NULL, 0);
+
     assert_int_equal(1, LY_ARRAY_COUNT(leaf->value.target[0].predicates));
-    assert_string_equal("value", leaf->value.target[1].node->name);
     assert_null(leaf->value.target[1].predicates);
-
-    test_printed_value(&leaf->value, "/t:list_inst[t:id=\"/t:leaflisttarget[.='b']\"]/t:value", LY_PREF_SCHEMA, s->mod_types->parsed);
-    test_printed_value(&leaf->value, "/types:list_inst[id=\"/types:leaflisttarget[.='b']\"]/value", LY_PREF_JSON, NULL);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal("/types:list_inst[id=\"/types:leaflisttarget[.='b']\"]/value", value.canonical);
-    assert_true(LY_ARRAY_COUNT(leaf->value.target) == LY_ARRAY_COUNT(value.target));
-    assert_true(leaf->value.target[0].node == value.target[0].node);
-    assert_true(LY_ARRAY_COUNT(leaf->value.target[0].predicates) == LY_ARRAY_COUNT(value.target[0].predicates));
-    assert_true(leaf->value.target[1].node == value.target[1].node);
-    assert_true(leaf->value.target[1].predicates == value.target[1].predicates); /* NULL */
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PRINTED_VALUE(&leaf->value, "/t:list_inst[t:id=\"/t:leaflisttarget[.='b']\"]/t:value", LY_PREF_SCHEMA, mod_types->parsed);
+    TEST_PRINTED_VALUE(&leaf->value, "/types:list_inst[id=\"/types:leaflisttarget[.='b']\"]/value", LY_PREF_JSON, NULL);
     lyd_free_all(tree);
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id><value>x</value></list>"
-            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[xdf:id='b']/xdf:value</xdf:inst>", LY_SUCCESS, "");
+    data = "<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id><value>x</value></list>"
+            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[xdf:id='b']/xdf:value</xdf:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:list[id='b']/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_5[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list[id='b']/value", result_5);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1,  "list", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0,  0x5, 1, "value", 1, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='a']</id><value>x</value></list_inst>"
+    data = "<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='a']</id><value>x</value></list_inst>"
             "<list_inst xmlns=\"urn:tests:types\"><id xmlns:b=\"urn:tests:types\">/b:leaflisttarget[.='b']</id><value>y</value></list_inst>"
             "<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list_inst[a:id=\"/a:leaflisttarget[.='a']\"]/a:value</a:inst>", LY_SUCCESS, "");
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list_inst[a:id=\"/a:leaflisttarget[.='a']\"]/a:value</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_string_equal("/types:list_inst[id=\"/types:leaflisttarget[.='a']\"]/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_6[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list_inst[id=\"/types:leaflisttarget[.='a']\"]/value", result_6);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list_inst", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0,  0x5, 1, "value", 0, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list_ident xmlns=\"urn:tests:types\"><id xmlns:dfs=\"urn:tests:defs\">dfs:ethernet</id><value>x</value></list_ident>"
+    data = "<list_ident xmlns=\"urn:tests:types\"><id xmlns:dfs=\"urn:tests:defs\">dfs:ethernet</id><value>x</value></list_ident>"
             "<list_ident xmlns=\"urn:tests:types\"><id xmlns:dfs=\"urn:tests:defs\">dfs:fast-ethernet</id><value>y</value></list_ident>"
-            "<a:inst xmlns:a=\"urn:tests:types\" xmlns:d=\"urn:tests:defs\">/a:list_ident[a:id='d:fast-ethernet']/a:value</a:inst>", LY_SUCCESS, "");
+            "<a:inst xmlns:a=\"urn:tests:types\" xmlns:d=\"urn:tests:defs\">/a:list_ident[a:id='d:fast-ethernet']/a:value</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_non_null(leaf->value.canonical);
-    assert_string_equal("/types:list_ident[id='defs:fast-ethernet']/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_7[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list_ident[id='defs:fast-ethernet']/value", result_7);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list_ident", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0,  0x5, 1, "value", 0, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list2 xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list2>"
+    data = "<list2 xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list2>"
             "<list2 xmlns=\"urn:tests:types\"><id>a:xxx</id><value>y</value></list2>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a:xxx'][a:value='y']/a:value</a:inst>", LY_SUCCESS, "");
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a:xxx'][a:value='y']/a:value</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_non_null(leaf->value.canonical);
-    assert_string_equal("/types:list2[id='a:xxx'][value='y']/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_8[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list2[id='a:xxx'][value='y']/value", result_8);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list2", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0, 0x105, 1, "value", 0, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list>"
+    data = "<list xmlns=\"urn:tests:types\"><id>types:xxx</id><value>x</value></list>"
             "<list xmlns=\"urn:tests:types\"><id>a:xxx</id><value>y</value></list>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list[a:id='a:xxx']/a:value</a:inst>", LY_SUCCESS, "");
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list[a:id='a:xxx']/a:value</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("inst", tree->schema->name);
-    leaf = (const struct lyd_node_term *)tree;
-    assert_non_null(leaf->value.canonical);
-    assert_string_equal("/types:list[id='a:xxx']/value", leaf->value.canonical);
+    const enum ly_path_pred_type result_9[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list[id='a:xxx']/value", result_9);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0, 0x5, 1, "value", 1, LYS_LEAF, 1, 0, NULL, 0);
     lyd_free_all(tree);
 
-    TEST_DATA("<list2 xmlns=\"urn:tests:types\"><id>a</id><value>a</value></list2>"
+    data = "<list2 xmlns=\"urn:tests:types\"><id>a</id><value>a</value></list2>"
             "<list2 xmlns=\"urn:tests:types\"><id>c</id><value>b</value></list2>"
             "<list2 xmlns=\"urn:tests:types\"><id>a</id><value>b</value></list2>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a'][a:value='b']/a:id</a:inst>", LY_SUCCESS, "");
-    leaf = (const struct lyd_node_term *)tree->prev;
-    assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
-    assert_string_equal("inst", leaf->schema->name);
-    assert_non_null(leaf->value.canonical);
-    assert_string_equal("/types:list2[id='a'][value='b']/id", leaf->value.canonical);
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a'][a:value='b']/a:id</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
+    tree = tree->prev;
+    const enum ly_path_pred_type result_10[] = {LY_PATH_PREDTYPE_LIST, LY_PATH_PREDTYPE_NONE};
+
+    TEST_PATTERN_1(tree, "inst", 1, INST, "/types:list2[id='a'][value='b']/id", result_10);
+    leaf = (struct lyd_node_term *)tree;
+    assert_int_equal(2, LY_ARRAY_COUNT(leaf->value.target));
+    CHECK_LYSC_NODE(leaf->value.target[0].node, NULL, 0, 0x85, 1, "list2", 1, LYS_LIST, 0, 0, NULL, 0);
+    CHECK_LYSC_NODE(leaf->value.target[1].node, NULL, 0, 0x105, 1,  "id", 1, LYS_LEAF, 1, 0, NULL, 0);
     assert_non_null(leaf = lyd_target(leaf->value.target, tree));
     assert_string_equal("a", leaf->value.canonical);
     assert_string_equal("b", ((struct lyd_node_term *)leaf->next)->value.canonical);
     lyd_free_all(tree);
 
     /* invalid value */
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>a</id></list><list xmlns=\"urn:tests:types\"><id>b</id><value>x</value></list>"
-            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[2]/xdf:value</xdf:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error. /types:inst");
-    TEST_DATA("<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:1leaftarget</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:1leaftarget\" value - syntax error. /types:inst");
-    TEST_DATA("<t:inst xmlns:t=\"urn:tests:types\">/t:cont:t:1leaftarget</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont:t:1leaftarget\" value - syntax error. /types:inst");
-    TEST_DATA("<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:invalid/t:path</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:invalid/t:path\" value - semantic error. /types:inst");
-    TEST_DATA("<inst xmlns=\"urn:tests:types\" xmlns:t=\"urn:tests:invalid\">/t:cont/t:leaftarget</inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaftarget\" value - semantic error. /types:inst");
-    TEST_DATA("<inst xmlns=\"urn:tests:types\">/cont/leaftarget</inst>", LY_EVALID,
-            "Invalid instance-identifier \"/cont/leaftarget\" value - syntax error. /types:inst");
+    data = "<list xmlns=\"urn:tests:types\"><id>a</id></list>"
+            "<list xmlns=\"urn:tests:types\"><id>b</id><value>x</value></list>"
+            "<xdf:inst xmlns:xdf=\"urn:tests:types\">/xdf:list[2]/xdf:value</xdf:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error.", "/types:inst");
+
+    data = "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:1leaftarget</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:1leaftarget\" value - syntax error.", "/types:inst");
+
+    data = "<t:inst xmlns:t=\"urn:tests:types\">/t:cont:t:1leaftarget</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont:t:1leaftarget\" value - syntax error.", "/types:inst");
+
+    data = "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:invalid/t:path</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:invalid/t:path\" value - semantic error.", "/types:inst");
+
+    data = "<inst xmlns=\"urn:tests:types\" xmlns:t=\"urn:tests:invalid\">/t:cont/t:leaftarget</inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaftarget\" value - semantic error.", "/types:inst");
+
+    TEST_TYPE_ERROR("inst", "/cont/leaftarget", "Invalid instance-identifier \"/cont/leaftarget\" value - syntax error.");
 
     /* instance-identifier is here in JSON format because it is already in internal representation without canonical prefixes */
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaftarget</t:inst>", LY_ENOTFOUND,
-            "Invalid instance-identifier \"/types:cont/leaftarget\" value - required instance not found. /types:inst");
+    data = "<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaftarget</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_ENOTFOUND, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:cont/leaftarget\" value - required instance not found.", "/types:inst");
 
     /* instance-identifier is here in JSON format because it is already in internal representation without canonical prefixes */
-    TEST_DATA("<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaftarget</t:inst>", LY_ENOTFOUND,
-            "Invalid instance-identifier \"/types:cont/leaftarget\" value - required instance not found. /types:inst");
+    data = "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaftarget</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_ENOTFOUND, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:cont/leaftarget\" value - required instance not found.", "/types:inst");
 
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><t:inst xmlns:t=\"urn:tests:types\">/t:leaflisttarget[1</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:leaflisttarget[1\" value - syntax error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">/t:cont[1]</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont[1]\" value - semantic error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">[1]</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"[1]\" value - syntax error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont><t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[id='1']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaflisttarget[id='1']\" value - syntax error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[t:id='1']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaflisttarget[t:id='1']\" value - semantic error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget><leaflisttarget>2</leaflisttarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[4]</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaflisttarget[4]\" value - semantic error. /types:inst");
-    TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[6]</t:inst-noreq>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaflisttarget[6]\" value - semantic error. /types:inst-noreq");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:value='x']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:listtarget[t:value='x']\" value - semantic error. /types:inst");
-    logbuf_clean();
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:leaflisttarget[1</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:leaflisttarget[1\" value - syntax error.", "/types:inst");
 
-    TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:value='x']</t:inst-noreq>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:listtarget[t:value='x']\" value - semantic error. /types:inst-noreq");
-    TEST_DATA("<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:x='x']</t:inst-noreq>", LY_ENOTFOUND,
-            "Invalid instance-identifier \"/t:cont/t:listtarget[t:x='x']\" value - semantic error. /types:inst-noreq");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[.='x']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:listtarget[.='x']\" value - semantic error. /types:inst");
+    data = "<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">/t:cont[1]</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont[1]\" value - semantic error.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"/><t:inst xmlns:t=\"urn:tests:types\">[1]</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[id='1']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaflisttarget[id='1']\" value - syntax error.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[t:id='1']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaflisttarget[t:id='1']\" value - semantic error.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget><leaflisttarget>2</leaflisttarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[4]</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaflisttarget[4]\" value - semantic error.", "/types:inst");
+
+    data = "<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[6]</t:inst-noreq>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaflisttarget[6]\" value - semantic error.", "/types:inst-noreq");
+
+    data = "<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:value='x']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:listtarget[t:value='x']\" value - semantic error.", "/types:inst");
+
+    data = "<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:value='x']</t:inst-noreq>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:listtarget[t:value='x']\" value - semantic error.", "/types:inst-noreq");
+
+    data = "<t:inst-noreq xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:x='x']</t:inst-noreq>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_ENOTFOUND, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:listtarget[t:x='x']\" value - semantic error.", "/types:inst-noreq");
+
+    data = "<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[.='x']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:listtarget[.='x']\" value - semantic error.", "/types:inst");
 
     /* instance-identifier is here in JSON format because it is already in internal representation without canonical prefixes */
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[.='2']</t:inst>", LY_ENOTFOUND,
-            "Invalid instance-identifier \"/types:cont/leaflisttarget[.='2']\" value - required instance not found. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[.='x']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:leaflisttarget[.='x']\" value - semantic error. /types:inst");
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:id='x']</t:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/t:cont/t:listtarget[t:id='x']\" value - semantic error. /types:inst");
+    data = "<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[.='2']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_ENOTFOUND, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:cont/leaflisttarget[.='2']\" value - required instance not found.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"><leaflisttarget>1</leaflisttarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:leaflisttarget[.='x']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:leaflisttarget[.='x']\" value - semantic error.", "/types:inst");
+
+    data = "<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:id='x']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:listtarget[t:id='x']\" value - semantic error.", "/types:inst");
 
     /* instance-identifier is here in JSON format because it is already in internal representation without canonical prefixes */
-    TEST_DATA("<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
-            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:id='2']</t:inst>", LY_ENOTFOUND,
-            "Invalid instance-identifier \"/types:cont/listtarget[id='2']\" value - required instance not found. /types:inst");
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget>"
+    data = "<cont xmlns=\"urn:tests:types\"><listtarget><id>1</id><value>x</value></listtarget></cont>"
+            "<t:inst xmlns:t=\"urn:tests:types\">/t:cont/t:listtarget[t:id='2']</t:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_ENOTFOUND, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:cont/listtarget[id='2']\" value - required instance not found.", "/types:inst");
+
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget>"
             "<leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:leaflisttarget[1][2]</a:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/a:leaflisttarget[1][2]\" value - syntax error. /types:inst");
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget>"
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:leaflisttarget[1][2]</a:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/a:leaflisttarget[1][2]\" value - syntax error.", "/types:inst");
+
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget>"
             "<leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:leaflisttarget[.='a'][.='b']</a:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/a:leaflisttarget[.='a'][.='b']\" value - syntax error. /types:inst");
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>a</id><value>x</value></list>"
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:leaflisttarget[.='a'][.='b']</a:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/a:leaflisttarget[.='a'][.='b']\" value - syntax error.", "/types:inst");
+
+    data = "<list xmlns=\"urn:tests:types\"><id>a</id><value>x</value></list>"
             "<list xmlns=\"urn:tests:types\"><id>b</id><value>y</value></list>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list[a:id='a'][a:id='b']/a:value</a:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/a:list[a:id='a'][a:id='b']/a:value\" value - syntax error. /types:inst");
-    TEST_DATA("<list2 xmlns=\"urn:tests:types\"><id>a</id><value>x</value></list2>"
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list[a:id='a'][a:id='b']/a:value</a:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/a:list[a:id='a'][a:id='b']/a:value\" value - syntax error.", "/types:inst");
+
+    data = "<list2 xmlns=\"urn:tests:types\"><id>a</id><value>x</value></list2>"
             "<list2 xmlns=\"urn:tests:types\"><id>b</id><value>y</value></list2>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a']/a:value</a:inst>", LY_EVALID,
-            "Invalid instance-identifier \"/a:list2[a:id='a']/a:value\" value - semantic error. /types:inst");
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a']/a:value</a:inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/a:list2[a:id='a']/a:value\" value - semantic error.", "/types:inst");
 
     /* check for validting instance-identifier with a complete data tree */
-    TEST_DATA("<list2 xmlns=\"urn:tests:types\"><id>a</id><value>a</value></list2>"
+    data = "<list2 xmlns=\"urn:tests:types\"><id>a</id><value>a</value></list2>"
             "<list2 xmlns=\"urn:tests:types\"><id>c</id><value>b</value></list2>"
             "<leaflisttarget xmlns=\"urn:tests:types\">a</leaflisttarget>"
             "<leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a'][a:value='a']/a:id</a:inst>", LY_SUCCESS, "");
-
+            "<a:inst xmlns:a=\"urn:tests:types\">/a:list2[a:id='a'][a:value='a']/a:id</a:inst>";
+    CHECK_PARSE_LYD(data, tree);
     /* key-predicate */
     data = "/types:list2[id='a'][value='b']/id";
-    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term *)tree->prev, data, strlen(data),
+    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(UTEST_LYCTX, (const struct lyd_node_term *)tree->prev, data, strlen(data),
             tree, NULL));
-    logbuf_assert("Invalid instance-identifier \"/types:list2[id='a'][value='b']/id\" value - required instance not found. /types:inst");
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:list2[id='a'][value='b']/id\" value - required instance not found.", "/types:inst");
     /* leaf-list-predicate */
     data = "/types:leaflisttarget[.='c']";
-    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term *)tree->prev, data, strlen(data),
+    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(UTEST_LYCTX, (const struct lyd_node_term *)tree->prev, data, strlen(data),
             tree, NULL));
-    logbuf_assert("Invalid instance-identifier \"/types:leaflisttarget[.='c']\" value - required instance not found. /types:inst");
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:leaflisttarget[.='c']\" value - required instance not found.", "/types:inst");
     /* position predicate */
     data = "/types:list_keyless[4]";
-    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(s->ctx, (const struct lyd_node_term *)tree->prev, data, strlen(data),
+    assert_int_equal(LY_ENOTFOUND, lyd_value_validate(UTEST_LYCTX, (const struct lyd_node_term *)tree->prev, data, strlen(data),
             tree, NULL));
-    logbuf_assert("Invalid instance-identifier \"/types:list_keyless[4]\" value - required instance not found. /types:inst");
+    CHECK_LOG_CTX("Invalid instance-identifier \"/types:list_keyless[4]\" value - required instance not found.", "/types:inst");
 
     lyd_free_all(tree);
 
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
-            "<inst xmlns=\"urn:tests:types\">/a:leaflisttarget[1]</inst>", LY_EVALID,
-            "Invalid instance-identifier \"/a:leaflisttarget[1]\" value - semantic error. /types:inst");
-
-    ly_in_free(in, 0);
-
-    s->func = NULL;
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">b</leaflisttarget>"
+            "<inst xmlns=\"urn:tests:types\">/a:leaflisttarget[1]</inst>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid instance-identifier \"/a:leaflisttarget[1]\" value - semantic error.", "/types:inst");
 }
 
 static void
 test_leafref(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_leafref;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
+    const char *data;
 
     /* types:lref: /leaflisttarget */
     /* types:lref2: ../list[id = current()/../str-norestr]/targets */
@@ -992,100 +834,112 @@
             "}}}";
 
     /* additional schema */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, schema, LYS_IN_YANG, NULL));
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
 
     /* valid data */
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget><lref xmlns=\"urn:tests:types\">y</lref>", LY_SUCCESS, "");
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget>"
+            "<leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
+            "<lref xmlns=\"urn:tests:types\">y</lref>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("lref", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "lref", 1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("y", leaf->value.canonical);
-    assert_int_equal(LY_TYPE_STRING, leaf->value.realtype->plugin->type);
+    CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 0, 1, STRING, "y");
     lyd_free_all(tree);
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
+    data = "<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
             "<list xmlns=\"urn:tests:types\"><id>y</id><targets>x</targets><targets>y</targets></list>"
-            "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">y</lref2>", LY_SUCCESS, "");
+            "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">y</lref2>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("lref2", tree->schema->name);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "lref2", 1, LYS_LEAF, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("y", leaf->value.canonical);
+    CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 0, 1, STRING, "y");
     lyd_free_all(tree);
 
-    TEST_DATA("<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
-            "<c xmlns=\"urn:tests:leafrefs\"><l><id>x</id><value>x</value><lr1>y</lr1></l></c>", LY_SUCCESS, "");
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
+    data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
+            "<c xmlns=\"urn:tests:leafrefs\"><l><id>x</id><value>x</value><lr1>y</lr1></l></c>";
+    CHECK_PARSE_LYD(data, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "c", 0, LYS_CONTAINER, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)(lyd_child(lyd_child(tree)->next)->prev);
-    assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
-    assert_string_equal("lr1", leaf->schema->name);
-    assert_string_equal("y", leaf->value.canonical);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, 0x5, 1, "lr1", 1, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 1, 1, STRING, "y");
     lyd_free_all(tree);
 
-    TEST_DATA("<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
+    data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
             "<c xmlns=\"urn:tests:leafrefs\"><l><id>y</id><value>y</value></l>"
-            "<l><id>x</id><value>x</value><lr2>y</lr2></l></c>", LY_SUCCESS, "");
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
+            "<l><id>x</id><value>x</value><lr2>y</lr2></l></c>";
+    CHECK_PARSE_LYD(data, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "c", 0, LYS_CONTAINER, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)(lyd_child(lyd_child(tree)->prev)->prev);
-    assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
-    assert_string_equal("lr2", leaf->schema->name);
-    assert_string_equal("y", leaf->value.canonical);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, 0x5, 1, "lr2", 1, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 1, 1, STRING, "y");
     lyd_free_all(tree);
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
+    data = "<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
             "<list xmlns=\"urn:tests:types\"><id>y</id><targets>c</targets><targets>d</targets></list>"
             "<c xmlns=\"urn:tests:leafrefs\"><x><x>y</x></x>"
-            "<l><id>x</id><value>x</value><lr3>c</lr3></l></c>", LY_SUCCESS, "");
-    assert_int_equal(LYS_CONTAINER, tree->schema->nodetype);
+            "<l><id>x</id><value>x</value><lr3>c</lr3></l></c>";
+    CHECK_PARSE_LYD(data, tree);
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, 0x5, 1, "c", 0, LYS_CONTAINER, 0, 0, NULL, 0);
     leaf = (struct lyd_node_term *)(lyd_child(lyd_child(tree)->prev)->prev);
-    assert_int_equal(LYS_LEAF, leaf->schema->nodetype);
-    assert_string_equal("lr3", leaf->schema->name);
-    assert_string_equal("c", leaf->value.canonical);
+    CHECK_LYSC_NODE(leaf->schema, NULL, 0, 0x5, 1, "lr3", 0, LYS_LEAF, 1, 0, NULL, 0);
+    CHECK_LYD_NODE_TERM(leaf, 0, 0, 0, 1, 1, STRING, "c");
     lyd_free_all(tree);
 
     /* invalid value */
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><lref xmlns=\"urn:tests:types\">y</lref>", LY_EVALID,
-            "Invalid leafref value \"y\" - no target instance \"/leaflisttarget\" with the same value. /types:lref");
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><lref xmlns=\"urn:tests:types\">y</lref>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"y\" - "
+            "no target instance \"/leaflisttarget\" with the same value.",
+            "/types:lref");
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
+    data = "<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
             "<list xmlns=\"urn:tests:types\"><id>y</id><targets>x</targets><targets>y</targets></list>"
-            "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">b</lref2>", LY_EVALID,
-            "Invalid leafref value \"b\" - no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value. /types:lref2");
+            "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">b</lref2>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"b\" - "
+            "no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value.",
+            "/types:lref2");
 
-    TEST_DATA("<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
+    data = "<list xmlns=\"urn:tests:types\"><id>x</id><targets>a</targets><targets>b</targets></list>"
             "<list xmlns=\"urn:tests:types\"><id>y</id><targets>x</targets><targets>y</targets></list>"
-            "<lref2 xmlns=\"urn:tests:types\">b</lref2>", LY_EVALID,
-            "Invalid leafref value \"b\" - no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value. /types:lref2");
+            "<lref2 xmlns=\"urn:tests:types\">b</lref2>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"b\" - "
+            "no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value.",
+            "/types:lref2");
 
-    TEST_DATA("<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">b</lref2>", LY_EVALID,
-            "Invalid leafref value \"b\" - no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value. /types:lref2");
+    data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr><lref2 xmlns=\"urn:tests:types\">b</lref2>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"b\" - "
+            "no target instance \"../list[id = current()/../str-norestr]/targets\" with the same value.",
+            "/types:lref2");
 
-    TEST_DATA("<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
-            "<c xmlns=\"urn:tests:leafrefs\"><l><id>x</id><value>x</value><lr1>a</lr1></l></c>", LY_EVALID,
-            "Invalid leafref value \"a\" - no target instance \"../../../t:str-norestr\" with the same value. /leafrefs:c/l[id='x'][value='x']/lr1");
+    data = "<str-norestr xmlns=\"urn:tests:types\">y</str-norestr>"
+            "<c xmlns=\"urn:tests:leafrefs\"><l><id>x</id><value>x</value><lr1>a</lr1></l></c>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"a\" - no target instance \"../../../t:str-norestr\" with the same value.",
+            "/leafrefs:c/l[id='x'][value='x']/lr1");
 
-    TEST_DATA("<str-norestr xmlns=\"urn:tests:types\">z</str-norestr>"
+    data = "<str-norestr xmlns=\"urn:tests:types\">z</str-norestr>"
             "<c xmlns=\"urn:tests:leafrefs\"><l><id>y</id><value>y</value></l>"
-            "<l><id>x</id><value>x</value><lr2>z</lr2></l></c>", LY_EVALID,
-            "Invalid leafref value \"z\" - no target instance \"../../l[id=current()/../../../t:str-norestr]"
-            "[value=current()/../../../t:str-norestr]/value\" with the same value. /leafrefs:c/l[id='x'][value='x']/lr2");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+            "<l><id>x</id><value>x</value><lr2>z</lr2></l></c>";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid leafref value \"z\" - no target instance \"../../l[id=current()/../../../t:str-norestr]"
+            "[value=current()/../../../t:str-norestr]/value\" with the same value.",
+            "/leafrefs:c/l[id='x'][value='x']/lr2");
 }
 
 static void
 test_union(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_union;
-
-    struct ly_in *in = NULL;
     struct lyd_node *tree;
     struct lyd_node_term *leaf;
-    struct lyd_value value = {0};
+    const char *data;
+    const struct lys_module *mod_defs;
+
+    assert_non_null(mod_defs = ly_ctx_get_module_implemented(UTEST_LYCTX, "defs"));
 
     /*
      * leaf un1 {type union {
@@ -1100,133 +954,84 @@
      */
 
     /* valid data */
-    TEST_DATA("<int8 xmlns=\"urn:tests:types\">12</int8><un1 xmlns=\"urn:tests:types\">12</un1>", LY_SUCCESS, "");
+    data = "<int8 xmlns=\"urn:tests:types\">12</int8><un1 xmlns=\"urn:tests:types\">12</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->next->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "12", INT8, "12", 12);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("12", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 0);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_INT8, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("12", leaf->value.subvalue->value.canonical);
-    assert_int_equal(12, leaf->value.subvalue->value.int8);
-
-    test_printed_value(&leaf->value, "12", LY_PREF_SCHEMA, NULL);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal("12", value.canonical);
-    assert_non_null(value.subvalue->prefix_data);
-    assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 0);
-    assert_int_equal(LY_TYPE_INT8, value.subvalue->value.realtype->basetype);
-    assert_string_equal("12", value.subvalue->value.canonical);
-    assert_int_equal(12, leaf->value.subvalue->value.int8);
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PRINTED_VALUE(&leaf->value, "12", LY_PREF_SCHEMA, NULL);
     lyd_free_all(tree);
 
-    TEST_DATA("<int8 xmlns=\"urn:tests:types\">12</int8><un1 xmlns=\"urn:tests:types\">2</un1>", LY_SUCCESS, "");
+    data = "<int8 xmlns=\"urn:tests:types\">12</int8><un1 xmlns=\"urn:tests:types\">2</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->next->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "2", STRING, "2");
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("2", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 0);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("2", leaf->value.subvalue->value.canonical);
+    TEST_PRINTED_VALUE(&leaf->value, "2", LY_PREF_SCHEMA, NULL);
     lyd_free_all(tree);
 
-    TEST_DATA("<un1 xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:fast-ethernet</un1>", LY_SUCCESS, "");
+    data = "<un1 xmlns=\"urn:tests:types\" xmlns:x=\"urn:tests:defs\">x:fast-ethernet</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "defs:fast-ethernet", IDENT, "defs:fast-ethernet", "fast-ethernet");
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("defs:fast-ethernet", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 1);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_IDENT, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("defs:fast-ethernet", leaf->value.subvalue->value.canonical);
-
-    test_printed_value(&leaf->value, "d:fast-ethernet", LY_PREF_SCHEMA, s->mod_defs->parsed);
-    test_printed_value(&leaf->value.subvalue->value, "d:fast-ethernet", LY_PREF_SCHEMA, s->mod_defs->parsed);
-
-    assert_int_equal(LY_SUCCESS, leaf->value.realtype->plugin->duplicate(s->ctx, &leaf->value, &value));
-    assert_string_equal("defs:fast-ethernet", value.canonical);
-    assert_string_equal("defs:fast-ethernet", value.subvalue->value.canonical);
-    assert_non_null(value.subvalue->prefix_data);
-    assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 1);
-    assert_int_equal(LY_TYPE_IDENT, value.subvalue->value.realtype->basetype);
-    assert_string_equal("fast-ethernet", value.subvalue->value.ident->name);
-    value.realtype->plugin->free(s->ctx, &value);
+    TEST_PRINTED_VALUE(&leaf->value, "d:fast-ethernet", LY_PREF_SCHEMA, mod_defs->parsed);
+    TEST_PRINTED_VALUE(&leaf->value.subvalue->value, "d:fast-ethernet", LY_PREF_SCHEMA, mod_defs->parsed);
     lyd_free_all(tree);
 
-    TEST_DATA("<un1 xmlns=\"urn:tests:types\" xmlns:d=\"urn:tests:defs\">d:superfast-ethernet</un1>", LY_SUCCESS, "");
+    data = "<un1 xmlns=\"urn:tests:types\" xmlns:d=\"urn:tests:defs\">d:superfast-ethernet</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->next;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "d:superfast-ethernet", STRING, "d:superfast-ethernet");
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("d:superfast-ethernet", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 1);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("d:superfast-ethernet", leaf->value.subvalue->value.canonical);
     lyd_free_all(tree);
 
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
-            "<un1 xmlns=\"urn:tests:types\" xmlns:a=\"urn:tests:types\">/a:leaflisttarget[.='y']</un1>", LY_SUCCESS, "");
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
+            "<un1 xmlns=\"urn:tests:types\" xmlns:a=\"urn:tests:types\">/a:leaflisttarget[.='y']</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    const enum ly_path_pred_type result_1[] = {LY_PATH_PREDTYPE_LEAFLIST};
+
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "/types:leaflisttarget[.='y']", INST, "/types:leaflisttarget[.='y']", result_1);
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("/types:leaflisttarget[.='y']", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
+
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 1);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_INST, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("/types:leaflisttarget[.='y']", leaf->value.subvalue->value.canonical);
     lyd_free_all(tree);
 
-    TEST_DATA("<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
-            "<un1 xmlns=\"urn:tests:types\" xmlns:a=\"urn:tests:types\">/a:leaflisttarget[3]</un1>", LY_SUCCESS, "");
+    data = "<leaflisttarget xmlns=\"urn:tests:types\">x</leaflisttarget><leaflisttarget xmlns=\"urn:tests:types\">y</leaflisttarget>"
+            "<un1 xmlns=\"urn:tests:types\" xmlns:a=\"urn:tests:types\">/a:leaflisttarget[3]</un1>";
+    CHECK_PARSE_LYD(data, tree);
     tree = tree->prev;
-    assert_int_equal(LYS_LEAF, tree->schema->nodetype);
-    assert_string_equal("un1", tree->schema->name);
+    TEST_PATTERN_1(tree, "un1", 0, UNION, "/a:leaflisttarget[3]", STRING, "/a:leaflisttarget[3]");
     leaf = (struct lyd_node_term *)tree;
-    assert_string_equal("/a:leaflisttarget[3]", leaf->value.canonical);
-    assert_non_null(leaf->value.subvalue->prefix_data);
     assert_int_equal(((struct ly_set *)leaf->value.subvalue->prefix_data)->count, 1);
-    assert_int_equal(LY_TYPE_UNION, leaf->value.realtype->basetype);
-    assert_int_equal(LY_TYPE_STRING, leaf->value.subvalue->value.realtype->basetype);
-    assert_string_equal("/a:leaflisttarget[3]", leaf->value.subvalue->value.canonical);
     lyd_free_all(tree);
 
-    TEST_DATA("<un1 xmlns=\"urn:tests:types\">123456789012345678901</un1>", LY_EVALID, "Invalid union value \"123456789012345678901\" - no matching subtype found. /types:un1");
-
-    ly_in_free(in, 0);
-    s->func = NULL;
+    TEST_TYPE_ERROR("un1", "123456789012345678901",
+            "Invalid union value \"123456789012345678901\" - no matching subtype found.");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_int, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_uint, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_dec64, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_string, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_bits, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_enums, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_binary, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_boolean, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_empty, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_identityref, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_instanceid, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_leafref, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_union, setup, teardown),
+        UTEST(test_int, setup),
+        UTEST(test_uint, setup),
+        UTEST(test_dec64, setup),
+        UTEST(test_string, setup),
+        UTEST(test_bits, setup),
+        UTEST(test_enums, setup),
+        UTEST(test_binary, setup),
+        UTEST(test_boolean, setup),
+        UTEST(test_empty, setup),
+        UTEST(test_identityref, setup),
+        UTEST(test_instanceid, setup),
+        UTEST(test_leafref, setup),
+        UTEST(test_union, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c
index 2e8bf5f..c29ac4d 100644
--- a/tests/utests/data/test_validation.c
+++ b/tests/utests/data/test_validation.c
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -23,42 +25,15 @@
 #include "tests/config.h"
 #include "tree_data_internal.h"
 #include "tree_schema.h"
-#include "utests.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
+#define LYD_TREE_CREATE(INPUT, MODEL) \
+                CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)
 
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
 static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
+test_when(void **state)
 {
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-setup(void **state)
-{
-    (void) state; /* unused */
-
-    const char *schema_a =
+    struct lyd_node *tree;
+    const char *schema =
             "module a {\n"
             "    namespace urn:tests:a;\n"
             "    prefix a;\n"
@@ -78,7 +53,30 @@
             "        type string;\n"
             "    }\n"
             "}";
-    const char *schema_b =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+    CHECK_PARSE_LYD_PARAM("<c xmlns=\"urn:tests:a\">hey</c>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("When condition \"/cont/b = 'val_b'\" not satisfied.", "/a:c");
+
+    LYD_TREE_CREATE("<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>", tree);
+    CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 0, LYS_LEAF, 0, 0, NULL, 1);
+    assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
+    lyd_free_all(tree);
+
+    LYD_TREE_CREATE("<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>", tree);
+    CHECK_LYSC_NODE(lyd_child(tree)->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "a", 1, LYS_LEAF, 1, 0, NULL, 1);
+    assert_int_equal(LYD_WHEN_TRUE, lyd_child(tree)->flags);
+    CHECK_LYSC_NODE(tree->next->schema, NULL, 0, LYS_CONFIG_W | LYS_STATUS_CURR, 1, "c", 0, LYS_LEAF, 0, 0, NULL, 1);
+    assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
+    lyd_free_all(tree);
+}
+
+static void
+test_mandatory(void **state)
+{
+    struct lyd_node *tree;
+    const char *schema =
             "module b {\n"
             "    namespace urn:tests:b;\n"
             "    prefix b;\n"
@@ -103,7 +101,27 @@
             "        type empty;\n"
             "    }\n"
             "}";
-    const char *schema_c =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+    CHECK_PARSE_LYD_PARAM("<d xmlns=\"urn:tests:b\"/>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Mandatory node \"choic\" instance does not exist.", "/b:choic");
+
+    CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Mandatory node \"c\" instance does not exist.", "/b:c");
+
+    CHECK_PARSE_LYD_PARAM("<a xmlns=\"urn:tests:b\">string</a>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Mandatory node \"c\" instance does not exist.", "/b:c");
+
+    LYD_TREE_CREATE("<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>", tree);
+    lyd_free_siblings(tree);
+}
+
+static void
+test_minmax(void **state)
+{
+    struct lyd_node *tree;
+    const char *schema =
             "module c {\n"
             "    namespace urn:tests:c;\n"
             "    prefix c;\n"
@@ -131,56 +149,431 @@
             "        type empty;\n"
             "    }\n"
             "}";
-    const char *schema_d =
-            "module d {\n"
-            "    namespace urn:tests:d;\n"
-            "    prefix d;\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    list lt {\n"
-            "        key \"k\";\n"
-            "        unique \"l1\";\n"
-            "        leaf k {\n"
-            "            type string;\n"
-            "        }\n"
-            "        leaf l1 {\n"
-            "            type string;\n"
-            "        }\n"
-            "    }\n"
-            "    list lt2 {\n"
-            "        key \"k\";\n"
-            "        unique \"cont/l2 l4\";\n"
-            "        unique \"l5 l6\";\n"
-            "        leaf k {\n"
-            "            type string;\n"
-            "        }\n"
-            "        container cont {\n"
-            "            leaf l2 {\n"
-            "                type string;\n"
-            "            }\n"
-            "        }\n"
-            "        leaf l4 {\n"
-            "            type string;\n"
-            "        }\n"
-            "        leaf l5 {\n"
-            "            type string;\n"
-            "        }\n"
-            "        leaf l6 {\n"
-            "            type string;\n"
-            "        }\n"
-            "        list lt3 {\n"
-            "            key \"kk\";\n"
-            "            unique \"l3\";\n"
-            "            leaf kk {\n"
-            "                type string;\n"
-            "            }\n"
-            "            leaf l3 {\n"
-            "                type string;\n"
-            "            }\n"
-            "        }\n"
-            "    }\n"
-            "}";
-    const char *schema_e =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+    CHECK_PARSE_LYD_PARAM("<d xmlns=\"urn:tests:c\"/>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Too few \"l\" instances.", "/c:choic/b/l");
+
+    CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:c\">val1</l>"
+            "<l xmlns=\"urn:tests:c\">val2</l>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Too few \"l\" instances.", "/c:choic/b/l");
+
+    LYD_TREE_CREATE("<l xmlns=\"urn:tests:c\">val1</l>"
+            "<l xmlns=\"urn:tests:c\">val2</l>"
+            "<l xmlns=\"urn:tests:c\">val3</l>", tree);
+    lyd_free_all(tree);
+
+    CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:c\">val1</l>"
+            "<l xmlns=\"urn:tests:c\">val2</l>"
+            "<l xmlns=\"urn:tests:c\">val3</l>"
+            "<lt xmlns=\"urn:tests:c\"><k>val1</k></lt>"
+            "<lt xmlns=\"urn:tests:c\"><k>val2</k></lt>"
+            "<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>"
+            "<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>"
+            "<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Too many \"lt\" instances.", "/c:lt");
+}
+
+const char *schema_d =
+        "module d {\n"
+        "    namespace urn:tests:d;\n"
+        "    prefix d;\n"
+        "    yang-version 1.1;\n"
+        "\n"
+        "    list lt {\n"
+        "        key \"k\";\n"
+        "        unique \"l1\";\n"
+        "        leaf k {\n"
+        "            type string;\n"
+        "        }\n"
+        "        leaf l1 {\n"
+        "            type string;\n"
+        "        }\n"
+        "    }\n"
+        "    list lt2 {\n"
+        "        key \"k\";\n"
+        "        unique \"cont/l2 l4\";\n"
+        "        unique \"l5 l6\";\n"
+        "        leaf k {\n"
+        "            type string;\n"
+        "        }\n"
+        "        container cont {\n"
+        "            leaf l2 {\n"
+        "                type string;\n"
+        "            }\n"
+        "        }\n"
+        "        leaf l4 {\n"
+        "            type string;\n"
+        "        }\n"
+        "        leaf l5 {\n"
+        "            type string;\n"
+        "        }\n"
+        "        leaf l6 {\n"
+        "            type string;\n"
+        "        }\n"
+        "        list lt3 {\n"
+        "            key \"kk\";\n"
+        "            unique \"l3\";\n"
+        "            leaf kk {\n"
+        "                type string;\n"
+        "            }\n"
+        "            leaf l3 {\n"
+        "                type string;\n"
+        "            }\n"
+        "        }\n"
+        "    }\n"
+        "}";
+
+static void
+test_unique(void **state)
+{
+    struct lyd_node *tree;
+
+    UTEST_ADD_MODULE(schema_d, LYS_IN_YANG, NULL, NULL);
+
+    LYD_TREE_CREATE("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>same</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "</lt>", tree);
+    lyd_free_all(tree);
+
+    LYD_TREE_CREATE("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>same</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <l1>not-same</l1>\n"
+            "</lt>", tree);
+    lyd_free_all(tree);
+
+    CHECK_PARSE_LYD_PARAM("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>same</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <l1>same</l1>\n"
+            "</lt>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\".", "/d:lt[k='val2']");
+
+    /* now try with more instances */
+    LYD_TREE_CREATE("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>1</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <l1>2</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <l1>3</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <l1>4</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <l1>5</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val6</k>\n"
+            "    <l1>6</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val7</k>\n"
+            "    <l1>7</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val8</k>\n"
+            "    <l1>8</l1>\n"
+            "</lt>", tree);
+    lyd_free_all(tree);
+
+    LYD_TREE_CREATE("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>1</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <l1>2</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <l1>3</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <l1>5</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val6</k>\n"
+            "    <l1>6</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val7</k>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val8</k>\n"
+            "</lt>", tree);
+    lyd_free_all(tree);
+
+    CHECK_PARSE_LYD_PARAM("<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <l1>1</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <l1>2</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <l1>4</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val6</k>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val7</k>\n"
+            "    <l1>2</l1>\n"
+            "</lt>\n"
+            "<lt xmlns=\"urn:tests:d\">\n"
+            "    <k>val8</k>\n"
+            "    <l1>8</l1>\n"
+            "</lt>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\".", "/d:lt[k='val2']");
+}
+
+static void
+test_unique_nested(void **state)
+{
+    struct lyd_node *tree;
+
+    UTEST_ADD_MODULE(schema_d, LYS_IN_YANG, NULL, NULL);
+
+    /* nested list uniquest are compared only with instances in the same parent list instance */
+    LYD_TREE_CREATE("<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <cont>\n"
+            "        <l2>1</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <cont>\n"
+            "        <l2>2</l2>\n"
+            "    </cont>\n"
+            "    <l4>2</l4>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>1</l3>\n"
+            "    </lt3>\n"
+            "    <lt3>\n"
+            "        <kk>val2</kk>\n"
+            "        <l3>2</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <cont>\n"
+            "        <l2>3</l2>\n"
+            "    </cont>\n"
+            "    <l4>3</l4>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>2</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <cont>\n"
+            "        <l2>4</l2>\n"
+            "    </cont>\n"
+            "    <l4>4</l4>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>3</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <cont>\n"
+            "        <l2>5</l2>\n"
+            "    </cont>\n"
+            "    <l4>5</l4>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>3</l3>\n"
+            "    </lt3>\n"
+            "</lt2>", tree);
+    lyd_free_all(tree);
+
+    CHECK_PARSE_LYD_PARAM("<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <cont>\n"
+            "        <l2>1</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <cont>\n"
+            "        <l2>2</l2>\n"
+            "    </cont>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>1</l3>\n"
+            "    </lt3>\n"
+            "    <lt3>\n"
+            "        <kk>val2</kk>\n"
+            "        <l3>2</l3>\n"
+            "    </lt3>\n"
+            "    <lt3>\n"
+            "        <kk>val3</kk>\n"
+            "        <l3>1</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <cont>\n"
+            "        <l2>3</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>2</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <cont>\n"
+            "        <l2>4</l2>\n"
+            "    </cont>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>3</l3>\n"
+            "    </lt3>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <cont>\n"
+            "        <l2>5</l2>\n"
+            "    </cont>\n"
+            "    <lt3>\n"
+            "        <kk>val1</kk>\n"
+            "        <l3>3</l3>\n"
+            "    </lt3>\n"
+            "</lt2>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Unique data leaf(s) \"l3\" not satisfied in"
+            " \"/d:lt2[k='val2']/lt3[kk='val3']\" and"
+            " \"/d:lt2[k='val2']/lt3[kk='val1']\".", "/d:lt2[k='val2']/lt3[kk='val1']");
+
+    CHECK_PARSE_LYD_PARAM("<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <cont>\n"
+            "        <l2>1</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <cont>\n"
+            "        <l2>2</l2>\n"
+            "    </cont>\n"
+            "    <l4>2</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <cont>\n"
+            "        <l2>3</l2>\n"
+            "    </cont>\n"
+            "    <l4>3</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <cont>\n"
+            "        <l2>2</l2>\n"
+            "    </cont>\n"
+            "    <l4>2</l4>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <cont>\n"
+            "        <l2>5</l2>\n"
+            "    </cont>\n"
+            "    <l4>5</l4>\n"
+            "</lt2>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Unique data leaf(s) \"cont/l2 l4\" not satisfied in \"/d:lt2[k='val4']\" and \"/d:lt2[k='val2']\".", "/d:lt2[k='val2']");
+
+    CHECK_PARSE_LYD_PARAM("<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val1</k>\n"
+            "    <cont>\n"
+            "        <l2>1</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <l5>1</l5>\n"
+            "    <l6>1</l6>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val2</k>\n"
+            "    <cont>\n"
+            "        <l2>2</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <l5>1</l5>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val3</k>\n"
+            "    <cont>\n"
+            "        <l2>3</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <l5>3</l5>\n"
+            "    <l6>3</l6>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val4</k>\n"
+            "    <cont>\n"
+            "        <l2>4</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <l6>1</l6>\n"
+            "</lt2>\n"
+            "<lt2 xmlns=\"urn:tests:d\">\n"
+            "    <k>val5</k>\n"
+            "    <cont>\n"
+            "        <l2>5</l2>\n"
+            "    </cont>\n"
+            "    <l4>1</l4>\n"
+            "    <l5>3</l5>\n"
+            "    <l6>3</l6>\n"
+            "</lt2>", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Unique data leaf(s) \"l5 l6\" not satisfied in \"/d:lt2[k='val5']\" and \"/d:lt2[k='val3']\".",
+            "/d:lt2[k='val3']");
+}
+
+static void
+test_dup(void **state)
+{
+    struct lyd_node *tree;
+    const char *schema =
             "module e {\n"
             "    namespace urn:tests:e;\n"
             "    prefix e;\n"
@@ -229,7 +622,69 @@
             "        }\n"
             "    }\n"
             "}";
-    const char *schema_f =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+    CHECK_PARSE_LYD_PARAM("<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"d\".", "/e:d");
+
+    CHECK_PARSE_LYD_PARAM("<lt xmlns=\"urn:tests:e\"><k>A</k></lt>"
+            "<lt xmlns=\"urn:tests:e\"><k>B</k></lt>"
+            "<lt xmlns=\"urn:tests:e\"><k>A</k></lt>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"lt\".", "/e:lt[k='A']");
+
+    CHECK_PARSE_LYD_PARAM("<ll xmlns=\"urn:tests:e\">A</ll>"
+            "<ll xmlns=\"urn:tests:e\">B</ll>"
+            "<ll xmlns=\"urn:tests:e\">B</ll>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"ll\".", "/e:ll[.='B']");
+
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"cont\".", "/e:cont");
+
+    /* same tests again but using hashes */
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:e\"><d>25</d><d>50</d><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll></cont>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"d\".", "/e:cont/d");
+
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
+            "<lt><k>a</k></lt>"
+            "<lt><k>b</k></lt>"
+            "<lt><k>c</k></lt>"
+            "<lt><k>d</k></lt>"
+            "<lt><k>c</k></lt></cont>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"lt\".", "/e:cont/lt[k='c']");
+
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
+            "<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"ll\".", "/e:cont/ll[.='d']");
+
+    /* cases */
+    CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:e\">a</l>"
+            "<l xmlns=\"urn:tests:e\">b</l>"
+            "<l xmlns=\"urn:tests:e\">c</l>"
+            "<l xmlns=\"urn:tests:e\">b</l>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Duplicate instance of \"l\".", "/e:l[.='b']");
+
+    CHECK_PARSE_LYD_PARAM("<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l>"
+            "<l xmlns=\"urn:tests:e\">c</l>"
+            "<a xmlns=\"urn:tests:e\">aa</a>",
+            LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Data for both cases \"a\" and \"b\" exist.", "/e:choic");
+}
+
+static void
+test_defaults(void **state)
+{
+    struct lyd_node *tree, *node, *diff;
+    const struct lys_module *mod;
+    const char *schema =
             "module f {\n"
             "    namespace urn:tests:f;\n"
             "    prefix f;\n"
@@ -294,42 +749,197 @@
             "        }\n"
             "    }\n"
             "}";
-    const char *schema_g =
-            "module g {\n"
-            "    namespace urn:tests:g;\n"
-            "    prefix g;\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    feature f1;\n"
-            "    feature f2;\n"
-            "    feature f3;\n"
-            "\n"
-            "    container cont {\n"
-            "        if-feature \"f1\";\n"
-            "        choice choic {\n"
-            "            if-feature \"f2 or f3\";\n"
-            "            leaf a {\n"
-            "                type string;\n"
-            "            }\n"
-            "            case b {\n"
-            "                if-feature \"f2 and f1\";\n"
-            "                leaf l {\n"
-            "                    type string;\n"
-            "                }\n"
-            "            }\n"
-            "        }\n"
-            "        leaf d {\n"
-            "            type uint32;\n"
-            "        }\n"
-            "        container cont2 {\n"
-            "            if-feature \"f2\";\n"
-            "            leaf e {\n"
-            "                type string;\n"
-            "            }\n"
-            "        }\n"
-            "    }\n"
-            "}";
-    const char *schema_h =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));\
+
+    /* get defaults */
+    tree = NULL;
+    assert_int_equal(lyd_validate_module(&tree, mod, 0, &diff), LY_SUCCESS);
+    assert_non_null(tree);
+    assert_non_null(diff);
+
+    /* check all defaults exist */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_WITHSIBLINGS);
+
+    /* check diff */
+    CHECK_LYD_STRING_PARAM(diff,
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def1</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def2</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def3</ll1>\n"
+            "<d xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">dflt1</ll2>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
+            "  <ll1 yang:operation=\"create\">def1</ll1>\n"
+            "  <ll1 yang:operation=\"create\">def2</ll1>\n"
+            "  <ll1 yang:operation=\"create\">def3</ll1>\n"
+            "  <d yang:operation=\"create\">15</d>\n"
+            "  <ll2 yang:operation=\"create\">dflt1</ll2>\n"
+            "  <ll2 yang:operation=\"create\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_WITHSIBLINGS);
+    lyd_free_all(diff);
+
+    /* create another explicit case and validate */
+    assert_int_equal(lyd_new_term(NULL, mod, "l", "value", 0, &node), LY_SUCCESS);
+    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&tree, UTEST_LYCTX, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+
+    /* check data tree */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<l xmlns=\"urn:tests:f\">value</l>\n"
+            "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_WITHSIBLINGS);
+
+    /* check diff */
+    CHECK_LYD_STRING_PARAM(diff,
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def1</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def2</ll1>\n"
+            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def3</ll1>\n",
+            LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_WITHSIBLINGS);
+    lyd_free_all(diff);
+
+    /* create explicit leaf-list and leaf and validate */
+    assert_int_equal(lyd_new_term(NULL, mod, "d", "15", 0, &node), LY_SUCCESS);
+    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
+    assert_int_equal(lyd_new_term(NULL, mod, "ll2", "dflt2", 0, &node), LY_SUCCESS);
+    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&tree, UTEST_LYCTX, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+
+    /* check data tree */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<l xmlns=\"urn:tests:f\">value</l>\n"
+            "<d xmlns=\"urn:tests:f\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_WITHSIBLINGS);
+
+    /* check diff */
+    CHECK_LYD_STRING_PARAM(diff,
+            "<d xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">dflt1</ll2>\n"
+            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">dflt2</ll2>\n",
+            LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_WITHSIBLINGS);
+    lyd_free_all(diff);
+
+    /* create first explicit container, which should become implicit */
+    assert_int_equal(lyd_new_inner(NULL, mod, "cont", 0, &node), LY_SUCCESS);
+    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&tree, UTEST_LYCTX, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+
+    /* check data tree */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<l xmlns=\"urn:tests:f\">value</l>\n"
+            "<d xmlns=\"urn:tests:f\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_WITHSIBLINGS);
+    /* check diff */
+    assert_null(diff);
+
+    /* create second explicit container, which should become implicit, so the first tree node should be removed */
+    assert_int_equal(lyd_new_inner(NULL, mod, "cont", 0, &node), LY_SUCCESS);
+    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&tree, UTEST_LYCTX, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+
+    /* check data tree */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<l xmlns=\"urn:tests:f\">value</l>\n"
+            "<d xmlns=\"urn:tests:f\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
+            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
+            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
+            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_IMPL_TAG | LYD_PRINT_WITHSIBLINGS);
+    /* check diff */
+    assert_null(diff);
+
+    /* similar changes for nested defaults */
+    assert_int_equal(lyd_new_term(tree->prev, NULL, "ll1", "def3", 0, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_term(tree->prev, NULL, "d", "5", 0, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_new_term(tree->prev, NULL, "ll2", "non-dflt", 0, NULL), LY_SUCCESS);
+    assert_int_equal(lyd_validate_all(&tree, UTEST_LYCTX, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
+
+    /* check data tree */
+    CHECK_LYD_STRING_PARAM(tree,
+            "<l xmlns=\"urn:tests:f\">value</l>\n"
+            "<d xmlns=\"urn:tests:f\">15</d>\n"
+            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
+            "<cont xmlns=\"urn:tests:f\">\n"
+            "  <ll1>def3</ll1>\n"
+            "  <d>5</d>\n"
+            "  <ll2>non-dflt</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WITHSIBLINGS);
+
+    /* check diff */
+    CHECK_LYD_STRING_PARAM(diff,
+            "<cont xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
+            "  <ll1 yang:operation=\"delete\">def1</ll1>\n"
+            "  <ll1 yang:operation=\"delete\">def2</ll1>\n"
+            "  <ll1 yang:operation=\"delete\">def3</ll1>\n"
+            "  <d yang:operation=\"delete\">15</d>\n"
+            "  <ll2 yang:operation=\"delete\">dflt1</ll2>\n"
+            "  <ll2 yang:operation=\"delete\">dflt2</ll2>\n"
+            "</cont>\n",
+            LYD_XML, LYD_PRINT_WD_ALL | LYD_PRINT_WITHSIBLINGS);
+    lyd_free_all(diff);
+    lyd_free_all(tree);
+}
+
+static void
+test_state(void **state)
+{
+    const char *data;
+    struct lyd_node *tree;
+    const char *schema =
             "module h {\n"
             "    namespace urn:tests:h;\n"
             "    prefix h;\n"
@@ -344,7 +954,28 @@
             "        }\n"
             "    }\n"
             "}";
-    const char *schema_i =
+
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+    data = "<cont xmlns=\"urn:tests:h\">\n"
+            "  <cont2>\n"
+            "    <l>val</l>\n"
+            "  </cont2>\n"
+            "</cont>\n";
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, LY_EVALID, tree);
+    CHECK_LOG_CTX("Invalid state data node \"cont2\" found.", "/h:cont/cont2");
+
+    CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
+    assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, NULL));
+    CHECK_LOG_CTX("Invalid state data node \"cont2\" found.", "/h:cont/cont2");
+    lyd_free_all(tree);
+}
+
+static void
+test_must(void **state)
+{
+    struct lyd_node *tree;
+    const char *schema =
             "module i {\n"
             "    namespace urn:tests:i;\n"
             "    prefix i;\n"
@@ -360,940 +991,82 @@
             "        }\n"
             "    }\n"
             "}";
-    const char *schema_j =
-            "module j {\n"
-            "    namespace urn:tests:j;\n"
-            "    prefix j;\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    feature feat1;\n"
-            "\n"
-            "    container cont {\n"
-            "        must \"false()\";\n"
-            "        list l1 {\n"
-            "            key \"k\";\n"
-            "            leaf k {\n"
-            "                type string;\n"
-            "            }\n"
-            "            action act {\n"
-            "                if-feature feat1;\n"
-            "                input {\n"
-            "                    must \"../../lf1 = 'true'\";\n"
-            "                    leaf lf2 {\n"
-            "                        type leafref {\n"
-            "                            path /lf3;\n"
-            "                        }\n"
-            "                    }\n"
-            "                }\n"
-            "                output {\n"
-            "                    must \"../../lf1 = 'true2'\";\n"
-            "                    leaf lf2 {\n"
-            "                        type leafref {\n"
-            "                            path /lf4;\n"
-            "                        }\n"
-            "                    }\n"
-            "                }\n"
-            "            }\n"
-            "        }\n"
-            "\n"
-            "        leaf lf1 {\n"
-            "            type string;\n"
-            "        }\n"
-            "    }\n"
-            "\n"
-            "    leaf lf3 {\n"
-            "        type string;\n"
-            "    }\n"
-            "\n"
-            "    leaf lf4 {\n"
-            "        type string;\n"
-            "    }\n"
-            "}";
-    struct ly_in *in;
-    const char *feats[] = {"feat1", NULL};
 
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
-    assert_non_null(ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_a, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_c, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_d, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_e, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_f, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_g, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_h, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_i, LYS_IN_YANG, NULL));
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(schema_j, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats, NULL));
-    ly_in_free(in, 0);
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-    (void)state;
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
-
-    return 0;
-}
-
-static int
-teardown_s(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-static void
-test_when(void **state)
-{
-    *state = test_when;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data = "<c xmlns=\"urn:tests:a\">hey</c>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("When condition \"/cont/b = 'val_b'\" not satisfied. /a:c");
-
-    data = "<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont><c xmlns=\"urn:tests:a\">hey</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_string_equal("c", tree->next->schema->name);
-    assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
-    lyd_free_all(tree);
-
-    data = "<cont xmlns=\"urn:tests:a\"><a>val</a><b>val_b</b></cont><c xmlns=\"urn:tests:a\">val_c</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    assert_string_equal("a", lyd_child(tree)->schema->name);
-    assert_int_equal(LYD_WHEN_TRUE, lyd_child(tree)->flags);
-    assert_string_equal("c", tree->next->schema->name);
-    assert_int_equal(LYD_WHEN_TRUE, tree->next->flags);
-    lyd_free_all(tree);
-
-    *state = NULL;
-}
-
-static void
-test_mandatory(void **state)
-{
-    *state = test_mandatory;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data = "<d xmlns=\"urn:tests:b\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Mandatory node \"choic\" instance does not exist. /b:choic");
-
-    data = "<l xmlns=\"urn:tests:b\">string</l><d xmlns=\"urn:tests:b\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
-
-    data = "<a xmlns=\"urn:tests:b\">string</a>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Mandatory node \"c\" instance does not exist. /b:c");
-
-    data = "<a xmlns=\"urn:tests:b\">string</a><c xmlns=\"urn:tests:b\">string2</c>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    *state = NULL;
-}
-
-static void
-test_minmax(void **state)
-{
-    *state = test_minmax;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data = "<d xmlns=\"urn:tests:c\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
-
-    data =
-            "<l xmlns=\"urn:tests:c\">val1</l>"
-            "<l xmlns=\"urn:tests:c\">val2</l>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Too few \"l\" instances. /c:choic/b/l");
-
-    data =
-            "<l xmlns=\"urn:tests:c\">val1</l>"
-            "<l xmlns=\"urn:tests:c\">val2</l>"
-            "<l xmlns=\"urn:tests:c\">val3</l>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<l xmlns=\"urn:tests:c\">val1</l>"
-            "<l xmlns=\"urn:tests:c\">val2</l>"
-            "<l xmlns=\"urn:tests:c\">val3</l>"
-            "<lt xmlns=\"urn:tests:c\"><k>val1</k></lt>"
-            "<lt xmlns=\"urn:tests:c\"><k>val2</k></lt>"
-            "<lt xmlns=\"urn:tests:c\"><k>val3</k></lt>"
-            "<lt xmlns=\"urn:tests:c\"><k>val4</k></lt>"
-            "<lt xmlns=\"urn:tests:c\"><k>val5</k></lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Too many \"lt\" instances. /c:lt");
-
-    *state = NULL;
-}
-
-static void
-test_unique(void **state)
-{
-    *state = test_unique;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>same</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>same</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <l1>not-same</l1>\n"
-            "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>same</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <l1>same</l1>\n"
-            "</lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val1']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
-
-    /* now try with more instances */
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>1</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <l1>2</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <l1>3</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <l1>4</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <l1>5</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val6</k>\n"
-            "    <l1>6</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val7</k>\n"
-            "    <l1>7</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val8</k>\n"
-            "    <l1>8</l1>\n"
-            "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>1</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <l1>2</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <l1>3</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <l1>5</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val6</k>\n"
-            "    <l1>6</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val7</k>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val8</k>\n"
-            "</lt>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <l1>1</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <l1>2</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <l1>4</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val6</k>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val7</k>\n"
-            "    <l1>2</l1>\n"
-            "</lt>\n"
-            "<lt xmlns=\"urn:tests:d\">\n"
-            "    <k>val8</k>\n"
-            "    <l1>8</l1>\n"
-            "</lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Unique data leaf(s) \"l1\" not satisfied in \"/d:lt[k='val7']\" and \"/d:lt[k='val2']\". /d:lt[k='val2']");
-
-    *state = NULL;
-}
-
-static void
-test_unique_nested(void **state)
-{
-    *state = test_unique_nested;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    /* nested list uniquest are compared only with instances in the same parent list instance */
-    data =
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <cont>\n"
-            "        <l2>1</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <cont>\n"
-            "        <l2>2</l2>\n"
-            "    </cont>\n"
-            "    <l4>2</l4>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>1</l3>\n"
-            "    </lt3>\n"
-            "    <lt3>\n"
-            "        <kk>val2</kk>\n"
-            "        <l3>2</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <cont>\n"
-            "        <l2>3</l2>\n"
-            "    </cont>\n"
-            "    <l4>3</l4>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>2</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <cont>\n"
-            "        <l2>4</l2>\n"
-            "    </cont>\n"
-            "    <l4>4</l4>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>3</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <cont>\n"
-            "        <l2>5</l2>\n"
-            "    </cont>\n"
-            "    <l4>5</l4>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>3</l3>\n"
-            "    </lt3>\n"
-            "</lt2>";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_siblings(tree);
-
-    data =
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <cont>\n"
-            "        <l2>1</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <cont>\n"
-            "        <l2>2</l2>\n"
-            "    </cont>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>1</l3>\n"
-            "    </lt3>\n"
-            "    <lt3>\n"
-            "        <kk>val2</kk>\n"
-            "        <l3>2</l3>\n"
-            "    </lt3>\n"
-            "    <lt3>\n"
-            "        <kk>val3</kk>\n"
-            "        <l3>1</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <cont>\n"
-            "        <l2>3</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>2</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <cont>\n"
-            "        <l2>4</l2>\n"
-            "    </cont>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>3</l3>\n"
-            "    </lt3>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <cont>\n"
-            "        <l2>5</l2>\n"
-            "    </cont>\n"
-            "    <lt3>\n"
-            "        <kk>val1</kk>\n"
-            "        <l3>3</l3>\n"
-            "    </lt3>\n"
-            "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Unique data leaf(s) \"l3\" not satisfied in \"/d:lt2[k='val2']/lt3[kk='val3']\" and"
-            " \"/d:lt2[k='val2']/lt3[kk='val1']\". /d:lt2[k='val2']/lt3[kk='val1']");
-
-    data =
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <cont>\n"
-            "        <l2>1</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <cont>\n"
-            "        <l2>2</l2>\n"
-            "    </cont>\n"
-            "    <l4>2</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <cont>\n"
-            "        <l2>3</l2>\n"
-            "    </cont>\n"
-            "    <l4>3</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <cont>\n"
-            "        <l2>2</l2>\n"
-            "    </cont>\n"
-            "    <l4>2</l4>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <cont>\n"
-            "        <l2>5</l2>\n"
-            "    </cont>\n"
-            "    <l4>5</l4>\n"
-            "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Unique data leaf(s) \"cont/l2 l4\" not satisfied in \"/d:lt2[k='val4']\" and \"/d:lt2[k='val2']\". /d:lt2[k='val2']");
-
-    data =
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val1</k>\n"
-            "    <cont>\n"
-            "        <l2>1</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <l5>1</l5>\n"
-            "    <l6>1</l6>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val2</k>\n"
-            "    <cont>\n"
-            "        <l2>2</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <l5>1</l5>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val3</k>\n"
-            "    <cont>\n"
-            "        <l2>3</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <l5>3</l5>\n"
-            "    <l6>3</l6>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val4</k>\n"
-            "    <cont>\n"
-            "        <l2>4</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <l6>1</l6>\n"
-            "</lt2>\n"
-            "<lt2 xmlns=\"urn:tests:d\">\n"
-            "    <k>val5</k>\n"
-            "    <cont>\n"
-            "        <l2>5</l2>\n"
-            "    </cont>\n"
-            "    <l4>1</l4>\n"
-            "    <l5>3</l5>\n"
-            "    <l6>3</l6>\n"
-            "</lt2>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Unique data leaf(s) \"l5 l6\" not satisfied in \"/d:lt2[k='val5']\" and \"/d:lt2[k='val3']\". /d:lt2[k='val3']");
-
-    *state = NULL;
-}
-
-static void
-test_dup(void **state)
-{
-    *state = test_dup;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data = "<d xmlns=\"urn:tests:e\">25</d><d xmlns=\"urn:tests:e\">50</d>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"d\". /e:d");
-
-    data = "<lt xmlns=\"urn:tests:e\"><k>A</k></lt><lt xmlns=\"urn:tests:e\"><k>B</k></lt><lt xmlns=\"urn:tests:e\"><k>A</k></lt>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"lt\". /e:lt[k='A']");
-
-    data = "<ll xmlns=\"urn:tests:e\">A</ll><ll xmlns=\"urn:tests:e\">B</ll><ll xmlns=\"urn:tests:e\">B</ll>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"ll\". /e:ll[.='B']");
-
-    data = "<cont xmlns=\"urn:tests:e\"></cont><cont xmlns=\"urn:tests:e\"/>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"cont\". /e:cont");
-
-    /* same tests again but using hashes */
-    data = "<cont xmlns=\"urn:tests:e\"><d>25</d><d>50</d><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"d\". /e:cont/d");
-
-    data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
-            "<lt><k>a</k></lt><lt><k>b</k></lt><lt><k>c</k></lt><lt><k>d</k></lt><lt><k>c</k></lt></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"lt\". /e:cont/lt[k='c']");
-
-    data = "<cont xmlns=\"urn:tests:e\"><ll>1</ll><ll>2</ll><ll>3</ll><ll>4</ll>"
-            "<ll>a</ll><ll>b</ll><ll>c</ll><ll>d</ll><ll>d</ll></cont>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"ll\". /e:cont/ll[.='d']");
-
-    /* cases */
-    data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><l xmlns=\"urn:tests:e\">b</l>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Duplicate instance of \"l\". /e:l[.='b']");
-
-    data = "<l xmlns=\"urn:tests:e\">a</l><l xmlns=\"urn:tests:e\">b</l><l xmlns=\"urn:tests:e\">c</l><a xmlns=\"urn:tests:e\">aa</a>";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Data for both cases \"a\" and \"b\" exist. /e:choic");
-
-    *state = NULL;
-}
-
-static void
-test_defaults(void **state)
-{
-    *state = test_defaults;
-
-    char *str;
-    struct lyd_node *tree, *node, *diff;
-    const struct lys_module *mod = ly_ctx_get_module_latest(ctx, "f");
-
-    struct ly_out *out;
-
-    assert_int_equal(LY_SUCCESS, ly_out_new_memory(&str, 0, &out));
-
-    /* get defaults */
-    tree = NULL;
-    assert_int_equal(lyd_validate_module(&tree, mod, 0, &diff), LY_SUCCESS);
-    assert_non_null(tree);
-    assert_non_null(diff);
-
-    /* check all defaults exist */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
-    assert_string_equal(str,
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def1</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def2</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">def3</ll1>\n"
-            "<d xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">dflt1</ll2>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"create\">\n"
-            "  <ll1 yang:operation=\"create\">def1</ll1>\n"
-            "  <ll1 yang:operation=\"create\">def2</ll1>\n"
-            "  <ll1 yang:operation=\"create\">def3</ll1>\n"
-            "  <d yang:operation=\"create\">15</d>\n"
-            "  <ll2 yang:operation=\"create\">dflt1</ll2>\n"
-            "  <ll2 yang:operation=\"create\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-    lyd_free_siblings(diff);
-
-    /* create another explicit case and validate */
-    assert_int_equal(lyd_new_term(NULL, mod, "l", "value", 0, &node), LY_SUCCESS);
-    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
-
-    /* check data tree */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<l xmlns=\"urn:tests:f\">value</l>\n"
-            "<d xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
-    assert_string_equal(str,
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def1</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def2</ll1>\n"
-            "<ll1 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">def3</ll1>\n");
-    ly_out_reset(out);
-    lyd_free_siblings(diff);
-
-    /* create explicit leaf-list and leaf and validate */
-    assert_int_equal(lyd_new_term(NULL, mod, "d", "15", 0, &node), LY_SUCCESS);
-    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
-    assert_int_equal(lyd_new_term(NULL, mod, "ll2", "dflt2", 0, &node), LY_SUCCESS);
-    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
-
-    /* check data tree */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<l xmlns=\"urn:tests:f\">value</l>\n"
-            "<d xmlns=\"urn:tests:f\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
-    assert_string_equal(str,
-            "<d xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">dflt1</ll2>\n"
-            "<ll2 xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"delete\">dflt2</ll2>\n");
-    ly_out_reset(out);
-    lyd_free_siblings(diff);
-
-    /* create first explicit container, which should become implicit */
-    assert_int_equal(lyd_new_inner(NULL, mod, "cont", 0, &node), LY_SUCCESS);
-    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
-
-    /* check data tree */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<l xmlns=\"urn:tests:f\">value</l>\n"
-            "<d xmlns=\"urn:tests:f\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    assert_null(diff);
-
-    /* create second explicit container, which should become implicit, so the first tree node should be removed */
-    assert_int_equal(lyd_new_inner(NULL, mod, "cont", 0, &node), LY_SUCCESS);
-    assert_int_equal(lyd_insert_sibling(tree, node, &tree), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
-
-    /* check data tree */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<l xmlns=\"urn:tests:f\">value</l>\n"
-            "<d xmlns=\"urn:tests:f\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def1</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def2</ll1>\n"
-            "  <ll1 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">def3</ll1>\n"
-            "  <d xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">15</d>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt1</ll2>\n"
-            "  <ll2 xmlns:ncwd=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\" ncwd:default=\"true\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    assert_null(diff);
-
-    /* similar changes for nested defaults */
-    assert_int_equal(lyd_new_term(tree->prev, NULL, "ll1", "def3", 0, NULL), LY_SUCCESS);
-    assert_int_equal(lyd_new_term(tree->prev, NULL, "d", "5", 0, NULL), LY_SUCCESS);
-    assert_int_equal(lyd_new_term(tree->prev, NULL, "ll2", "non-dflt", 0, NULL), LY_SUCCESS);
-    assert_int_equal(lyd_validate_all(&tree, ctx, LYD_VALIDATE_PRESENT, &diff), LY_SUCCESS);
-
-    /* check data tree */
-    lyd_print_all(out, tree, LYD_XML, LYD_PRINT_WD_IMPL_TAG);
-    assert_string_equal(str,
-            "<l xmlns=\"urn:tests:f\">value</l>\n"
-            "<d xmlns=\"urn:tests:f\">15</d>\n"
-            "<ll2 xmlns=\"urn:tests:f\">dflt2</ll2>\n"
-            "<cont xmlns=\"urn:tests:f\">\n"
-            "  <ll1>def3</ll1>\n"
-            "  <d>5</d>\n"
-            "  <ll2>non-dflt</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-
-    /* check diff */
-    lyd_print_all(out, diff, LYD_XML, LYD_PRINT_WD_ALL);
-    assert_string_equal(str,
-            "<cont xmlns=\"urn:tests:f\" xmlns:yang=\"urn:ietf:params:xml:ns:yang:1\" yang:operation=\"none\">\n"
-            "  <ll1 yang:operation=\"delete\">def1</ll1>\n"
-            "  <ll1 yang:operation=\"delete\">def2</ll1>\n"
-            "  <ll1 yang:operation=\"delete\">def3</ll1>\n"
-            "  <d yang:operation=\"delete\">15</d>\n"
-            "  <ll2 yang:operation=\"delete\">dflt1</ll2>\n"
-            "  <ll2 yang:operation=\"delete\">dflt2</ll2>\n"
-            "</cont>\n");
-    ly_out_reset(out);
-    lyd_free_siblings(diff);
-
-    lyd_free_siblings(tree);
-    ly_out_free(out, NULL, 1);
-
-    *state = NULL;
-}
-
-static void
-test_state(void **state)
-{
-    *state = test_state;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data =
-            "<cont xmlns=\"urn:tests:h\">\n"
-            "  <cont2>\n"
-            "    <l>val</l>\n"
-            "  </cont2>\n"
-            "</cont>\n";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_NO_STATE, 0, &tree));
-    assert_null(tree);
-    logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
-
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, &tree));
-    assert_null(tree);
-    logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
-
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
-
-    assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT | LYD_VALIDATE_NO_STATE, NULL));
-    logbuf_assert("Invalid state data node \"cont2\" found. /h:cont/cont2");
-
-    lyd_free_siblings(tree);
-
-    *state = NULL;
-}
-
-static void
-test_must(void **state)
-{
-    *state = test_must;
-
-    const char *data;
-    struct lyd_node *tree;
-
-    data =
-            "<cont xmlns=\"urn:tests:i\">\n"
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:i\">\n"
             "  <l>wrong</l>\n"
             "  <l2>val</l2>\n"
-            "</cont>\n";
-    assert_int_equal(LY_EVALID, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_null(tree);
-    logbuf_assert("Must condition \"../l = 'right'\" not satisfied. /i:cont/l2");
+            "</cont>\n", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+    CHECK_LOG_CTX("Must condition \"../l = 'right'\" not satisfied.", "/i:cont/l2");
 
-    data =
-            "<cont xmlns=\"urn:tests:i\">\n"
+    LYD_TREE_CREATE("<cont xmlns=\"urn:tests:i\">\n"
             "  <l>right</l>\n"
             "  <l2>val</l2>\n"
-            "</cont>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
-    assert_non_null(tree);
-    lyd_free_tree(tree);
-
-    *state = NULL;
+            "</cont>\n", tree);
+    lyd_free_all(tree);
 }
 
+const char *schema_j =
+        "module j {\n"
+        "    namespace urn:tests:j;\n"
+        "    prefix j;\n"
+        "    yang-version 1.1;\n"
+        "\n"
+        "    feature feat1;\n"
+        "\n"
+        "    container cont {\n"
+        "        must \"false()\";\n"
+        "        list l1 {\n"
+        "            key \"k\";\n"
+        "            leaf k {\n"
+        "                type string;\n"
+        "            }\n"
+        "            action act {\n"
+        "                if-feature feat1;\n"
+        "                input {\n"
+        "                    must \"../../lf1 = 'true'\";\n"
+        "                    leaf lf2 {\n"
+        "                        type leafref {\n"
+        "                            path /lf3;\n"
+        "                        }\n"
+        "                    }\n"
+        "                }\n"
+        "                output {\n"
+        "                    must \"../../lf1 = 'true2'\";\n"
+        "                    leaf lf2 {\n"
+        "                        type leafref {\n"
+        "                            path /lf4;\n"
+        "                        }\n"
+        "                    }\n"
+        "                }\n"
+        "            }\n"
+        "        }\n"
+        "\n"
+        "        leaf lf1 {\n"
+        "            type string;\n"
+        "        }\n"
+        "    }\n"
+        "\n"
+        "    leaf lf3 {\n"
+        "        type string;\n"
+        "    }\n"
+        "\n"
+        "    leaf lf4 {\n"
+        "        type string;\n"
+        "    }\n"
+        "}";
+const char *feats_j[] = {"feat1", NULL};
+
 static void
 test_action(void **state)
 {
-    *state = test_action;
-
-    const char *data;
     struct ly_in *in;
     struct lyd_node *tree, *op_tree;
 
-    data =
+    UTEST_ADD_MODULE(schema_j, LYS_IN_YANG, feats_j, NULL);
+
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(
             "<cont xmlns=\"urn:tests:j\">\n"
             "  <l1>\n"
             "    <k>val1</k>\n"
@@ -1301,57 +1074,48 @@
             "      <lf2>target</lf2>\n"
             "    </act>\n"
             "  </l1>\n"
-            "</cont>\n";
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &op_tree, NULL));
+            "</cont>\n", &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_XML, &op_tree, NULL));
     assert_non_null(op_tree);
 
     /* missing leafref */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_RPC, NULL));
-    logbuf_assert("Invalid leafref value \"target\" - no target instance \"/lf3\" with the same value."
-            " /j:cont/l1[k='val1']/act/lf2");
+    CHECK_LOG_CTX("Invalid leafref value \"target\" - no target instance \"/lf3\" with the same value.", "/j:cont/l1[k='val1']/act/lf2");
     ly_in_free(in, 0);
 
-    data =
-            "<cont xmlns=\"urn:tests:j\">\n"
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:j\">\n"
             "  <lf1>not true</lf1>\n"
             "</cont>\n"
-            "<lf3 xmlns=\"urn:tests:j\">target</lf3>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
+            "<lf3 xmlns=\"urn:tests:j\">target</lf3>\n",
+            LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
 
     /* input must false */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALIDATE_OP_RPC, NULL));
-    logbuf_assert("Must condition \"../../lf1 = 'true'\" not satisfied. /j:cont/l1[k='val1']/act");
+    CHECK_LOG_CTX("Must condition \"../../lf1 = 'true'\" not satisfied.", "/j:cont/l1[k='val1']/act");
 
-    lyd_free_siblings(tree);
-    data =
-            "<cont xmlns=\"urn:tests:j\">\n"
+    lyd_free_all(tree);
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:j\">\n"
             "  <lf1>true</lf1>\n"
             "</cont>\n"
-            "<lf3 xmlns=\"urn:tests:j\">target</lf3>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
+            "<lf3 xmlns=\"urn:tests:j\">target</lf3>\n",
+            LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
 
     /* success */
     assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALIDATE_OP_RPC, NULL));
 
     lyd_free_tree(op_tree);
     lyd_free_siblings(tree);
-
-    *state = NULL;
 }
 
 static void
 test_reply(void **state)
 {
-    *state = test_reply;
-
-    const char *data;
     struct ly_in *in;
     struct lyd_node *tree, *op_tree, *request;
 
-    data =
+    UTEST_ADD_MODULE(schema_j, LYS_IN_YANG, feats_j, NULL);
+
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(
             "<cont xmlns=\"urn:tests:j\">\n"
             "  <l1>\n"
             "    <k>val1</k>\n"
@@ -1359,14 +1123,12 @@
             "      <lf2>target</lf2>\n"
             "    </act>\n"
             "  </l1>\n"
-            "</cont>\n";
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(ctx, in, LYD_XML, &request, NULL));
+            "</cont>\n", &in));
+    assert_int_equal(LY_SUCCESS, lyd_parse_rpc(UTEST_LYCTX, in, LYD_XML, &request, NULL));
     assert_non_null(request);
     ly_in_free(in, 0);
 
-    data = "<lf2 xmlns=\"urn:tests:j\">target</lf2>";
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory("<lf2 xmlns=\"urn:tests:j\">target</lf2>", &in));
     assert_int_equal(LY_SUCCESS, lyd_parse_reply(request, in, LYD_XML, &op_tree, NULL));
     lyd_free_all(request);
     assert_non_null(op_tree);
@@ -1374,55 +1136,48 @@
 
     /* missing leafref */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, NULL, LYD_VALIDATE_OP_REPLY, NULL));
-    logbuf_assert("Invalid leafref value \"target\" - no target instance \"/lf4\" with the same value."
-            " /j:cont/l1[k='val1']/act/lf2");
+    CHECK_LOG_CTX("Invalid leafref value \"target\" - no target instance \"/lf4\" with the same value.", "/j:cont/l1[k='val1']/act/lf2");
 
-    data =
-            "<cont xmlns=\"urn:tests:j\">\n"
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:j\">\n"
             "  <lf1>not true</lf1>\n"
             "</cont>\n"
-            "<lf4 xmlns=\"urn:tests:j\">target</lf4>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
+            "<lf4 xmlns=\"urn:tests:j\">target</lf4>\n",
+            LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
 
     /* input must false */
     assert_int_equal(LY_EVALID, lyd_validate_op(op_tree, tree, LYD_VALIDATE_OP_REPLY, NULL));
-    logbuf_assert("Must condition \"../../lf1 = 'true2'\" not satisfied. /j:cont/l1[k='val1']/act");
+    CHECK_LOG_CTX("Must condition \"../../lf1 = 'true2'\" not satisfied.", "/j:cont/l1[k='val1']/act");
 
-    lyd_free_siblings(tree);
-    data =
-            "<cont xmlns=\"urn:tests:j\">\n"
+    lyd_free_all(tree);
+    CHECK_PARSE_LYD_PARAM("<cont xmlns=\"urn:tests:j\">\n"
             "  <lf1>true2</lf1>\n"
             "</cont>\n"
-            "<lf4 xmlns=\"urn:tests:j\">target</lf4>\n";
-    assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_ONLY, 0, &tree));
-    assert_non_null(tree);
+            "<lf4 xmlns=\"urn:tests:j\">target</lf4>\n",
+            LYD_XML, LYD_PARSE_ONLY, 0, LY_SUCCESS, tree);
 
     /* success */
     assert_int_equal(LY_SUCCESS, lyd_validate_op(op_tree, tree, LYD_VALIDATE_OP_REPLY, NULL));
 
     lyd_free_tree(op_tree);
-    lyd_free_siblings(tree);
-
-    *state = NULL;
+    lyd_free_all(tree);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_teardown(test_when, teardown_s),
-        cmocka_unit_test_teardown(test_mandatory, teardown_s),
-        cmocka_unit_test_teardown(test_minmax, teardown_s),
-        cmocka_unit_test_teardown(test_unique, teardown_s),
-        cmocka_unit_test_teardown(test_unique_nested, teardown_s),
-        cmocka_unit_test_teardown(test_dup, teardown_s),
-        cmocka_unit_test_teardown(test_defaults, teardown_s),
-        cmocka_unit_test_teardown(test_state, teardown_s),
-        cmocka_unit_test_teardown(test_must, teardown_s),
-        cmocka_unit_test_teardown(test_action, teardown_s),
-        cmocka_unit_test_teardown(test_reply, teardown_s),
+        UTEST(test_when),
+        UTEST(test_mandatory),
+        UTEST(test_minmax),
+        UTEST(test_unique),
+        UTEST(test_unique_nested),
+        UTEST(test_dup),
+        UTEST(test_defaults),
+        UTEST(test_state),
+        UTEST(test_must),
+        UTEST(test_action),
+        UTEST(test_reply),
     };
 
-    return cmocka_run_group_tests(tests, setup, teardown);
+    return cmocka_run_group_tests(tests, NULL, NULL);
 }
diff --git a/tests/utests/extensions/test_metadata.c b/tests/utests/extensions/test_metadata.c
index a5c153b..5a48b86 100644
--- a/tests/utests/extensions/test_metadata.c
+++ b/tests/utests/extensions/test_metadata.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for Metadata extension (annotation) support
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,101 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
+#define _UTEST_MAIN_
 #include "utests.h"
 
 #include "libyang.h"
 #include "plugins_exts_metadata.h"
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct state_s {
-    void *func;
-    struct ly_ctx *ctx;
-};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-setup(void **state)
-{
-    struct state_s *s;
-
-    s = calloc(1, sizeof *s);
-    assert_non_null(s);
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &s->ctx));
-    *state = s;
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-    struct state_s *s = (struct state_s *)(*state);
-
-#if ENABLE_LOGGER_CHECKING
-    if (s->func) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-
-    ly_ctx_destroy(s->ctx, NULL);
-    free(s);
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_yang(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_yang;
-
     const struct lys_module *mod;
     struct lysc_ext_instance *e;
     struct lyext_metadata *ant;
-    struct ly_in *in;
 
     const char *data = "module a {yang-version 1.1; namespace urn:tests:extensions:metadata:a; prefix a;"
             "import ietf-yang-metadata {prefix md;}"
@@ -120,9 +37,7 @@
             "}}";
     const char *feats[] = {"f", NULL};
 
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(s->ctx, in, LYS_IN_YANG, feats, &mod));
-    ly_in_free(in, 0);
+    UTEST_ADD_MODULE(data, LYS_IN_YANG, feats, &mod);
     assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->exts));
     e = &mod->compiled->exts[0];
     assert_non_null(ant = (struct lyext_metadata *)e->data);
@@ -133,55 +48,49 @@
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa;}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa");
 
     /* not allowed substatement */
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa {default x;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance. /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance.", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of units substatement */
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa {type string; units x; units y;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate keyword \"units\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"units\".", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of status substatement */
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa {type string; status current; status obsolete;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate keyword \"status\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"status\".", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of status substatement */
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa {type string; type uint8;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate keyword \"type\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"type\".", "/aa:{extension='md:annotation'}/aa");
 
     /* duplication of the same annotation */
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:metadata:aa; prefix aa;"
             "import ietf-yang-metadata {prefix md;}"
             "md:annotation aa {type string;} md:annotation aa {type uint8;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - metadata, version 1\": "
-            "Extension md:annotation is instantiated multiple times.) /aa:{extension='md:annotation'}/aa");
-
-    s->func = NULL;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - metadata, version 1\": "
+            "Extension md:annotation is instantiated multiple times.)", "/aa:{extension='md:annotation'}/aa");
 }
 
 static void
 test_yin(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_yin;
-
     const struct lys_module *mod;
     struct lysc_ext_instance *e;
     struct lyext_metadata *ant;
@@ -200,7 +109,7 @@
             "  <type name=\"uint8\"/>\n"
             "  <units name=\"meters\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YIN, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, &mod));
     assert_int_equal(1, LY_ARRAY_COUNT(mod->compiled->exts));
     e = &mod->compiled->exts[0];
     assert_non_null(ant = (struct lyext_metadata*)e->data);
@@ -213,8 +122,8 @@
             "<import module=\"ietf-yang-metadata\"><prefix value=\"md\"/></import>\n"
             "<md:annotation name=\"aa\"/>\n"
             "</module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"md:annotation aa\".", "/aa:{extension='md:annotation'}/aa");
 
     /* not allowed substatement */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"aa\">\n"
@@ -223,8 +132,8 @@
             "<md:annotation name=\"aa\">\n"
             "  <default value=\"x\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance. /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"md:annotation aa\" extension instance.", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of units substatement */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"aa\">\n"
@@ -235,8 +144,8 @@
             "  <units name=\"x\"/>\n"
             "  <units name=\"y\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Duplicate keyword \"units\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"units\".", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of status substatement */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"aa\">\n"
@@ -247,8 +156,8 @@
             "  <status value=\"current\"/>\n"
             "  <status value=\"obsolete\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Duplicate keyword \"status\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"status\".", "/aa:{extension='md:annotation'}/aa");
 
     /* invalid cardinality of status substatement */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"aa\">\n"
@@ -258,8 +167,8 @@
             "  <type name=\"string\"/>\n"
             "  <type name=\"uint8\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Duplicate keyword \"type\". /aa:{extension='md:annotation'}/aa");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Duplicate keyword \"type\".", "/aa:{extension='md:annotation'}/aa");
 
     /* duplication of the same annotation */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"aa\">\n"
@@ -270,18 +179,17 @@
             "</md:annotation><md:annotation name=\"aa\">\n"
             "  <type name=\"uint8\"/>\n"
             "</md:annotation></module>";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YIN, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - metadata, version 1\": "
-            "Extension md:annotation is instantiated multiple times.) /aa:{extension='md:annotation'}/aa");
-    s->func = NULL;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YIN, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - metadata, version 1\": "
+            "Extension md:annotation is instantiated multiple times.)", "/aa:{extension='md:annotation'}/aa");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_yang, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_yin, setup, teardown),
+        UTEST(test_yang),
+        UTEST(test_yin),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/extensions/test_nacm.c b/tests/utests/extensions/test_nacm.c
index 2736af9..d8eb157 100644
--- a/tests/utests/extensions/test_nacm.c
+++ b/tests/utests/extensions/test_nacm.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for NACM extensions support
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,99 +11,25 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
+#define _UTEST_MAIN_
 #include "utests.h"
 
 #include "libyang.h"
-#include "tests/config.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct state_s {
-    void *func;
-    struct ly_ctx *ctx;
-};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
 
 static int
 setup(void **state)
 {
-    struct state_s *s;
+    UTEST_SETUP;
 
-    s = calloc(1, sizeof *s);
-    assert_non_null(s);
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &s->ctx));
-    assert_non_null(ly_ctx_load_module(s->ctx, "ietf-netconf-acm", "2018-02-14", NULL));
-
-    *state = s;
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
+    assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-acm", "2018-02-14", NULL));
 
     return 0;
 }
 
-static int
-teardown(void **state)
-{
-    struct state_s *s = (struct state_s *)(*state);
-
-#if ENABLE_LOGGER_CHECKING
-    if (s->func) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-
-    ly_ctx_destroy(s->ctx, NULL);
-    free(s);
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
 static void
 test_deny_all(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_deny_all;
-
     const struct lys_module *mod;
     struct lysc_node_container *cont;
     struct lysc_node_leaf *leaf;
@@ -115,7 +41,7 @@
             "leaf b {type string;}}";
 
     /* valid data */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, &mod));
     assert_non_null(cont = (struct lysc_node_container *)mod->compiled->data);
     assert_non_null(leaf = (struct lysc_node_leaf *)cont->child);
     assert_non_null(e = &cont->exts[0]);
@@ -129,27 +55,23 @@
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
             "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
             "nacm:default-deny-all;}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
-            "Extension nacm:default-deny-all is allowed only in a data nodes, but it is placed in \"module\" statement.) /aa:{extension='nacm:default-deny-all'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - NACM, version 1\": "
+            "Extension nacm:default-deny-all is allowed only in a data nodes, but it is placed in \"module\" statement.)",
+            "/aa:{extension='nacm:default-deny-all'}");
 
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
             "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
             "leaf l { type string; nacm:default-deny-all; nacm:default-deny-write;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
-            "Extension nacm:default-deny-write is mixed with nacm:default-deny-all.) /aa:l/{extension='nacm:default-deny-write'}");
-
-    s->func = NULL;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - NACM, version 1\": "
+            "Extension nacm:default-deny-write is mixed with nacm:default-deny-all.)",
+            "/aa:l/{extension='nacm:default-deny-write'}");
 }
 
 static void
 test_deny_write(void **state)
 {
-    struct state_s *s = (struct state_s *)(*state);
-
-    s->func = test_deny_write;
-
     const struct lys_module *mod;
     struct lysc_node_container *cont;
     struct lysc_node_leaf *leaf;
@@ -161,7 +83,7 @@
             "leaf b {type string;}}";
 
     /* valid data */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(s->ctx, data, LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, &mod));
     assert_non_null(cont = (struct lysc_node_container *)mod->compiled->data);
     assert_non_null(leaf = (struct lysc_node_leaf *)cont->child);
     assert_non_null(e = &cont->exts[0]);
@@ -175,26 +97,26 @@
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
             "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
             "notification notif {nacm:default-deny-write;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
-            "Extension nacm:default-deny-write is not allowed in notification statement.) /aa:notif/{extension='nacm:default-deny-write'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - NACM, version 1\": "
+            "Extension nacm:default-deny-write is not allowed in notification statement.)",
+            "/aa:notif/{extension='nacm:default-deny-write'}");
 
     data = "module aa {yang-version 1.1; namespace urn:tests:extensions:nacm:aa; prefix en;"
             "import ietf-netconf-acm {revision-date 2018-02-14; prefix nacm;}"
             "leaf l { type string; nacm:default-deny-write; nacm:default-deny-write;}}";
-    assert_int_equal(LY_EVALID, lys_parse_mem(s->ctx, data, LYS_IN_YANG, NULL));
-    logbuf_assert("Extension plugin \"libyang 2 - NACM, version 1\": "
-            "Extension nacm:default-deny-write is instantiated multiple times.) /aa:l/{extension='nacm:default-deny-write'}");
-
-    s->func = NULL;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Extension plugin \"libyang 2 - NACM, version 1\": "
+            "Extension nacm:default-deny-write is instantiated multiple times.)",
+            "/aa:l/{extension='nacm:default-deny-write'}");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_deny_all, setup, teardown),
-        cmocka_unit_test_setup_teardown(test_deny_write, setup, teardown),
+        UTEST(test_deny_all, setup),
+        UTEST(test_deny_write, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index c107e76..3b9c81e 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from parser_yang.c
  *
- * Copyright (c) 2018 CESNET, z.s.p.o.
+ * Copyright (c) 2018-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -21,7 +23,6 @@
 #include "schema_compile.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
 
 /* originally static functions from tree_schema_free.c and parser_yang.c */
 void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
@@ -63,103 +64,53 @@
 LY_ERR parse_when(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_when **when_p);
 LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts);
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static void
-logger_setup(void)
-{
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+struct lys_yang_parser_ctx *YCTX;
 
 static int
-setup_f(void **state)
+setup(void **state)
 {
-    struct lys_yang_parser_ctx *pctx;
-    LY_ERR ret;
+    UTEST_SETUP;
 
-    logger_setup();
+    /* allocate parser context */
+    YCTX = calloc(1, sizeof(*YCTX));
+    YCTX->format = LYS_IN_YANG;
+    YCTX->pos_type = LY_VLOG_LINE;
+    YCTX->line = 1;
 
-    pctx = calloc(1, sizeof *pctx);
-    pctx->format = LYS_IN_YANG;
-    pctx->pos_type = LY_VLOG_LINE;
-    pctx->line = 1;
+    /* allocate new parsed module */
+    YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
 
-    pctx->parsed_mod = calloc(1, sizeof *pctx->parsed_mod);
-    pctx->parsed_mod->mod = calloc(1, sizeof *pctx->parsed_mod->mod);
-    pctx->parsed_mod->mod->parsed = pctx->parsed_mod;
-    ret = ly_ctx_new(NULL, 0, &pctx->parsed_mod->mod->ctx);
-    if (ret) {
-        return ret;
-    }
+    /* allocate new module */
+    YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
+    YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
+    YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
 
-    *state = pctx;
     return 0;
 }
 
 static int
-teardown_f(void **state)
+teardown(void **state)
 {
-    struct lys_yang_parser_ctx *pctx = *state;
-    struct ly_ctx *ctx = pctx->parsed_mod->mod->ctx;
+    lys_module_free(YCTX->parsed_mod->mod, NULL);
+    free(YCTX);
+    YCTX = NULL;
 
-    lys_module_free(pctx->parsed_mod->mod, NULL);
-    ly_ctx_destroy(ctx, NULL);
-    free(pctx);
+    UTEST_TEARDOWN;
 
     return 0;
 }
 
 #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
     in.current = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, FUNC(ctx, &in, RESULT)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+    assert_int_equal(LY_EVALID, FUNC(YCTX, &in, RESULT)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number "LINE".");\
     CLEANUP
-
 static void
 test_helpers(void **state)
 {
     struct ly_in in = {0};
     char *buf, *p;
     size_t len, size;
-    struct lys_yang_parser_ctx *ctx = *state;
     uint8_t prefix = 0;
 
     /* storing into buffer */
@@ -177,28 +128,28 @@
     /* invalid first characters */
     len = 0;
     in.current = "2invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = ".invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = "-invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* invalid following characters */
     len = 3; /* number of characters read before the str content */
     in.current = "!";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = ":";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* valid colon for prefixed identifiers */
     len = size = 0;
     p = NULL;
     prefix = 0;
     in.current = "x:id";
-    assert_int_equal(LY_SUCCESS, buf_store_char(ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
+    assert_int_equal(LY_SUCCESS, buf_store_char(YCTX, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
     assert_int_equal(1, len);
     assert_null(buf);
     assert_string_equal(":id", in.current);
     assert_int_equal('x', p[len - 1]);
-    assert_int_equal(LY_SUCCESS, buf_store_char(ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_SUCCESS, buf_store_char(YCTX, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     assert_int_equal(2, len);
     assert_string_equal("id", in.current);
     assert_int_equal(':', p[len - 1]);
@@ -206,208 +157,176 @@
     prefix = 0;
 
     /* checking identifiers */
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, NULL));
-    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, '#', 1, NULL));
-    logbuf_assert("Invalid identifier first character '#' (0x0023). Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, NULL));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, '#', 1, NULL));
+    CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1.");
 
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, 'a', 1, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, 'a', 1, &prefix));
     assert_int_equal(0, prefix);
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
     assert_int_equal(1, prefix);
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
     assert_int_equal(1, prefix);
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, 'b', 0, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, 'b', 0, &prefix));
     assert_int_equal(2, prefix);
     /* second colon is invalid */
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
-    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
 }
 
+#define TEST_GET_ARGUMENT_SUCCESS(INPUT_TEXT, CTX, ARG_TYPE, EXPECT_WORD, EXPECT_LEN, EXPECT_CURRENT)\
+    {\
+        const char * text  = INPUT_TEXT;\
+        in.current = text;\
+        assert_int_equal(LY_SUCCESS, get_argument(CTX, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));\
+        assert_string_equal(word, EXPECT_WORD);\
+        assert_int_equal(len, EXPECT_LEN);\
+        assert_string_equal(EXPECT_CURRENT, in.current);\
+    }
+
 static void
 test_comments(void **state)
 {
     struct ly_in in = {0};
-    struct lys_yang_parser_ctx *ctx = *state;
     char *word, *buf;
     size_t len;
+    const char *in_text;
 
-    in.current = " // this is a text of / one * line */ comment\nargument;";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_string_equal("argument;", word);
+    // in.current = " // this is a text of / one * line */ comment\nargument;";
+    in_text = " // this is a text of / one * line */ comment\nargument;";
+    TEST_GET_ARGUMENT_SUCCESS(in_text, YCTX, Y_STR_ARG, "argument;", 8, ";");
     assert_null(buf);
-    assert_int_equal(8, len);
 
-    in.current = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_string_equal("argument", word);
+    in_text = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
+    TEST_GET_ARGUMENT_SUCCESS(in_text, YCTX, Y_STR_ARG, "argument", 8, ";");
     assert_ptr_equal(buf, word);
-    assert_int_equal(8, len);
     free(word);
 
     in.current = " this is one line comment on last line";
-    assert_int_equal(LY_SUCCESS, skip_comment(ctx, &in, 1));
+    assert_int_equal(LY_SUCCESS, skip_comment(YCTX, &in, 1));
     assert_true(in.current[0] == '\0');
 
     in.current = " this is a not terminated comment x";
-    assert_int_equal(LY_EVALID, skip_comment(ctx, &in, 2));
-    logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5.");
+    assert_int_equal(LY_EVALID, skip_comment(YCTX, &in, 2));
+    CHECK_LOG_CTX("Unexpected end-of-input, non-terminated comment.", "Line number 5.");
     assert_true(in.current[0] == '\0');
 }
 
 static void
 test_arg(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     char *word, *buf;
     size_t len;
 
     /* missing argument */
     in.current = ";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
+    assert_int_equal(LY_SUCCESS, get_argument(YCTX, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
     assert_null(word);
 
     in.current = "{";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"{\", expected an argument.", "Line number 1.");
 
     /* invalid escape sequence */
     in.current = "\"\\s\"";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
-    in.current = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_int_equal(2, len);
-    assert_string_equal("\\s\'", word);
-    assert_int_equal('\0', in.current[0]); /* input has been eaten */
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Double-quoted string unknown special character \'\\s\'.", "Line number 1.");
+
+    TEST_GET_ARGUMENT_SUCCESS("\'\\s\'", YCTX, Y_STR_ARG, "\\s\'", 2, "");
 
     /* invalid character after the argument */
     in.current = "hello\"";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
-    in.current = "hello}";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace.", "Line number 1.");
 
+    in.current = "hello}";
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace.", "Line number 1.");
     /* invalid identifier-ref-arg-str */
     in.current = "pre:pre:value";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
 
     in.current = "\"\";"; /* empty identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Statement argument is required. Line number 1.");
-    logbuf_clean();
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Statement argument is required.", "Line number 1.");
+
     in.current = "\"\";"; /* empty reference identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Statement argument is required. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Statement argument is required.", "Line number 1.");
 
-    in.current = "hello/x\t"; /* slash is not an invalid character */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_int_equal(7, len);
-    assert_string_equal("hello/x\t", word);
-
+    /* slash is not an invalid character */
+    TEST_GET_ARGUMENT_SUCCESS("hello/x\t", YCTX, Y_STR_ARG, "hello/x\t", 7, "\t");
     assert_null(buf);
 
     /* different quoting */
-    in.current = "hello ";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello ", word);
+    TEST_GET_ARGUMENT_SUCCESS("hello/x\t", YCTX, Y_STR_ARG, "hello/x\t", 7, "\t");
 
-    in.current = "hello/*comment*/\n";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_false(strncmp("hello", word, len));
+    TEST_GET_ARGUMENT_SUCCESS("hello ", YCTX, Y_STR_ARG, "hello ", 5, " ");
 
-    in.current = "\"hello\\n\\t\\\"\\\\\";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
-    assert_int_equal(9, len);
-    assert_string_equal("hello\n\t\"\\", word);
+    TEST_GET_ARGUMENT_SUCCESS("hello/*comment*/\n", YCTX, Y_STR_ARG, "hello/*comment*/\n", 5, "\n");
+
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\\n\\t\\\"\\\\\";", YCTX, Y_STR_ARG, "hello\n\t\"\\", 9, ";");
     free(buf);
 
-    ctx->indent = 14;
-    in.current = "\"hello \t\n\t\t world!\"";
+    YCTX->indent = 14;
     /* - space and tabs before newline are stripped out
      * - space and tabs after newline (indentation) are stripped out
      */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
-    assert_ptr_equal(word, buf);
-    assert_int_equal(14, len);
-    assert_string_equal("hello\n  world!", word);
+    TEST_GET_ARGUMENT_SUCCESS("\"hello \t\n\t\t world!\"", YCTX, Y_STR_ARG, "hello\n  world!", 14, "");
     free(buf);
-    /* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */
-    ctx->indent = 14;
-    in.current = "\"hello \\t\n\t\\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+
+/* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello \\t\n\t\\t world!\"", YCTX, Y_STR_ARG, "hello \t\n\t world!", 16, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(16, len);
-    assert_string_equal("hello \t\n\t world!", word);
     free(buf);
+
     /* Do not handle whitespaces after backslash-escaped newline as indentation */
-    ctx->indent = 14;
-    in.current = "\"hello\\n\t\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\\n\t\t world!\"", YCTX, Y_STR_ARG, "hello\n\t\t world!", 15, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(15, len);
-    assert_string_equal("hello\n\t\t world!", word);
     free(buf);
 
-    ctx->indent = 14;
-    in.current = "\"hello\n \tworld!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\n \tworld!\"", YCTX, Y_STR_ARG, "hello\nworld!", 12, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(12, len);
-    assert_string_equal("hello\nworld!", word);
     free(buf);
 
-    in.current = "\'hello\'";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_false(strncmp("hello", word, 5));
+    TEST_GET_ARGUMENT_SUCCESS("\'hello\'", YCTX, Y_STR_ARG, "hello'", 5, "");
 
-    in.current = "\"hel\"  +\t\n\"lo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    TEST_GET_ARGUMENT_SUCCESS("\"hel\"  +\t\n\"lo\"", YCTX, Y_STR_ARG, "hello", 5, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
     free(buf);
+
     in.current = "\"hel\"  +\t\nlo"; /* unquoted the second part */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Both string parts divided by '+' must be quoted. Line number 6.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Both string parts divided by '+' must be quoted.", "Line number 6.");
 
-    in.current = "\'he\'\t\n+ \"llo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
+    TEST_GET_ARGUMENT_SUCCESS("\'he\'\t\n+ \"llo\"", YCTX, Y_STR_ARG, "hello", 5, "");
     free(buf);
 
-    in.current = " \t\n\"he\"+\'llo\'";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
+    TEST_GET_ARGUMENT_SUCCESS(" \t\n\"he\"+\'llo\'", YCTX, Y_STR_ARG, "hello", 5, "");
     free(buf);
 
     /* missing argument */
     in.current = ";";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 8.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \";\", expected an argument.", "Line number 8.");
 }
 
+#define TEST_STMS_SUCCESS(INPUT_TEXT, CTX, ACTION, EXPECT_WORD)\
+                   in.current = INPUT_TEXT;\
+                   assert_int_equal(LY_SUCCESS, get_keyword(CTX, &in, &kw, &word, &len));\
+                   assert_int_equal(ACTION, kw);\
+                   assert_int_equal(strlen(EXPECT_WORD), len);\
+                   assert_true(0 == strncmp(EXPECT_WORD, word, len))
+
 static void
 test_stmts(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     const char *p;
     enum ly_stmt kw;
@@ -415,418 +334,201 @@
     size_t len;
 
     in.current = "\n// comment\n\tinput\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_INPUT, kw);
     assert_int_equal(5, len);
     assert_string_equal("input\t{", word);
     assert_string_equal("\t{", in.current);
 
     in.current = "\t /* comment */\t output\n\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_OUTPUT, kw);
     assert_int_equal(6, len);
     assert_string_equal("output\n\t{", word);
     assert_string_equal("\n\t{", in.current);
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
     assert_int_equal(1, len);
     assert_string_equal("{", word);
     assert_string_equal("", in.current);
 
     in.current = "/input { "; /* invalid slash */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid identifier first character '/'. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid identifier first character '/'.", "Line number 4.");
 
     in.current = "not-a-statement-nor-extension { "; /* invalid identifier */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword.", "Line number 4.");
 
     in.current = "path;"; /* missing sep after the keyword */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"path;\", expected a keyword followed by a separator.", "Line number 4.");
 
-    in.current = "action ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ACTION, kw);
-    assert_int_equal(6, len);
-    in.current = "anydata ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ANYDATA, kw);
-    assert_int_equal(7, len);
-    in.current = "anyxml ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ANYXML, kw);
-    assert_int_equal(6, len);
-    in.current = "argument ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ARGUMENT, kw);
-    assert_int_equal(8, len);
-    in.current = "augment ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_AUGMENT, kw);
-    assert_int_equal(7, len);
-    in.current = "base ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BASE, kw);
-    assert_int_equal(4, len);
-    in.current = "belongs-to ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BELONGS_TO, kw);
-    assert_int_equal(10, len);
-    in.current = "bit ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BIT, kw);
-    assert_int_equal(3, len);
-    in.current = "case ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CASE, kw);
-    assert_int_equal(4, len);
-    in.current = "choice ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CHOICE, kw);
-    assert_int_equal(6, len);
-    in.current = "config ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONFIG, kw);
-    assert_int_equal(6, len);
-    in.current = "contact ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONTACT, kw);
-    assert_int_equal(7, len);
-    in.current = "container ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONTAINER, kw);
-    assert_int_equal(9, len);
-    in.current = "default ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEFAULT, kw);
-    assert_int_equal(7, len);
-    in.current = "description ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DESCRIPTION, kw);
-    assert_int_equal(11, len);
-    in.current = "deviate ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEVIATE, kw);
-    assert_int_equal(7, len);
-    in.current = "deviation ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEVIATION, kw);
-    assert_int_equal(9, len);
-    in.current = "enum ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ENUM, kw);
-    assert_int_equal(4, len);
-    in.current = "error-app-tag ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ERROR_APP_TAG, kw);
-    assert_int_equal(13, len);
-    in.current = "error-message ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ERROR_MESSAGE, kw);
-    assert_int_equal(13, len);
-    in.current = "extension ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_EXTENSION, kw);
-    assert_int_equal(9, len);
-    in.current = "feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_FEATURE, kw);
-    assert_int_equal(7, len);
-    in.current = "fraction-digits ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_FRACTION_DIGITS, kw);
-    assert_int_equal(15, len);
-    in.current = "grouping ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_GROUPING, kw);
-    assert_int_equal(8, len);
-    in.current = "identity ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IDENTITY, kw);
-    assert_int_equal(8, len);
-    in.current = "if-feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IF_FEATURE, kw);
-    assert_int_equal(10, len);
-    in.current = "import ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IMPORT, kw);
-    assert_int_equal(6, len);
-    in.current = "include ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_INCLUDE, kw);
-    assert_int_equal(7, len);
-    in.current = "input{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_INPUT, kw);
-    assert_int_equal(5, len);
-    in.current = "key ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_KEY, kw);
-    assert_int_equal(3, len);
-    in.current = "leaf ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LEAF, kw);
-    assert_int_equal(4, len);
-    in.current = "leaf-list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LEAF_LIST, kw);
-    assert_int_equal(9, len);
-    in.current = "length ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LENGTH, kw);
-    assert_int_equal(6, len);
-    in.current = "list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LIST, kw);
-    assert_int_equal(4, len);
-    in.current = "mandatory ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MANDATORY, kw);
-    assert_int_equal(9, len);
-    in.current = "max-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MAX_ELEMENTS, kw);
-    assert_int_equal(12, len);
-    in.current = "min-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MIN_ELEMENTS, kw);
-    assert_int_equal(12, len);
-    in.current = "modifier ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MODIFIER, kw);
-    assert_int_equal(8, len);
-    in.current = "module ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MODULE, kw);
-    assert_int_equal(6, len);
-    in.current = "must ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MUST, kw);
-    assert_int_equal(4, len);
-    in.current = "namespace ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_NAMESPACE, kw);
-    assert_int_equal(9, len);
-    in.current = "notification ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_NOTIFICATION, kw);
-    assert_int_equal(12, len);
-    in.current = "ordered-by ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ORDERED_BY, kw);
-    assert_int_equal(10, len);
-    in.current = "organization ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ORGANIZATION, kw);
-    assert_int_equal(12, len);
-    in.current = "output ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_OUTPUT, kw);
-    assert_int_equal(6, len);
-    in.current = "path ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PATH, kw);
-    assert_int_equal(4, len);
-    in.current = "pattern ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PATTERN, kw);
-    assert_int_equal(7, len);
-    in.current = "position ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_POSITION, kw);
-    assert_int_equal(8, len);
-    in.current = "prefix ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PREFIX, kw);
-    assert_int_equal(6, len);
-    in.current = "presence ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PRESENCE, kw);
-    assert_int_equal(8, len);
-    in.current = "range ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_RANGE, kw);
-    assert_int_equal(5, len);
-    in.current = "reference ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REFERENCE, kw);
-    assert_int_equal(9, len);
-    in.current = "refine ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REFINE, kw);
-    assert_int_equal(6, len);
-    in.current = "require-instance ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REQUIRE_INSTANCE, kw);
-    assert_int_equal(16, len);
-    in.current = "revision ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REVISION, kw);
-    assert_int_equal(8, len);
-    in.current = "revision-date ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REVISION_DATE, kw);
-    assert_int_equal(13, len);
-    in.current = "rpc ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_RPC, kw);
-    assert_int_equal(3, len);
-    in.current = "status ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_STATUS, kw);
-    assert_int_equal(6, len);
-    in.current = "submodule ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SUBMODULE, kw);
-    assert_int_equal(9, len);
-    in.current = "type ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_TYPE, kw);
-    assert_int_equal(4, len);
-    in.current = "typedef ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_TYPEDEF, kw);
-    assert_int_equal(7, len);
-    in.current = "unique ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_UNIQUE, kw);
-    assert_int_equal(6, len);
-    in.current = "units ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_UNITS, kw);
-    assert_int_equal(5, len);
-    in.current = "uses ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_USES, kw);
-    assert_int_equal(4, len);
-    in.current = "value ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_VALUE, kw);
-    assert_int_equal(5, len);
-    in.current = "when ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_WHEN, kw);
-    assert_int_equal(4, len);
-    in.current = "yang-version ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_YANG_VERSION, kw);
-    assert_int_equal(12, len);
-    in.current = "yin-element ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_YIN_ELEMENT, kw);
-    assert_int_equal(11, len);
-    in.current = ";config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_SEMICOLON, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("action ", YCTX, LY_STMT_ACTION, "action");
+
+    TEST_STMS_SUCCESS("anydata ", YCTX, LY_STMT_ANYDATA, "anydata");
+    TEST_STMS_SUCCESS("anyxml ", YCTX, LY_STMT_ANYXML, "anyxml");
+    TEST_STMS_SUCCESS("argument ", YCTX, LY_STMT_ARGUMENT, "argument");
+    TEST_STMS_SUCCESS("augment ", YCTX, LY_STMT_AUGMENT, "augment");
+    TEST_STMS_SUCCESS("base ", YCTX, LY_STMT_BASE, "base");
+    TEST_STMS_SUCCESS("belongs-to ", YCTX, LY_STMT_BELONGS_TO, "belongs-to");
+    TEST_STMS_SUCCESS("bit ", YCTX, LY_STMT_BIT, "bit");
+    TEST_STMS_SUCCESS("case ", YCTX, LY_STMT_CASE, "case");
+    TEST_STMS_SUCCESS("choice ", YCTX, LY_STMT_CHOICE, "choice");
+    TEST_STMS_SUCCESS("config ", YCTX, LY_STMT_CONFIG, "config");
+    TEST_STMS_SUCCESS("contact ", YCTX, LY_STMT_CONTACT, "contact");
+    TEST_STMS_SUCCESS("container ", YCTX, LY_STMT_CONTAINER, "container");
+    TEST_STMS_SUCCESS("default ", YCTX, LY_STMT_DEFAULT, "default");
+    TEST_STMS_SUCCESS("description ", YCTX, LY_STMT_DESCRIPTION, "description");
+    TEST_STMS_SUCCESS("deviate ", YCTX, LY_STMT_DEVIATE, "deviate");
+    TEST_STMS_SUCCESS("deviation ", YCTX, LY_STMT_DEVIATION, "deviation");
+    TEST_STMS_SUCCESS("enum ", YCTX, LY_STMT_ENUM, "enum");
+    TEST_STMS_SUCCESS("error-app-tag ", YCTX, LY_STMT_ERROR_APP_TAG, "error-app-tag");
+    TEST_STMS_SUCCESS("error-message ", YCTX, LY_STMT_ERROR_MESSAGE, "error-message");
+    TEST_STMS_SUCCESS("extension ", YCTX, LY_STMT_EXTENSION, "extension");
+    TEST_STMS_SUCCESS("feature ", YCTX, LY_STMT_FEATURE, "feature");
+    TEST_STMS_SUCCESS("fraction-digits ", YCTX, LY_STMT_FRACTION_DIGITS, "fraction-digits");
+    TEST_STMS_SUCCESS("grouping ", YCTX, LY_STMT_GROUPING, "grouping");
+    TEST_STMS_SUCCESS("identity ", YCTX, LY_STMT_IDENTITY, "identity");
+    TEST_STMS_SUCCESS("if-feature ", YCTX, LY_STMT_IF_FEATURE, "if-feature");
+    TEST_STMS_SUCCESS("import ", YCTX, LY_STMT_IMPORT, "import");
+    TEST_STMS_SUCCESS("include ", YCTX, LY_STMT_INCLUDE, "include");
+    TEST_STMS_SUCCESS("input{", YCTX, LY_STMT_INPUT, "input");
+    TEST_STMS_SUCCESS("key ", YCTX, LY_STMT_KEY, "key");
+    TEST_STMS_SUCCESS("leaf ", YCTX, LY_STMT_LEAF, "leaf");
+    TEST_STMS_SUCCESS("leaf-list ", YCTX, LY_STMT_LEAF_LIST, "leaf-list");
+    TEST_STMS_SUCCESS("length ", YCTX, LY_STMT_LENGTH, "length");
+    TEST_STMS_SUCCESS("list ", YCTX, LY_STMT_LIST, "list");
+    TEST_STMS_SUCCESS("mandatory ", YCTX, LY_STMT_MANDATORY, "mandatory");
+    TEST_STMS_SUCCESS("max-elements ", YCTX, LY_STMT_MAX_ELEMENTS, "max-elements");
+    TEST_STMS_SUCCESS("min-elements ", YCTX, LY_STMT_MIN_ELEMENTS, "min-elements");
+    TEST_STMS_SUCCESS("modifier ", YCTX, LY_STMT_MODIFIER, "modifier");
+    TEST_STMS_SUCCESS("module ", YCTX, LY_STMT_MODULE, "module");
+    TEST_STMS_SUCCESS("must ", YCTX, LY_STMT_MUST, "must");
+    TEST_STMS_SUCCESS("namespace ", YCTX, LY_STMT_NAMESPACE, "namespace");
+    TEST_STMS_SUCCESS("notification ", YCTX, LY_STMT_NOTIFICATION, "notification");
+    TEST_STMS_SUCCESS("ordered-by ", YCTX, LY_STMT_ORDERED_BY, "ordered-by");
+    TEST_STMS_SUCCESS("organization ", YCTX, LY_STMT_ORGANIZATION, "organization");
+    TEST_STMS_SUCCESS("output ", YCTX, LY_STMT_OUTPUT, "output");
+    TEST_STMS_SUCCESS("path ", YCTX, LY_STMT_PATH, "path");
+    TEST_STMS_SUCCESS("pattern ", YCTX, LY_STMT_PATTERN, "pattern");
+    TEST_STMS_SUCCESS("position ", YCTX, LY_STMT_POSITION, "position");
+    TEST_STMS_SUCCESS("prefix ", YCTX, LY_STMT_PREFIX, "prefix");
+    TEST_STMS_SUCCESS("presence ", YCTX, LY_STMT_PRESENCE, "presence");
+    TEST_STMS_SUCCESS("range ", YCTX, LY_STMT_RANGE, "range");
+    TEST_STMS_SUCCESS("reference ", YCTX, LY_STMT_REFERENCE, "reference");
+    TEST_STMS_SUCCESS("refine ", YCTX, LY_STMT_REFINE, "refine");
+    TEST_STMS_SUCCESS("require-instance ", YCTX, LY_STMT_REQUIRE_INSTANCE, "require-instance");
+    TEST_STMS_SUCCESS("revision ", YCTX, LY_STMT_REVISION, "revision");
+    TEST_STMS_SUCCESS("revision-date ", YCTX, LY_STMT_REVISION_DATE, "revision-date");
+    TEST_STMS_SUCCESS("rpc ", YCTX, LY_STMT_RPC, "rpc");
+    TEST_STMS_SUCCESS("status ", YCTX, LY_STMT_STATUS, "status");
+    TEST_STMS_SUCCESS("submodule ", YCTX, LY_STMT_SUBMODULE, "submodule");
+    TEST_STMS_SUCCESS("type ", YCTX, LY_STMT_TYPE, "type");
+    TEST_STMS_SUCCESS("typedef ", YCTX, LY_STMT_TYPEDEF, "typedef");
+    TEST_STMS_SUCCESS("unique ", YCTX, LY_STMT_UNIQUE, "unique");
+    TEST_STMS_SUCCESS("units ", YCTX, LY_STMT_UNITS, "units");
+    TEST_STMS_SUCCESS("uses ", YCTX, LY_STMT_USES, "uses");
+    TEST_STMS_SUCCESS("value ", YCTX, LY_STMT_VALUE, "value");
+    TEST_STMS_SUCCESS("when ", YCTX, LY_STMT_WHEN, "when");
+    TEST_STMS_SUCCESS("yang-version ", YCTX, LY_STMT_YANG_VERSION, "yang-version");
+    TEST_STMS_SUCCESS("yin-element ", YCTX, LY_STMT_YIN_ELEMENT, "yin-element");
+    TEST_STMS_SUCCESS(";config false;", YCTX, LY_STMT_SYNTAX_SEMICOLON, ";");
     assert_string_equal("config false;", in.current);
-    in.current = "{ config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("{ config false;", YCTX, LY_STMT_SYNTAX_LEFT_BRACE, "{");
     assert_string_equal(" config false;", in.current);
-    in.current = "}";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_RIGHT_BRACE, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("}", YCTX, LY_STMT_SYNTAX_RIGHT_BRACE, "}");
     assert_string_equal("", in.current);
 
     /* geenric extension */
     in.current = p = "nacm:default-deny-write;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_EXTENSION_INSTANCE, kw);
     assert_int_equal(23, len);
     assert_ptr_equal(p, word);
 }
 
+#define TEST_MINMAX_SUCCESS(INPUT_TEXT, CTX, TYPE, VALUE)\
+    in.current = INPUT_TEXT;\
+    if(TYPE == LYS_SET_MIN){\
+       assert_int_equal(LY_SUCCESS, parse_minelements(CTX, &in, &value, &flags, &ext));\
+    }\
+    if(TYPE == LYS_SET_MAX){\
+       assert_int_equal(LY_SUCCESS, parse_maxelements(CTX, &in, &value, &flags, &ext));\
+    }\
+    assert_int_equal(TYPE, flags);\
+    assert_int_equal(VALUE, value)
+
 static void
 test_minmax(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     uint16_t flags = 0;
     uint32_t value = 0;
     struct lysp_ext_instance *ext = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     in.current = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"1invalid\" of \"min-elements\".", "Line number 1.");
 
     flags = value = 0;
     in.current = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"min-elements\".", "Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
     in.current = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Value \"4294967296\" is out of \"min-elements\" bounds.", "Line number 1.");
 
     flags = value = 0;
-    in.current = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MIN, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1; ...", YCTX, LYS_SET_MIN, 1);
 
     flags = value = 0;
-    in.current = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MIN, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MIN, 1);
     assert_non_null(ext);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
     ext = NULL;
 
     flags = value = 0;
     in.current = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"min-elements\".", "Line number 1.");
 
     in.current = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"1invalid\" of \"max-elements\".", "Line number 1.");
 
     flags = value = 0;
     in.current = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"max-elements\".", "Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
     in.current = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Value \"4294967296\" is out of \"max-elements\" bounds.", "Line number 1.");
 
     flags = value = 0;
-    in.current = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1; ...", YCTX, LYS_SET_MAX, 1);
 
     flags = value = 0;
-    in.current = " unbounded; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(0, value);
+    TEST_MINMAX_SUCCESS(" unbounded; ...", YCTX, LYS_SET_MAX, 0);
 
     flags = value = 0;
-    in.current = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MAX, 1);
     assert_non_null(ext);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
     ext = NULL;
 
     flags = value = 0;
     in.current = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"max-elements\".", "Line number 1.");
 }
 
 static struct lysp_module *
@@ -872,51 +574,51 @@
 static void
 test_module(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_module *mod = NULL;
     struct lysp_submodule *submod = NULL;
     struct lys_module *m;
     struct ly_in in = {0};
     struct lys_glob_unres unres = {0};
+    struct lys_yang_parser_ctx *ctx_p;
 
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
     /* missing mandatory substatements */
     in.current = " name {}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
     assert_string_equal("name", mod->mod->name);
-    logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    CHECK_LOG_CTX("Missing mandatory keyword \"namespace\" as a child of \"module\".", "Line number 1.");
 
+    mod = mod_renew(YCTX);
     in.current = " name {namespace urn:x;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
     assert_string_equal("urn:x", mod->mod->ns);
-    logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    CHECK_LOG_CTX("Missing mandatory keyword \"prefix\" as a child of \"module\".", "Line number 1.");
+    mod = mod_renew(YCTX);
 
     in.current = " name {namespace urn:x;prefix \"x\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_string_equal("x", mod->mod->prefix);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
 #define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
 #define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
 #define TEST_NODE(NODETYPE, INPUT, NAME) \
         in.current = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod)); \
+        assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod)); \
         assert_non_null(mod->data); \
         assert_int_equal(NODETYPE, mod->data->nodetype); \
         assert_string_equal(NAME, mod->data->name); \
-        mod = mod_renew(ctx);
+        mod = mod_renew(YCTX);
 #define TEST_GENERIC(INPUT, TARGET, TEST) \
         in.current = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod)); \
+        assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod)); \
         assert_non_null(TARGET); \
         TEST; \
-        mod = mod_renew(ctx);
+        mod = mod_renew(YCTX);
 #define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE) \
         TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \
-                         parse_module, mod, LINE, mod = mod_renew(ctx))
+                         parse_module, mod, LINE, mod = mod_renew(YCTX))
 
     /* duplicated namespace, prefix */
     TEST_DUP("namespace", "y", "z", "1");
@@ -928,9 +630,9 @@
 
     /* not allowed in module (submodule-specific) */
     in.current = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid keyword \"belongs-to\" as a child of \"module\".", "Line number 1.");
+    mod = mod_renew(YCTX);
 
     /* anydata */
     TEST_NODE(LYS_ANYDATA, "anydata test;}", "test");
@@ -965,39 +667,37 @@
     TEST_GENERIC("identity test;}", mod->identities,
             assert_string_equal("test", mod->identities[0].name));
     /* import */
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
     TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
             assert_string_equal("zzz", mod->imports[0].name));
 
     /* import - prefix collision */
     in.current = SCHEMA_BEGINNING "import zzz {prefix x;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Prefix \"x\" already used as module prefix.", "Line number 2.");
+    mod = mod_renew(YCTX);
+
     in.current = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Prefix \"y\" already used to import \"zzz\" module.", "Line number 2.");
+
+    mod = mod_renew(YCTX);
     in.current = "module name10 {yang-version 1.1;namespace urn:x;prefix \"x\";import zzz {prefix y;}import zzz {prefix z;}}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Single revision of the module \"zzz\" imported twice.");
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Single revision of the module \"zzz\" imported twice.", NULL);
 
     /* include */
-    store = 1;
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
     in.current = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Input data contains module in situation when a submodule is expected.");
-    store = -1;
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL);
 
-    store = 1;
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
     in.current = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Submodule \"belongs-to\" value \"wrong-name\" does not match its module name \"name\". Line number 1.");
-    store = -1;
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL);
 
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
     TEST_GENERIC("include xxx;}", mod->includes,
             assert_string_equal("xxx", mod->includes[0].name));
 
@@ -1029,44 +729,43 @@
     TEST_NODE(LYS_USES, "uses test;}", "test");
     /* yang-version */
     in.current = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid value \"10\" of \"yang-version\".", "Line number 3.");
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version 1;yang-version 1.1;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Duplicate keyword \"yang-version\".", "Line number 3.");
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version 1;}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_int_equal(1, mod->version);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_int_equal(2, mod->version);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
-    struct lys_yang_parser_ctx *ctx_p = NULL;
     in.current = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 1.");
+    CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after module, expected end-of-input.", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
     in.current = "prefix " SCHEMA_BEGINNING "}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
     in.current = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Invalid keyword \"position\" as a child of \"enum\". Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"position\" as a child of \"enum\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
@@ -1074,57 +773,58 @@
     TEST_GENERIC("prefix:test;}", mod->exts,
             assert_string_equal("prefix:test", mod->exts[0].name);
             assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
     /* invalid substatement */
     in.current = SCHEMA_BEGINNING "must false;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"module\".", "Line number 3.");
 
     /* submodule */
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
     /* missing mandatory substatements */
     in.current = " subname {}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\".", "Line number 3.");
     assert_string_equal("subname", submod->name);
-    logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+
+    submod = submod_renew(YCTX);
 
     in.current = " subname {belongs-to name {prefix x;}}";
-    assert_int_equal(LY_SUCCESS, parse_submodule(ctx, &in, submod));
+    assert_int_equal(LY_SUCCESS, parse_submodule(YCTX, &in, submod));
     assert_string_equal("name", submod->mod->name);
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
 #undef SCHEMA_BEGINNING
 #define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
 
     /* duplicated namespace, prefix */
     in.current = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod)); \
-    logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Duplicate keyword \"belongs-to\".", "Line number 3.");
+    submod = submod_renew(YCTX);
 
     /* not allowed in submodule (module-specific) */
     in.current = SCHEMA_BEGINNING "namespace \"urn:z\";}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
-    logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Invalid keyword \"namespace\" as a child of \"submodule\".", "Line number 3.");
+    submod = submod_renew(YCTX);
     in.current = SCHEMA_BEGINNING "prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
-    logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Invalid keyword \"prefix\" as a child of \"submodule\".", "Line number 3.");
+    submod = submod_renew(YCTX);
 
     in.current = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx->parsed_mod->mod->ctx, (struct lys_parser_ctx *)ctx, &in, &submod));
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, &in, &submod));
+    CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after submodule, expected end-of-input.", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
-    logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 1.");
 
     in.current = "prefix " SCHEMA_BEGINNING "}";
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx->parsed_mod->mod->ctx, (struct lys_parser_ctx *)ctx, &in, &submod));
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, &in, &submod));
+    CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
-    logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
 #undef TEST_GENERIC
 #undef TEST_NODE
@@ -1135,54 +835,58 @@
 static void
 test_deviation(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_deviation *d = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
-                     &d, "1", FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free); d = NULL)
+                     &d, "1", FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free); d = NULL)
 
     TEST_DUP("description", "a", "b");
     TEST_DUP("reference", "a", "b");
 
     /* full content */
     in.current = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviation(ctx, &in, &d));
+    assert_int_equal(LY_SUCCESS, parse_deviation(YCTX, &in, &d));
     assert_non_null(d);
     assert_string_equal(" ...", in.current);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* missing mandatory substatement */
     in.current = " test {description text;}";
-    assert_int_equal(LY_EVALID, parse_deviation(ctx, &in, &d));
-    logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    assert_int_equal(LY_EVALID, parse_deviation(YCTX, &in, &d));
+    CHECK_LOG_CTX("Missing mandatory keyword \"deviate\" as a child of \"deviation\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* invalid substatement */
     in.current = " test {deviate not-supported; status obsolete;}";
-    assert_int_equal(LY_EVALID, parse_deviation(ctx, &in, &d));
-    logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    assert_int_equal(LY_EVALID, parse_deviation(YCTX, &in, &d));
+    CHECK_LOG_CTX("Invalid keyword \"status\" as a child of \"deviation\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
-
 #undef TEST_DUP
 }
 
+#define TEST_DEVIATE_SUCCESS(INPUT_TEXT, REMAIN_TEXT)\
+                    in.current = INPUT_TEXT;\
+                    assert_int_equal(LY_SUCCESS, parse_deviate(YCTX, &in, &d));\
+                    assert_non_null(d);\
+                    assert_string_equal(REMAIN_TEXT, in.current);\
+                    lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
+
 static void
 test_deviate(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_deviate *d = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
     TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
-                     &d, "1", lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL)
+                     &d, "1", lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL)
 
     TEST_DUP("add", "config", "true", "false");
     TEST_DUP("replace", "default", "int8", "uint8");
@@ -1193,33 +897,17 @@
     TEST_DUP("add", "units", "kilometers", "miles");
 
     /* full contents */
-    in.current = " not-supported {prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
+    TEST_DEVIATE_SUCCESS(" not-supported {prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...", " ...");
 
     /* invalid substatements */
 #define TEST_NOT_SUP(DEV, STMT, VALUE) \
     in.current = " "DEV" {"STMT" "VALUE";}..."; \
-    assert_int_equal(LY_EVALID, parse_deviate(ctx, &in, &d)); \
-    logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL
+    assert_int_equal(LY_EVALID, parse_deviate(YCTX, &in, &d)); \
+    CHECK_LOG_CTX("Deviate \""DEV"\" does not support keyword \""STMT"\".", "Line number 1.");\
+    lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
 
     TEST_NOT_SUP("not-supported", "units", "meters");
     TEST_NOT_SUP("not-supported", "must", "1");
@@ -1240,10 +928,9 @@
     TEST_NOT_SUP("replace", "unique", "a");
 
     in.current = " nonsence; ...";
-    assert_int_equal(LY_EVALID, parse_deviate(ctx, &in, &d));
-    logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_deviate(YCTX, &in, &d));
+    CHECK_LOG_CTX("Invalid value \"nonsence\" of \"deviate\".", "Line number 1.");\
     assert_null(d);
-
 #undef TEST_NOT_SUP
 #undef TEST_DUP
 }
@@ -1251,18 +938,17 @@
 static void
 test_container(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node**)&c)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node**)&c)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)c); c = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1275,58 +961,48 @@
     /* full content */
     in.current = "cont {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; leaf l {type string;}"
             "leaf-list ll {type string;} list li;must 'expr';notification not; presence true; reference test;status current;typedef t {type int8;}uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    assert_non_null(c);
-    assert_int_equal(LYS_CONTAINER, c->nodetype);
-    assert_string_equal("cont", c->name);
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LYSP_NODE(c, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "cont", 0, LYS_CONTAINER, 0, "test", 1);
     assert_non_null(c->actions);
     assert_non_null(c->child);
-    assert_string_equal("test", c->dsc);
-    assert_non_null(c->exts);
     assert_non_null(c->groupings);
-    assert_non_null(c->iffeatures);
     assert_non_null(c->musts);
     assert_non_null(c->notifs);
     assert_string_equal("true", c->presence);
-    assert_string_equal("test", c->ref);
     assert_non_null(c->typedefs);
-    assert_non_null(c->when);
-    assert_null(c->parent);
-    assert_null(c->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 
     /* invalid */
     in.current = " cont {augment /root;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid keyword \"augment\" as a child of \"container\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
     in.current = " cont {nonsence true;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid character sequence \"nonsence\", expected a keyword.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     in.current = " cont {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - "
+            "the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 }
 
 static void
 test_leaf(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_leaf *l = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaf(ctx, &in, NULL, (struct lysp_node**)&l)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_leaf(YCTX, &in, NULL, (struct lysp_node**)&l)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("default", "x", "y");
@@ -1342,56 +1018,42 @@
     /* full content - without mandatory which is mutual exclusive with default */
     in.current = "l {config false;default \"xxx\";description test;if-feature f;"
             "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LEAF, l->nodetype);
-    assert_string_equal("l", l->name);
-    assert_string_equal("test", l->dsc);
+    assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "l", 0, LYS_LEAF, 0, "test", 1);
     assert_string_equal("xxx", l->dflt.str);
     assert_string_equal("yyy", l->units);
     assert_string_equal("string", l->type.name);
-    assert_non_null(l->exts);
-    assert_non_null(l->iffeatures);
     assert_non_null(l->musts);
-    assert_string_equal("test", l->ref);
-    assert_non_null(l->when);
-    assert_null(l->parent);
-    assert_null(l->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* full content - now with mandatory */
     in.current = "l {mandatory true; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LEAF, l->nodetype);
-    assert_string_equal("l", l->name);
+    assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, NULL, 0, LYS_MAND_TRUE, 0, "l", 0, LYS_LEAF, 0, NULL, 0);
     assert_string_equal("string", l->type.name);
-    assert_int_equal(LYS_MAND_TRUE, l->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* invalid */
     in.current = " l {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 }
 
 static void
 test_leaflist(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_leaflist *ll = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node**)&ll)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node**)&ll)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ll); ll = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1409,11 +1071,8 @@
     in.current = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
             "max-elements 10;must 'expr';ordered-by user;reference test;"
             "status current;type string; units zzz;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    assert_non_null(ll);
-    assert_int_equal(LYS_LEAFLIST, ll->nodetype);
-    assert_string_equal("ll", ll->name);
-    assert_string_equal("test", ll->dsc);
+    assert_int_equal(LY_SUCCESS, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LYSP_NODE(ll, "test", 1, 0x446, 1, "ll", 0, LYS_LEAFLIST, 0, "test", 1);
     assert_non_null(ll->dflts);
     assert_int_equal(2, LY_ARRAY_COUNT(ll->dflts));
     assert_string_equal("xxx", ll->dflts[0].str);
@@ -1422,56 +1081,47 @@
     assert_int_equal(10, ll->max);
     assert_int_equal(0, ll->min);
     assert_string_equal("string", ll->type.name);
-    assert_non_null(ll->exts);
-    assert_non_null(ll->iffeatures);
     assert_non_null(ll->musts);
-    assert_string_equal("test", ll->ref);
-    assert_non_null(ll->when);
-    assert_null(ll->parent);
-    assert_null(ll->next);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
     /* full content - now with min-elements */
     in.current = "ll {min-elements 10; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    assert_non_null(ll);
-    assert_int_equal(LYS_LEAFLIST, ll->nodetype);
-    assert_string_equal("ll", ll->name);
+    assert_int_equal(LY_SUCCESS, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LYSP_NODE(ll, NULL, 0, 0x200, 0, "ll", 0, LYS_LEAFLIST, 0, NULL, 0);
     assert_string_equal("string", ll->type.name);
     assert_int_equal(0, ll->max);
     assert_int_equal(10, ll->min);
     assert_int_equal(LYS_SET_MIN, ll->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
     /* invalid */
     in.current = " ll {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf-list\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
     in.current = " ll {default xx; type string;} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 }
 
 static void
 test_list(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_list *l = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_list(ctx, &in, NULL, (struct lysp_node**)&l)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_list(YCTX, &in, NULL, (struct lysp_node**)&l)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1488,11 +1138,9 @@
     in.current = "l {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; key l; leaf l {type string;}"
             "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;"
             "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_list(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LIST, l->nodetype);
-    assert_string_equal("l", l->name);
-    assert_string_equal("test", l->dsc);
+    assert_int_equal(LY_SUCCESS, parse_list(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, 1, "l",
+            0, LYS_LIST, 0, "test", 1);
     assert_string_equal("l", l->key);
     assert_non_null(l->uniques);
     assert_int_equal(2, LY_ARRAY_COUNT(l->uniques));
@@ -1500,40 +1148,32 @@
     assert_string_equal("yyy", l->uniques[1].str);
     assert_int_equal(10, l->max);
     assert_int_equal(1, l->min);
-    assert_non_null(l->exts);
-    assert_non_null(l->iffeatures);
     assert_non_null(l->musts);
-    assert_string_equal("test", l->ref);
-    assert_non_null(l->when);
-    assert_null(l->parent);
-    assert_null(l->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* invalid content */
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     in.current = "l {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_list(ctx, &in, NULL, (struct lysp_node **)&l));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_list(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 }
 
 static void
 test_choice(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_choice *ch = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_choice(ctx, &in, NULL, (struct lysp_node**)&ch)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)ch); ch = NULL;
+    assert_int_equal(LY_EVALID, parse_choice(YCTX, &in, NULL, (struct lysp_node**)&ch)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ch); ch = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("default", "a", "b");
@@ -1547,46 +1187,32 @@
     /* full content - without default due to a collision with mandatory */
     in.current = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(ctx, &in, NULL, (struct lysp_node **)&ch));
-    assert_non_null(ch);
-    assert_int_equal(LYS_CHOICE, ch->nodetype);
-    assert_string_equal("ch", ch->name);
-    assert_string_equal("test", ch->dsc);
-    assert_non_null(ch->exts);
-    assert_non_null(ch->iffeatures);
-    assert_string_equal("test", ch->ref);
-    assert_non_null(ch->when);
-    assert_null(ch->parent);
-    assert_null(ch->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+    assert_int_equal(LY_SUCCESS, parse_choice(YCTX, &in, NULL, (struct lysp_node **)&ch));
+    CHECK_LYSP_NODE(ch, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "ch", 0, LYS_CHOICE, 0, "test", 1);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
 
     /* full content - the default missing from the previous node */
     in.current = "ch {default c;case c;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(ctx, &in, NULL, (struct lysp_node **)&ch));
-    assert_non_null(ch);
-    assert_int_equal(LYS_CHOICE, ch->nodetype);
-    assert_string_equal("ch", ch->name);
+    assert_int_equal(LY_SUCCESS, parse_choice(YCTX, &in, NULL, (struct lysp_node **)&ch));
+    CHECK_LYSP_NODE(ch, NULL, 0, 0, 0, "ch", 0, LYS_CHOICE, 0, NULL, 0);
     assert_string_equal("c", ch->dflt.str);
-    assert_int_equal(0, ch->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
 }
 
 static void
 test_case(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_case *cs = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_case(ctx, &in, NULL, (struct lysp_node**)&cs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)cs); cs = NULL;
+    assert_int_equal(LY_EVALID, parse_case(YCTX, &in, NULL, (struct lysp_node**)&cs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)cs); cs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1597,46 +1223,35 @@
     /* full content */
     in.current = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_case(ctx, &in, NULL, (struct lysp_node **)&cs));
-    assert_non_null(cs);
-    assert_int_equal(LYS_CASE, cs->nodetype);
-    assert_string_equal("cs", cs->name);
-    assert_string_equal("test", cs->dsc);
-    assert_non_null(cs->exts);
-    assert_non_null(cs->iffeatures);
-    assert_string_equal("test", cs->ref);
-    assert_non_null(cs->when);
-    assert_null(cs->parent);
-    assert_null(cs->next);
-    assert_int_equal(LYS_STATUS_CURR, cs->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+    assert_int_equal(LY_SUCCESS, parse_case(YCTX, &in, NULL, (struct lysp_node **)&cs));
+    CHECK_LYSP_NODE(cs, "test", 1, LYS_STATUS_CURR, 1, "cs", 0, LYS_CASE, 0, "test", 1);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
 
     /* invalid content */
     in.current = "cs {config true} ...";
-    assert_int_equal(LY_EVALID, parse_case(ctx, &in, NULL, (struct lysp_node **)&cs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+    assert_int_equal(LY_EVALID, parse_case(YCTX, &in, NULL, (struct lysp_node **)&cs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"case\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
 }
 
 static void
 test_any(void **state, enum ly_stmt kw)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_anydata *any = NULL;
     struct ly_in in = {0};
 
     if (kw == LY_STMT_ANYDATA) {
-        ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+        YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
     } else {
-        ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+        YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     }
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_any(ctx, &in, kw, NULL, (struct lysp_node**)&any)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)any); any = NULL;
+    assert_int_equal(LY_EVALID, parse_any(YCTX, &in, kw, NULL, (struct lysp_node**)&any)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)any); any = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1648,20 +1263,12 @@
 
     /* full content */
     in.current = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_any(ctx, &in, kw, NULL, (struct lysp_node **)&any));
-    assert_non_null(any);
-    assert_int_equal(kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
-    assert_string_equal("any", any->name);
-    assert_string_equal("test", any->dsc);
-    assert_non_null(any->exts);
-    assert_non_null(any->iffeatures);
+    assert_int_equal(LY_SUCCESS, parse_any(YCTX, &in, kw, NULL, (struct lysp_node **)&any));
+    // CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, TYPE, PARENT, REF, WHEN)
+    uint16_t node_type = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML;
+    CHECK_LYSP_NODE(any, "test", 1, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "any", 0, node_type, 0, "test", 1);
     assert_non_null(any->musts);
-    assert_string_equal("test", any->ref);
-    assert_non_null(any->when);
-    assert_null(any->parent);
-    assert_null(any->next);
-    assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)any); any = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)any); any = NULL;
 }
 
 static void
@@ -1679,18 +1286,17 @@
 static void
 test_grouping(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_grp *grp = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1700,7 +1306,7 @@
     /* full content */
     in.current = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
             "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_grouping(ctx, &in, NULL, &grp));
+    assert_int_equal(LY_SUCCESS, parse_grouping(YCTX, &in, NULL, &grp));
     assert_non_null(grp);
     assert_int_equal(LYS_GROUPING, grp->nodetype);
     assert_string_equal("grp", grp->name);
@@ -1709,37 +1315,36 @@
     assert_string_equal("test", grp->ref);
     assert_null(grp->parent);
     assert_int_equal(LYS_STATUS_CURR, grp->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     /* invalid content */
     in.current = "grp {config true} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"grouping\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     in.current = "grp {must 'expr'} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp));
-    logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp));
+    CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"grouping\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 }
 
 static void
 test_action(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_action *rpcs = NULL;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_action(ctx, &in, NULL, &rpcs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    assert_int_equal(LY_EVALID, parse_action(YCTX, &in, NULL, &rpcs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("input", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a");
@@ -1750,13 +1355,13 @@
 
     /* full content */
     in.current = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
     in.current = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
             "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
             " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}"
             "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
             " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ...";
-    assert_int_equal(LY_SUCCESS, parse_action(ctx, &in, (struct lysp_node *)c, &rpcs));
+    assert_int_equal(LY_SUCCESS, parse_action(YCTX, &in, (struct lysp_node *)c, &rpcs));
     assert_non_null(rpcs);
     assert_int_equal(LYS_ACTION, rpcs->nodetype);
     assert_string_equal("func", rpcs->name);
@@ -1782,34 +1387,33 @@
     assert_non_null(rpcs->output.typedefs);
     assert_non_null(rpcs->output.data);
 
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
     /* invalid content */
     in.current = "func {config true} ...";
-    assert_int_equal(LY_EVALID, parse_action(ctx, &in, NULL, &rpcs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    assert_int_equal(LY_EVALID, parse_action(YCTX, &in, NULL, &rpcs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"rpc\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
 }
 
 static void
 test_notification(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_notif *notifs = NULL;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_notif(ctx, &in, NULL, &notifs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    assert_int_equal(LY_EVALID, parse_notif(YCTX, &in, NULL, &notifs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1818,10 +1422,10 @@
 
     /* full content */
     in.current = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
     in.current = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
             "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}";
-    assert_int_equal(LY_SUCCESS, parse_notif(ctx, &in, (struct lysp_node *)c, &notifs));
+    assert_int_equal(LY_SUCCESS, parse_notif(YCTX, &in, (struct lysp_node *)c, &notifs));
     assert_non_null(notifs);
     assert_int_equal(LYS_NOTIF, notifs->nodetype);
     assert_string_equal("ntf", notifs->name);
@@ -1835,33 +1439,32 @@
     assert_non_null(notifs->data);
     assert_int_equal(LYS_STATUS_CURR, notifs->flags);
 
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
     /* invalid content */
     in.current = "ntf {config true} ...";
-    assert_int_equal(LY_EVALID, parse_notif(ctx, &in, NULL, &notifs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    assert_int_equal(LY_EVALID, parse_notif(YCTX, &in, NULL, &notifs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"notification\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
 }
 
 static void
 test_uses(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_uses *u = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_uses(ctx, &in, NULL, (struct lysp_node**)&u)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)u); u = NULL;
+    assert_int_equal(LY_EVALID, parse_uses(YCTX, &in, NULL, (struct lysp_node**)&u)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)u); u = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1871,38 +1474,27 @@
 
     /* full content */
     in.current = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_uses(ctx, &in, NULL, (struct lysp_node **)&u));
-    assert_non_null(u);
-    assert_int_equal(LYS_USES, u->nodetype);
-    assert_string_equal("grpref", u->name);
-    assert_string_equal("test", u->dsc);
-    assert_non_null(u->exts);
-    assert_non_null(u->iffeatures);
-    assert_string_equal("test", u->ref);
+    assert_int_equal(LY_SUCCESS, parse_uses(YCTX, &in, NULL, (struct lysp_node **)&u));
+    CHECK_LYSP_NODE(u, "test", 1, LYS_STATUS_CURR, 1, "grpref", 0, LYS_USES, 0, "test", 1);
     assert_non_null(u->augments);
     assert_non_null(u->refines);
-    assert_non_null(u->when);
-    assert_null(u->parent);
-    assert_null(u->next);
-    assert_int_equal(LYS_STATUS_CURR, u->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)u); u = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)u); u = NULL;
 }
 
 static void
 test_augment(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_augment *a = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_augment(ctx, &in, NULL, &a)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
+    assert_int_equal(LY_EVALID, parse_augment(YCTX, &in, NULL, &a)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1913,7 +1505,7 @@
     /* full content */
     in.current = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_augment(ctx, &in, NULL, &a));
+    assert_int_equal(LY_SUCCESS, parse_augment(YCTX, &in, NULL, &a));
     assert_non_null(a);
     assert_int_equal(LYS_AUGMENT, a->nodetype);
     assert_string_equal("/target/nodeid", a->nodeid);
@@ -1924,24 +1516,23 @@
     assert_non_null(a->when);
     assert_null(a->parent);
     assert_int_equal(LYS_STATUS_CURR, a->flags);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
 }
 
 static void
 test_when(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_when *w = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_when(ctx, &in, &w)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    assert_int_equal(LY_EVALID, parse_when(YCTX, &in, &w)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1949,68 +1540,67 @@
 
     /* full content */
     in.current = "expression {description test;reference test;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_when(ctx, &in, &w));
+    assert_int_equal(LY_SUCCESS, parse_when(YCTX, &in, &w));
     assert_non_null(w);
     assert_string_equal("expression", w->cond);
     assert_string_equal("test", w->dsc);
     assert_string_equal("test", w->ref);
     assert_non_null(w->exts);
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 
     /* empty condition */
     in.current = "\"\";";
-    assert_int_equal(LY_SUCCESS, parse_when(ctx, &in, &w));
-    logbuf_assert("Empty argument of when statement does not make sense.");
+    assert_int_equal(LY_SUCCESS, parse_when(YCTX, &in, &w));
+    CHECK_LOG_CTX("Empty argument of when statement does not make sense.", NULL);
     assert_non_null(w);
     assert_string_equal("", w->cond);
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 }
 
 static void
 test_value(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     int64_t val = 0;
     uint16_t flags = 0;
 
     in.current = "-0;";
-    assert_int_equal(parse_type_enum_value_pos(ctx, &in, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
+    assert_int_equal(parse_type_enum_value_pos(YCTX, &in, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
     assert_int_equal(val, 0);
 
     in.current = "-0;";
     flags = 0;
-    assert_int_equal(parse_type_enum_value_pos(ctx, &in, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
+    assert_int_equal(parse_type_enum_value_pos(YCTX, &in, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-0\" of \"position\".", "Line number 1.");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_helpers, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_comments, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_arg, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_stmts, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_minmax, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_module, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviation, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviate, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_container, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaflist, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_list, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_choice, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_case, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_anydata, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_anyxml, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_action, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_notification, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_grouping, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_uses, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_augment, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_when, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_value, setup_f, teardown_f),
+        UTEST(test_helpers, setup, teardown),
+        UTEST(test_comments, setup, teardown),
+        UTEST(test_arg, setup, teardown),
+        UTEST(test_stmts, setup, teardown),
+        UTEST(test_minmax, setup, teardown),
+        UTEST(test_module, setup, teardown),
+        UTEST(test_deviation, setup, teardown),
+        UTEST(test_deviate, setup, teardown),
+        UTEST(test_container, setup, teardown),
+        UTEST(test_leaf, setup, teardown),
+        UTEST(test_leaflist, setup, teardown),
+        UTEST(test_list, setup, teardown),
+        UTEST(test_choice, setup, teardown),
+        UTEST(test_case, setup, teardown),
+        UTEST(test_anydata, setup, teardown),
+        UTEST(test_anyxml, setup, teardown),
+        UTEST(test_action, setup, teardown),
+        UTEST(test_notification, setup, teardown),
+        UTEST(test_grouping, setup, teardown),
+        UTEST(test_uses, setup, teardown),
+        UTEST(test_augment, setup, teardown),
+        UTEST(test_when, setup, teardown),
+        UTEST(test_value, setup, teardown),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index fe33de4..5adcf3a 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -3,7 +3,7 @@
  * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
  * @brief unit tests for functions from parser_yin.c
  *
- * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2015 - 2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -22,7 +24,6 @@
 #include "schema_compile.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
 #include "xml.h"
 #include "xpath.h"
 
@@ -122,251 +123,153 @@
 #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
 #define ELEMENT_WRAPPER_END "</status>"
 
-struct test_parser_yin_state {
-    struct ly_ctx *ctx;
-    struct lys_yin_parser_ctx *yin_ctx;
-    struct ly_in *in;
-    bool finished_correctly;
-};
+#define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\
+    CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, NULL, INSUBSTMT, 0, "urn:example:extensions:c-define", 0, 0x2, 0x1)
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
-    str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
-    CLEANUP
-
-int
-setup_ly_ctx(void **state)
-{
-    struct test_parser_yin_state *st = NULL;
-
-    /* allocate state variable */
-    (*state) = st = calloc(1, sizeof(*st));
-    if (!st) {
-        fprintf(stderr, "Memmory allocation failed");
-        return EXIT_FAILURE;
-    }
-
-    /* create new libyang context */
-    ly_ctx_new(NULL, 0, &st->ctx);
-
-    return EXIT_SUCCESS;
-}
-
-int
-destroy_ly_ctx(void **state)
-{
-    struct test_parser_yin_state *st = *state;
-
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st);
-
-    return EXIT_SUCCESS;
-}
+struct lys_yin_parser_ctx *YCTX;
 
 static int
-setup_f(void **state)
+setup_ctx(void **state)
 {
-    struct test_parser_yin_state *st = *state;
-
-#if ENABLE_LOGGER_CHECKING
-    /* setup logger */
-    ly_set_log_clb(logger, 1);
-#endif
-
     /* allocate parser context */
-    st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
-    st->yin_ctx->format = LYS_IN_YIN;
+    YCTX = calloc(1, sizeof(*YCTX));
+    YCTX->format = LYS_IN_YIN;
 
     /* allocate new parsed module */
-    st->yin_ctx->parsed_mod = calloc(1, sizeof *st->yin_ctx->parsed_mod);
+    YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
 
     /* allocate new module */
-    st->yin_ctx->parsed_mod->mod = calloc(1, sizeof *st->yin_ctx->parsed_mod->mod);
-    st->yin_ctx->parsed_mod->mod->ctx = st->ctx;
-    st->yin_ctx->parsed_mod->mod->parsed = st->yin_ctx->parsed_mod;
+    YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
+    YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
+    YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
 
-    st->in = NULL;
-
-    return EXIT_SUCCESS;
+    return 0;
 }
 
 static int
-teardown_f(void **state)
+setup(void **state)
 {
-    struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
+    UTEST_SETUP;
 
-#if ENABLE_LOGGER_CHECKING
-    /* teardown logger */
-    if (!st->finished_correctly && (logbuf[0] != '\0')) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
+    setup_ctx(state);
 
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lys_module_free(st->yin_ctx->parsed_mod->mod, NULL);
-    free(st->yin_ctx);
-    ly_in_free(st->in, 0);
-
-    return EXIT_SUCCESS;
-}
-
-static struct test_parser_yin_state *
-reset_state(void **state)
-{
-    ((struct test_parser_yin_state *)*state)->finished_correctly = true;
-    logbuf[0] = '\0';
-    teardown_f(state);
-    setup_f(state);
-
-    return *state;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
+    return 0;
 }
 
 static int
-setup_element_test(void **state)
+teardown_ctx(void **UNUSED(state))
 {
-    struct test_parser_yin_state *st;
+    lyxml_ctx_free(YCTX->xmlctx);
+    lys_module_free(YCTX->parsed_mod->mod, NULL);
+    free(YCTX);
+    YCTX = NULL;
 
-    setup_f(state);
-    st = *state;
-
-    lydict_insert(st->ctx, "module-name", 0, &st->yin_ctx->parsed_mod->mod->name);
-
-    return EXIT_SUCCESS;
+    return 0;
 }
 
+static int
+teardown(void **state)
+{
+    teardown_ctx(state);
+
+    UTEST_TEARDOWN;
+
+    return 0;
+}
+
+#define RESET_STATE \
+    ly_in_free(UTEST_IN, 0); \
+    UTEST_IN = NULL; \
+    teardown_ctx(state); \
+    setup_ctx(state)
+
 static void
 test_yin_match_keyword(void **state)
 {
-    struct test_parser_yin_state *st = *state;
-
     const char *prefix;
     size_t prefix_len;
+
     /* create mock yin namespace in xml context */
-    const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
+    ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    prefix = YCTX->xmlctx->prefix;
+    prefix_len = YCTX->xmlctx->prefix_len;
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    prefix = st->yin_ctx->xmlctx->prefix;
-    prefix_len = st->yin_ctx->xmlctx->prefix_len;
-
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix,  prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
-
-    st->finished_correctly = true;
+    assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
+    assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
+    assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
+    assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
+    assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
+    assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
+    assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
+    assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
+    assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
+    assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
+    assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
+    assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
+    assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
+    assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
+    assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
+    assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
+    assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
+    assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
+    assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
+    assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
+    assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
+    assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix,  prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
+    assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
+    assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
+    assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
+    assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
+    assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
+    assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
+    assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
+    assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
+    assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
+    assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
+    assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
+    assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
+    assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
+    assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
+    assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
+    assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
+    assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
+    assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
+    assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
+    assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
+    assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
+    assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
+    assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
+    assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
+    assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
+    assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
+    assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
+    assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
+    assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
+    assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
+    assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
+    assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
+    assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
+    assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
+    assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
+    assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
+    assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
+    assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
+    assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
+    assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
+    assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
+    assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
+    assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
+    assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
+    assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
 }
 
 static void
-test_yin_match_argument_name(void **state)
+test_yin_match_argument_name(void **UNUSED(state))
 {
-    (void)state; /* unused */
-
     assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
     assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
     assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
@@ -384,95 +287,87 @@
 static void
 test_yin_parse_element_generic(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_ext_instance exts;
     LY_ERR ret;
+    const char *arg;
+    const char *stmt;
+    const char *data;
 
     memset(&exts, 0, sizeof(exts));
 
-    const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
+    data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-
-    ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
+    ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
-    assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
-    assert_string_equal(exts.child->arg, "text_value");
-    assert_string_equal(exts.child->child->stmt, "attr");
-    assert_string_equal(exts.child->child->arg, "value");
-    assert_true(exts.child->child->flags & LYS_YIN_ATTR);
-    lysp_ext_instance_free(st->ctx, &exts);
-    st = reset_state(state);
+    assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
+    stmt = "urn:example:extensions:elem";
+    arg = "text_value";
+    CHECK_LYSP_STMT(exts.child, arg, 1, 0, 0x45, 0, stmt);
+    stmt = "attr";
+    arg = "value";
+    CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, &exts);
+    RESET_STATE;
 
     data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
+    ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
-    assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
-    assert_null(exts.child->child);
-    assert_null(exts.child->arg);
-    lysp_ext_instance_free(st->ctx, &exts);
-
-    st->finished_correctly = true;
+    assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
+    stmt = "urn:example:extensions:elem";
+    CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, 0x45, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, &exts);
 }
 
 static void
 test_yin_parse_extension_instance(void **state)
 {
     LY_ERR ret;
-    struct test_parser_yin_state *st = *state;
     struct lysp_ext_instance *exts = NULL;
+    struct lysp_stmt *act_child;
     const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
+    const char *exts_name;
+    const char *stmt = "value1";
+    const char *arg = "test";
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_string_equal(exts->name, "urn:example:extensions:ext");
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
-    assert_true(exts->yin & LYS_YIN);
-    assert_string_equal(exts->child->stmt, "value1");
-    assert_string_equal(exts->child->arg, "test");
-    assert_null(exts->child->child);
-    assert_true(exts->child->flags & LYS_YIN_ATTR);
-    assert_string_equal(exts->child->next->stmt, "value");
-    assert_string_equal(exts->child->next->arg, "test2");
-    assert_null(exts->child->next->child);
-    assert_true(exts->child->next->flags & LYS_YIN_ATTR);
+    exts_name = "urn:example:extensions:ext";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
 
-    assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
-    assert_string_equal(exts->child->next->next->arg, "text");
-    assert_null(exts->child->next->next->child);
-    assert_null(exts->child->next->next->next);
-    assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
-    lysp_ext_instance_free(st->ctx, exts);
+    CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "value";
+    arg = "test2";
+    CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "urn:example:extensions:subelem";
+    arg = "text";
+    CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, 0x45, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
-    assert_null(exts->argument);
-    assert_null(exts->child);
-    assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->yin & LYS_YIN);
-    lysp_ext_instance_free(st->ctx, exts);
+    exts_name = "urn:example:extensions:extension-elem";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data =
             "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
@@ -484,71 +379,65 @@
             "     </myext:ext-sub2>\n"
             "     <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
             "</myext:ext>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
 
-    assert_string_equal(exts->name, "urn:example:extensions:ext");
-    assert_null(exts->argument);
-    assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->yin & LYS_YIN);
-    assert_string_equal(exts->child->stmt, "attr1");
-    assert_string_equal(exts->child->arg, "text1");
-    assert_null(exts->child->child);
-    assert_true(exts->child->flags & LYS_YIN_ATTR);
+    exts_name = "urn:example:extensions:ext";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
 
-    assert_string_equal(exts->child->next->stmt, "attr2");
-    assert_string_equal(exts->child->next->arg, "text2");
-    assert_null(exts->child->next->child);
-    assert_true(exts->child->next->flags & LYS_YIN_ATTR);
+    stmt = "attr1";
+    arg = "text1";
+    act_child = exts->child;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
+    stmt = "attr2";
+    arg = "text2";
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub1";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, NULL, 0, 0x45, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub2";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 1, stmt);
 
-    assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
-    assert_null(exts->child->next->next->arg);
-    assert_null(exts->child->next->next->child);
-    assert_int_equal(exts->child->next->next->flags, 0);
+    stmt = "sattr1";
+    arg = "stext2";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub21";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
-    assert_null(exts->child->next->next->next->arg);
-    assert_int_equal(exts->child->next->next->next->flags, 0);
-    assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
-    assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
-    assert_null(exts->child->next->next->next->child->child);
-    assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
+    stmt = "urn:example:extensions:ext-sub211";
+    arg = NULL;
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
-    assert_null(exts->child->next->next->next->child->next->arg);
-    assert_null(exts->child->next->next->next->child->next->next);
-    assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
+    stmt = "sattr21";
+    arg = "text21";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211");
-    assert_null(exts->child->next->next->next->child->next->child->arg);
-    assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
-    assert_null(exts->child->next->next->next->child->next->child->next);
+    stmt = "urn:example:extensions:ext-sub3";
+    arg = NULL;
+    act_child = exts->child->next->next->next->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
+    stmt = "attr3";
+    arg = "text3";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
-    assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
-    assert_null(exts->child->next->next->next->child->next->child->child->next);
-    assert_null(exts->child->next->next->next->child->next->child->child->child);
-    assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
-
-    assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
-    assert_null(exts->child->next->next->next->next->arg);
-    assert_null(exts->child->next->next->next->next->next);
-    assert_int_equal(exts->child->next->next->next->next->flags, 0);
-
-    assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
-    assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
-    assert_null(exts->child->next->next->next->next->child->next);
-    assert_null(exts->child->next->next->next->next->child->child);
-    assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
-
-    lysp_ext_instance_free(st->ctx, exts);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data =
             "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
@@ -564,10 +453,10 @@
             "     <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
             "     <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
             "</myext:extension-elem>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_string_equal(exts->child->arg, "act-name");
     assert_string_equal(exts->child->next->arg, "target");
@@ -579,18 +468,15 @@
     assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
     assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
     assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
-    lysp_ext_instance_free(st->ctx, exts);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
-
-    st->finished_correctly = true;
+    RESET_STATE;
 }
 
 static void
 test_yin_parse_content(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     LY_ERR ret = LY_SUCCESS;
     const char *data =
             "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
@@ -627,7 +513,7 @@
             "</prefix>";
     struct lysp_ext_instance *exts = NULL;
     const char **if_features = NULL;
-    const char *value, *err_msg, *app_tag, *units;
+    const char *value, *error_message, *app_tag, *units;
     struct lysp_qname def = {0};
     struct lysp_ext *ext_def = NULL;
     struct lysp_when *when_p = NULL;
@@ -635,18 +521,18 @@
     struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
     uint16_t config = 0;
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
     struct yin_subelement subelems[17] = {
         {LY_STMT_CONFIG, &config, 0},
         {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
         {LY_STMT_ENUM, &enum_type, 0},
         {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
-        {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
+        {LY_STMT_ERROR_MESSAGE, &error_message, 0},
         {LY_STMT_EXTENSION, &ext_def, 0},
         {LY_STMT_IF_FEATURE, &if_features, 0},
         {LY_STMT_LENGTH, &len_type, 0},
@@ -661,47 +547,49 @@
         {LY_STMT_ARG_TEXT, &value, 0}
     };
 
-    ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     /* check parsed values */
     assert_string_equal(def.str, "default-value");
-    assert_string_equal(exts->name, "urn:example:extensions:custom");
-    assert_string_equal(exts->argument, "totally amazing extension");
+    const char *exts_name = "urn:example:extensions:custom";
+    const char *exts_arg = "totally amazing extension";
+
+    CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, NULL,
+            LYEXT_SUBSTMT_PREFIX, 0, exts_name, 0, 0x1, 0x1);
     assert_string_equal(value, "wsefsdf");
     assert_string_equal(units, "radians");
     assert_string_equal(when_p->cond, "condition...");
     assert_string_equal(when_p->dsc, "when_desc");
     assert_string_equal(when_p->ref, "when_ref");
     assert_int_equal(config, LYS_CONFIG_W);
-    assert_int_equal(pos_enum.value, 25);
-    assert_true(pos_enum.flags & LYS_SET_VALUE);
-    assert_int_equal(val_enum.value, -5);
-    assert_true(val_enum.flags & LYS_SET_VALUE);
+    CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
+    CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
     assert_int_equal(req_type.require_instance, 1);
     assert_true(req_type.flags &= LYS_SET_REQINST);
     assert_string_equal(range_type.range->arg.str, "5..10");
     assert_true(range_type.flags & LYS_SET_RANGE);
-    assert_string_equal(err_msg, "error-msg");
+    assert_string_equal(error_message, "error-msg");
     assert_string_equal(app_tag, "err-app-tag");
     assert_string_equal(enum_type.enums->name, "yay");
-    assert_string_equal(len_type.length->arg.str, "baf");
+    CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
+            NULL, NULL, 0, NULL);
     assert_true(len_type.flags & LYS_SET_LENGTH);
     assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
     assert_true(patter_type.flags & LYS_SET_PATTERN);
     /* cleanup */
-    lysp_ext_instance_free(st->ctx, exts);
-    lysp_when_free(st->ctx, when_p);
-    lysp_ext_free(st->ctx, ext_def);
-    FREE_STRING(st->ctx, *if_features);
-    FREE_STRING(st->ctx, err_msg);
-    FREE_STRING(st->ctx, app_tag);
-    FREE_STRING(st->ctx, units);
-    FREE_STRING(st->ctx, patter_type.patterns->arg.str);
-    FREE_STRING(st->ctx, def.str);
-    FREE_STRING(st->ctx, range_type.range->arg.str);
-    FREE_STRING(st->ctx, len_type.length->arg.str);
-    FREE_STRING(st->ctx, enum_type.enums->name);
-    FREE_STRING(st->ctx, value);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
+    lysp_when_free(UTEST_LYCTX, when_p);
+    lysp_ext_free(UTEST_LYCTX, ext_def);
+    FREE_STRING(UTEST_LYCTX, *if_features);
+    FREE_STRING(UTEST_LYCTX, error_message);
+    FREE_STRING(UTEST_LYCTX, app_tag);
+    FREE_STRING(UTEST_LYCTX, units);
+    FREE_STRING(UTEST_LYCTX, patter_type.patterns->arg.str);
+    FREE_STRING(UTEST_LYCTX, def.str);
+    FREE_STRING(UTEST_LYCTX, range_type.range->arg.str);
+    FREE_STRING(UTEST_LYCTX, len_type.length->arg.str);
+    FREE_STRING(UTEST_LYCTX, enum_type.enums->name);
+    FREE_STRING(UTEST_LYCTX, value);
     LY_ARRAY_FREE(if_features);
     LY_ARRAY_FREE(exts);
     LY_ARRAY_FREE(ext_def);
@@ -710,7 +598,7 @@
     free(when_p);
     free(range_type.range);
     free(len_type.length);
-    st = reset_state(state);
+    RESET_STATE;
 
     /* test unique subelem */
     const char *prefix_value;
@@ -722,16 +610,16 @@
             "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
             "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
             ELEMENT_WRAPPER_END;
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
-    lydict_remove(st->ctx, prefix_value);
-    lydict_remove(st->ctx, value);
-    st = reset_state(state);
+    CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
+    lydict_remove(UTEST_LYCTX, prefix_value);
+    lydict_remove(UTEST_LYCTX, value);
+    RESET_STATE;
 
     /* test first subelem */
     data = ELEMENT_WRAPPER_START
@@ -742,67 +630,62 @@
     struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
         {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1.");
-    lydict_remove(st->ctx, prefix_value);
-    st = reset_state(state);
+    CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
+    lydict_remove(UTEST_LYCTX, prefix_value);
+    RESET_STATE;
 
     /* test mandatory subelem */
     data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
     struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
 }
 
 static void
 test_validate_value(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
 
     /* create some XML context */
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
-    st->yin_ctx->xmlctx->dynamic = 0;
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
+    YCTX->xmlctx->dynamic = 0;
 
-    st->yin_ctx->xmlctx->value = "#invalid";
-    st->yin_ctx->xmlctx->value_len = 8;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
-    logbuf_assert("Invalid identifier character '#' (0x0023). Line number 1.");
+    YCTX->xmlctx->value = "#invalid";
+    YCTX->xmlctx->value_len = 8;
+    assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
+    CHECK_LOG_CTX("Invalid identifier character '#' (0x0023).", "Line number 1.");
 
-    st->yin_ctx->xmlctx->value = "";
-    st->yin_ctx->xmlctx->value_len = 0;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
+    YCTX->xmlctx->value = "";
+    YCTX->xmlctx->value_len = 0;
+    assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
 
-    st->yin_ctx->xmlctx->value = "pre:b";
-    st->yin_ctx->xmlctx->value_len = 5;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
+    YCTX->xmlctx->value = "pre:b";
+    YCTX->xmlctx->value_len = 5;
+    assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
+    assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
 
-    st->yin_ctx->xmlctx->value = "pre:pre:b";
-    st->yin_ctx->xmlctx->value_len = 9;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
-
-    st->finished_correctly = true;
+    YCTX->xmlctx->value = "pre:pre:b";
+    YCTX->xmlctx->value_len = 9;
+    assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
 }
 
 /* helper function to simplify unit test of each element using parse_content function */
 LY_ERR
-test_element_helper(struct test_parser_yin_state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
+test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
 {
     const char *name, *prefix;
     size_t name_len, prefix_len;
@@ -881,21 +764,21 @@
         {LY_STMT_ARG_VALUE, dest, 0}
     };
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    prefix = st->yin_ctx->xmlctx->prefix;
-    prefix_len = st->yin_ctx->xmlctx->prefix_len;
-    name = st->yin_ctx->xmlctx->name;
-    name_len = st->yin_ctx->xmlctx->name_len;
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    prefix = YCTX->xmlctx->prefix;
+    prefix_len = YCTX->xmlctx->prefix_len;
+    name = YCTX->xmlctx->name;
+    name_len = YCTX->xmlctx->name_len;
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
+    ret = yin_parse_content(YCTX, subelems, 71, yin_match_keyword(YCTX, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
 
     /* free parser and input */
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    st->yin_ctx->xmlctx = NULL;
-    ly_in_free(st->in, 0);
-    st->in = NULL;
+    lyxml_ctx_free(YCTX->xmlctx);
+    YCTX->xmlctx = NULL;
+    ly_in_free(UTEST_IN, 0);
+    UTEST_IN = NULL;
     return ret;
 }
 
@@ -904,7 +787,6 @@
 static void
 test_enum_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_type type = {};
     const char *data;
 
@@ -918,34 +800,27 @@
             "     " EXT_SUBELEM "\n"
             "</enum>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.enums->name, "enum-name");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
+
+    CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
     assert_string_equal(type.enums->iffeatures[0].str, "feature");
-    assert_int_equal(type.enums->value, 55);
-    assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
-    assert_string_equal(type.enums->dsc, "desc...");
-    assert_string_equal(type.enums->ref, "ref...");
-    assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(type.enums->exts->insubstmt_index, 0);
-    assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
 
     data = ELEMENT_WRAPPER_START
             "<enum name=\"enum-name\"></enum>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_string_equal(type.enums->name, "enum-name");
-    lysp_type_free(st->ctx, &type);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_bit_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_type type = {};
     const char *data;
 
@@ -959,34 +834,27 @@
             EXT_SUBELEM
             "</bit>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.bits->name, "bit-name");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
+
+    CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
     assert_string_equal(type.bits->iffeatures[0].str, "feature");
-    assert_int_equal(type.bits->value, 55);
-    assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
-    assert_string_equal(type.bits->dsc, "desc...");
-    assert_string_equal(type.bits->ref, "ref...");
-    assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(type.bits->exts->insubstmt_index, 0);
-    assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
 
     data = ELEMENT_WRAPPER_START
             "<bit name=\"bit-name\"> </bit>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.bits->name, "bit-name");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_meta_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     char *value = NULL;
     const char *data;
     struct lysp_ext_instance *exts = NULL;
@@ -995,16 +863,13 @@
     data = ELEMENT_WRAPPER_START
             "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
-    assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[1].insubstmt_index, 0);
-    assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ORGANIZATION);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LYEXT_SUBSTMT_ORGANIZATION);
+
     assert_string_equal(value, "organization...");
-    FREE_STRING(st->ctx, value);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, value);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     value = NULL;
     exts = NULL;
 
@@ -1012,13 +877,11 @@
     data = ELEMENT_WRAPPER_START
             "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONTACT);
     assert_string_equal(value, "contact...");
-    FREE_STRING(st->ctx, value);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, value);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     value = NULL;
 
@@ -1026,66 +889,59 @@
     data = ELEMENT_WRAPPER_START
             "<description><text>description...</text>" EXT_SUBELEM "</description>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DESCRIPTION);
     assert_string_equal(value, "description...");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
-    FREE_STRING(st->ctx, value);
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
     assert_string_equal(value, "reference...");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
-    FREE_STRING(st->ctx, value);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_REFERENCE);
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
-    FREE_STRING(st->ctx, value);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* missing text subelement */
     data = ELEMENT_WRAPPER_START
             "<reference>reference...</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1.");
-    FREE_STRING(st->ctx, value);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element.", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_import_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_import *imports = NULL;
     struct import_meta imp_meta = {"prefix", &imports};
@@ -1100,16 +956,11 @@
             "    <reference><text>import reference</text></reference>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(imports->name, "a");
-    assert_string_equal(imports->prefix, "a_mod");
-    assert_string_equal(imports->rev, "2015-01-01");
-    assert_string_equal(imports->dsc, "import description");
-    assert_string_equal(imports->ref, "import reference");
-    assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    assert_int_equal(imports->exts->insubstmt_index, 0);
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
+            "a_mod", "import reference", "2015-01-01");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* min subelems */
@@ -1118,16 +969,17 @@
             "    <prefix value=\"a_mod\"/>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(imports->prefix, "a_mod");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
+            "a_mod", NULL, "");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* invalid (missing prefix) */
     data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* invalid reused prefix */
@@ -1136,9 +988,9 @@
             "    <prefix value=\"prefix\"/>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 3.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -1147,52 +999,47 @@
             "</import>\n"
             "<import module=\"a\">\n"
             "    <prefix value=\"a\"/>\n"
-            "</import>"
+            "</import>\n"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Prefix \"a\" already used to import \"a\" module. Line number 6.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
-    st->finished_correctly = true;
 }
 
 static void
 test_status_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* test valid values */
     data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_CURR);
 
     data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_DEPRC);
 
     data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_OBSLT);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_STATUS);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* test invalid value */
     data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1.");
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
+            "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
 }
 
 static void
 test_ext_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_ext *ext = NULL;
 
@@ -1206,119 +1053,99 @@
             EXT_SUBELEM
             "</extension>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(ext->name, "ext_name");
-    assert_string_equal(ext->argument, "arg");
-    assert_true(ext->flags & LYS_STATUS_CURR);
-    assert_string_equal(ext->dsc, "ext_desc");
-    assert_string_equal(ext->ref, "ext_ref");
-    assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(ext->exts[0].insubstmt_index, 0);
-    assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_ext_free(st->ctx, ext);
+    assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LYEXT_SUBSTMT_SELF);
+    lysp_ext_free(UTEST_LYCTX, ext);
     LY_ARRAY_FREE(ext);
     ext = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(ext->name, "ext_name");
-    lysp_ext_free(st->ctx, ext);
+    assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
+    lysp_ext_free(UTEST_LYCTX, ext);
     LY_ARRAY_FREE(ext);
     ext = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_element_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_YINELEM_TRUE);
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_YINELEM_TRUE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_YINELEM);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
     assert_true(flags & LYS_YINELEM_TRUE);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1.");
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_yangversion_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint8_t version = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
     assert_true(version & LYS_VERSION_1_0);
 
     data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
     assert_true(version & LYS_VERSION_1_1);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_VERSION);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     /* invalid value */
     data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1\" and \"1.1\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
+            "Valid values are \"1\" and \"1.1\".", "Line number 1.");
 }
 
 static void
 test_mandatory_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t man = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
     assert_int_equal(man, LYS_MAND_TRUE);
     man = 0;
 
     data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
     assert_int_equal(man, LYS_MAND_FALSE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_MANDATORY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_argument_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     const char *arg;
@@ -1332,16 +1159,14 @@
             EXT_SUBELEM
             "</argument>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
     assert_string_equal(arg, "arg-name");
     assert_true(flags & LYS_YINELEM_TRUE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ARGUMENT);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     flags = 0;
-    FREE_STRING(st->ctx, arg);
+    FREE_STRING(UTEST_LYCTX, arg);
     arg = NULL;
 
     /* min subelems */
@@ -1349,18 +1174,15 @@
             "<argument name=\"arg\">"
             "</argument>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(arg, "arg");
     assert_true(flags == 0);
-    FREE_STRING(st->ctx, arg);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, arg);
 }
 
 static void
 test_base_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **bases = NULL;
     struct lysp_ext_instance *exts = NULL;
@@ -1372,14 +1194,12 @@
             EXT_SUBELEM
             "     </base>\n"
             "</identity>";
-    assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*bases, "base-name");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *bases);
+    FREE_STRING(UTEST_LYCTX, *bases);
     LY_ARRAY_FREE(bases);
 
     /* as type subelement */
@@ -1388,232 +1208,195 @@
             EXT_SUBELEM
             "     </base>\n"
             "</type>";
-    assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*type.bases, "base-name");
     assert_true(type.flags & LYS_SET_BASE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *type.bases);
+    FREE_STRING(UTEST_LYCTX, *type.bases);
     LY_ARRAY_FREE(type.bases);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_belongsto_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_submodule submod;
     struct lysp_ext_instance *exts = NULL;
 
+    lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
+
     data = ELEMENT_WRAPPER_START
             "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
     assert_string_equal(submod.prefix, "pref");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BELONGSTO);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, submod.prefix);
+    FREE_STRING(UTEST_LYCTX, submod.prefix);
 
     data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
 }
 
 static void
 test_config_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_CONFIG_W);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONFIG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     flags = 0;
 
     data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_CONFIG_R);
     flags = 0;
 
     data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_default_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_qname val = {0};
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val.str, "defaul-value");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DEFAULT);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val.str);
+    FREE_STRING(UTEST_LYCTX, val.str);
     val.str = NULL;
 
     data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
 }
 
 static void
 test_err_app_tag_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM "</error-app-tag>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ERRTAG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
     val = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
 }
 
 static void
 test_err_msg_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ERRMSG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
 }
 
 static void
 test_fracdigits_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
     /* valid value */
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_FRACDIGITS);
     assert_int_equal(type.fraction_digits, 10);
     assert_true(type.flags & LYS_SET_FRDIGITS);
-    FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
 
     /* invalid values */
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 }
 
 static void
 test_iffeature_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **iffeatures = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*iffeatures, "local-storage");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_IFFEATURE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *iffeatures);
+    FREE_STRING(UTEST_LYCTX, *iffeatures);
     LY_ARRAY_FREE(iffeatures);
     iffeatures = NULL;
 
     data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
     LY_ARRAY_FREE(iffeatures);
     iffeatures = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_length_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1627,17 +1410,12 @@
             EXT_SUBELEM
             "</length>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.length->arg.str, "length-str");
-    assert_string_equal(type.length->emsg, "err-msg");
-    assert_string_equal(type.length->eapptag, "err-app-tag");
-    assert_string_equal(type.length->dsc, "desc");
-    assert_string_equal(type.length->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.length, "length-str", "desc",
+            "err-app-tag", "err-msg", 1, "ref");
     assert_true(type.flags & LYS_SET_LENGTH);
-    assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.length->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
@@ -1645,78 +1423,67 @@
             "<length value=\"length-str\">"
             "</length>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.length->arg.str, "length-str");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.length, "length-str", NULL,
+            NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     assert_true(type.flags & LYS_SET_LENGTH);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_modifier_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *pat;
     struct lysp_ext_instance *exts = NULL;
 
-    assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\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_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
     assert_string_equal(pat, "\x015pattern");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_MODIFIER);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, pat);
+    FREE_STRING(UTEST_LYCTX, pat);
 
-    assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\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.");
-    FREE_STRING(st->ctx, pat);
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
+            "Only valid value is \"invert-match\".", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, pat);
 }
 
 static void
 test_namespace_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *ns;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
     assert_string_equal(ns, "ns");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_NAMESPACE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, ns);
+    FREE_STRING(UTEST_LYCTX, ns);
 
     data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
 }
 
 static void
 test_pattern_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1731,145 +1498,119 @@
             EXT_SUBELEM
             "</pattern>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_true(type.flags & LYS_SET_PATTERN);
-    assert_string_equal(type.patterns->arg.str, "\x015super_pattern");
-    assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
-    assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
-    assert_string_equal(type.patterns->emsg, "err-msg-value");
-    assert_string_equal(type.patterns->ref, "pattern-ref");
-    assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
+            "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.patterns->arg.str, "\x006pattern");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_value_position_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type_enum en = {};
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 55);
-    assert_true(en.flags & LYS_SET_VALUE);
-    assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(en.exts[0].insubstmt_index, 0);
-    assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
-    FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]),  LYEXT_SUBSTMT_VALUE);
+    FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, -55);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     /* valid positions */
     data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 55);
-    assert_true(en.flags & LYS_SET_VALUE);
-    assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(en.exts[0].insubstmt_index, 0);
-    assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
-    FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]),  LYEXT_SUBSTMT_POSITION);
+    FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     /* invalid values */
     data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     /*invalid positions */
     data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 }
 
 static void
 test_prefix_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *value = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
     assert_string_equal(value, "pref");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_PREFIX);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, value);
+    FREE_STRING(UTEST_LYCTX, value);
 
     data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
     assert_string_equal(value, "pref");
-    FREE_STRING(st->ctx, value);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, value);
 }
 
 static void
 test_range_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1883,147 +1624,121 @@
             EXT_SUBELEM
             "</range>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.range->arg.str, "range-str");
-    assert_string_equal(type.range->dsc, "desc");
-    assert_string_equal(type.range->eapptag, "err-app-tag");
-    assert_string_equal(type.range->emsg, "err-msg");
-    assert_string_equal(type.range->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.range, "range-str", "desc",
+            "err-app-tag", "err-msg", 1, "ref");
     assert_true(type.flags & LYS_SET_RANGE);
-    assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.range->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.range->arg.str, "range-str");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.range, "range-str", NULL,
+            NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_reqinstance_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_int_equal(type.require_instance, 1);
     assert_true(type.flags & LYS_SET_REQINST);
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_REQINSTANCE);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_int_equal(type.require_instance, 0);
     assert_true(type.flags & LYS_SET_REQINST);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
     memset(&type, 0, sizeof(type));
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_revision_date_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     char rev[LY_REV_SIZE];
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM "</revision-date>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
     assert_string_equal(rev, "2000-01-01");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_REVISIONDATE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
     assert_string_equal(rev, "2000-01-01");
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
 }
 
 static void
 test_unique_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **values = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*values, "tag");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, *values);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_UNIQUE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, *values);
     LY_ARRAY_FREE(values);
     values = NULL;
 
     data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
     assert_string_equal(*values, "tag");
-    FREE_STRING(st->ctx, *values);
+    FREE_STRING(UTEST_LYCTX, *values);
     LY_ARRAY_FREE(values);
     values = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_units_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *values = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
     assert_string_equal(values, "name");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, values);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_UNITS);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, values);
     values = NULL;
 
     data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
     assert_string_equal(values, "name");
-    FREE_STRING(st->ctx, values);
+    FREE_STRING(UTEST_LYCTX, values);
     values = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_when_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_when *when = NULL;
 
@@ -2034,56 +1749,46 @@
             EXT_SUBELEM
             "</when>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(when->cond, "cond");
-    assert_string_equal(when->dsc, "desc");
-    assert_string_equal(when->ref, "ref");
-    assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(when->exts[0].insubstmt_index, 0);
-    assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_when_free(st->ctx, when);
+    assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_when_free(UTEST_LYCTX, when);
     free(when);
     when = NULL;
 
     data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(when->cond, "cond");
-    lysp_when_free(st->ctx, when);
+    assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
+    lysp_when_free(UTEST_LYCTX, when);
     free(when);
     when = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_text_value_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
 
     data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "text");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "text");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal("", val);
-    FREE_STRING(st->ctx, val);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, val);
 }
 
 static void
 test_type_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -2103,21 +1808,22 @@
             EXT_SUBELEM
             "</type>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_string_equal(type.name, "type-name");
     assert_string_equal(*type.bases, "base-name");
     assert_string_equal(type.bits->name,  "bit");
     assert_string_equal(type.enums->name,  "enum");
     assert_int_equal(type.fraction_digits, 2);
-    assert_string_equal(type.length->arg.str, "length");
+    CHECK_LYSP_RESTR(type.length, "length", NULL,
+            NULL, NULL, 0, NULL);
     assert_string_equal(type.path->expr, "/path");
-    assert_string_equal(type.patterns->arg.str, "\006pattern");
-    assert_string_equal(type.range->arg.str, "range");
+    CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
+            NULL, NULL, 0, NULL);
+    CHECK_LYSP_RESTR(type.range, "range", NULL,
+            NULL, NULL, 0, NULL);
     assert_int_equal(type.require_instance, 1);
     assert_string_equal(type.types->name, "sub-type-name");
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_SELF);
     assert_true(type.flags & LYS_SET_BASE);
     assert_true(type.flags & LYS_SET_BIT);
     assert_true(type.flags & LYS_SET_ENUM);
@@ -2128,168 +1834,144 @@
     assert_true(type.flags & LYS_SET_RANGE);
     assert_true(type.flags & LYS_SET_REQINST);
     assert_true(type.flags & LYS_SET_TYPE);
-    lysp_type_free(st->ctx, &type);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_max_elems_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node_list list = {};
     struct lysp_node_leaflist llist = {};
     struct lysp_refine refine = {};
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM "</max-elements> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.max, 0);
     assert_true(refine.flags & LYS_SET_MAX);
-    assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refine.exts[0].insubstmt_index, 0);
-    assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM "</max-elements> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
     assert_int_equal(list.max, 5);
-    assert_true(list.flags & LYS_SET_MAX);
-    assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(list.exts[0].insubstmt_index, 0);
-    assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
+    CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM "</max-elements> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
     assert_int_equal(llist.max, 85);
-    assert_true(llist.flags & LYS_SET_MAX);
-    assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(llist.exts[0].insubstmt_index, 0);
-    assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
+    CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.max, 10);
     assert_true(refine.flags & LYS_SET_MAX);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 }
 
 static void
 test_min_elems_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node_list list = {};
     struct lysp_node_leaflist llist = {};
     struct lysp_refine refine = {};
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM "</min-elements> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.min, 0);
     assert_true(refine.flags & LYS_SET_MIN);
-    assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refine.exts[0].insubstmt_index, 0);
-    assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM "</min-elements> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
     assert_int_equal(list.min, 41);
     assert_true(list.flags & LYS_SET_MIN);
-    assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(list.exts[0].insubstmt_index, 0);
-    assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM "</min-elements> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
     assert_int_equal(llist.min, 50);
     assert_true(llist.flags & LYS_SET_MIN);
-    assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(llist.exts[0].insubstmt_index, 0);
-    assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
 }
 
 static void
 test_ordby_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_ORDBY_SYSTEM);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ORDEREDBY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_ORDBY_USER);
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
+            "Valid values are \"system\" and \"user\".", "Line number 1.");
 }
 
 static void
 test_any_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_anydata *parsed = NULL;
+    uint16_t flags;
 
     /* anyxml max subelems */
     data = ELEMENT_WRAPPER_START
@@ -2305,23 +1987,15 @@
             EXT_SUBELEM
             "</anyxml>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYXML);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "any-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "any-name", 0, LYS_ANYXML, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* anydata max subelems */
@@ -2338,47 +2012,36 @@
             EXT_SUBELEM
             "</anydata>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYDATA);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "any-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     node_meta.parent = (void *)0x10;
     data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
     assert_ptr_equal(parsed->parent, node_meta.parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYDATA);
-    assert_null(parsed->next);
-    assert_null(parsed->exts);
-    lysp_node_free(st->ctx, siblings);
-
-    st->finished_correctly = true;
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
 }
 
 static void
 test_leaf_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_leaf *parsed = NULL;
+    uint16_t flags;
 
     /* max elements */
     data = ELEMENT_WRAPPER_START
@@ -2397,49 +2060,39 @@
             EXT_SUBELEM
             "</leaf>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaf *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_LEAF);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "leaf");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "leaf", 0, LYS_LEAF, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
     assert_string_equal(parsed->musts->arg.str, "must-cond");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
     assert_string_equal(parsed->dflt.str, "def-val");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min elements */
     data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaf *)siblings;
     assert_string_equal(parsed->name, "leaf");
     assert_string_equal(parsed->type.name, "type");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_leaf_list_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_leaflist *parsed = NULL;
+    uint16_t flags;
 
     data = ELEMENT_WRAPPER_START
             "<leaf-list name=\"llist\">\n"
@@ -2459,29 +2112,21 @@
             EXT_SUBELEM
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
     assert_string_equal(parsed->dflts[0].str, "def-val0");
     assert_string_equal(parsed->dflts[1].str, "def-val1");
-    assert_string_equal(parsed->dsc, "desc");
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->max, 5);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2500,27 +2145,19 @@
             EXT_SUBELEM
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
-    assert_string_equal(parsed->dsc, "desc");
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->min, 5);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2539,25 +2176,19 @@
             "    <when condition=\"when-cond\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
-    assert_string_equal(parsed->dsc, "desc");
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
+    CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->min, 5);
     assert_int_equal(parsed->max, 15);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2565,11 +2196,11 @@
             "    <type name=\"type\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
     assert_string_equal(parsed->name, "llist");
     assert_string_equal(parsed->type.name, "type");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* invalid combinations */
@@ -2580,9 +2211,9 @@
             "    <type name=\"type\"/>"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 4.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2592,85 +2223,72 @@
             "    <type name=\"type\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 5.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
             "<leaf-list name=\"llist\">"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_presence_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "presence-val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, val);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_PRESENCE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "presence-val");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
 }
 
 static void
 test_key_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "key-value");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, val);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_KEY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "key-value");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
 }
 
 static void
 test_typedef_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_tpdf *tpdfs = NULL;
     struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
@@ -2686,7 +2304,7 @@
             EXT_SUBELEM
             "</typedef>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(tpdfs[0].dflt.str, "def-val");
     assert_string_equal(tpdfs[0].dsc, "desc-text");
     assert_string_equal(tpdfs[0].name, "tpdf-name");
@@ -2694,10 +2312,8 @@
     assert_string_equal(tpdfs[0].type.name, "type");
     assert_string_equal(tpdfs[0].units, "uni");
     assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
-    assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
-    assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
     tpdfs = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2705,19 +2321,16 @@
             "    <type name=\"type\"/>\n"
             "</typedef>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(tpdfs[0].name, "tpdf-name");
     assert_string_equal(tpdfs[0].type.name, "type");
-    FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
+    FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
     tpdfs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_refine_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_refine *refines = NULL;
 
@@ -2737,7 +2350,7 @@
             EXT_SUBELEM
             "</refine>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
     assert_string_equal(refines->nodeid, "target");
     assert_string_equal(refines->dflts[0].str, "def");
     assert_string_equal(refines->dsc, "desc");
@@ -2749,26 +2362,21 @@
     assert_string_equal(refines->musts->arg.str, "cond");
     assert_string_equal(refines->presence, "presence");
     assert_string_equal(refines->ref, "ref");
-    assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refines->exts[0].insubstmt_index, 0);
-    assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, refines, lysp_refine_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
     refines = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
     assert_string_equal(refines->nodeid, "target");
-    FREE_ARRAY(st->ctx, refines, lysp_refine_free);
+    FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
     refines = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_uses_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
@@ -2787,39 +2395,29 @@
             EXT_SUBELEM
             "</uses>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_uses *)&siblings[0];
-    assert_string_equal(parsed->name, "uses-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_true(parsed->flags & LYS_STATUS_OBSLT);
+    CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
+            "uses-name", 0, LYS_USES, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_USES);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->refines->nodeid, "target");
-    assert_string_equal(parsed->when->cond, "cond");
     assert_string_equal(parsed->augments->nodeid, "target");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(siblings[0].name, "uses-name");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_revision_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_revision *revs = NULL;
 
@@ -2831,43 +2429,38 @@
             EXT_SUBELEM
             "</revision>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
     assert_string_equal(revs->date, "2018-12-25");
     assert_string_equal(revs->dsc, "desc");
     assert_string_equal(revs->ref, "ref");
-    assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(revs->exts[0].insubstmt_index, 0);
-    assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
     assert_string_equal(revs->date, "2005-05-05");
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
 
     /* invalid value */
     data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_include_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_include *includes = NULL;
     struct include_meta inc_meta = {"module-name", &includes};
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <description><text>desc</text></description>\n"
@@ -2876,56 +2469,53 @@
             EXT_SUBELEM
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(includes->name, "mod");
     assert_string_equal(includes->dsc, "desc");
     assert_string_equal(includes->ref, "ref");
     assert_string_equal(includes->rev, "1999-09-09");
-    assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(includes->exts[0].insubstmt_index, 0);
-    assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(includes->name, "mod");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
     /* invalid combinations */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0;
+    YCTX->parsed_mod->version = LYS_VERSION_1_0;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <description><text>desc</text></description>\n"
             "    <revision-date date=\"1999-09-09\"/>\n"
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 2.");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
+            "Line number 2.");
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0;
+    YCTX->parsed_mod->version = LYS_VERSION_1_0;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <reference><text>ref</text></reference>\n"
             "    <revision-date date=\"1999-09-09\"/>\n"
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 2.");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
+            "Line number 2.");
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_list_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
@@ -2960,9 +2550,8 @@
             EXT_SUBELEM
             "</list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_list *)&siblings[0];
-    assert_string_equal(parsed->dsc, "desc");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
     assert_string_equal(parsed->child->next->name, "anyx");
@@ -2980,53 +2569,45 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
+    uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "list-name", 0, LYS_LIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
     assert_string_equal(parsed->groupings->name, "grp");
     assert_string_equal(parsed->actions->name, "action");
     assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
     assert_string_equal(parsed->notifs->name, "notf");
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_true(parsed->flags & LYS_CONFIG_W);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->key, "key");
     assert_int_equal(parsed->min, 10);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "list-name");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->typedefs->name, "tpdf");
     assert_string_equal(parsed->uniques->str, "utag");
-    assert_string_equal(parsed->when->cond, "when");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
-    ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_list *)&siblings[0];
-    assert_string_equal(parsed->name, "list-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "list-name", 0, LYS_LIST, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_notification_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_notif *notifs = NULL;
     struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<notification name=\"notif-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3047,7 +2628,7 @@
             EXT_SUBELEM
             "</notification>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(notifs->name, "notif-name");
     assert_string_equal(notifs->data->name, "anyd");
     assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
@@ -3075,26 +2656,21 @@
     assert_null(notifs->parent);
     assert_string_equal(notifs->ref, "ref");
     assert_string_equal(notifs->typedefs->name, "tpdf");
-    assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(notifs->exts[0].insubstmt_index, 0);
-    assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, notifs, lysp_notif_free);
     notifs = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(notifs->name, "notif-name");
-    FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
+    FREE_ARRAY(UTEST_LYCTX, notifs, lysp_notif_free);
     notifs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_grouping_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_grp *grps = NULL;
     struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
@@ -3120,7 +2696,7 @@
             EXT_SUBELEM
             "</grouping>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(grps->name, "grp-name");
     assert_string_equal(grps->data->name, "anyd");
     assert_string_equal(grps->data->next->name, "anyx");
@@ -3142,33 +2718,28 @@
     assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
     assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
     assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
-    assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(grps->exts[0].insubstmt_index, 0);
-    assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, grps, lysp_grp_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, grps, lysp_grp_free);
     grps = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(grps->name, "grp-name");
-    FREE_ARRAY(st->ctx, grps, lysp_grp_free);
+    FREE_ARRAY(UTEST_LYCTX, grps, lysp_grp_free);
     grps = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_container_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_container *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<container name=\"cont-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3194,19 +2765,16 @@
             EXT_SUBELEM
             "</container>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_container *)siblings;
-    assert_string_equal(parsed->name, "cont-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CONTAINER);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
+
     assert_string_equal(parsed->iffeatures[0].str, "iff");
-    assert_string_equal(parsed->musts->arg.str, "cond");
     assert_string_equal(parsed->presence, "presence");
     assert_string_equal(parsed->typedefs->name, "tpdf");
     assert_string_equal(parsed->groupings->name, "sub-grp");
@@ -3229,35 +2797,31 @@
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
     assert_string_equal(parsed->notifs->name, "notf");
     assert_string_equal(parsed->actions->name, "act");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
-    ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_container *)siblings;
-    assert_string_equal(parsed->name, "cont-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_case_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_case *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<case name=\"case-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3276,16 +2840,13 @@
             EXT_SUBELEM
             "</case>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_case *)siblings;
-    assert_string_equal(parsed->name, "case-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CASE);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "case-name", 0, LYS_CASE, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
@@ -3304,34 +2865,30 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_case *)siblings;
-    assert_string_equal(parsed->name, "case-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "case-name", 0, LYS_CASE, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_choice_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_choice *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<choice name=\"choice-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3353,16 +2910,13 @@
             EXT_SUBELEM
             "</choice>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_choice *)siblings;
-    assert_string_equal(parsed->name, "choice-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CHOICE);
-    assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
@@ -3381,33 +2935,30 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_choice *)siblings;
     assert_string_equal(parsed->name, "choice-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_inout_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_action_inout inout = {};
     struct inout_meta inout_meta = {NULL, &inout};
 
     /* max subelements */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<input>\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3424,10 +2975,9 @@
             EXT_SUBELEM
             "</input>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(inout.parent);
-    assert_int_equal(inout.nodetype, LYS_INPUT);
-    assert_string_equal(inout.musts->arg.str, "cond");
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
+    CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
     assert_string_equal(inout.typedefs->name, "tpdf");
     assert_string_equal(inout.groupings->name, "sub-grp");
     assert_string_equal(inout.data->name, "anyd");
@@ -3447,14 +2997,12 @@
     assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(inout.data->next->next->next->next->next->next->next->next);
-    assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(inout.exts[0].insubstmt_index, 0);
-    assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_action_inout_free(st->ctx, &inout);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* max subelements */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<output>\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3471,9 +3019,8 @@
             EXT_SUBELEM
             "</output>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(inout.parent);
-    assert_int_equal(inout.nodetype, LYS_OUTPUT);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
     assert_string_equal(inout.musts->arg.str, "cond");
     assert_string_equal(inout.typedefs->name, "tpdf");
     assert_string_equal(inout.groupings->name, "sub-grp");
@@ -3494,42 +3041,38 @@
     assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(inout.data->next->next->next->next->next->next->next->next);
-    assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(inout.exts[0].insubstmt_index, 0);
-    assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_action_inout_free(st->ctx, &inout);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    lysp_action_inout_free(st->ctx, &inout);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    lysp_action_inout_free(st->ctx, &inout);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* invalid combinations */
     data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
     memset(&inout, 0, sizeof inout);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_action_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_action *actions = NULL;
     struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
+    uint16_t flags;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<action name=\"act\">\n"
             "    <description><text>desc</text></description>\n"
@@ -3545,26 +3088,27 @@
             ELEMENT_WRAPPER_END;
     /* there must be parent for action */
     act_meta.parent = (void *)1;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
     act_meta.parent = NULL;
-    assert_non_null(actions->parent);
-    assert_int_equal(actions->nodetype, LYS_ACTION);
-    assert_true(actions->flags & LYS_STATUS_DEPRC);
-    assert_string_equal(actions->name, "act");
-    assert_string_equal(actions->dsc, "desc");
-    assert_string_equal(actions->ref, "ref");
+    flags = LYS_STATUS_DEPRC;
+    CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
+            1, 0, 0, 0,\
+            1, 0,\
+            "act", LYS_ACTION, \
+            1, 0, 0, 1,\
+            1, 0,\
+            1, "ref", 1);
+
     assert_string_equal(actions->iffeatures[0].str, "iff");
     assert_string_equal(actions->typedefs->name, "tpdf");
     assert_string_equal(actions->groupings->name, "grouping");
-    assert_string_equal(actions->input.data->name, "uses-name");
     assert_string_equal(actions->output.musts->arg.str, "cond");
-    assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(actions->exts[0].insubstmt_index, 0);
-    assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    assert_string_equal(actions->input.data->name, "uses-name");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<rpc name=\"act\">\n"
             "    <description><text>desc</text></description>\n"
@@ -3578,43 +3122,41 @@
             EXT_SUBELEM
             "</rpc>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(actions->parent);
-    assert_int_equal(actions->nodetype, LYS_RPC);
-    assert_true(actions->flags & LYS_STATUS_DEPRC);
-    assert_string_equal(actions->name, "act");
-    assert_string_equal(actions->dsc, "desc");
-    assert_string_equal(actions->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    flags = LYS_STATUS_DEPRC;
+    CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
+            1, 0, 0, 0,\
+            1, 0,\
+            "act", LYS_RPC, \
+            1, 0, 0, 1,\
+            1, 0,\
+            0, "ref", 1);
+
     assert_string_equal(actions->iffeatures[0].str, "iff");
     assert_string_equal(actions->typedefs->name, "tpdf");
     assert_string_equal(actions->groupings->name, "grouping");
     assert_string_equal(actions->input.data->name, "uses-name");
     assert_string_equal(actions->output.musts->arg.str, "cond");
-    assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(actions->exts[0].insubstmt_index, 0);
-    assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(actions->name, "act");
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_augment_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_augment *augments = NULL;
     struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<augment target-node=\"target\">\n"
             "    <action name=\"action\"/>\n"
@@ -3636,7 +3178,7 @@
             EXT_SUBELEM
             "</augment>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(augments->nodeid, "target");
     assert_null(augments->parent);
     assert_int_equal(augments->nodetype, LYS_AUGMENT);
@@ -3666,25 +3208,20 @@
     assert_null(augments->child->next->next->next->next->next->next->next->next->next);
     assert_string_equal(augments->actions->name, "action");
     assert_string_equal(augments->notifs->name, "notif");
-    assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(augments->exts[0].insubstmt_index, 0);
-    assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, augments, lysp_augment_free)
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, augments, lysp_augment_free)
     augments = NULL;
 
     data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(augments->nodeid, "target");
-    FREE_ARRAY(st->ctx, augments, lysp_augment_free)
+    FREE_ARRAY(UTEST_LYCTX, augments, lysp_augment_free)
     augments = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_deviate_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_deviate *deviates = NULL;
     struct lysp_deviate_add *d_add;
@@ -3693,30 +3230,30 @@
 
     /* all valid arguments with min subelems */
     data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_ADD);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_DELETE);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3726,12 +3263,10 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3748,7 +3283,7 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_add = (struct lysp_deviate_add *)deviates;
     assert_int_equal(d_add->mod, LYS_DEV_ADD);
     assert_null(d_add->next);
@@ -3756,13 +3291,11 @@
     assert_string_equal(d_add->musts->arg.str, "cond");
     assert_string_equal(d_add->uniques[0].str, "utag");
     assert_string_equal(d_add->dflts[0].str, "def");
-    assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
+    assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
     assert_int_equal(d_add->min, 5);
     assert_int_equal(d_add->max, 15);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3778,20 +3311,18 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_rpl = (struct lysp_deviate_rpl *)deviates;
     assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
     assert_null(d_rpl->next);
     assert_string_equal(d_rpl->type->name, "newtype");
     assert_string_equal(d_rpl->units, "uni");
     assert_string_equal(d_rpl->dflt.str, "def");
-    assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
+    assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
     assert_int_equal(d_rpl->min, 5);
     assert_int_equal(d_rpl->max, 15);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3804,7 +3335,7 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_del = (struct lysp_deviate_del *)deviates;
     assert_int_equal(d_del->mod, LYS_DEV_DELETE);
     assert_null(d_del->next);
@@ -3812,32 +3343,34 @@
     assert_string_equal(d_del->musts->arg.str, "c");
     assert_string_equal(d_del->uniques[0].str, "tag");
     assert_string_equal(d_del->dflts[0].str, "default");
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     /* invalid arguments */
     data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -3845,16 +3378,13 @@
             "    <must condition=\"c\"/>\n"
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 2.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Deviate of this type doesn't allow \"must\" as it's sub-element.", "Line number 2.");
 }
 
 static void
 test_deviation_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_deviation *deviations = NULL;
 
@@ -3864,10 +3394,10 @@
             "    <deviate value=\"not-supported\"/>\n"
             "</deviation>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
     assert_string_equal(deviations->nodeid, "target");
     assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
 
     /* max subelems */
@@ -3879,26 +3409,22 @@
             EXT_SUBELEM
             "</deviation>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
     assert_string_equal(deviations->nodeid, "target");
     assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
     assert_string_equal(deviations->ref, "ref");
     assert_string_equal(deviations->dsc, "desc");
-    assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviations->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
 
     /* invalid */
     data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
-    logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
-    /* TODO */
-    st->finished_correctly = true;
-}
+    CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
+    /* TODO */}
 
 static struct lysp_module *
 mod_renew(struct lys_yin_parser_ctx *ctx)
@@ -3917,9 +3443,8 @@
 static void
 test_module_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
-    struct lysp_module *lysp_mod = mod_renew(st->yin_ctx);
+    struct lysp_module *lysp_mod = mod_renew(YCTX);
 
     /* max subelems */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
@@ -3954,10 +3479,10 @@
             "    <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
             EXT_SUBELEM "\n"
             "</module>\n";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
 
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
     assert_string_equal(lysp_mod->revs, "2019-02-02");
     assert_string_equal(lysp_mod->mod->ns, "ns");
@@ -3968,7 +3493,8 @@
     assert_string_equal(lysp_mod->mod->dsc, "desc");
     assert_string_equal(lysp_mod->mod->ref, "ref");
     assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
-    assert_string_equal(lysp_mod->imports->name, "a-mod");
+    CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
+            "imp-pref", NULL, "");
     assert_string_equal(lysp_mod->includes->name, "b-mod");
     assert_string_equal(lysp_mod->extensions->name, "ext");
     assert_string_equal(lysp_mod->features->name, "feature");
@@ -3996,40 +3522,36 @@
     assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
     assert_string_equal(lysp_mod->notifs->name, "notf");
     assert_string_equal(lysp_mod->deviations->nodeid, "target");
-    assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
-    assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LYEXT_SUBSTMT_SELF);
 
     /* min subelems */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_mod = mod_renew(st->yin_ctx);
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_mod = mod_renew(YCTX);
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
             "    <namespace uri=\"ns\"/>\n"
             "    <prefix value=\"pref\"/>\n"
             "    <yang-version value=\"1.1\"/>\n"
             "</module>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
 
     /* incorrect subelem order */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_mod = mod_renew(st->yin_ctx);
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_mod = mod_renew(YCTX);
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
             "    <feature name=\"feature\"/>\n"
             "    <namespace uri=\"ns\"/>\n"
             "    <prefix value=\"pref\"/>\n"
             "    <yang-version value=\"1.1\"/>\n"
             "</module>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
-    logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 3.");
-
-    st->finished_correctly = true;
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
+    CHECK_LOG_CTX("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\".", "Line number 3.");
 }
 
 static struct lysp_submodule *
@@ -4050,9 +3572,8 @@
 static void
 test_submodule_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
-    struct lysp_submodule *lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
 
     /* max subelements */
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
@@ -4088,10 +3609,10 @@
             "    <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
             EXT_SUBELEM "\n"
             "</submodule>\n";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
 
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
     assert_string_equal(lysp_submod->name, "mod");
     assert_string_equal(lysp_submod->revs, "2019-02-02");
     assert_string_equal(lysp_submod->prefix, "pref");
@@ -4101,7 +3622,8 @@
     assert_string_equal(lysp_submod->dsc, "desc");
     assert_string_equal(lysp_submod->ref, "ref");
     assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
-    assert_string_equal(lysp_submod->imports->name, "a-mod");
+    CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
+            "imp-pref", NULL, "");
     assert_string_equal(lysp_submod->includes->name, "b-mod");
     assert_string_equal(lysp_submod->extensions->name, "ext");
     assert_string_equal(lysp_submod->features->name, "feature");
@@ -4129,45 +3651,40 @@
     assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
     assert_string_equal(lysp_submod->notifs->name, "notf");
     assert_string_equal(lysp_submod->deviations->nodeid, "target");
-    assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
-    assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LYEXT_SUBSTMT_SELF);
 
     /* min subelemnts */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_submod = submod_renew(YCTX, "module-name");
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
             "</submodule>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
     assert_string_equal(lysp_submod->prefix, "pref");
     assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
 
     /* incorrect subelem order */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_submod = submod_renew(YCTX, "module-name");
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <reference><text>ref</text></reference>\n"
             "    <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
             "</submodule>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
-    logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 4.");
-
-    st->finished_correctly = true;
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
+    CHECK_LOG_CTX("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\".", "Line number 4.");
 }
 
 static void
 test_yin_parse_module(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lys_module *mod;
     struct lys_yin_parser_ctx *yin_ctx = NULL;
@@ -4175,7 +3692,7 @@
     struct lys_glob_unres unres = {0};
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
             "    <yang-version value=\"1.1\"/>\n"
             "    <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
@@ -4201,7 +3718,7 @@
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
     assert_null(mod->parsed->exts->child->next->child);
     assert_string_equal(mod->parsed->exts->child->next->arg, "test");
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4209,7 +3726,7 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\""
             "    xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
             "    xmlns:foo=\"urn:example:foo\""
@@ -4240,7 +3757,7 @@
             "</module>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4248,7 +3765,7 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <namespace uri=\"urn:example:foo\"/>\n"
@@ -4256,7 +3773,7 @@
             "</module>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4264,18 +3781,18 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</submodule>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL);
-    logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
+    CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <namespace uri=\"urn:example:foo\"/>\n"
@@ -4284,26 +3801,23 @@
             "<module>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID);
-    logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 6.");
+    CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_parse_submodule(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lys_yin_parser_ctx *yin_ctx = NULL;
     struct lysp_submodule *submod = NULL;
     struct ly_in *in;
 
-    lydict_insert(st->ctx, "a", 0, &st->yin_ctx->parsed_mod->mod->name);
+    lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
 
     data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
             "<submodule name=\"asub\""
@@ -4330,7 +3844,7 @@
             "    </augment>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4345,7 +3859,7 @@
             "    </belongs-to>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4356,8 +3870,8 @@
             "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</module>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EINVAL);
-    logbuf_assert("Input data contains module in situation when a submodule is expected.");
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
+    CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4378,15 +3892,13 @@
             "    </belongs-to>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EVALID);
-    logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 8.");
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
+    CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
-
-    st->finished_correctly = true;
 }
 
 int
@@ -4394,75 +3906,75 @@
 {
 
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
+        UTEST(test_yin_match_keyword, setup, teardown),
+        UTEST(test_yin_parse_element_generic, setup, teardown),
+        UTEST(test_yin_parse_extension_instance, setup, teardown),
+        UTEST(test_yin_parse_content, setup, teardown),
+        UTEST(test_validate_value, setup, teardown),
 
-        cmocka_unit_test(test_yin_match_argument_name),
-        cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_f),
+        UTEST(test_yin_match_argument_name),
+        cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
 
-        cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_f, teardown_f),
+        cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
     };
 
-    return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
+    return cmocka_run_group_tests(tests, NULL, NULL);
 }
diff --git a/tests/utests/schema/test_printer_yang.c b/tests/utests/schema/test_printer_yang.c
index 4296c05..124bb28 100644
--- a/tests/utests/schema/test_printer_yang.c
+++ b/tests/utests/schema/test_printer_yang.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from printer_yang.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,80 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "context.h"
 #include "out.h"
 #include "printer_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
 
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
     const char *orig = "module a {\n"
             "  yang-version 1.1;\n"
@@ -125,9 +63,8 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -167,7 +104,7 @@
             "  prefix b;\n\n"
             "  revision 2019-04-16;\n"
             "}\n";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -198,7 +135,7 @@
             "  namespace \"urn:test:c\";\n"
             "  prefix c;\n"
             "}\n";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -207,9 +144,7 @@
     assert_int_equal(strlen(compiled), ly_out_printed(out));
     assert_string_equal(printed, compiled);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static LY_ERR
@@ -226,9 +161,6 @@
 static void
 test_submodule(void **state)
 {
-    *state = test_submodule;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
     const char *mod_yang = "module a {\n"
             "  yang-version 1.1;\n"
@@ -259,25 +191,23 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, submod_yang);
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, mod_yang, LYS_IN_YANG, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yang);
+    UTEST_ADD_MODULE(mod_yang, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod, mod->parsed->includes[0].submodule, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(submod_yang), ly_out_printed(out));
     assert_string_equal(printed, submod_yang);
 
     *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_submodule, logger_setup, logger_teardown),
+        UTEST(test_module),
+        UTEST(test_submodule),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_printer_yin.c b/tests/utests/schema/test_printer_yin.c
index 3688faa..d1d42e8 100644
--- a/tests/utests/schema/test_printer_yin.c
+++ b/tests/utests/schema/test_printer_yin.c
@@ -3,7 +3,7 @@
  * @author: Fred Gan <ganshaolong@vip.qq.com>
  * @brief unit tests for functions from printer_yin.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,80 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "context.h"
 #include "out.h"
 #include "printer_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
 
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
 
     const char *orig =
@@ -577,16 +515,13 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YIN, 0, 0));
     assert_int_equal(strlen(ori_res), ly_out_printed(out));
     assert_string_equal(printed, ori_res);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static LY_ERR
@@ -603,9 +538,6 @@
 static void
 test_submodule(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
 
     const char *mod_yin =
@@ -645,25 +577,23 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, submod_yin);
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, mod_yin, LYS_IN_YIN, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yin);
+
+    UTEST_ADD_MODULE(mod_yin, LYS_IN_YIN, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod, mod->parsed->includes[0].submodule, LYS_OUT_YIN, 0, 0));
     assert_int_equal(strlen(submod_yin), ly_out_printed(out));
     assert_string_equal(printed, submod_yin);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_submodule, logger_setup, logger_teardown),
+        UTEST(test_module),
+        UTEST(test_submodule),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c
index ebe8af3..7e7a351 100644
--- a/tests/utests/schema/test_schema.c
+++ b/tests/utests/schema/test_schema.c
@@ -11,73 +11,14 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
+#define _UTEST_MAIN_
 #include "test_schema.h"
 
 #include <string.h>
 
 #include "log.h"
 #include "parser_schema.h"
-#include "tests/config.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#if ENABLE_LOGGER_CHECKING
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-
-#if ENABLE_LOGGER_CHECKING
-    /* setup logger */
-    ly_set_log_clb(logger, 1);
-#endif
-
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-#if ENABLE_LOGGER_CHECKING
-    logbuf[0] = '\0';
-#endif
-}
 
 LY_ERR
 test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
@@ -109,15 +50,15 @@
 {
     const struct CMUnitTest tests[] = {
         /** test_schema_common.c */
-        cmocka_unit_test_setup_teardown(test_getnext, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_date, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_revisions, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_typedef, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_accessible_tree, logger_setup, logger_teardown),
+        UTEST(test_getnext),
+        UTEST(test_date),
+        UTEST(test_revisions),
+        UTEST(test_typedef),
+        UTEST(test_accessible_tree),
 
         /** test_schema_stmts.c */
-        cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_feature, logger_setup, logger_teardown),
+        UTEST(test_identity),
+        UTEST(test_feature),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_schema.h b/tests/utests/schema/test_schema.h
index 2599db3..d3cacb7 100644
--- a/tests/utests/schema/test_schema.h
+++ b/tests/utests/schema/test_schema.h
@@ -15,22 +15,12 @@
 #ifndef TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
 #define TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
 
+#include "utests.h"
+
 #include "log.h"
 #include "parser_schema.h"
 #include "tests/config.h"
 
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-extern char logbuf[];
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-void logbuf_clean(void);
-
 LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
         const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT * format,
         const char **module_data, void (**free_module_data)(void *model_data, void *user_data));
@@ -49,7 +39,7 @@
     "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
     "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
 
-#define TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, STR) \
+#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
     if (YIN) { \
         if (RFC7950) { \
             STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
@@ -64,30 +54,31 @@
         } \
     }
 
-#define TEST_SCHEMA_OK(CTX, RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
+#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
     { \
     const char *test_str__; \
-    TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
+    TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
     }
 
-#define TEST_SCHEMA_ERR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG) \
+#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
     { \
     const char *test_str__; \
-    TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
-    assert_int_not_equal(lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
-    logbuf_assert(ERRMSG); \
+    TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+    assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
+    CHECK_LOG_CTX(ERRMSG, ERRPATH); \
     }
 
-#define TEST_STMT_DUP(CTX, RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
+#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
     if (YIN) { \
-        TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+        TEST_SCHEMA_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
     } else { \
-        TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
-                        "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+        TEST_SCHEMA_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
+                        "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
     }
 
-#define TEST_STMT_SUBSTM_ERR(CTX, RFC7950, STMT, SUBSTMT, VALUE) ;\
-        TEST_SCHEMA_ERR(CTX, RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\". Line number 1.");
+#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
+        TEST_SCHEMA_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
+                        "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
 
 #endif /* TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_ */
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
index 8e3bc5d..ab4b3b2 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -11,6 +11,7 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#include "test_schema.h"
 
 #include <string.h>
 
@@ -18,24 +19,16 @@
 #include "log.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
-
-#include "test_schema.h"
 
 void
 test_getnext(void **state)
 {
-    *state = test_getnext;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node = NULL, *four;
     const struct lysc_node_container *cont;
     const struct lysc_action *rpc;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;"
             "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}"
             "  list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}"
             "  anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}"
@@ -119,68 +112,58 @@
     assert_string_equal("h-output", node->name);
     assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("c", node->name);
     assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("d", node->name);
     assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("c", node->name);
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
     assert_string_equal("a", node->name);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 void
 test_date(void **state)
 {
-    *state = test_date;
-
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date"));
-    logbuf_assert("Invalid argument date (lysp_check_date()).");
+    CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date"));
-    logbuf_assert("Invalid argument date_len (lysp_check_date()).");
+    CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date"));
-    logbuf_assert("Invalid value \"nonsencexx\" of \"date\".");
+    CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date"));
-    logbuf_assert("Invalid value \"123x-11-11\" of \"date\".");
+    CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date"));
-    logbuf_assert("Invalid value \"2018-13-11\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date"));
-    logbuf_assert("Invalid value \"2018-11-41\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date"));
-    logbuf_assert("Invalid value \"2018-02-29\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date"));
-    logbuf_assert("Invalid value \"2018.02-28\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date"));
-    logbuf_assert("Invalid value \"2018-02.28\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL);
 
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date"));
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date"));
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date"));
-
-    *state = NULL;
 }
 
 void
 test_revisions(void **state)
 {
-    (void) state; /* unused */
-
     struct lysp_revision *revs = NULL, *rev;
 
-    logbuf_clean();
     /* no error, it just does nothing */
     lysp_sort_revisions(NULL);
-    logbuf_assert("");
+    CHECK_LOG(NULL, NULL);
 
     /* revisions are stored in wrong order - the newest is the last */
     LY_ARRAY_NEW_RET(NULL, revs, rev, );
@@ -202,127 +185,112 @@
 void
 test_typedef(void **state)
 {
-    *state = test_typedef;
-
-    struct ly_ctx *ctx = NULL;
     const char *str;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"binary\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"binary\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"bits\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"bits\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"boolean\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"boolean\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"decimal64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"decimal64\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"empty\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"empty\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"enumeration\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"enumeration\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int8\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int8\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int16\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int16\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int32\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int32\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int64\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"identityref\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"identityref\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"leafref\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"leafref\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"string\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"string\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef union {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"union\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"union\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint8\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint8\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint16\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint16\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint32\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint32\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint64\" of typedef - name collision with a built-in type.", "Line number 1.");
 
     str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} "
             "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}"
             "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}"
             "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}"
             "typedef uint32_ {type string;} typedef uint64_ {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
 
     str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"test\" of typedef - name collision with another top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"test\" of typedef - name collision with another top-level type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"y\" of typedef - name collision with another scoped type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"y\" of typedef - name collision with another scoped type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"y\" of typedef - name collision with sibling type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"y\" of typedef - name collision with sibling type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
     str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - name collision with another top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - name collision with another top-level type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
     str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
     str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 }
 
 void
 test_accessible_tree(void **state)
 {
-    *state = test_accessible_tree;
-
-    struct ly_ctx *ctx = NULL;
     const char *str;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-    logbuf_clean();
-
     /* config -> config */
-    str =
-            "module a {\n"
+    str = "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -339,12 +307,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* config -> state leafref */
-    str =
-            "module b {\n"
+    str = "module b {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -361,14 +328,12 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
-            " (as the leafref does), but it does not. /b:cont2/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
+            " (as the leafref does), but it does not.", "/b:cont2/l2");
 
     /* config -> state must */
-    str =
-            "module b {\n"
+    str = "module b {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -384,13 +349,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".", NULL);
 
     /* state -> config */
-    str =
-            "module c {\n"
+    str = "module c {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -408,12 +371,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* notif -> state */
-    str =
-            "module d {\n"
+    str = "module d {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -431,12 +393,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* notif -> notif */
-    str =
-            "module e {\n"
+    str = "module e {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    notification notif {\n"
@@ -451,12 +412,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> state */
-    str =
-            "module f {\n"
+    str = "module f {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -476,12 +436,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> rpc input */
-    str =
-            "module g {\n"
+    str = "module g {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -498,12 +457,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> rpc output leafref */
-    str =
-            "module h {\n"
+    str = "module h {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -521,13 +479,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"l\" in path. /h:rp/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"l\" in path.", "/h:rp/l2");
 
     /* rpc input -> rpc output must */
-    str =
-            "module h {\n"
+    str = "module h {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -544,13 +500,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/l2\".", NULL);
 
     /* rpc input -> notif leafref */
-    str =
-            "module i {\n"
+    str = "module i {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -568,13 +522,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"notif\" in path. /i:rp/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"notif\" in path.", "/i:rp/l2");
 
     /* rpc input -> notif must */
-    str =
-            "module i {\n"
+    str = "module i {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -591,13 +543,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/l2\".", NULL);
 
     /* action output -> state */
-    str =
-            "module j {\n"
+    str = "module j {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -624,12 +574,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* action output -> action input leafref */
-    str =
-            "module k {\n"
+    str = "module k {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -656,13 +605,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"l\" in path. /k:cont/ll/act/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"l\" in path.", "/k:cont/ll/act/l2");
 
     /* action output -> action input must */
-    str =
-            "module k {\n"
+    str = "module k {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -688,10 +635,6 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/l2\".");
-    logbuf_clean();
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/l2\".", NULL);
 }
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
index 24417c4..1cd8ced 100644
--- a/tests/utests/schema/test_schema_stmts.c
+++ b/tests/utests/schema/test_schema_stmts.c
@@ -11,49 +11,41 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#include "test_schema.h"
 
 #include <string.h>
 
 #include "context.h"
 #include "log.h"
-#include "test_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#include "test_schema.h"
 
 void
 test_identity(void **state)
 {
-    *state = test_identity;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod, *mod_imp;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     /*
      * parsing YANG
      */
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "description", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "reference", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "status", "current", "obsolete", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "description", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "reference", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "status", "current", "obsolete", "1");
 
     /* full content */
-    TEST_SCHEMA_OK(ctx, 1, 0, "identityone",
+    TEST_SCHEMA_OK(1, 0, "identityone",
             "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}"
             "identity a; identity b; extension ext; feature x; feature y;", mod);
     assert_non_null(mod->parsed->identities);
     assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities));
 
     /* invalid substatement */
-    TEST_STMT_SUBSTM_ERR(ctx, 0, "identity", "organization", "XXX");
+    TEST_STMT_SUBSTM_ERR(0, "identity", "organization", "XXX");
 
     /*
      * parsing YIN
      */
     /* max subelems */
-    TEST_SCHEMA_OK(ctx, 1, 1, "identityone-yin", "<identity name=\"ident-name\">"
+    TEST_SCHEMA_OK(1, 1, "identityone-yin", "<identity name=\"ident-name\">"
             "<if-feature name=\"iff\"/>"
             "<base name=\"base-name\"/>"
             "<status value=\"deprecated\"/>"
@@ -75,19 +67,20 @@
     assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
 
     /* min subelems */
-    TEST_SCHEMA_OK(ctx, 1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
+    TEST_SCHEMA_OK(1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
     assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities));
     assert_string_equal(mod->parsed->identities[0].name, "ident-name");
 
     /* invalid substatement */
-    TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
-            "Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
+    TEST_SCHEMA_ERR(0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
+            "Invalid sub-elemnt \"if-feature\" of \"identity\" element - "
+            "this sub-element is allowed only in modules with version 1.1 or newer.", "Line number 1.");
 
     /*
      * compiling
      */
-    TEST_SCHEMA_OK(ctx, 0, 0, "a", "identity a1;", mod_imp);
-    TEST_SCHEMA_OK(ctx, 1, 0, "b", "import a {prefix a;}"
+    TEST_SCHEMA_OK(0, 0, "a", "identity a1;", mod_imp);
+    TEST_SCHEMA_OK(1, 0, "b", "import a {prefix a;}"
             "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}"
             "identity b4 {base b:b1; base b3;}", mod);
     assert_non_null(mod_imp->compiled);
@@ -107,34 +100,34 @@
     assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived));
     assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]);
 
-    TEST_SCHEMA_OK(ctx, 1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
+    TEST_SCHEMA_OK(1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
     assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
     assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]);
 
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;identity i1;",
-            "Duplicate identifier \"i1\" of identity statement. Line number 1.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\". /inv:{identity='i1'}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself. /inv:{identity='i1'}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
-            "Identity \"i1\" is indirectly derived from itself. /inv:{identity='i3'}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;identity i1;",
+            "Duplicate identifier \"i1\" of identity statement.", "Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\".", "/inv:{identity='i1'}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself.", "/inv:{identity='i1'}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
+            "Identity \"i1\" is indirectly derived from itself.", "/inv:{identity='i3'}");
 
     /* base in non-implemented module */
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb,
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
             "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}");
-    TEST_SCHEMA_OK(ctx, 0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
+    TEST_SCHEMA_OK(0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
 
     /* default value from non-implemented module */
-    TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
+    TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
             "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value"
-            " - identity found in non-implemented module \"base\".). /ident2:l");
+            " - identity found in non-implemented module \"base\".).", "/ident2:l");
 
     /* default value in typedef from non-implemented module */
-    TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
+    TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
             "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid"
-            " identityref \"b:i2\" value - identity found in non-implemented module \"base\".). /ident2:l");
+            " identityref \"b:i2\" value - identity found in non-implemented module \"base\".).", "/ident2:l");
 
     /*
      * printing
@@ -143,45 +136,37 @@
     /*
      * cleanup
      */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 void
 test_feature(void **state)
 {
-    *state = test_feature;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysp_feature *f;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     /*
      * parsing YANG
      */
 
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "description", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "reference", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "status", "current", "obsolete", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "description", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "reference", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "status", "current", "obsolete", "1");
 
     /* full content */
-    TEST_SCHEMA_OK(ctx, 1, 0, "featureone",
+    TEST_SCHEMA_OK(1, 0, "featureone",
             "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}"
             "extension ext; feature x; feature y;", mod);
     assert_non_null(mod->parsed->features);
     assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features));
 
     /* invalid substatement */
-    TEST_STMT_SUBSTM_ERR(ctx, 0, "feature", "organization", "XXX");
+    TEST_STMT_SUBSTM_ERR(0, "feature", "organization", "XXX");
 
     /*
      * parsing YIN
      */
     /* max subelems */
-    TEST_SCHEMA_OK(ctx, 0, 1, "featureone-yin", "<feature name=\"feature-name\">"
+    TEST_SCHEMA_OK(0, 1, "featureone-yin", "<feature name=\"feature-name\">"
             "<if-feature name=\"iff\"/>"
             "<status value=\"deprecated\"/>"
             "<description><text>desc</text></description>"
@@ -199,19 +184,19 @@
     assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
 
     /* min subelems */
-    TEST_SCHEMA_OK(ctx, 0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
+    TEST_SCHEMA_OK(0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
     assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features));
     assert_string_equal(mod->parsed->features[0].name, "feature-name");
 
     /* invalid substatement */
-    TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
-            "Unexpected sub-element \"organization\" of \"feature\" element. Line number 1.");
+    TEST_SCHEMA_ERR(0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
+            "Unexpected sub-element \"organization\" of \"feature\" element.", "Line number 1.");
 
     /*
      * compiling
      */
 
-    TEST_SCHEMA_OK(ctx, 1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
+    TEST_SCHEMA_OK(1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
             "feature orfeature {if-feature \"f1 or f2\";}\n"
             "feature andfeature {if-feature \"f1 and f2\";}\n"
             "feature f6 {if-feature \"not f1\";}\n"
@@ -227,42 +212,42 @@
     }
 
     /* some invalid expressions */
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}",
-            "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
-            "Invalid value \"f and\" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}",
-            "Invalid value \"or\" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
-            "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
-            "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
-            "Invalid value \"---\" of if-feature - unable to find feature \"---\".");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
-            "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;",
-            "Duplicate identifier \"f1\" of feature statement. Line number 1.");
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature f1;}",
+            "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
+            "Invalid value \"f and\" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature 'or';}",
+            "Invalid value \"or\" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
+            "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
+            "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
+            "Invalid value \"---\" of if-feature - unable to find feature \"---\".", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
+            "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f1;",
+            "Duplicate identifier \"f1\" of feature statement.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;",
-            "Duplicate identifier \"f1\" of feature statement. Line number 1.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
-            "Feature \"f1\" is indirectly referenced from itself.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}",
-            "Feature \"f1\" is referenced from itself.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}",
-            "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
-            "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
-            "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
-            "Invalid value \"f1 not \" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
-            "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
-            "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;feature f1;",
+            "Duplicate identifier \"f1\" of feature statement.", "Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
+            "Feature \"f1\" is indirectly referenced from itself.", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f1;}",
+            "Feature \"f1\" is referenced from itself.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f {if-feature ();}",
+            "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
+            "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
+            "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
+            "Invalid value \"f1 not \" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
+            "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
+            "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.", NULL);
 
     /*
      * printing
@@ -271,7 +256,4 @@
     /*
      * cleanup
      */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 7f0e4da..6f5977c 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "in.h"
@@ -18,66 +20,18 @@
 #include "path.h"
 #include "plugins_types.h"
 #include "schema_compile.h"
-#include "utests.h"
 #include "xpath.h"
 
-void yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx);
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-
-    if (path && path[0]) {
-        snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-    } else {
-        strncpy(logbuf, msg, BUFSIZE - 1);
-    }
-}
-
-#endif
-
 static int
-logger_setup(void **state)
+setup(void **state)
 {
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_SETUP;
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIRS));
+
     return 0;
 }
 
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str);logbuf_clean()
-#else
-#   define logbuf_assert(str)
-#endif
-
 static LY_ERR
 test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
         const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
@@ -92,11 +46,8 @@
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
     const char *str;
     struct ly_in *in;
-    struct ly_ctx *ctx = NULL;
     struct lys_module *mod = NULL;
     struct lysp_feature *f;
     struct lysc_iffeature *iff;
@@ -104,24 +55,22 @@
 
     str = "module test {namespace urn:test; prefix t;"
             "feature f1;feature f2 {if-feature f1;}}";
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     assert_int_equal(LY_EINVAL, lys_compile(NULL, 0, NULL));
-    logbuf_assert("Invalid argument mod (lys_compile()).");
+    CHECK_LOG("Invalid argument mod (lys_compile()).", NULL);
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
     assert_int_equal(0, mod->implemented);
     assert_int_equal(LY_SUCCESS, lys_compile(mod, 0, &unres));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     assert_null(mod->compiled);
     mod->implemented = 1;
     assert_int_equal(LY_SUCCESS, lys_compile(mod, 0, &unres));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     assert_non_null(mod->compiled);
     assert_string_equal("test", mod->name);
     assert_string_equal("urn:test", mod->ns);
@@ -141,60 +90,52 @@
     /* submodules cannot be compiled directly */
     str = "submodule test {belongs-to xxx {prefix x;}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EINVAL, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_EINVAL, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
-    logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
+    CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
 
     /* data definition name collision in top level */
     str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EEXIST, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /aa:a");
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_EEXIST, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/aa:a");
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_name_collisions(void **state)
 {
-    (void) state; /* unused */
-
-    struct ly_ctx *ctx;
     const char *yang_data;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* top-level */
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  leaf c {type empty;}"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  notification c;"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  rpc c;"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
@@ -206,51 +147,45 @@
             "    }"
             "  }"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:ch/c/c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:ch/c/c");
+    UTEST_LOG_CLEAN;
 
     /* nested */
     yang_data = "module a {namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "container a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "notification a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "action a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     /* grouping */
-
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_container(void **state)
 {
-    (void) state; /* unused */
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_container *cont;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
     assert_int_equal(LYS_CONTAINER, cont->nodetype);
@@ -258,8 +193,8 @@
     assert_true(cont->flags & LYS_CONFIG_W);
     assert_true(cont->flags & LYS_STATUS_CURR);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing explicit \"deprecated\" status that was already specified in parent, inheriting.");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing explicit \"deprecated\" status that was already specified in parent, inheriting.", NULL);
     assert_non_null(mod->compiled);
     assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
     assert_true(cont->flags & LYS_CONFIG_R);
@@ -269,16 +204,11 @@
     assert_true(cont->flags & LYS_CONFIG_R);
     assert_true(cont->flags & LYS_STATUS_DEPRC);
     assert_string_equal("child", cont->name);
-
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_leaflist(void **state)
 {
-    *state = test_node_leaflist;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     struct lysc_node_leaflist *ll;
@@ -286,9 +216,7 @@
     const char *dflt;
     uint8_t dynamic;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "typedef mytype {type union {type leafref {path ../target;} type string;}}"
             "leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
             "leaf-list ll2 {type leafref {path ../target;}}"
@@ -312,13 +240,13 @@
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_int_equal(0, ll->min);
     assert_int_equal((uint32_t)-1, ll->max);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
             "leaf-list ll1 {type mytype;default 1; default 1; config false;}"
             "leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
@@ -340,26 +268,26 @@
     assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, ll->flags);
 
     /* ordered-by is ignored for state data, RPC/action output parameters and notification content */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
             "leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG, &mod));
     /* but warning is present: */
-    logbuf_assert("The ordered-by statement is ignored in lists representing state data (/d:ll).");
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing state data (/d:ll).", NULL);
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG, ll->flags);
-    logbuf_clean();
+    UTEST_LOG_CLEAN;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e;"
             "rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll).");
-    logbuf_clean();
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll).", NULL);
+    UTEST_LOG_CLEAN;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f;"
             "notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("The ordered-by statement is ignored in lists representing notification content (/f:event/ll).");
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing notification content (/f:event/ll).", NULL);
 
     /* forward reference in default */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;"
             "leaf ref {type instance-identifier {require-instance true;} default \"/g:g[.='val']\";}"
             "leaf-list g {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(l = (struct lysc_node_leaf *)mod->compiled->data);
@@ -367,38 +295,32 @@
     assert_non_null(l->dflt);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /aa:ll");
+    CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/aa:ll");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid empty value \"x\".). /bb:ll");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "/bb:ll");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
             "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_non_null(ll->dflts);
     assert_int_equal(3, LY_ARRAY_COUNT(ll->dflts));
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
             "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Configuration leaf-list has multiple defaults of the same value \"one\". /dd:ll");
+    CHECK_LOG_CTX("Configuration leaf-list has multiple defaults of the same value \"one\".", "/dd:ll");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
             "leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Invalid instance-identifier \"/ee:g\" value - semantic error.). /ee:ref");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Invalid instance-identifier \"/ee:g\" value - semantic error.).", "/ee:ref");
 }
 
 static void
 test_node_list(void **state)
 {
-    *state = test_node_list;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_list *list;
     struct lysc_node *child;
@@ -409,10 +331,8 @@
             "list l2 {config false;leaf value {type string;}}}";
     const char *feats[] = {"f", NULL};
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats, &mod));
     ly_in_free(in, 0);
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -431,7 +351,7 @@
     assert_false(list->child->flags & LYS_KEY);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG | LYS_KEYLESS, list->flags);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
             "list l {key a; unique \"a c/b:b\"; unique \"c/e d\";"
             "leaf a {type string; default x;} leaf d {type string;config false;}"
             "container c {leaf b {type string;}leaf e{type string;config false;}}}}",
@@ -455,7 +375,7 @@
     assert_string_equal("d", list->uniques[1][1]->name);
     assert_true(list->uniques[1][1]->flags & LYS_UNIQUE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;"
             "list l {key a;leaf a {type empty;}}}", LYS_IN_YANG, &mod));
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -465,7 +385,7 @@
     assert_int_equal(LY_TYPE_EMPTY, ((struct lysc_node_leaf *)list->child)->type->basetype);
 
     /* keys order */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
             "list l {key \"d b c\";leaf a {type string;} leaf b {type string;} leaf c {type string;} leaf d {type string;}}}", LYS_IN_YANG, &mod));
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -484,74 +404,66 @@
     assert_false(child->flags & LYS_KEY);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing key in list representing configuration data. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Missing key in list representing configuration data.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
             "list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("List's key must not have any \"when\" statement. /bb:l/x");
+    CHECK_LOG_CTX("List's key must not have any \"when\" statement.", "/bb:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
             "list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Key \"x\" is disabled by its if-features. /cc:l/x");
+    CHECK_LOG_CTX("Key \"x\" is disabled by its if-features.", "/cc:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;"
             "list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Key of the configuration list must not be status leaf. /dd:l/x");
+    CHECK_LOG_CTX("Key of the configuration list must not be status leaf.", "/dd:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;"
             "list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Configuration node cannot be child of any state data node. /ee:l/x");
+    CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/ee:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;"
             "list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("The list's key \"x\" not found. /ff:l");
+    CHECK_LOG_CTX("The list's key \"x\" not found.", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;"
             "list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf. /gg:l");
+    CHECK_LOG_CTX("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
             "list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Unique statement \"x y\" refers to leaves with different config type. /hh:l");
+    CHECK_LOG_CTX("Unique statement \"x y\" refers to leaves with different config type.", "/hh:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;"
             "list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\". /ii:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\".", "/ii:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;"
             "list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"c/x\" - target node not found. /jj:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c/x\" - target node not found.", "/jj:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
             "list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator. /kk:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator.", "/kk:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
             "list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicated key identifier \"x\". /ll:l");
+    CHECK_LOG_CTX("Duplicated key identifier \"x\".", "/ll:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;"
             "list l {key x;leaf x {type empty;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("List's key cannot be of \"empty\" type until it is in YANG 1.1 module. /mm:l/x");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("List's key cannot be of \"empty\" type until it is in YANG 1.1 module.", "/mm:l/x");
 }
 
 static void
 test_node_choice(void **state)
 {
-    *state = test_node_choice;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_choice *ch;
     struct lysc_node_case *cs;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;feature f;"
             "choice ch {default a:b; when \"true()\"; case a {leaf a1 {type string;}leaf a2 {type string;}}"
             "leaf b {type string;}}}", LYS_IN_YANG, &mod));
     ch = (struct lysc_node_choice *)mod->compiled->data;
@@ -578,81 +490,65 @@
     assert_ptr_equal(cs, cs->child->parent);
     assert_ptr_equal(ch->dflt, cs);
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /aa:ch/x/x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa;"
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/aa:ch/x/x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa;"
             "choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /aa2:ch/b/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/aa2:ch/b/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
             "choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of case statement. /bb:ch/a");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb2 {namespace urn:bb2;prefix bb;"
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of case statement.", "/bb:ch/a");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb2 {namespace urn:bb2;prefix bb;"
             "choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"b\" of case statement. /bb2:ch/b");
+    CHECK_LOG_CTX("Duplicate identifier \"b\" of case statement.", "/bb2:ch/b");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ca {namespace urn:ca;prefix ca;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ca {namespace urn:ca;prefix ca;"
             "choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Default case \"c\" not found. /ca:ch");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
+    CHECK_LOG_CTX("Default case \"c\" not found.", "/ca:ch");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
             "choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Default case \"a:a\" not found. /cb:ch");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+    CHECK_LOG_CTX("Default case \"a:a\" not found.", "/cb:ch");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
             "choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Mandatory node \"x\" under the default case \"a\". /cc:ch");
+    CHECK_LOG_CTX("Mandatory node \"x\" under the default case \"a\".", "/cc:ch");
     /* TODO check with mandatory nodes from augment placed into the case */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_anydata(void **state)
 {
-    *state = test_node_anydata;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_anydata *any;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
             "anydata any {config false;mandatory true;}}", LYS_IN_YANG, &mod));
     any = (struct lysc_node_anydata *)mod->compiled->data;
     assert_non_null(any);
     assert_int_equal(LYS_ANYDATA, any->nodetype);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE | LYS_SET_CONFIG, any->flags);
 
-    logbuf_clean();
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
             "anyxml any;}", LYS_IN_YANG, &mod));
     any = (struct lysc_node_anydata *)mod->compiled->data;
     assert_non_null(any);
     assert_int_equal(LYS_ANYXML, any->nodetype);
     assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, any->flags);
-    logbuf_assert("Use of anyxml to define configuration data is not recommended. /b:any"); /* warning */
+    CHECK_LOG_CTX("Use of anyxml to define configuration data is not recommended. /b:any", NULL);     /* warning */
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 }
 
 static void
 test_action(void **state)
 {
-    *state = test_action;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_action *rpc;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG, &mod));
     rpc = mod->compiled->rpcs;
     assert_non_null(rpc);
@@ -661,7 +557,7 @@
     assert_int_equal(LYS_STATUS_CURR, rpc->flags);
     assert_string_equal("a", rpc->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
             "action b {input {leaf x {type int8;} leaf y {type int8;}}"
             "output {must \"result > 25\"; must \"/top\"; leaf result {type int16;}}}}"
             "augment /top/b/output {leaf result2 {type string;}}}", LYS_IN_YANG, &mod));
@@ -675,49 +571,41 @@
     assert_int_equal(2, LY_ARRAY_COUNT(rpc->output.musts));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/bb:x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/cc:c/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"z\" of data definition/RPC/action/notification statement.", "/dd:c/z");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"w\" of data definition/RPC/action/notification statement.", "/ee:w");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
             "augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside another RPC/action. /ff:{augment='/test/input/a'}/invalid");
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside another RPC/action.", "/ff:{augment='/test/input/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
             "augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside notification. /gg:{augment='/test/a'}/invalid");
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/gg:{augment='/test/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
             "grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside notification. /hh:test/a/{uses='grp'}/invalid");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/hh:test/a/{uses='grp'}/invalid");
 }
 
 static void
 test_notification(void **state)
 {
-    *state = test_notification;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_notif *notif;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG, &mod));
     notif = mod->compiled->notifs;
     assert_non_null(notif);
@@ -732,7 +620,7 @@
     assert_string_equal("a2", notif[1].name);
     assert_null(notif[1].data);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
             "notification b1 {leaf x {type int8;}} notification b2 {must \"/top\";}}}", LYS_IN_YANG, &mod));
     notif = lysc_node_notifs(mod->compiled->data);
     assert_non_null(notif);
@@ -749,34 +637,31 @@
     assert_int_equal(1, LY_ARRAY_COUNT(notif[1].musts));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/bb:x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/cc:c/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"z\" of data definition/RPC/action/notification statement.", "/dd:c/z");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"w\" of data definition/RPC/action/notification statement.", "/ee:w");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
             "augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /ff:{augment='/test/input/a'}/invalid");
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/ff:{augment='/test/input/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
             "augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside another notification. /gg:{augment='/test/a'}/invalid");
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside another notification.", "/gg:{augment='/test/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
             "grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /hh:test/input/a/{uses='grp'}/invalid");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/hh:test/input/a/{uses='grp'}/invalid");
 }
 
 /**
@@ -786,15 +671,10 @@
 static void
 test_type_range(void **state)
 {
-    *state = test_type_range;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT8, type->basetype);
@@ -806,7 +686,7 @@
     assert_int_equal(127, ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(127, ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT16, type->basetype);
@@ -818,7 +698,7 @@
     assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT32, type->basetype);
@@ -830,7 +710,7 @@
     assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT64, type->basetype);
@@ -842,7 +722,7 @@
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT8, type->basetype);
@@ -854,7 +734,7 @@
     assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT16, type->basetype);
@@ -866,7 +746,7 @@
     assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT32, type->basetype);
@@ -878,7 +758,7 @@
     assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT64, type->basetype);
@@ -890,7 +770,7 @@
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
             "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -900,7 +780,7 @@
     assert_non_null(((struct lysc_type_num *)type)->range->parts);
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;"
             "typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}"
             "leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -914,23 +794,15 @@
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
     assert_int_equal(1, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_type_length(void **state)
 {
-    *state = test_type_length;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -941,7 +813,7 @@
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -950,7 +822,7 @@
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -959,7 +831,7 @@
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -968,7 +840,7 @@
     assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -977,7 +849,7 @@
     assert_int_equal(1, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -988,7 +860,7 @@
     assert_int_equal(20, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(30, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -999,7 +871,7 @@
     assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1009,7 +881,7 @@
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1019,7 +891,7 @@
     assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1031,7 +903,7 @@
     assert_int_equal(60, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1050,7 +922,7 @@
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
             "typedef mytype2 {type mytype {pattern '[0-9]*';}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1062,7 +934,7 @@
     assert_int_equal(10, ((struct lysc_type_str *)type)->length->parts[0].min_u64);
     assert_int_equal(100, ((struct lysc_type_str *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
             "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1075,72 +947,64 @@
     assert_int_equal(10, ((struct lysc_type_str *)type)->length->parts[0].max_u64);
 
     /* invalid values */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - value \"-10\" does not fit the type limitations. /aa:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - invalid value \"18446744073709551616\". /bb:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data after max keyword (.. 10). /cc:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (10). /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (10). /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data (x). /ff:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data before min keyword (50 | ). /gg:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected beginning of the expression (| 50). /hh:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..). /ii:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected \"..\" without a lower bound. /jj:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected end of the expression (10 |). /kk:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (15). /kl:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - value \"-10\" does not fit the type limitations.", "/aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - invalid value \"18446744073709551616\".", "/bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data after max keyword (.. 10).", "/cc:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data (x).", "/ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data before min keyword (50 | ).", "/gg:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected beginning of the expression (| 50).", "/hh:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..).", "/ii:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected \"..\" without a lower bound.", "/jj:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression (10 |).", "/kk:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (15).", "/kl:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length 11;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (11) is not equally or more limiting. /ll:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (11) is not equally or more limiting.", "/ll:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting. /mm:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting.", "/mm:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting. /nn:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting.", "/nn:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting. /oo:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting.", "/oo:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
             "leaf l {type mytype {length 15;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (15) is not equally or more limiting. /pp:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15) is not equally or more limiting.", "/pp:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
             "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting. /qq:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting.", "/qq:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting. /rr:l");
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting.", "/rr:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid type restrictions for binary type. /ss:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid type restrictions for binary type.", "/ss:l");
 }
 
 static void
 test_type_pattern(void **state)
 {
-    *state = test_type_pattern;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
             "pattern .* {error-app-tag errortag;error-message error;}"
             "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1156,7 +1020,7 @@
     assert_string_equal("[0-9].*[0-9]", ((struct lysc_type_str *)type)->patterns[1]->expr);
     assert_int_equal(1, ((struct lysc_type_str *)type)->patterns[1]->inverted);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
             "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1169,7 +1033,7 @@
     assert_string_equal("[0-4]*", ((struct lysc_type_str *)type)->patterns[1]->expr);
     assert_int_equal(1, ((struct lysc_type_str *)type)->patterns[1]->refcount);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
             "leaf l {type mytype {length 10;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1181,7 +1045,7 @@
     assert_int_equal(2, ((struct lysc_type_str *)type)->patterns[0]->refcount);
 
     /* test substitutions */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type string {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type string {"
             "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1189,23 +1053,15 @@
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_str *)type)->patterns));
     assert_string_equal("^\\p{IsLatinExtended-A}$", ((struct lysc_type_str *)type)->patterns[0]->expr);
     /* TODO check some data "^ř$" */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_type_enum(void **state)
 {
-    *state = test_type_enum;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
             "enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}"
             "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1224,139 +1080,132 @@
     assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[4].name);
     assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[4].value);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
             "enum 11; enum min {value -2147483648;}enum x$&;"
             "enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}",
             LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[1].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("seven", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(7, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[1].value);
 
     const char *new_module = "module moc_c {yang-version 1.1; namespace urn:moc_c;prefix moc_c;feature f; typedef mytype {type enumeration {"
-                                        "enum first{value -270;} enum second; enum third {value -400;} enum fourth;}} leaf l { type mytype;}}";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, new_module, LYS_IN_YANG, &mod));
+            "enum first{value -270;} enum second; enum third {value -400;} enum fourth;}} leaf l { type mytype;}}";
 
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
+
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(4, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("first", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(-270, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("second", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(-269, ((struct lysc_type_enum*)type)->enums[1].value);
-    assert_string_equal("third", ((struct lysc_type_enum*)type)->enums[2].name);
-    assert_int_equal(-400, ((struct lysc_type_enum*)type)->enums[2].value);
-    assert_string_equal("fourth", ((struct lysc_type_enum*)type)->enums[3].name);
-    assert_int_equal(-268, ((struct lysc_type_enum*)type)->enums[3].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(4, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(-270, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(-269, ((struct lysc_type_enum *)type)->enums[1].value);
+    assert_string_equal("third", ((struct lysc_type_enum *)type)->enums[2].name);
+    assert_int_equal(-400, ((struct lysc_type_enum *)type)->enums[2].value);
+    assert_string_equal("fourth", ((struct lysc_type_enum *)type)->enums[3].name);
+    assert_int_equal(-268, ((struct lysc_type_enum *)type)->enums[3].value);
 
     new_module = "module moc_d {yang-version 1.1; namespace urn:moc_d;prefix moc_d;feature f; typedef mytype {type enumeration {"
-                 "enum first; enum second;}} leaf l { type mytype;}}";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, new_module, LYS_IN_YANG, &mod));
+            "enum first; enum second;}} leaf l { type mytype;}}";
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
 
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("first", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(0, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("second", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(1, ((struct lysc_type_enum*)type)->enums[1].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(0, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(1, ((struct lysc_type_enum *)type)->enums[1].value);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
             "enum one {if-feature f;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one {value -2147483649;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-2147483649\" of \"value\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid value \"-2147483649\" of \"value\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one {value 2147483648;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"2147483648\" of \"value\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid value \"2147483648\" of \"value\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one; enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"one\" of enum statement. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Duplicate identifier \"one\" of enum statement.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum '';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not be zero-length. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not be zero-length.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum ' x';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not have any leading or trailing whitespaces (\" x\"). Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\" x\").", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum 'x ';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not have any leading or trailing whitespaces (\"x \"). Line number 1.");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\"x \").", "Line number 1.");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum 'inva\nlid';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).");
+    CHECK_LOG_CTX("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing enum substatement for enumeration type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing enum substatement for enumeration type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum two;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - derived type adds new item \"two\". /cc:l");
+    CHECK_LOG_CTX("Invalid enumeration - derived type adds new item \"two\".", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
+    CHECK_LOG_CTX("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type.", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647. /ee:l");
+    CHECK_LOG_CTX("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - value 1 collide in items \"y\" and \"x\". /ff:l");
+    CHECK_LOG_CTX("Invalid enumeration - value 1 collide in items \"y\" and \"x\".", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
             "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing enum substatement for enumeration type mytype. /gg:l");
+    CHECK_LOG_CTX("Missing enum substatement for enumeration type mytype.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enumeration type can be subtyped only in YANG 1.1 modules. /hh:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Enumeration type can be subtyped only in YANG 1.1 modules.", "/hh:l");
 }
 
 static void
 test_type_bits(void **state)
 {
-    *state = test_type_bits;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
-                                        "bit automin; bit one {if-feature f; position 1;}"
-                                        "bit two; bit seven {position 7;} bit five {position 5;} bit eight;}}}", LYS_IN_YANG, &mod));
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
+            "bit automin; bit one {if-feature f; position 1;}"
+            "bit two; bit seven {position 7;} bit five {position 5;} bit eight;}}}", LYS_IN_YANG, &mod));
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_BITS, type->basetype);
-    assert_non_null(((struct lysc_type_bits*)type)->bits);
-    assert_int_equal(5, LY_ARRAY_COUNT(((struct lysc_type_bits*)type)->bits));
-    assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name);
-    assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position);
-    assert_string_equal("two", ((struct lysc_type_bits*)type)->bits[1].name);
-    assert_int_equal(2, ((struct lysc_type_bits*)type)->bits[1].position);
-    assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[2].name);
-    assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[2].position);
-    assert_string_equal("five", ((struct lysc_type_bits*)type)->bits[3].name);
-    assert_int_equal(5, ((struct lysc_type_bits*)type)->bits[3].position);
-    assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[4].name);
-    assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[4].position);
+    assert_non_null(((struct lysc_type_bits *)type)->bits);
+    assert_int_equal(5, LY_ARRAY_COUNT(((struct lysc_type_bits *)type)->bits));
+    assert_string_equal("automin", ((struct lysc_type_bits *)type)->bits[0].name);
+    assert_int_equal(0, ((struct lysc_type_bits *)type)->bits[0].position);
+    assert_string_equal("two", ((struct lysc_type_bits *)type)->bits[1].name);
+    assert_int_equal(2, ((struct lysc_type_bits *)type)->bits[1].position);
+    assert_string_equal("seven", ((struct lysc_type_bits *)type)->bits[2].name);
+    assert_int_equal(7, ((struct lysc_type_bits *)type)->bits[2].position);
+    assert_string_equal("five", ((struct lysc_type_bits *)type)->bits[3].name);
+    assert_int_equal(5, ((struct lysc_type_bits *)type)->bits[3].position);
+    assert_string_equal("eight", ((struct lysc_type_bits *)type)->bits[4].name);
+    assert_int_equal(8, ((struct lysc_type_bits *)type)->bits[4].position);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
             "bit automin; bit one;bit two; bit seven {position 7;}bit eight;}} leaf l { type mytype {bit eight;bit seven;bit automin;}}}",
             LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1372,65 +1221,57 @@
     assert_int_equal(8, ((struct lysc_type_bits *)type)->bits[2].position);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
             "bit one {if-feature f;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one {position -1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-1\" of \"position\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"position\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one {position 4294967296;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"4294967296\" of \"position\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid value \"4294967296\" of \"position\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one; bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Duplicate identifier \"one\" of bit statement.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit '11';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier first character '1' (0x0031). Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid identifier first character '1' (0x0031).", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit 'x1$1';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier character '$' (0x0024). Line number 1.");
+    CHECK_LOG_CTX("Invalid identifier character '$' (0x0024).", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing bit substatement for bits type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing bit substatement for bits type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit two;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - derived type adds new item \"two\". /cc:l");
+    CHECK_LOG_CTX("Invalid bits - derived type adds new item \"two\".", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295. /ee:l");
+    CHECK_LOG_CTX("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type.", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - position 1 collide in items \"y\" and \"x\". /ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid bits - position 1 collide in items \"y\" and \"x\".", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
             "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing bit substatement for bits type mytype. /gg:l");
+    CHECK_LOG_CTX("Missing bit substatement for bits type mytype.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Bits type can be subtyped only in YANG 1.1 modules. /hh:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Bits type can be subtyped only in YANG 1.1 modules.", "/hh:l");
 }
 
 static void
 test_type_dec64(void **state)
 {
-    *state = test_type_dec64;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
             "fraction-digits 2;range min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1442,7 +1283,7 @@
     assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec *)type)->range->parts[0].min_64);
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec *)type)->range->parts[0].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
             "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1458,7 +1299,7 @@
     assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].min_64);
     assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_int_equal(LY_TYPE_DEC64, type->basetype);
@@ -1470,58 +1311,50 @@
     assert_int_equal(6553500, ((struct lysc_type_dec *)type)->range->parts[0].max_64);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"0\" of \"fraction-digits\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Value \"19\" is out of \"fraction-digits\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"0\" of \"fraction-digits\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"fraction-digits\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Value \"19\" is out of \"fraction-digits\" bounds.", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing fraction-digits substatement for decimal64 type. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing fraction-digits substatement for decimal64 type mytype. /ab:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type mytype.", "/ab:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
             "range '3.142';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits. /bb:l");
+    CHECK_LOG_CTX("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
             "range '4 | 3.14';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - values are not in ascending order (3.14). /cc:l");
+    CHECK_LOG_CTX("Invalid range restriction - values are not in ascending order (3.14).", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
             "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
             "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type. /de:l");
+    CHECK_LOG_CTX("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type.", "/de:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - invalid value \"-10000000000000000000\". /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    CHECK_LOG_CTX("Invalid range restriction - invalid value \"-10000000000000000000\".", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - invalid value \"10000000000000000000\". /ee:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid range restriction - invalid value \"10000000000000000000\".", "/ee:l");
 }
 
 static void
 test_type_instanceid(void **state)
 {
-    *state = test_type_instanceid;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
             "leaf l1 {type instance-identifier {require-instance true;}}"
             "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1540,28 +1373,20 @@
     assert_int_equal(1, ((struct lysc_type_instanceid *)type)->require_instance);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"yes\" of \"require-instance\". Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"yes\" of \"require-instance\".", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type restrictions for instance-identifier type. /aa:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid type restrictions for instance-identifier type.", "/aa:l");
 }
 
 static void
 test_type_identityref(void **state)
 {
-    *state = test_type_identityref;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
             "typedef mytype {type identityref {base i;}}"
             "leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1579,7 +1404,7 @@
     assert_string_equal("k", ((struct lysc_type_identityref *)type)->bases[0]->name);
     assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
             "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1590,89 +1415,81 @@
     assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing base substatement for identityref type. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing base substatement for identityref type.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing base substatement for identityref type mytype. /bb:l");
+    CHECK_LOG_CTX("Missing base substatement for identityref type mytype.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
             "leaf l {type mytype {base i;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid base substatement for the type not directly derived from identityref built-in type. /cc:l");
+    CHECK_LOG_CTX("Invalid base substatement for the type not directly derived from identityref built-in type.", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
             "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
             "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Multiple bases in identityref type are allowed only in YANG 1.1 modules. /ee:l");
+    CHECK_LOG_CTX("Multiple bases in identityref type are allowed only in YANG 1.1 modules.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Unable to find base (j) of identityref. /ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Unable to find base (j) of identityref.", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid prefix used for base (x:j) of identityref. /gg:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid prefix used for base (x:j) of identityref.", "/gg:l");
 }
 
 static void
 test_type_leafref(void **state)
 {
-    *state = test_type_leafref;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     const char *path;
     struct lyxp_expr *expr;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* lys_path_parse() */
     path = "invalid_path";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "..";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "..[";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "../";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "/";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
 
     path = "../../pref:id/xxx[predicate]/invalid!!!";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
-    logbuf_assert("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.", NULL);
 
     path = "/absolute/prefix:path";
-    assert_int_equal(LY_SUCCESS, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     assert_int_equal(4, expr->used);
     assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[0]);
     assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[1]);
     assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[2]);
     assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[3]);
-    lyxp_expr_free(ctx, expr);
+    lyxp_expr_free(UTEST_LYCTX, expr);
 
     /* complete leafref paths */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
             "leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}"
             "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/a:target1", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_equal(mod, ly_resolve_prefix(ctx, "a", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "a", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
@@ -1685,7 +1502,7 @@
     assert_int_equal(LY_TYPE_UINT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
             "typedef mytype2 {type mytype;} typedef mytype3 {type leafref {path /target;}} leaf ref {type mytype2;}"
             "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1693,13 +1510,13 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* prefixes are reversed to check using correct context of the path! */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
             "typedef mytype3 {type c:mytype {require-instance false;}}"
             "leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1707,7 +1524,7 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_not_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
@@ -1716,11 +1533,11 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_not_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; import b {prefix b;}"
             "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1733,7 +1550,7 @@
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* conditional leafrefs */
-    /*assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
+    /*assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
                                         "leaf ref1 {if-feature 'f1 and f2';type leafref {path /target;}}"
                                         "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
@@ -1745,7 +1562,7 @@
     assert_non_null(((struct lysc_type_leafref*)type)->realtype);
     assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref*)type)->realtype->basetype);*/
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;"
             "list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}"
             "container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
             "leaf address {type leafref{ path \"../../interface[  name = current()/../ifname ]/address/ip\";}}}}",
@@ -1760,7 +1577,7 @@
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;"
             "leaf source {type leafref {path \"/endpoint-parent[id=current()/../field]/endpoint/name\";}}"
             "leaf field {type int32;}list endpoint-parent {key id;leaf id {type int32;}"
             "list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG, &mod));
@@ -1774,21 +1591,21 @@
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
     /* leafref to imported (not yet implemented) module */
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h  {type uint16;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import h {prefix h;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h  {type uint16;}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import h {prefix h;}"
             "leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "h"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "h"));
     assert_int_equal(1, mod->implemented);
     assert_non_null(mod->compiled->data);
     assert_string_equal("h", mod->compiled->data->name);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j  {type string;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;import j {prefix j;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j  {type string;}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;import j {prefix j;}"
             "leaf i {type leafref {path \"/ilist[name = current()/../j:j]/value\";}}"
             "list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1796,13 +1613,13 @@
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "j"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "j"));
     assert_int_equal(1, mod->implemented);
     assert_non_null(mod->compiled->data);
     assert_string_equal("j", mod->compiled->data->name);
 
     /* leafref with a default value */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;"
             "leaf source {type leafref {path \"../target\";}default true;}"
             "leaf target {type boolean;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1817,208 +1634,192 @@
     assert_int_equal(1, ((struct lysc_node_leaf *)mod->compiled->data)->dflt->boolean);
 
     /* invalid paths */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"invalid\" in path. /aa:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Not found node \"invalid\" in path.", "/aa:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Too many parent references in path. /bb:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Too many parent references in path.", "/bb:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"a\" found (prefix format schema stored mapping). /cc:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
+    CHECK_LOG_CTX("No module connected with the prefix \"a\" found (prefix format schema stored mapping).", "/cc:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
             "container a {leaf target2 {type uint8;}} leaf ref1 {type leafref {"
             "path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("List predicate defined for container \"a\" in path. /dd:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("List predicate defined for container \"a\" in path.", "/dd:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.", NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list. /ff:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
+    CHECK_LOG_CTX("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list.", "/ff:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
             "status deprecated;}} leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\". /gg:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+    CHECK_LOG_CTX("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\".", "/gg:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
             "leaf ref1 {type leafref;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing path substatement for leafref type. /hh:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/hh:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
             "leaf ref1 {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing path substatement for leafref type mytype. /ii:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;"
+    CHECK_LOG_CTX("Missing path substatement for leafref type mytype.", "/ii:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;feature f;"
             "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"target\" in path. /jj:ref");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+    CHECK_LOG_CTX("Not found node \"target\" in path.", "/jj:ref");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
             "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not. /kk:ref");
+    CHECK_LOG_CTX("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not.", "/kk:ref");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
             "leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules. /ll:ref");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
+    CHECK_LOG_CTX("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules.", "/ll:ref");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
             "leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules. /mm:ref");
+    CHECK_LOG_CTX("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules.", "/mm:ref");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name is current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../ifname/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath expression end.");
+    CHECK_LOG_CTX("Unexpected XPath expression end.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[x:name=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"x\" found (prefix format schema stored mapping). /pp:address");
+    CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/pp:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[id=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"id\" in path. /qq:address");
+    CHECK_LOG_CTX("Not found node \"id\" in path.", "/qq:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name=current() /  .. / ifname][name=current()/../test]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate predicate key \"name\" in path.");
+    CHECK_LOG_CTX("Duplicate predicate key \"name\" in path.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module tt {namespace urn:tt;prefix tt;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"]\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"]\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module uu {namespace urn:uu;prefix uu;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/..ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character number 31 of expression '/interface[name = current()/..ifname]/ip'.");
+    CHECK_LOG_CTX("Invalid character number 31 of expression '/interface[name = current()/..ifname]/ip'.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module vv {namespace urn:vv;prefix vv;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module vv {namespace urn:vv;prefix vv;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ww {namespace urn:ww;prefix ww;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"]\" (\"]/ip\").");
+    CHECK_LOG_CTX("Unexpected XPath token \"]\" (\"]/ip\").", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module xx {namespace urn:xx;prefix xx;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/../$node]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module yy {namespace urn:yy;prefix yy;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module yy {namespace urn:yy;prefix yy;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../x:ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"x\" found (prefix format schema stored mapping). /yy:address");
+    CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/yy:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zz {namespace urn:zz;prefix zz;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zz {namespace urn:zz;prefix zz;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../xxx]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"xxx\" in path. /zz:address");
+    CHECK_LOG_CTX("Not found node \"xxx\" in path.", "/zz:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zza {namespace urn:zza;prefix zza;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zza {namespace urn:zza;prefix zza;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}container c;"
             "leaf address {type leafref{ path \"/interface[name=current()/../c]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Leaf expected instead of container \"c\" in leafref predicate in path. /zza:address");
+    CHECK_LOG_CTX("Leaf expected instead of container \"c\" in leafref predicate in path.", "/zza:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzb {namespace urn:zzb;prefix zzb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzb {namespace urn:zzb;prefix zzb;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}container c;}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[c=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Key expected instead of container \"c\" in path. /zzb:address");
+    CHECK_LOG_CTX("Key expected instead of container \"c\" in path.", "/zzb:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzc {namespace urn:zzc;prefix zzc;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzc {namespace urn:zzc;prefix zzc;"
             "leaf source {type leafref {path \"../target\";}default true;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"target\" in path. /zzc:source");
+    CHECK_LOG_CTX("Not found node \"target\" in path.", "/zzc:source");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzd {namespace urn:zzd;prefix zzd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzd {namespace urn:zzd;prefix zzd;"
             "leaf source {type leafref {path \"../target\";}default true;}"
             "leaf target {type uint8;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid uint8 value \"true\".). /zzd:source");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid uint8 value \"true\".).", "/zzd:source");
 
     /* circular chain */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aaa {namespace urn:aaa;prefix aaa;"
             "leaf ref1 {type leafref {path /ref2;}}"
             "leaf ref2 {type leafref {path /ref3;}}"
             "leaf ref3 {type leafref {path /ref4;}}"
             "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected. /aaa:ref4");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected.", "/aaa:ref4");
 }
 
 static void
 test_type_empty(void **state)
 {
-    *state = test_type_empty;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "leaf l {type empty; default x;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid empty value \"x\".). /aa:l");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid type \"mytype\" - \"empty\" type must not have a default value (x). /bb:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid type \"mytype\" - \"empty\" type must not have a default value (x).", "/bb:l");
 }
 
 static void
 test_type_union(void **state)
 {
-    *state = test_type_union;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
             "typedef mytype {type union {type int8; type mybasetype;}}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -2030,7 +1831,7 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[0]->basetype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[1]->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
             "typedef mytype {type union {type int8; type mybasetype;}}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -2043,7 +1844,7 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[1]->basetype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[2]->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
             "typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
             "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}",
@@ -2061,47 +1862,39 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype->basetype);
 
     /* invalid unions */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing type substatement for union type mytype. /aa:l");
+    CHECK_LOG_CTX("Missing type substatement for union type mytype.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing type substatement for union type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing type substatement for union type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
             "leaf l {type mytype {type string;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type substatement for the type not directly derived from union built-in type. /cc:l");
+    CHECK_LOG_CTX("Invalid type substatement for the type not directly derived from union built-in type.", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
             "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
+    CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
             "typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ef:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ef:l");
 }
 
 static void
 test_type_dflt(void **state)
 {
-    *state = test_type_union;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     struct lysc_node_leaf *leaf;
     uint8_t dynamic;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* default is not inherited from union's types */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -2114,34 +1907,34 @@
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt);
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type mybasetype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference (typedf's default does not reference own type)*/
+    assert_int_equal(3, type->refcount);     /* 2x type reference, 1x default value's reference (typedf's default does not reference own type)*/
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("xxx", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference */
+    assert_int_equal(3, type->refcount);     /* 2x type reference, 1x default value's reference */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("goodbye", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("yyy", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
             "typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}"
             "leaf l2 {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(6, type->refcount); /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
+    assert_int_equal(6, type->refcount);     /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("goodbye", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
@@ -2149,18 +1942,18 @@
     assert_string_equal("yyy", leaf->units);
     type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
     assert_non_null(type);
-    assert_int_equal(6, type->refcount); /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
+    assert_int_equal(6, type->refcount);     /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data->next;
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("xxx", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
             "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(4, type->refcount); /* 3x type reference, 1x default value's reference (typedef's default does not reference own type) */
+    assert_int_equal(4, type->refcount);     /* 3x type reference, 1x default value's reference (typedef's default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
@@ -2168,99 +1961,75 @@
     assert_string_equal("xxx", leaf->units);
 
     /* mandatory leaf does not takes default value from type */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
             "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt);
     assert_string_equal("xxx", ((struct lysc_node_leaf *)mod->compiled->data)->units);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_status(void **state)
 {
-    *state = test_status;
 
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"current\" status is in conflict with the parent's \"deprecated\" status. /aa:c/l");
+    CHECK_LOG_CTX("A \"current\" status is in conflict with the parent's \"deprecated\" status.", "/aa:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
             "container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"current\" status is in conflict with the parent's \"obsolete\" status. /bb:c/l");
+    CHECK_LOG_CTX("A \"current\" status is in conflict with the parent's \"obsolete\" status.", "/bb:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
             "container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /cc:c/l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/cc:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:dd;prefix d;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:dd;prefix d;"
             "container c {leaf l {status obsolete; type string;}}"
             "container d {leaf m {when \"../../c/l\"; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A current definition \"m\" is not allowed to reference obsolete definition \"l\". /cc:d/m");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("A current definition \"m\" is not allowed to reference obsolete definition \"l\".", "/cc:d/m");
 }
 
 static void
 test_grouping(void **state)
 {
-    *state = test_grouping;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
     /* result ok, but a warning about not used locally scoped grouping printed */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
             "container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Locally scoped grouping \"grp2\" not used.");
-    logbuf_clean();
+    CHECK_LOG_CTX("Locally scoped grouping \"grp2\" not used.", NULL);
+    UTEST_LOG_CLEAN;
 
     /* result ok - when statement or leafref target must be checked only at the place where the grouping is really instantiated */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; grouping grp {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; grouping grp {"
             "leaf ref {type leafref {path \"../name\";}}"
             "leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("");
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* invalid - error in a non-instantiated grouping */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing path substatement for leafref type. /aa:{grouping='grp'}/x");
-    logbuf_clean();
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:{grouping='grp'}/x");
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing path substatement for leafref type. /aa:a/{grouping='grp'}/x");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:a/{grouping='grp'}/x");
 }
 
 static void
 test_uses(void **state)
 {
-    *state = test_uses;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *parent, *child;
     const struct lysc_node_container *cont;
     const struct lysc_node_choice *choice;
     const struct lysc_node_case *cs;
 
-    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 grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
             "grouping grp {leaf x {type mytype;} leaf y {type string; if-feature f;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
             "grouping grp_a_top {leaf a1 {type int8;}}"
             "container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG, &mod));
     assert_non_null((parent = mod->compiled->data));
@@ -2276,8 +2045,8 @@
     assert_ptr_equal(mod, child->module);
     assert_null((child = child->next));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
     assert_string_equal("b", mod->compiled->data->name);
@@ -2294,8 +2063,8 @@
     assert_int_equal(2, mod->compiled->data->next->when[0]->refcount);
     assert_null(mod->compiled->data->next->when[0]->context);
 
-    logbuf_clean();
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:ii;prefix ii;"
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:ii;prefix ii;"
             "grouping grp {leaf l {type string;}leaf k {type string; status obsolete;}}"
             "uses grp {status deprecated;}}", LYS_IN_YANG, &mod));
     assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
@@ -2304,9 +2073,9 @@
     assert_int_equal(LYS_LEAF, mod->compiled->data->next->nodetype);
     assert_string_equal("k", mod->compiled->data->next->name);
     assert_true(LYS_STATUS_OBSLT & mod->compiled->data->next->flags);
-    logbuf_assert(""); /* no warning about inheriting deprecated flag from uses */
+    CHECK_LOG(NULL, NULL);     /* no warning about inheriting deprecated flag from uses */
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
             "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_non_null(child = lysc_node_children(mod->compiled->data, 0));
@@ -2314,7 +2083,7 @@
     assert_non_null(child = lysc_node_children(child, 0));
     assert_string_equal("x", child->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
             "container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     cont = (const struct lysc_node_container *)mod->compiled->data;
@@ -2324,7 +2093,7 @@
     assert_string_equal("g", cont->actions[0].name);
     assert_string_equal("ultra g", cont->actions[0].dsc);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
             "container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     cont = (const struct lysc_node_container *)mod->compiled->data;
@@ -2335,11 +2104,11 @@
     assert_string_equal("ultra g", cont->notifs[0].dsc);
 
     /* empty grouping */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
     assert_null(mod->compiled->data);
 
     /* choice in uses */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {yang-version 1.1;namespace urn:h;prefix h; grouping grp {choice gch {case gc1 { leaf y { type string;}} case gc2 {leaf z {type string;}}}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1;namespace urn:h;prefix h; grouping grp {choice gch {case gc1 { leaf y { type string;}} case gc2 {leaf z {type string;}}}}"
             "choice ch {case one { leaf x {type string;}} case two { uses grp;}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     choice = (const struct lysc_node_choice *)mod->compiled->data;
@@ -2357,7 +2126,7 @@
     assert_string_equal("gch", cs->child->name);
 
     /* top-level uses with augment and refine */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i; grouping grp {container g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i; grouping grp {container g;}"
             "uses grp {augment g {leaf x {type int8;}} refine g {description \"dsc\";}}}",
             LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
@@ -2369,63 +2138,57 @@
     assert_string_equal("x", child->name);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Grouping \"missinggrp\" referenced by a uses statement not found. /aa:{uses='missinggrp'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Grouping \"missinggrp\" referenced by a uses statement not found.", "/aa:{uses='missinggrp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;uses grp;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;uses grp;"
             "grouping grp {leaf a{type string;}uses grp1;}"
             "grouping grp1 {leaf b {type string;}uses grp2;}"
             "grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Grouping \"grp\" references itself through a uses statement. /bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}");
+    CHECK_LOG_CTX("Grouping \"grp\" references itself through a uses statement.", "/bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid prefix used for grouping reference. /cc:{uses='a:missingprefix'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid prefix used for grouping reference.", "/cc:{uses='a:missingprefix'}");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
             "leaf a {type string;}uses grp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /dd:{uses='grp'}/dd:a");
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/dd:{uses='grp'}/dd:a");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
             "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ee:{uses='grp'}/ee:l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/ee:{uses='grp'}/ee:l");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
             "leaf l {type int8;}uses grp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"l\" of data definition/RPC/action/notification statement. /ff:{uses='grp'}/ff:l");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
+    CHECK_LOG_CTX("Duplicate identifier \"l\" of data definition/RPC/action/notification statement.", "/ff:{uses='grp'}/ff:l");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
             "uses grp;leaf m {type int8;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"m\" of data definition/RPC/action/notification statement. /fg:m");
+    CHECK_LOG_CTX("Duplicate identifier \"m\" of data definition/RPC/action/notification statement.", "/fg:m");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
             "leaf g {type string;}"
             "container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"/g\" - name test expected instead of \"/\". /gg:top/{uses='grp'}/{augment='/g'}");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"/g\" - name test expected instead of \"/\".", "/gg:top/{uses='grp'}/{augment='/g'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
             "grouping grp {notification g { description \"super g\";}}"
             "container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Refine(s) target node \"h\" in grouping \"grp\" was not found. /hh:top/{uses='grp'}");
+    CHECK_LOG_CTX("Refine(s) target node \"h\" in grouping \"grp\" was not found.", "/hh:top/{uses='grp'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
             "grouping grp {action g { description \"super g\";}}"
             "container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Refine(s) target node \"i\" in grouping \"grp\" was not found. /ii:top/{uses='grp'}");
+    CHECK_LOG_CTX("Refine(s) target node \"i\" in grouping \"grp\" was not found.", "/ii:top/{uses='grp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
             "grouping grp {leaf j { when \"1\"; type invalid;}}"
             "container top {uses grp;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Referenced type \"invalid\" not found. /jj:top/{uses='grp'}/j");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Referenced type \"invalid\" not found.", "/jj:top/{uses='grp'}/j");
 }
 
 static void
 test_refine(void **state)
 {
-    *state = test_refine;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node *parent, *child;
     struct lysc_node_leaf *leaf;
@@ -2434,8 +2197,6 @@
     struct ly_in *in;
     const char *data, *feats1[] = {"f", NULL}, *feats2[] = {"fa", NULL};
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     data = "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}"
             "grouping grp {container c {leaf l {type mytype; default goodbye;}"
             "leaf-list ll {type mytype; default goodbye; max-elements 6;}"
@@ -2444,7 +2205,7 @@
             "anydata a {mandatory false; if-feature f; description original; reference original;}"
             "container c {config false; leaf l {type string;}}}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats1, NULL));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats1, NULL));
 
     data = "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;"
             "uses g:grp {refine c/l {default hello; config false;}"
@@ -2455,7 +2216,7 @@
             "refine c/ll {max-elements 5;}"
             "refine c/c {config true;presence indispensable;}}}";
     ly_in_memory(in, data);
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats2, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats2, &mod));
     ly_in_free(in, 0);
 
     assert_non_null((parent = mod->compiled->data));
@@ -2507,7 +2268,7 @@
     assert_true(LYS_CONFIG_W & child->flags);
     assert_true(LYS_CONFIG_W & ((struct lysc_node_container *)child)->child->flags);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
             "uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG, &mod));
     assert_non_null((leaf = (struct lysc_node_leaf *)((struct lysc_node_container *)mod->compiled->data)->child->prev->prev->prev));
     assert_int_equal(LYS_LEAF, leaf->nodetype);
@@ -2517,77 +2278,71 @@
     assert_int_equal(0, dynamic);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
             "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of container node - it is not possible to replace \"default\" property. /aa:{uses='g:grp'}/aa:c/{refine='c'}");
+    CHECK_LOG_CTX("Invalid refine of container node - it is not possible to replace \"default\" property.", "/aa:{uses='g:grp'}/aa:c/{refine='c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
             "uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf with too many (2) default properties. /bb:{uses='g:grp'}/bb:c/l/{refine='c/l'}");
+    CHECK_LOG_CTX("Invalid refine of leaf with too many (2) default properties.", "/bb:{uses='g:grp'}/bb:c/l/{refine='c/l'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
             "uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules. /cc:{uses='g:grp'}/cc:c/ll/{refine='c/ll'}");
+    CHECK_LOG_CTX("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules.", "/cc:{uses='g:grp'}/cc:c/ll/{refine='c/ll'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
             "uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf-list node - it is not possible to replace \"mandatory\" property. /dd:{uses='g:grp'}/dd:c/ll/{refine='c/ll'}");
+    CHECK_LOG_CTX("Invalid refine of leaf-list node - it is not possible to replace \"mandatory\" property.", "/dd:{uses='g:grp'}/dd:c/ll/{refine='c/ll'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
             "uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of mandatory - leaf already has \"default\" statement. /ee:{uses='g:grp'}/{refine='c/l'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ee:{uses='g:grp'}/ee:c/l");
+    // CHECK_LOG_CTX("Invalid refine of mandatory - leaf already has \"default\" statement.", "/ee:{uses='g:grp'}/{refine='c/l'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ee:{uses='g:grp'}/ee:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
             "uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of mandatory - choice already has \"default\" statement. /ef:{uses='g:grp'}/{refine='c/ch'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ef:{uses='g:grp'}/ef:c/ch");
+    // CHECK_LOG_CTX("Invalid refine of mandatory - choice already has \"default\" statement.", "/ef:{uses='g:grp'}/{refine='c/ch'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ef:{uses='g:grp'}/ef:c/ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
             "uses g:grp {refine c/ch/ca/ca {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Mandatory node \"ca\" under the default case \"ca\". /ff:{uses='g:grp'}/ff:c/ch");
+    CHECK_LOG_CTX("Mandatory node \"ca\" under the default case \"ca\".", "/ff:{uses='g:grp'}/ff:c/ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
             "uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of default - the node is mandatory. /gg:{uses='g:grp'}/{refine='c/x'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /gg:{uses='g:grp'}/gg:c/x");
+    // CHECK_LOG_CTX("Invalid refine of default - the node is mandatory.", "/gg:{uses='g:grp'}/{refine='c/x'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg:{uses='g:grp'}/gg:c/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
             "uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of config - configuration node cannot be child of any state data node. /hh:{uses='g:grp'}/{refine='c/c/l'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /hh:{uses='g:grp'}/hh:c/c/l");
+    // CHECK_LOG_CTX("Invalid refine of config - configuration node cannot be child of any state data node.", "/hh:{uses='g:grp'}/{refine='c/c/l'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/hh:{uses='g:grp'}/hh:c/c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
             "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ii:{uses='grp'}/ii:l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/ii:{uses='grp'}/ii:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
             "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf node - it is not possible to replace \"presence\" property. /jj:{uses='g:grp'}/jj:c/x/{refine='c/x'}");
+    CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"presence\" property.", "/jj:{uses='g:grp'}/jj:c/x/{refine='c/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
             "uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of choice node - it is not possible to add \"must\" property. /kk:{uses='g:grp'}/kk:c/ch/{refine='c/ch'}");
+    CHECK_LOG_CTX("Invalid refine of choice node - it is not possible to add \"must\" property.", "/kk:{uses='g:grp'}/kk:c/ch/{refine='c/ch'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
             "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf node - it is not possible to replace \"min-elements\" property. /ll:{uses='g:grp'}/ll:c/x/{refine='c/x'}");
+    CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"min-elements\" property.", "/ll:{uses='g:grp'}/ll:c/x/{refine='c/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
             "uses g:grp {refine c/ll {min-elements 10;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\". /mm:{uses='g:grp'}/{refine='c/ll'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm:{uses='g:grp'}/mm:c/ll");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    // CHECK_LOG_CTX("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\".", "/mm:{uses='g:grp'}/{refine='c/ll'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm:{uses='g:grp'}/mm:c/ll");
 }
 
 static void
 test_augment(void **state)
 {
-    *state = test_augment;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node;
     const struct lysc_node_choice *ch;
@@ -2596,20 +2351,18 @@
     const struct lysc_action *rpc;
     const struct lysc_notif *notif;
 
-    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; typedef atype {type string;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}"
             "container top {leaf a {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
             "leaf b {type a:atype;}}", LYS_IN_YANG, &mod));
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
             "augment /a:top { container c {leaf c {type a:atype;}}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
             "augment /a:top/c:c { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG, &mod));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "b"));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "c"));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "d"));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "b"));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "c"));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "d"));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
     assert_non_null(node = lysc_node_children(node, 0));
@@ -2623,7 +2376,7 @@
     assert_non_null(node = node->next);
     assert_string_equal(node->name, "c");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
             "augment /ch/c {when 1; leaf lc2 {type uint16;}}"
             "augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG, &mod));
     assert_non_null((ch = (const struct lysc_node_choice *)mod->compiled->data));
@@ -2649,15 +2402,15 @@
     assert_string_equal("a", c->child->name);
     assert_null(c->next);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
             "container c;"
             "augment /c {uses g;}}", LYS_IN_YANG, &mod));
     assert_non_null(node = lysc_node_children(mod->compiled->data, 0));
     assert_string_equal(node->name, "a");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
             "augment /c {container sub;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;include gsub; container c;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;include gsub; container c;"
             "augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_string_equal("c", mod->compiled->data->name);
@@ -2666,8 +2419,8 @@
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("main", node->name);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
             "augment /hi:top {container p {presence XXX; leaf x {mandatory true;type string;}}}"
             "augment /hi:top {list ll {key x;leaf x {type string;}leaf y {mandatory true; type string;}}}"
             "augment /hi:top {leaf l {type string; mandatory true; config false;}}"
@@ -2676,7 +2429,7 @@
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("l", node->name);
     assert_true(node->flags & LYS_MAND_TRUE);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
     assert_non_null(node = mod->compiled->data);
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("p", node->name);
@@ -2686,10 +2439,10 @@
     assert_string_equal("l", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
             "augment /hi:func/hi:input {leaf x {type string;}}"
             "augment /hi:func/hi:output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
     assert_non_null(rpc = mod->compiled->rpcs);
     assert_int_equal(1, LY_ARRAY_COUNT(rpc));
     assert_non_null(rpc->input.data);
@@ -2699,7 +2452,7 @@
     assert_string_equal("y", rpc->output.data->name);
     assert_null(rpc->output.data->next);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
             "grouping grp {notification grp-notif;}"
             "augment /root {uses grp;}}", LYS_IN_YANG, &mod));
     assert_non_null(cont = (const struct lysc_node_container *)mod->compiled->data);
@@ -2707,53 +2460,47 @@
     assert_non_null(notif = cont->notifs);
     assert_int_equal(1, LY_ARRAY_COUNT(notif));
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
             "augment /x/ {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression. /aa:{augment='/x/'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression.", "/aa:{augment='/x/'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
             "augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment target node \"/x\" from module \"aa\" was not found.");
+    CHECK_LOG_CTX("Augment target node \"/x\" from module \"aa\" was not found.", NULL);
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
             "augment /c {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /bb:c/a");
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/bb:c/a");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
             "augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target. /cc:{augment='/c/a'}");
+    CHECK_LOG_CTX("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target.", "/cc:{augment='/c/a'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
             "augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid augment of container node which is not allowed to contain case node \"b\". /dd:{augment='/c'}");
+    CHECK_LOG_CTX("Invalid augment of container node which is not allowed to contain case node \"b\".", "/dd:{augment='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
             "augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid augment adding mandatory node \"c\" without making it conditional via when statement. /ee:{augment='/hi:top'}");
+    CHECK_LOG_CTX("Invalid augment adding mandatory node \"c\" without making it conditional via when statement.", "/ee:{augment='/hi:top'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; container top;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; container top;"
             "augment ../top {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"../top\" - \"/\" expected instead of \"..\". /ff:{augment='../top'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"../top\" - \"/\" expected instead of \"..\".", "/ff:{augment='../top'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; rpc func;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; rpc func;"
             "augment /func {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment's absolute-schema-nodeid \"/func\" refers to a RPC node which is not an allowed augment's target. /gg:{augment='/func'}");
+    CHECK_LOG_CTX("Augment's absolute-schema-nodeid \"/func\" refers to a RPC node which is not an allowed augment's target.", "/gg:{augment='/func'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module hh {namespace urn:i;prefix i;import himp {prefix hi;}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:i;prefix i;import himp {prefix hi;}"
             "augment /hi:func/input {leaf x {type string;}}"
             "augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"/hi:func/input\" - target node not found. /hh:{augment='/hi:func/input'}");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/hi:func/input\" - target node not found.", "/hh:{augment='/hi:func/input'}");
 }
 
 static void
 test_deviation(void **state)
 {
-    *state = test_deviation;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node;
     const struct lysc_node_list *list;
@@ -2762,15 +2509,13 @@
     const char *str;
     uint8_t dynamic;
 
-    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;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a;"
             "container top {leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
             "choice ch {default c; case b {leaf b{type string;}} case a {leaf a{type string;} leaf x {type string;}}"
             " case c {leaf c{type string;}}}"
             "rpc func1 { input { leaf x {type int8;}} output {leaf y {type int8;}}}"
             "rpc func2;}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
             "deviation /a:top/a:b {deviate not-supported;}"
             "deviation /a:ch/a:a/a:x {deviate not-supported;}"
             "deviation /a:ch/a:c {deviate not-supported;}"
@@ -2780,7 +2525,7 @@
             "deviation /a:func1/a:input {deviate not-supported;}"
             "deviation /a:func1/a:output {deviate not-supported;}"
             "deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
     assert_non_null(node = lysc_node_children(node, 0));
@@ -2797,7 +2542,7 @@
     assert_null(mod->compiled->rpcs[0].input.data);
     assert_null(mod->compiled->rpcs[0].output.data);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
             "leaf c1 {type mytype;} leaf c2 {type mytype; units meters;} leaf c3 {type mytype; units meters;}"
             "deviation /c1 {deviate add {units meters;}}"
             "deviation /c2 {deviate delete {units meters;}}"
@@ -2812,7 +2557,7 @@
     assert_string_equal("c3", node->name);
     assert_string_equal("centimeters", ((struct lysc_node_leaf *)node)->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
             "container c2 {presence yes; must 1; must 2;} leaf c3 {type string; must 1; must 3;}"
             "deviation /c1 {deviate add {must 3;}}"
             "deviation /c2 {deviate delete {must 2;}}"
@@ -2829,18 +2574,18 @@
     assert_string_equal("c3", node->name);
     assert_null(((struct lysc_node_leaf *)node)->musts);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}"
             "choice a {default aa;leaf aa {type string;} leaf ab {type string;} leaf ac {type string; mandatory true;}}"
             "choice b {default ba;leaf ba {type string;} leaf bb {type string;}}"
             "leaf c {default hello; type string;}"
             "leaf-list d {default hello; default world; type string;}"
             "leaf c2 {type mytype;} leaf-list d2 {type mytype;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
             "deviation /x:a {deviate delete {default aa;}}"
             "deviation /x:b {deviate delete {default ba;}}"
             "deviation /x:c {deviate delete {default hello;}}"
             "deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2854,19 +2599,19 @@
     assert_non_null(leaf = (struct lysc_node_leaf *)llist->next);
     assert_string_equal("nothing", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
-    assert_int_equal(5, leaf->dflt->realtype->refcount); /* 3x type reference, 2x default value reference (typedef's default does not reference own type) */
+    assert_int_equal(5, leaf->dflt->realtype->refcount);     /* 3x type reference, 2x default value reference (typedef's default does not reference own type) */
     assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
     assert_int_equal(1, LY_ARRAY_COUNT(llist->dflts));
     assert_string_equal("nothing", llist->dflts[0]->realtype->plugin->print(llist->dflts[0], LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
             "deviation /x:b {deviate add {default x:ba;}}"
             "deviation /x:c {deviate add {default bye;}}"
             "deviation /x:d {deviate add {default all; default people;}}"
             "deviation /x:c2 {deviate add {default hi; must 1;}}"
             "deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2888,7 +2633,7 @@
     assert_non_null(leaf->dflt);
     assert_string_equal("hi", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
-    assert_int_equal(6, leaf->dflt->realtype->refcount); /* 3x type reference, 3x default value reference
+    assert_int_equal(6, leaf->dflt->realtype->refcount);     /* 3x type reference, 3x default value reference
     - previous type's default values were replaced by node's default values where d2 now has 2 default values */
     assert_int_equal(1, LY_ARRAY_COUNT(leaf->musts));
     assert_int_equal(0, LY_ARRAY_COUNT(leaf->musts[0].prefixes));
@@ -2899,10 +2644,10 @@
     assert_string_equal("all", llist->dflts[1]->realtype->plugin->print(llist->dflts[1], LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
             "deviation /x:b {deviate replace {default x:ba;}}"
             "deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2913,16 +2658,16 @@
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module i {namespace urn:i;prefix i;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module i {namespace urn:i;prefix i;"
             "list l1 {key a; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
             "list l2 {key a; unique \"b c\"; unique \"d\"; leaf a {type string;} leaf b {type string;}"
             "         leaf c {type string;} leaf d {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;import i {prefix i;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;import i {prefix i;}"
             "augment /i:l1 {leaf j_c {type string;}}"
             "deviation /i:l1 {deviate add {unique \"i:b j_c\"; }}"
             "deviation /i:l1 {deviate add {unique \"i:c\";}}"
             "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "i")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "i")));
     assert_non_null(list = (struct lysc_node_list *)mod->compiled->data);
     assert_string_equal("l1", list->name);
     assert_int_equal(2, LY_ARRAY_COUNT(list->uniques));
@@ -2935,7 +2680,7 @@
     assert_string_equal("l2", list->name);
     assert_null(list->uniques);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k; leaf a {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k; leaf a {type string;}"
             "container top {leaf x {type string;} leaf y {type string; config false;}}"
             "deviation /a {deviate add {config false; }}"
             "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
@@ -2952,7 +2697,7 @@
     assert_string_equal("y", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
             "container top {config false; leaf x {type string;}}"
             "deviation /a {deviate replace {config true;}}"
             "deviation /top {deviate replace {config true;}}}", LYS_IN_YANG, &mod));
@@ -2966,7 +2711,7 @@
     assert_string_equal("x", node->name);
     assert_true(node->flags & LYS_CONFIG_W);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;"
             "container a {leaf a {type string;}}"
             "container b {leaf b {mandatory true; type string;}}"
             "deviation /a/a {deviate add {mandatory true;}}"
@@ -2977,10 +2722,10 @@
     assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
     assert_non_null(node = node->next);
     assert_string_equal("b", node->name);
-    assert_false(node->flags & LYS_MAND_MASK); /* just unset on container */
+    assert_false(node->flags & LYS_MAND_MASK);     /* just unset on container */
     assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module n {yang-version 1.1; namespace urn:n;prefix n;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module n {yang-version 1.1; namespace urn:n;prefix n;"
             "leaf a {default test; type string;}"
             "leaf b {mandatory true; type string;}"
             "deviation /a {deviate add {mandatory true;} deviate delete {default test;}}"
@@ -2994,7 +2739,7 @@
     assert_non_null(((struct lysc_node_leaf *)node)->dflt);
     assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module o {namespace urn:o;prefix o;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module o {namespace urn:o;prefix o;"
             "leaf-list a {type string;}"
             "list b {config false;}"
             "leaf-list c {min-elements 1; max-elements 10; type string;}"
@@ -3020,7 +2765,7 @@
     assert_int_equal(1, ((struct lysc_node_list *)node)->min);
     assert_int_equal(10, ((struct lysc_node_list *)node)->max);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
             "leaf a {type string; default 10;} leaf-list b {type string;}"
             "deviation /a {deviate replace {type mytype;}}"
             "deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG, &mod));
@@ -3039,10 +2784,10 @@
     assert_int_equal(1, llist->dflts[0]->uint8);
 
     /* instance-identifiers with NULL canonical are changed to string types with a canonical value equal to the original value */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
             "leaf q {type instance-identifier; default \"/e:d2[.='a']\";}"
             "leaf-list ql {type instance-identifier; default \"/e:d[.='b']\"; default \"/e:d2[.='c']\";}}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
             "deviation /q:q { deviate replace {type string;}}"
             "deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG, NULL));
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
@@ -3056,7 +2801,7 @@
     assert_int_equal(LY_TYPE_STRING, llist->dflts[0]->realtype->basetype);
     assert_string_equal("/e:d2[.='c']", llist->dflts[1]->canonical);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module r {yang-version 1.1; namespace urn:r;prefix r;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module r {yang-version 1.1; namespace urn:r;prefix r;"
             "typedef mytype {type uint8; default 200;}"
             "leaf r {type mytype;} leaf-list lr {type mytype;}"
             "deviation /r:r {deviate replace {type string;}}"
@@ -3068,7 +2813,7 @@
     assert_string_equal("lr", llist->name);
     assert_null(llist->dflts);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module s {yang-version 1.1; namespace urn:s;prefix s;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module s {yang-version 1.1; namespace urn:s;prefix s;"
             "leaf s {type instance-identifier {require-instance true;} default /s:x;}"
             "leaf x {type string;} leaf y {type string;}"
             "deviation /s:s {deviate replace {default /s:y;}}}", LYS_IN_YANG, &mod));
@@ -3081,29 +2826,29 @@
         free((char *)str);
     }
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module t {namespace urn:t;prefix t;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module t {namespace urn:t;prefix t;"
             "leaf l {type string;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module u {namespace urn:u;prefix u;import t {prefix t;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module u {namespace urn:u;prefix u;import t {prefix t;}"
             "identity ident;"
             "deviation /t:l {deviate replace {type identityref {base ident;}}}"
             "}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "t")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "t")));
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
     assert_string_equal("ident", ((struct lysc_type_identityref *)leaf->type)->bases[0]->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module v {namespace urn:v;prefix v;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module v {namespace urn:v;prefix v;"
             "identity ident; identity ident2 { base ident; }"
             "}", LYS_IN_YANG, NULL));
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule w-sub { belongs-to w { prefix w; }"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule w-sub { belongs-to w { prefix w; }"
             "import v { prefix v_pref; }"
             "leaf l { type string; default \"v_pref:ident2\"; }"
             "}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module w {namespace urn:w;prefix w;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module w {namespace urn:w;prefix w;"
             "include w-sub;"
             "}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module x {namespace urn:x;prefix x;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module x {namespace urn:x;prefix x;"
             "import w { prefix w_pref; } import v { prefix v_pref; }"
             "deviation /w_pref:l { deviate replace { type identityref { base v_pref:ident; } } }"
             "}", LYS_IN_YANG, NULL));
@@ -3111,246 +2856,237 @@
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module y {namespace urn:y;prefix y;"
-                                  "container cont {leaf l {type string;}}"
-                                  "leaf bl2 {type string;}"
-                                  "}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module z {namespace urn:z;prefix z;"
-                                  "import y {prefix y;}"
-                                  "deviation \"/y:cont/y:l\" {deviate replace {type leafref {path \"/al\";}}}"
-                                  "leaf al {type string;}"
-                                  "leaf al2 {type leafref {path \"/y:bl2\";}}"
-                                  "}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "y")));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module y {namespace urn:y;prefix y;"
+            "container cont {leaf l {type string;}}"
+            "leaf bl2 {type string;}"
+            "}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module z {namespace urn:z;prefix z;"
+            "import y {prefix y;}"
+            "deviation \"/y:cont/y:l\" {deviate replace {type leafref {path \"/al\";}}}"
+            "leaf al {type string;}"
+            "leaf al2 {type leafref {path \"/y:bl2\";}}"
+            "}", LYS_IN_YANG, NULL));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "y")));
     assert_non_null(leaf = (struct lysc_node_leaf *)lysc_node_children(mod->compiled->data, 0));
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
             "deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Deviation(s) target node \"/a:top/a:z\" from module \"aa1\" was not found.");
+    CHECK_LOG_CTX("Deviation(s) target node \"/a:top/a:z\" from module \"aa1\" was not found.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
             "deviation /a:top/a:a {deviate not-supported;}"
             "deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Multiple deviations of \"/a:top/a:a\" with one of them being \"not-supported\". /");
+    CHECK_LOG_CTX("Multiple deviations of \"/a:top/a:a\" with one of them being \"not-supported\".", "/");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
             "deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"a:top/a:a\" - \"/\" expected instead of \"a:top\". /bb:{deviation='a:top/a:a'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"a:top/a:a\" - \"/\" expected instead of \"a:top\".", "/bb:{deviation='a:top/a:a'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c;"
             "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to add \"units\" property. /cc:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"units\" property.", "/cc:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
             "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\"). /cd:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\").", "/cd:{deviation='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to delete \"units\" property. /dd1:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to delete \"units\" property.", "/dd1:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which is not present. /dd2:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which is not present.", "/dd2:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\"."
-            " /dd3:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\".",
+            "/dd3:{deviation='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
             "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to replace \"units\" property. /ee1:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"units\" property.", "/ee1:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
             "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"units\" property \"meters\" which is not present. /ee2:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation replacing \"units\" property \"meters\" which is not present.", "/ee2:{deviation='/c'}");
 
     /* the default is already deleted in /e:a byt module f */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
             "deviation /e:a {deviate delete {default x:aa;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"x:aa\" which is not present. /ff1:{deviation='/e:a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"x:aa\" which is not present.", "/ff1:{deviation='/e:a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
             "deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"e:b\" which does not match the target's property value \"x:ba\". /ff3:{deviation='/e:b'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"e:b\" which does not match the target's property value \"x:ba\".", "/ff3:{deviation='/e:b'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
             "deviation /a {deviate delete {default x;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of anyxml node - it is not possible to delete \"default\" property. /ff5:{deviation='/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to delete \"default\" property.", "/ff5:{deviation='/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
             "deviation /e:c {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\". /ff6:{deviation='/e:c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\".", "/ff6:{deviation='/e:c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
             "deviation /e:d {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values. /ff7:{deviation='/e:d'}");
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values.", "/ff7:{deviation='/e:d'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
             "deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"x:ba\"). /gg1:{deviation='/e:b'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"x:ba\").", "/gg1:{deviation='/e:b'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
             "deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"x:a\" of choice. "
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"x:a\" of choice. "
                   "The prefix does not match any imported module of the deviation module. /gg2:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
             "deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists. /gg3:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists.", "/gg3:{deviation='/e:a'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
             "deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"hello\"). /gg4:{deviation='/e:c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"hello\").", "/gg4:{deviation='/e:c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
             "deviation /e:a {deviate add {default e:ac;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"e:ac\" of choice - mandatory node \"ac\" under the default case. /gg4:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"e:ac\" of choice - mandatory node \"ac\" under the default case.", "/gg4:{deviation='/e:a'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
             "deviation /x {deviate add {default error;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf. /gg5:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /gg5:x");
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf.", "/gg5:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg5:x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
             "deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property. /hh1:{deviation='/e:d'}");
+    CHECK_LOG_CTX("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property.", "/hh1:{deviation='/e:d'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
             "deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values. /ii1:{deviation='/i:l1'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values.", "/ii1:{deviation='/i:l1'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
             "deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values. /ii2:{deviation='/i:l2'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values.", "/ii2:{deviation='/i:l2'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
             "deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf node - it is not possible to delete \"unique\" property. /ii3:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to delete \"unique\" property.", "/ii3:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
             "deviation /x {deviate add {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf node - it is not possible to add \"unique\" property. /ii4:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to add \"unique\" property.", "/ii4:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
             "deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of case node - it is not possible to add \"config\" property. /jj1:{deviation='/ch/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to add \"config\" property.", "/jj1:{deviation='/ch/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
             "deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj2:{deviation='/top/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /jj2:top/x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
+    /*CHECK_LOG_CTX("Invalid deviation of config - configuration node cannot be child of any state data node.", "/jj2:{deviation='/top/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj2:top/x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
             "deviation /top/x {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"config\" property \"config false\" which is not present. /jj3:{deviation='/top/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"config\" property \"config false\" which is not present.", "/jj3:{deviation='/top/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
             "deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of case node - it is not possible to replace \"config\" property. /jj4:{deviation='/ch/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
+    CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to replace \"config\" property.", "/jj4:{deviation='/ch/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
             "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj5:{deviation='/top'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /jj5:top");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
+    /*CHECK_LOG_CTX("Invalid deviation of config - configuration node cannot be child of any state data node.", "/jj5:{deviation='/top'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj5:top");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
             "deviation /x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"config\" property which already exists (with value \"config false\"). /jj6:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"config\" property which already exists (with value \"config false\").", "/jj6:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
             "deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to add \"mandatory\" property. /kk1:{deviation='/top'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"mandatory\" property.", "/kk1:{deviation='/top'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
             "deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to replace \"mandatory\" property. /kk2:{deviation='/top'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"mandatory\" property.", "/kk2:{deviation='/top'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
             "deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk3:{deviation='/top/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present.", "/kk3:{deviation='/top/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
             "deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\"). /kk4:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\").", "/kk4:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
             "deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf. /ll1:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf.", "/ll1:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf-list. /ll2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf-list.", "/ll2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
             "deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default case and mandatory choice. /ll2:{deviation='/ch'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll2:ch");
+    /*CHECK_LOG_CTX("Invalid deviation combining default case and mandatory choice.", "/ll2:{deviation='/ch'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
             "deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5. /mm1:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5.", "/mm1:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
             "deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10.", "/mm2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1. /mm3:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm3:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1.", "/mm3:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm3:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
             "deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm4:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm4:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10.", "/mm4:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm4:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm5:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").", "/mm5:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm6:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").", "/mm6:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
             "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm7:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").", "/mm7:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
             "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm8:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").", "/mm8:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
             "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"min-elements\" property which is not present. /mm9:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm9:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
             "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"min-elements\" property which is not present. /mm10:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm10:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"max-elements\" property which is not present. /mm11:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
+    CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm11:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"max-elements\" property which is not present. /mm12:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm12:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
             "deviation /x {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of anyxml node - it is not possible to replace \"type\" property. /nn1:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to replace \"type\" property.", "/nn1:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
             "deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /nn2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /nn2:x");
+    /*CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/nn2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/nn2:x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
             "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
             "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
             "deviation /x {deviate add {default 300;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo3:x");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo3:x");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
             "container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
             "deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"x\" in path. /pp:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Not found node \"x\" in path.", "/pp:l");
 }
 
 static void
 test_when(void **state)
 {
-    *state = test_when;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3376,9 +3112,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\"). /a:cont/lst/val");
+    CHECK_LOG_CTX("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\").", "/a:cont/lst/val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3404,9 +3140,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\"). /a:cont/lst/val");
+    CHECK_LOG_CTX("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\").", "/a:cont/lst/val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3416,9 +3152,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3432,9 +3168,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3447,44 +3183,41 @@
             "    container cont;\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:cont/val");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:cont/val");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_name_collisions, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_length, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_range, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_pattern, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_enum, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_bits, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_dec64, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_instanceid, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_identityref, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_leafref, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_empty, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_union, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_dflt, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_status, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_container, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_leaflist, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_list, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_choice, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_anydata, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_refine, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_deviation, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_when, logger_setup, logger_teardown),
+        UTEST(test_module, setup),
+        UTEST(test_name_collisions, setup),
+        UTEST(test_type_length, setup),
+        UTEST(test_type_range, setup),
+        UTEST(test_type_pattern, setup),
+        UTEST(test_type_enum, setup),
+        UTEST(test_type_bits, setup),
+        UTEST(test_type_dec64, setup),
+        UTEST(test_type_instanceid, setup),
+        UTEST(test_type_identityref, setup),
+        UTEST(test_type_leafref, setup),
+        UTEST(test_type_empty, setup),
+        UTEST(test_type_union, setup),
+        UTEST(test_type_dflt, setup),
+        UTEST(test_status, setup),
+        UTEST(test_node_container, setup),
+        UTEST(test_node_leaflist, setup),
+        UTEST(test_node_list, setup),
+        UTEST(test_node_choice, setup),
+        UTEST(test_node_anydata, setup),
+        UTEST(test_action, setup),
+        UTEST(test_notification, setup),
+        UTEST(test_grouping, setup),
+        UTEST(test_uses, setup),
+        UTEST(test_refine, setup),
+        UTEST(test_augment, setup),
+        UTEST(test_deviation, setup),
+        UTEST(test_when, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
deleted file mode 100644
index ecce490..0000000
--- a/tests/utests/test_context.c
+++ /dev/null
@@ -1,528 +0,0 @@
-/*
- * @file set.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
- * @brief unit tests for functions from context.c
- *
- * Copyright (c) 2018 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://opensource.org/licenses/BSD-3-Clause
- */
-
-#include "common.h"
-#include "context.h"
-#include "in.h"
-#include "schema_compile.h"
-#include "tests/config.h"
-#include "tree_schema_internal.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-static void
-test_searchdirs(void **state)
-{
-    *state = test_searchdirs;
-
-    struct ly_ctx *ctx;
-    const char * const *list;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
-    /* invalid arguments */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(NULL, NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_set_searchdir()).");
-    assert_null(ly_ctx_get_searchdirs(NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_get_searchdirs()).");
-    assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdir(NULL, NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_unset_searchdir()).");
-
-    /* readable and executable, but not a directory */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, TESTS_BIN "/utest_context"));
-    logbuf_assert("Given search directory \""TESTS_BIN "/utest_context\" is not a directory.");
-    /* not executable */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, __FILE__));
-    logbuf_assert("Unable to fully access search directory \""__FILE__ "\" (Permission denied).");
-    /* not existing */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, "/nonexistingfile"));
-    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory).");
-
-    /* ly_set_add() fails */
-    /* no change */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, NULL));
-
-    /* correct path */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN "/utests"));
-    assert_int_equal(1, ctx->search_paths.count);
-    assert_string_equal(TESTS_BIN "/utests", ctx->search_paths.objs[0]);
-
-    /* duplicated paths */
-    assert_int_equal(LY_EEXIST, ly_ctx_set_searchdir(ctx, TESTS_BIN "/utests"));
-    assert_int_equal(1, ctx->search_paths.count);
-    assert_string_equal(TESTS_BIN "/utests", ctx->search_paths.objs[0]);
-
-    /* another paths - add 8 to fill the initial buffer of the searchpaths list */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN "/CMakeFiles"));
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC "/../src"));
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC "/../CMakeModules"));
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC "/../doc"));
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC));
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN));
-    assert_int_equal(7, ctx->search_paths.count);
-
-    /* get searchpaths */
-    list = ly_ctx_get_searchdirs(ctx);
-    assert_non_null(list);
-    assert_string_equal(TESTS_BIN "/utests", list[0]);
-    assert_string_equal(TESTS_BIN "/CMakeFiles", list[1]);
-    assert_string_equal(TESTS_SRC, list[5]);
-    assert_string_equal(TESTS_BIN, list[6]);
-    assert_null(list[7]);
-
-    /* removing searchpaths */
-    /* nonexisting */
-    assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdir(ctx, "/nonexistingfile"));
-    logbuf_assert("Invalid argument value (ly_ctx_unset_searchdir()).");
-    /* first */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(ctx, TESTS_BIN"/utests"));
-    assert_string_not_equal(TESTS_BIN"/utests", list[0]);
-    assert_int_equal(6, ctx->search_paths.count);
-    /* middle */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(ctx, TESTS_SRC));
-    assert_int_equal(5, ctx->search_paths.count);
-    /* last */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(ctx, TESTS_BIN));
-    assert_int_equal(4, ctx->search_paths.count);
-    /* all */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(ctx, NULL));
-    assert_int_equal(0, ctx->search_paths.count);
-
-    /* again - no change */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdir(ctx, NULL));
-
-    /* cleanup */
-    ly_ctx_destroy(ctx, NULL);
-
-    /* test searchdir list in ly_ctx_new() */
-    assert_int_equal(LY_EINVAL, ly_ctx_new("/nonexistingfile", 0, &ctx));
-    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory).");
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_SRC":"TESTS_BIN":"TESTS_BIN":"TESTS_SRC, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-    assert_int_equal(2, ctx->search_paths.count);
-    assert_string_equal(TESTS_SRC, ctx->search_paths.objs[0]);
-    assert_string_equal(TESTS_BIN, ctx->search_paths.objs[1]);
-
-    /* cleanup */
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
-}
-
-static void
-test_options(void **state)
-{
-    *state = test_options;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0xffff, &ctx));
-
-    /* invalid arguments */
-    assert_int_equal(0, ly_ctx_get_options(NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_get_options()).");
-
-    assert_int_equal(LY_EINVAL, ly_ctx_set_options(NULL, 0));
-    logbuf_assert("Invalid argument ctx (ly_ctx_set_options()).");
-    assert_int_equal(LY_EINVAL, ly_ctx_unset_options(NULL, 0));
-    logbuf_assert("Invalid argument ctx (ly_ctx_unset_options()).");
-
-    /* option not allowed to be changed */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_options(ctx, LY_CTX_NO_YANGLIBRARY));
-    logbuf_assert("Invalid argument option (ly_ctx_set_options()).");
-    assert_int_equal(LY_EINVAL, ly_ctx_set_options(ctx, LY_CTX_NO_YANGLIBRARY));
-    logbuf_assert("Invalid argument option (ly_ctx_set_options()).");
-
-    /* unset */
-    /* LY_CTX_ALL_IMPLEMENTED */
-    assert_int_not_equal(0, ctx->flags & LY_CTX_ALL_IMPLEMENTED);
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_ALL_IMPLEMENTED));
-    assert_int_equal(0, ctx->flags & LY_CTX_ALL_IMPLEMENTED);
-
-    /* LY_CTX_REF_IMPLEMENTED */
-    assert_int_not_equal(0, ctx->flags & LY_CTX_REF_IMPLEMENTED);
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_REF_IMPLEMENTED));
-    assert_int_equal(0, ctx->flags & LY_CTX_REF_IMPLEMENTED);
-
-    /* LY_CTX_DISABLE_SEARCHDIRS */
-    assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS);
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_DISABLE_SEARCHDIRS));
-    assert_int_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS);
-
-    /* LY_CTX_DISABLE_SEARCHDIR_CWD */
-    assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_DISABLE_SEARCHDIR_CWD));
-    assert_int_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
-
-    /* LY_CTX_PREFER_SEARCHDIRS */
-    assert_int_not_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS);
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_PREFER_SEARCHDIRS));
-    assert_int_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS);
-
-    assert_int_equal(ctx->flags, ly_ctx_get_options(ctx));
-
-    /* set back */
-    /* LY_CTX_ALL_IMPLEMENTED */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_ALL_IMPLEMENTED));
-    assert_int_not_equal(0, ctx->flags & LY_CTX_ALL_IMPLEMENTED);
-
-    /* LY_CTX_REF_IMPLEMENTED */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_REF_IMPLEMENTED));
-    assert_int_not_equal(0, ctx->flags & LY_CTX_REF_IMPLEMENTED);
-
-    /* LY_CTX_DISABLE_SEARCHDIRS */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_DISABLE_SEARCHDIRS));
-    assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS);
-
-    /* LY_CTX_DISABLE_SEARCHDIR_CWD */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_DISABLE_SEARCHDIR_CWD));
-    assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD);
-
-    /* LY_CTX_PREFER_SEARCHDIRS */
-    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_PREFER_SEARCHDIRS));
-    assert_int_not_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS);
-
-    assert_int_equal(ctx->flags, ly_ctx_get_options(ctx));
-
-    /* cleanup */
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
-}
-
-static LY_ERR
-test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
-        const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
-        const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
-{
-    *module_data = user_data;
-    *format = LYS_IN_YANG;
-    *free_module_data = NULL;
-    return LY_SUCCESS;
-}
-
-static void
-test_models(void **state)
-{
-    *state = test_models;
-
-    struct ly_ctx *ctx;
-    struct ly_in *in;
-    const char *str;
-    struct lys_module *mod1, *mod2;
-    struct lys_glob_unres unres = {0};
-
-    /* invalid arguments */
-    assert_int_equal(0, ly_ctx_get_module_set_id(NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_get_module_set_id()).");
-
-    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_int_equal(LY_SUCCESS, ly_in_new_memory("module x {namespace urn:x;prefix x;}", &in));
-    assert_int_equal(LY_EINVAL, lys_create_module(ctx, in, 4, 1, NULL, NULL, NULL, &unres, &mod1));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    logbuf_assert("Invalid schema input format.");
-
-    /* import callback */
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, (void *)(str = "test"));
-    assert_ptr_equal(test_imp_clb, ctx->imp_clb);
-    assert_ptr_equal(str, ctx->imp_clb_data);
-    assert_ptr_equal(test_imp_clb, ly_ctx_get_module_imp_clb(ctx, (void **)&str));
-    assert_string_equal("test", str);
-
-    ly_ctx_set_module_imp_clb(ctx, NULL, NULL);
-    assert_null(ctx->imp_clb);
-    assert_null(ctx->imp_clb_data);
-
-    /* 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_int_equal(LY_EVALID, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    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_int_equal(LY_SUCCESS, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module y {namespace urn:y;prefix y;}", &in));
-    assert_int_equal(LY_EVALID, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    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_int_equal(LY_EVALID, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod1));
-    lys_compile_unres_glob_revert(ctx, &unres);
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    logbuf_assert("Name collision between submodules of name \"y\". Line number 1.");
-    store = -1;
-
-    /* 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;}");
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory("module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", &in));
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod2));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    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));
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod1));
-    ly_in_free(in, 0);
-    mod1->implemented = 1;
-    assert_int_equal(LY_SUCCESS, lys_compile(mod1, 0, &unres));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    assert_non_null(mod1->compiled);
-    assert_non_null(mod1->parsed);
-
-#if 0
-    /* TODO in case we are able to remove the parsed schema, here we will test how it will handle missing import parsed schema */
-
-    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));
-    /* 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_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, &mod2));
-    /*logbuf_assert("Unable to reload \"w\" module to import it into \"z\", source data not found.");*/
-    logbuf_assert("Recompilation of module \"w\" failed.");
-    assert_null(mod2);
-    ly_in_free(in, 0);
-#endif
-
-    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));
-    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_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod2));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_free(in, 0);
-    assert_non_null(mod2);
-    assert_non_null(mod1->parsed);
-    assert_string_equal("w", mod1->name);
-
-    /* cleanup */
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
-}
-
-static void
-test_imports(void **state)
-{
-    *state = test_imports;
-
-    struct ly_ctx *ctx;
-    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_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_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->parsed->imports[0].module;
-    assert_int_equal(2, import->latest_revision);
-    assert_int_equal(0, mod1->latest_revision);
-    assert_ptr_not_equal(mod1, import);
-    assert_string_equal("2019-09-17", import->revision);
-    assert_int_equal(0, import->implemented);
-    assert_non_null(ly_ctx_get_module(ctx, "a", "2019-09-16"));
-    ly_ctx_destroy(ctx, NULL);
-
-    /* import callback provides older revision of module 'a' than present in context, so when importing a, the newer revision
-     * 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_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_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->parsed->imports[0].module;
-    assert_ptr_equal(mod1, import);
-    assert_int_equal(2, import->latest_revision);
-    assert_int_equal(1, import->implemented);
-    assert_string_equal("2019-09-18", import->revision);
-    assert_null(ly_ctx_get_module(ctx, "a", "2019-09-17"));
-    ly_ctx_destroy(ctx, NULL);
-
-    /* cleanup */
-    *state = NULL;
-}
-
-static void
-test_get_models(void **state)
-{
-    *state = test_get_models;
-
-    struct ly_ctx *ctx;
-    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;}";
-    struct ly_in *in0, *in1, *in2;
-    struct lys_glob_unres unres = {0};
-
-    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 */
-    assert_ptr_equal(NULL, ly_ctx_get_module(NULL, NULL, NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_get_module()).");
-    assert_ptr_equal(NULL, ly_ctx_get_module(ctx, NULL, NULL));
-    logbuf_assert("Invalid argument name (ly_ctx_get_module()).");
-    assert_ptr_equal(NULL, ly_ctx_get_module_ns(NULL, NULL, NULL));
-    logbuf_assert("Invalid argument ctx (ly_ctx_get_module_ns()).");
-    assert_ptr_equal(NULL, ly_ctx_get_module_ns(ctx, NULL, NULL));
-    logbuf_assert("Invalid argument ns (ly_ctx_get_module_ns()).");
-    assert_null(ly_ctx_get_module(ctx, "nonsence", NULL));
-
-    /* internal modules */
-    assert_null(ly_ctx_get_module_implemented(ctx, "ietf-yang-types"));
-    mod = ly_ctx_get_module_implemented(ctx, "yang");
-    assert_non_null(mod);
-    assert_non_null(mod->parsed);
-    assert_string_equal("yang", mod->name);
-    mod2 = ly_ctx_get_module_implemented_ns(ctx, mod->ns);
-    assert_ptr_equal(mod, mod2);
-    assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-metadata", "2016-08-05"));
-    assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-types", "2013-07-15"));
-    assert_non_null(ly_ctx_get_module(ctx, "ietf-inet-types", "2013-07-15"));
-    assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14"));
-
-    /* select module by revision */
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    /* invalid attempts - implementing module of the same name and inserting the same module */
-    assert_int_equal(LY_EDENIED, lys_create_module(ctx, in2, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
-    logbuf_assert("Module \"a@2018-10-23\" is already implemented in the context.");
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_reset(in1);
-    /* it is already there, fine */
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in1, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, NULL));
-    /* insert the second module only as imported, not implemented */
-    lys_compile_unres_glob_erase(ctx, &unres);
-    ly_in_reset(in2);
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in2, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod2));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    assert_non_null(mod2);
-    assert_ptr_not_equal(mod, mod2);
-    mod = ly_ctx_get_module_latest(ctx, "a");
-    assert_ptr_equal(mod, mod2);
-    mod2 = ly_ctx_get_module_latest_ns(ctx, mod->ns);
-    assert_ptr_equal(mod, mod2);
-    /* work with module with no revision */
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in0, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
-    lys_compile_unres_glob_erase(ctx, &unres);
-    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_int_equal(LY_EINVAL, lys_create_module(ctx, in1, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
-    logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
-    lys_compile_unres_glob_erase(ctx, &unres);
-
-    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);
-
-    /* cleanup */
-    *state = NULL;
-    ly_in_free(in0, 0);
-    ly_in_free(in1, 0);
-    ly_in_free(in2, 0);
-    ly_ctx_destroy(ctx, NULL);
-}
-
-int
-main(void)
-{
-    const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_searchdirs, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_options, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_models, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_imports, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_get_models, logger_setup, logger_teardown),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
diff --git a/tests/utests/test_yanglib.c b/tests/utests/test_yanglib.c
deleted file mode 100644
index 071944f..0000000
--- a/tests/utests/test_yanglib.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/**
- * @file test_yanglib.c
- * @author: Michal Vasko <mvasko@cesnet.cz>
- * @brief unit tests for ietf-yang-library data
- *
- * Copyright (c) 2020 CESNET, z.s.p.o.
- *
- * This source code is licensed under BSD 3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://opensource.org/licenses/BSD-3-Clause
- */
-
-#include <string.h>
-
-#include "utests.h"
-
-#include "context.h"
-#include "in.h"
-#include "log.h"
-#include "set.h"
-#include "tests/config.h"
-#include "tree_data.h"
-#include "tree_schema.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-struct ly_ctx *ctx; /* context for tests */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static LY_ERR
-test_imp_clb(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data,
-        LYS_INFORMAT *format, const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
-{
-    const char *schema_a_sub =
-            "submodule a_sub {\n"
-            "    belongs-to a {\n"
-            "        prefix a;\n"
-            "    }\n"
-            "    yang-version 1.1;\n"
-            "\n"
-            "    feature feat1;\n"
-            "\n"
-            "    list l3 {\n"
-            "        key \"a\";\n"
-            "        leaf a {\n"
-            "            type uint16;\n"
-            "        }\n"
-            "        leaf b {\n"
-            "            type uint16;\n"
-            "        }\n"
-            "    }\n"
-            "}\n";
-
-    assert_string_equal(mod_name, "a");
-    assert_null(mod_rev);
-    if (!submod_name) {
-        return LY_ENOTFOUND;
-    }
-    assert_string_equal(submod_name, "a_sub");
-    assert_null(sub_rev);
-    assert_null(user_data);
-
-    *format = LYS_IN_YANG;
-    *module_data = schema_a_sub;
-    *free_module_data = NULL;
-    return LY_SUCCESS;
-}
-
-static int
-setup(void **state)
-{
-    (void) state; /* unused */
-
-    const char *schema_a =
-            "module a {\n"
-            "  namespace urn:tests:a;\n"
-            "  prefix a;\n"
-            "  yang-version 1.1;\n"
-            "\n"
-            "  include a_sub;\n"
-            "\n"
-            "  list l2 {\n"
-            "    key \"a\";\n"
-            "    leaf a {\n"
-            "      type uint16;\n"
-            "    }\n"
-            "    leaf b {\n"
-            "      type uint16;\n"
-            "    }\n"
-            "  }\n"
-            "}";
-    const char *schema_b =
-            "module b {\n"
-            "  namespace urn:tests:b;\n"
-            "  prefix b;\n"
-            "  yang-version 1.1;\n"
-            "\n"
-            "  import a {\n"
-            "    prefix a;\n"
-            "  }\n"
-            "\n"
-            "  deviation /a:l2 {\n"
-            "    deviate add {\n"
-            "      max-elements 40;\n"
-            "    }\n"
-            "  }\n"
-            "\n"
-            "  leaf foo {\n"
-            "    type string;\n"
-            "  }\n"
-            "}";
-
-    const struct lys_module *mod;
-    const char *feats[] = {"feat1", NULL};
-    struct ly_in *in;
-
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_DIR_MODULES_YANG, 0, &ctx));
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, NULL);
-
-    assert_int_equal(LY_SUCCESS, ly_in_new_memory(schema_a, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats, &mod));
-    ly_in_free(in, 0);
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, schema_b, LYS_IN_YANG, NULL));
-
-    return 0;
-}
-
-static int
-teardown(void **state)
-{
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#else
-    (void) state; /* unused */
-#endif
-
-    ly_ctx_destroy(ctx, NULL);
-    ctx = NULL;
-
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-static void
-test_yanglib(void **state)
-{
-    *state = test_yanglib;
-
-    struct lyd_node *tree;
-    struct ly_set *set;
-    LY_ERR ret;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_get_yanglib_data(ctx, &tree));
-
-    /* make sure there is "a" with a submodule and deviation */
-    ret = lyd_find_xpath(tree, "/ietf-yang-library:yang-library/module-set/module[name='a'][submodule/name='a_sub']"
-            "[feature='feat1'][deviation='b']", &set);
-    assert_int_equal(ret, LY_SUCCESS);
-
-    assert_int_equal(set->count, 1);
-    ly_set_free(set, NULL);
-
-    lyd_free_all(tree);
-    *state = NULL;
-}
-
-int
-main(void)
-{
-    const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_yanglib, setup, teardown),
-    };
-
-    return cmocka_run_group_tests(tests, NULL, NULL);
-}
diff --git a/tests/utests/utests.h b/tests/utests/utests.h
index 0f0b720..d3de91c 100644
--- a/tests/utests/utests.h
+++ b/tests/utests/utests.h
@@ -1,5 +1,1081 @@
+/**
+ * @file   utests.h
+ * @author Radek Iša <isa@cesnet.cz>
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @brief  this file contains macros for simplification test writing
+ *
+ * Copyright (c) 2020 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     https://opensource.org/licenses/BSD-3-Clause
+ */
+
+#ifndef _UTESTS_H_
+#define _UTESTS_H_
+
+#define _POSIX_C_SOURCE 200809L /* strdup */
+
 #include <setjmp.h>
 #include <stdarg.h>
 #include <stddef.h>
 
 #include <cmocka.h>
+
+#include <string.h>
+
+#include "libyang.h"
+#include "tests/config.h"
+
+/**
+ * TESTS OVERVIEW
+ *
+ * To include utest's environment, just include "utests.h" in the test's source
+ * code. In case it is the main source code for a cmocka test group (there is a
+ * main() function), define _UTEST_MAIN_ before including this header.
+ *
+ * TESTS VARIABLES
+ *
+ * Checking macros use internal storage to store various variables necessary
+ * during the checking. It is possible to access these variables using the
+ * following macros:
+ *
+ * UTEST_LYCTX    - libyang context
+ * UTEST_IN       - input handler
+ * UTEST_OUT      - output handler
+ *
+ * All these variables are cleaned with test's teardown.
+ *
+ * TESTS SETUP
+ *
+ * CMocka's CMUnitTest list definition macros (cmoka_unit_test*()) are replaced
+ * by UTEST macro with possibility to specify own setup and teardown functions:
+ *
+ * UTEST(test_func) - only implicit setup and teardown functions are used
+ * UTEST(test_func, setup) - implicit teardown but own setup
+ * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
+ *
+ * Note that the tests environment always provide (and need) internal setup and
+ * teardown functions. In case the test-specific setup or teardown are used, they
+ * are supposed to include UTEST_SETUP at the setup beginning and UTEST_TEARDOWN
+ * at the teardown end.
+ *
+ * Libyang context is part of the prepared environment. To add a schema into the
+ * context (despite it is in the test-specific setup or in test function itself),
+ * use UTEST_ADD_MODULE macro.
+ *
+ * LOGGING
+ *
+ * There are 2 macros to check content of the log from the previously called
+ * libyang function. CHECK_LOG macro test only the last error message and path
+ * stored directly via logging callback. CHECK_LOG_CTX gets error message and
+ * path from the libyang context (in case the function does not store the error
+ * information into the libyang context, the message cannot be checked this way).
+ * libyang is set to store multiple error information, so multiple couples of
+ * error message and path can be provided to be checked (the first couple
+ * corresponds to the latest error). The macro also cleanups the errors list, so
+ * it is fine to check that there is no error after succeeding successful
+ * function call.
+ */
+
+/**
+ * @brief Test's context to provide common storage for various variables.
+ */
+struct utest_context {
+    struct ly_ctx *ctx;  /**< libyang context */
+
+    char *err_msg;       /**< Directly logged error message */
+    char *err_path;      /**< Directly logged error path */
+
+    struct ly_in *in;    /**< Input handler */
+    struct ly_out *out;  /**< Outpu handler */
+};
+
+/**
+ * @brief Shortcut to access utest_context.
+ */
+#define _UC ((struct utest_context *)*state)
+
+/**
+ * @brief libyang context provider.
+ */
+#define UTEST_LYCTX (_UC->ctx)
+
+/**
+ * @brief Context's input handler provider
+ */
+#define UTEST_IN (_UC->in)
+
+/**
+ * @brief Context's input handler provider
+ */
+#define UTEST_OUT (_UC->out)
+
+/**
+ * @brief Parse (and validate) data from the input handler as a YANG data tree.
+ *
+ * @param[in] INPUT The input data in the specified @p format to parse (and validate)
+ * @param[in] INPUT_FORMAT Format of the input data to be parsed. Can be 0 to try to detect format from the input handler.
+ * @param[in] PARSE_OPTIONS Options for parser, see @ref dataparseroptions.
+ * @param[in] VALIDATE_OPTIONS Options for the validation phase, see @ref datavalidationoptions.
+ * @param[in] OUT_STATUS expected return status
+ * @param[out] OUT_NODE Resulting data tree built from the input data. Note that NULL can be a valid result as a representation of an empty YANG data tree.
+ * The returned data are expected to be freed using LYD_TREE_DESTROY().
+ */
+#define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, OUT_STATUS, OUT_NODE) \
+    assert_int_equal(OUT_STATUS, lyd_parse_data_mem(_UC->ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE)); \
+    if (OUT_STATUS == LY_SUCCESS) { \
+        assert_non_null(OUT_NODE); \
+    } else { \
+        assert_null(OUT_NODE); \
+    }
+
+/**
+ * @brief Check if lyd_node and his subnodes have correct values. Print lyd_node and his sunodes int o string in json or xml format.
+ * @param[in] NODE pointer to lyd_node
+ * @param[in] TEXT expected output string in json or xml format.
+ * @param[in] FORMAT format of input text. LYD_JSON, LYD_XML
+ * @param[in] PARAM  options [Data printer flags](@ref dataprinterflags).
+ */
+#define CHECK_LYD_STRING_PARAM(NODE, TEXT, FORMAT, PARAM) \
+    { \
+        char *test; \
+        lyd_print_mem(&test, NODE, FORMAT, PARAM); \
+        assert_string_equal(test, TEXT); \
+        free(test); \
+    }
+
+/**
+ * @brief Compare two lyd_node structure. Macro print lyd_node structure into string and then compare string. Print function use these two parameters. LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK;
+ * @param[in] NODE_1 pointer to lyd_node
+ * @param[in] NODE_2 pointer to lyd_node
+ */
+#define CHECK_LYD(NODE_1, NODE_2) \
+    { \
+        char *test_1; \
+        char *test_2; \
+        lyd_print_mem(&test_1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK); \
+        lyd_print_mem(&test_2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK); \
+        assert_string_equal(test_1, test_2); \
+        free(test_1); \
+        free(test_2); \
+    }
+
+/*
+ * SUPPORT MACROS
+ */
+
+/**
+ * @brief Internal macro witch assert that two given string are equal or are both null.
+ *
+ * @param[in] STRING string to check
+ * @param[in] TEXT   string to compare
+ */
+#define CHECK_STRING(STRING, TEXT)\
+    if (TEXT == NULL) { \
+        assert_null(STRING); \
+    } else { \
+        assert_non_null(STRING); \
+        assert_string_equal(STRING, TEXT); \
+    }
+
+/**
+ * @brief Internal macro witch assert that pointer is null when flag is 0.
+ *
+ * @param[in] POINTER pointer to check
+ * @param[in] FLAG    0 -> pointer is NULL, 1 -> pointer is not null
+ */
+#define CHECK_POINTER(POINTER, FLAG) \
+    assert_true(FLAG == 0 ? POINTER == NULL : POINTER != NULL)
+
+/**
+ * @brief Internal macro check size of [sized array](@ref sizedarrays)'s
+ *
+ * @param[in] ARRAY pointer to [sized array](@ref sizedarrays)
+ * @param[in] SIZE  expected [sized array](@ref sizedarrays) size of array
+ */
+#define CHECK_ARRAY(ARRAY, SIZE) \
+    assert_true((SIZE == 0) ? \
+                (ARRAY == NULL) : \
+                (ARRAY != NULL && SIZE == LY_ARRAY_COUNT(ARRAY)));
+
+/*
+ *   LIBYANG NODE CHECKING
+ */
+
+/**
+ * @brief assert that lysp_action_inout structure members are correct
+ * @param[in] NODE      pointer to lysp_action_inout variable
+ * @param[in] DATA      0 -> check if pointer to data is NULL, 1 -> check if pointer to data is not null
+ * @param[in] EXTS      expected [sized array](@ref sizedarrays) size of extens list
+ * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
+ * @param[in] MUSTS     expected [sized array](@ref sizedarrays) size of must restriction list
+ * @param[in] NODETYPE  node type. LYS_INPUT or LYS_OUTPUT
+ * @param[in] PARENT    0 -> check if node is root, 1 -> check if node is not root
+ * @param[in] TYPEDEFS  expected [sized array](@ref sizedarrays) size of typedefs list
+ */
+#define CHECK_LYSP_ACTION_INOUT(NODE, DATA, EXTS, GROUPINGS, MUSTS, NODETYPE, PARENT, TYPEDEFS) \
+    assert_non_null(NODE); \
+    CHECK_POINTER((NODE)->data, DATA); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    CHECK_ARRAY((NODE)->groupings, GROUPINGS); \
+    CHECK_ARRAY((NODE)->musts, MUSTS); \
+    assert_int_equal((NODE)->nodetype, NODETYPE); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_ARRAY((NODE)->typedefs, TYPEDEFS);
+
+/**
+ * @brief assert that lysp_action structure members are correct
+ * @param[in] NODE    pointer to lysp_action variable
+ * @param[in] DSC     expected description
+ * @param[in] EXTS    expected [sized array](@ref sizedarrays) size of extension list
+ * @param[in] FLAGS   expected [schema node flags](@ref snodeflags)
+ * @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
+ * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of if-feature expressions list
+ * @param[in] INPUT_*    ::LYSP_ACTION_INOUT_CHECK
+ * @param[in] NAME     expected name
+ * @param[in] NODETYPE node type. LYS_RPC or LYS_ACTION
+ * @param[in] OUTPUT_*    ::LYSP_ACTION_INOUT_CHECK
+ * @param[in] PARENT   0-> check if node is root, 1-> check if node is not root
+ * @param[in] REF      expected reference
+ * @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of list of typedefs
+ */
+#define CHECK_LYSP_ACTION(NODE, DSC, EXTS, FLAGS, GROUPINGS, IFFEATURES, \
+            INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, INPUT_MUSTS, \
+            INPUT_PARENT, INPUT_TYPEDEFS, \
+            NAME, NODETYPE, \
+            OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, OUTPUT_MUSTS, \
+            OUTPUT_PARENT, OUTPUT_TYPEDEFS, \
+            PARENT, REF, TYPEDEFS) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_ARRAY((NODE)->groupings, GROUPINGS); \
+    CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
+    CHECK_LYSP_ACTION_INOUT(&((NODE)->input), INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, \
+                INPUT_MUSTS, LYS_INPUT, INPUT_PARENT, INPUT_TYPEDEFS); \
+    assert_string_equal((NODE)->name, NAME); \
+    assert_int_equal((NODE)->nodetype, NODETYPE); \
+    CHECK_LYSP_ACTION_INOUT(&((NODE)->output), OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, \
+                OUTPUT_MUSTS, LYS_OUTPUT, OUTPUT_PARENT, OUTPUT_TYPEDEFS); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_ARRAY((NODE)->typedefs, TYPEDEFS) \
+
+/**
+ * @brief assert that lysp_when structure members are correct
+ * @param[in] NODE pointer to lysp_when variable
+ * @param[in] COND expected string specifid condition
+ * @param[in] DSC  expected string description statement
+ * @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
+ * @param[in] REF  expected string reference
+ */
+#define CHECK_LYSP_WHEN(NODE, COND, DSC, EXTS, REF) \
+    assert_non_null(NODE); \
+    assert_string_equal((NODE)->cond, COND); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    if (REF == NULL) { \
+        assert_null((NODE)->ref); \
+    } else { \
+        assert_non_null((NODE)->ref); \
+        assert_string_equal((NODE)->ref, REF); \
+    }
+
+/**
+ * @brief assert that lysp_restr structure members are correct
+ * @param[in] NODE pointer to lysp_restr variable
+ * @param[in] ARG_STR expected string. The restriction expression/value
+ * @param[in] DSC     expected descrition
+ * @param[in] EAPPTAG expected string reprezenting error-app-tag value
+ * @param[in] EMSG    expected string reprezenting error message
+ * @param[in] EXTS    expected [sized array](@ref sizedarrays) size of list of extension array
+ * @param[in] REF     expected reference
+ */
+
+#define CHECK_LYSP_RESTR(NODE, ARG_STR, DSC, EAPPTAG, EMSG, EXTS, REF) \
+    assert_non_null(NODE); \
+    assert_non_null((NODE)->arg.mod); \
+    assert_string_equal((NODE)->arg.str, ARG_STR); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_STRING((NODE)->eapptag, EAPPTAG); \
+    CHECK_STRING((NODE)->emsg, EMSG); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    CHECK_STRING((NODE)->ref, REF);
+
+/**
+ * @brief assert that lysp_import structure members are correct
+ * @param[in] NODE   pointer to lysp_import variable
+ * @param[in] DSC    expected description or NULL
+ * @param[in] EXTS   expected [sized array](@ref sizedarrays) size of list of extensions
+ * @param[in] NAME   expected name of imported module
+ * @param[in] PREFIX expected prefix for the data from the imported schema
+ * @param[in] REF    expected reference
+ * @prame[in] REV    expected reprezenting date in format "11-10-2020"
+ */
+#define CHECK_LYSP_IMPORT(NODE, DSC, EXTS, NAME, PREFIX, REF, REV) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    /*assert_non_null((NODE)->module); // ?? it is mandatory but in some test it doesnt work */ \
+    assert_string_equal((NODE)->name, NAME); \
+    assert_string_equal((NODE)->prefix, PREFIX); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_STRING((NODE)->rev, REV); \
+
+/**
+ * @brief assert that lysp_ext structure members are correct
+ * @param[in] NODE pointer to lysp_ext_instance variable
+ * @param[in] ARGUMENT expected argument name
+ * @param[in] COMPILED 0 -> compiled data dosnt exists, 1 -> compiled data exists
+ * @param[in] DSC      expected string reprezent description
+ * @param[in] EXTS     expected [sized array](@ref sizedarrays) size of list of extension instances
+ * @param[in] FLAGS    expected LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags)
+ * @param[in] NAME     expected name
+ * @param[in] REF      expected ref
+ */
+#define CHECK_LYSP_EXT(NODE, ARGUMENT, COMPILED, DSC, EXTS, FLAGS, NAME, REF) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->argument, ARGUMENT); \
+    CHECK_POINTER((NODE)->compiled, COMPILED); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    assert_string_equal((NODE)->name, NAME); \
+    CHECK_STRING((NODE)->ref, REF);
+
+/**
+ * @brief assert that lysp_ext_instance structure members are correct
+ * @param[in] NODE      pointer to lysp_ext_instance variable
+ * @param[in] ARGUMENT  expected optional value of the extension's argument
+ * @param[in] CHILD     0 -> node doesnt have child, 1 -> node have children
+ * @param[in] COMPILED  0 -> compiled data dosnt exists, 1 -> compiled data exists
+ * @param[in] INSUBSTMS expected value identifying placement of the extension instance
+ * @param[in] INSUBSTMS_INDEX expected indentifi index
+ * @param[in] PARENT    0-> check if node is root, 1-> check if node is not root
+ * @param[in] PARENT_TYPE expected parent type ::LYEXT_PARENT. not relevat if PARENT == 0
+ * @param[in] YIN       expected flag for YIN source format, can be set to LYS_YIN
+ */
+#define CHECK_LYSP_EXT_INSTANCE(NODE, ARGUMENT, CHILD, COMPILED, INSUBSTMT, INSUBSTMT_INDEX, NAME, HAS_PARENT, PARENT_TYPE, YIN) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->argument, ARGUMENT); \
+    CHECK_POINTER((NODE)->child, CHILD); \
+    CHECK_POINTER((NODE)->compiled, COMPILED); \
+    /*assert_int_equal((NODE)->flags, LYS_INTERNAL);*/ \
+    assert_int_equal((NODE)->insubstmt, INSUBSTMT); \
+    assert_int_equal((NODE)->insubstmt_index, INSUBSTMT_INDEX); \
+    assert_string_equal((NODE)->name, NAME); \
+    if (HAS_PARENT) { \
+        assert_non_null((NODE)->parent); \
+        assert_int_equal((NODE)->parent_type, PARENT_TYPE); \
+    } else { \
+        assert_null((NODE)->parent); \
+    } \
+    assert_int_equal((NODE)->yin, YIN);
+
+/**
+ * @brief assert that lysp_stmt structure members are correct
+ * @param[in] NODE  pointer to lysp_stmt variable
+ * @param[in] ARG   expected statemet argumet
+ * @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
+ * @param[in] FLAGS expected statement flags, can be set to LYS_YIN_ATTR
+ * @param[in] KW    expected numeric respresentation of the stmt value
+ * @param[in] NEXT  0 -> pointer is NULL, 1 -> pointer is not null
+ * @param[in] STMS  expected identifier of the statement
+ */
+#define CHECK_LYSP_STMT(NODE, ARG, CHILD, FLAGS, KW, NEXT, STMT) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->arg, ARG); \
+    CHECK_POINTER((NODE)->child, CHILD); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    assert_int_equal((NODE)->kw, KW); \
+    CHECK_POINTER((NODE)->next, NEXT); \
+    assert_string_equal((NODE)->stmt, STMT); \
+
+/**
+ * @brief assert that lysp_type_enum structure members are correct
+ * @param[in] NODE pointer to lysp_type_enum variable
+ * @param[in] DSC   expected description
+ * @param[in] EXTS  expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] FLAGS only LYS_STATUS_ and LYS_SET_VALUE values are allowed
+ * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] NAME  expected name
+ * @param[in] REF   expected reference statement
+ * @param[in] VALUE expected enum's value or bit's position
+ */
+#define CHECK_LYSP_TYPE_ENUM(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, REF, VALUE) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
+    CHECK_STRING((NODE)->name, NAME); \
+    CHECK_STRING((NODE)->ref, REF); \
+    assert_int_equal(VALUE, (NODE)->value);
+
+/**
+ * @brief assert that lysp_node structure members are correct
+ * @param[in] NODE  pointer to lysp_node variable
+ * @param[in] DSC   expected description statement
+ * @param[in] EXTS  expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] FLAGS [schema node flags](@ref snodeflags)
+ * @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] NAME  expected name
+ * @param[in] NEXT  0 pointer is null, 1 pointer is not null
+ * @param[in] NODETYPE  node type LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, LYS_LEAFLIST,
+ *                      LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, LYS_ACTION, LYS_NOTIF,
+ *                      LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, LYS_AUGMENT
+ * @param[in] PARENT    0-> check if node is root, 1-> check if node is not root
+ * @param[in] REF       expected reference statement
+ * @param[in] WHEN      0-> pointer is null, 1 -> pointer is not null
+ */
+#define CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, NODETYPE, PARENT, REF, WHEN) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
+    CHECK_STRING((NODE)->name, NAME); \
+    CHECK_POINTER((NODE)->next, NEXT); \
+    assert_int_equal((NODE)->nodetype, NODETYPE); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_POINTER((NODE)->when, WHEN);
+
+/**
+ * @brief assert that lysc_notif structure members are correct
+ * @param[in] NODE    pointer to lysp_notif variable
+ * @param[in] DATA    0 pointer is null, 1 pointer is not null
+ * @param[in] DSC     expected description
+ * @param[in] EXTS    expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] FLAGS   [schema node flags](@ref snodeflags)
+ * @param[in] MODULE  0 pointer is null, 1 pointer is not null
+ * @param[in] MUSTS   expected [sized array](@ref sizedarrays) size of list of must restriction
+ * @param[in] NAME    expected name
+ * @param[in] PARENT  0-> check if node is root, 1-> check if node is not root
+ * @param[in] PRIV    0-> pointer is null, 1-> pointer is not null
+ * @param[in] REF     expected reference
+ * @param[in] WHEN    expected [sized array](@ref sizedarrays) size of list of pointers to when statements
+ */
+#define CHECK_LYSC_NOTIF(NODE, DATA, DSC, EXTS, FLAGS, MODULE, MUSTS, NAME, PARENT, PRIV, REF, WHEN) \
+    assert_non_null(NODE); \
+    CHECK_POINTER((NODE)->data, DATA); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_POINTER((NODE)->module, MODULE); \
+    CHECK_ARRAY((NODE)->musts, MUSTS); \
+    assert_string_equal((NODE)->name, NAME); \
+    assert_int_equal((NODE)->nodetype, LYS_NOTIF); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_POINTER((NODE)->priv, PRIV); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_ARRAY((NODE)->when, WHEN);
+
+/**
+ * @brief assert that lysc_action_inout structure members are correct
+ * @param[in] NODE      pointer to lysp_notif variable
+ * @param[in] DATA      0 pointer is null, 1 pointer is not null
+ * @param[in] MUST      expected [sized array](@ref sizedarrays) size of list of must restrictions
+ * @param[in] NODETYPE  LYS_INPUT or LYS_OUTPUT
+ */
+#define CHECK_LYSC_ACTION_INOUT(NODE, DATA, MUST, NODETYPE) \
+    assert_non_null(NODE); \
+    CHECK_POINTER((NODE)->data, DATA); \
+    CHECK_ARRAY((NODE)->musts, MUST); \
+    assert_int_equal((NODE)->nodetype, NODETYPE);
+
+/**
+ * @brief assert that lysc_action structure members are correct
+ * @param[in] NODE    pointer to lysp_action variable
+ * @param[in] DSC     string description statement
+ * @param[in] EXTS    expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] FLAGS   [schema node flags](@ref snodeflags)
+ * @param[in] INPUT_DATA 0 pointer is null, 1 pointer is not null
+ * @param[in] INPUT_MUST expected [sized array](@ref sizedarrays) size of input list of must restrictions
+ * @param[in] INPUT_EXTS expected [sized array](@ref sizedarrays) size of the input extension instances of input
+ * @param[in] MODULE  0 pointer is null, 1 pointer is not null
+ * @param[in] NAME    expected name
+ * @param[in] NODETYPE    LYS_RPC, LYS_ACTION
+ * @param[in] OUTPUT_DATA 0 pointer is null, 1 pointer is not null
+ * @param[in] OUTPUT_MUST expected [sized array](@ref sizedarrays) size of output list of must restrictions
+ * @param[in] OUTPUT_EXTS expected [sized array](@ref sizedarrays) size of the output extension instances of input
+ * @param[in] PARENT  0-> check if node is root, 1-> check if node is not root
+ * @param[in] PRIV    0-> pointer is null, 1-> pointer is not null
+ * @param[in] REF     expected reference
+ * @param[in] WHEN    expected [sized array](@ref sizedarrays) size of list of pointers to when statements
+ */
+#define CHECK_LYSC_ACTION(NODE, DSC, EXTS, FLAGS, INPUT_DATA, INPUT_MUST, INPUT_EXTS, MODULE, NAME, NODETYPE, \
+            OUTPUT_DATA, OUTPUT_MUST, OUTPUT_EXTS, PARENT, PRIV, REF, WHEN) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_LYSC_ACTION_INOUT(&(NODE)->input, INPUT_DATA, INPUT_MUST, LYS_INPUT); \
+    CHECK_ARRAY((NODE)->input_exts, INPUT_EXTS); \
+    CHECK_POINTER((NODE)->module, MODULE); \
+    assert_string_equal((NODE)->name, NAME); \
+    assert_int_equal((NODE)->nodetype, NODETYPE); \
+    CHECK_LYSC_ACTION_INOUT(&(NODE)->output, OUTPUT_DATA, OUTPUT_MUST, LYS_OUTPUT); \
+    CHECK_ARRAY((NODE)->output_exts, OUTPUT_EXTS); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_POINTER((NODE)->priv, PRIV); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_ARRAY((NODE)->when, WHEN);
+
+/**
+ * @brief assert that lysc_node structure members are correct
+ * @param[in] NODE    pointer to lysc_node variable
+ * @param[in] DSC     expected description
+ * @param[in] EXTS    expected [sized array](@ref sizedarrays) size of list of the extension instances
+ * @param[in] FLAGS   [schema node flags](@ref snodeflags)
+ * @param[in] MODULE  0 pointer is null, 1 pointer is not null
+ * @param[in] NAME    expected name
+ * @param[in] NEXT    0 pointer is null, 1 pointer is not null
+ * @param[in] NODETYPE    type of the node  LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF,
+ *                    LYS_LEAFLIST, LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC,
+ *                    LYS_ACTION, LYS_NOTIF, LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING,
+ *                    LYS_AUGMENT
+ * @param[in] PARENT  0-> check if node is root, 1-> check if node is not root
+ * @param[in] PRIV    0-> pointer is null, 1-> pointer is not null
+ * @param[in] REF     expected reference
+ * @param[in] WHEN    expected [sized array](@ref sizedarrays) size of list of pointers to when statements
+ */
+#define CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, NODETYPE, PARENT, PRIV, REF, WHEN) \
+    assert_non_null(NODE); \
+    CHECK_STRING((NODE)->dsc, DSC); \
+    CHECK_ARRAY((NODE)->exts, EXTS); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_POINTER((NODE)->module, MODULE); \
+    assert_string_equal((NODE)->name, NAME); \
+    CHECK_POINTER((NODE)->next, NEXT); \
+    assert_int_equal((NODE)->nodetype, NODETYPE); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    assert_non_null((NODE)->prev); \
+    CHECK_POINTER((NODE)->priv, PRIV); \
+    CHECK_STRING((NODE)->ref, REF); \
+    CHECK_ARRAY((NODE)->when, WHEN);
+
+/**
+ * @brief assert that lyd_meta structure members are correct
+ * @param[in] NODE       pointer to lyd_meta variable
+ * @param[in] ANNOTATION 0 pointer is null, 1 pointer is not null
+ * @param[in] NAME       expected name
+ * @param[in] NEXT       0 pointer is null, 1 pointer is not null
+ * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
+ *                     part of text reprezenting LY_DATA_TYPE.
+ * @param[in] ...              ::CHECK_LYD_VALUE
+ */
+#define CHECK_LYD_META(NODE, ANNOTATION, NAME, NEXT, PARENT, TYPE_VAL, ...) \
+    assert_non_null(NODE); \
+    CHECK_POINTER((NODE)->annotation, ANNOTATION); \
+    assert_string_equal((NODE)->name, NAME); \
+    CHECK_POINTER((NODE)->next, NEXT); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    CHECK_LYD_VALUE((NODE)->value, TYPE_VAL, ##__VA_ARGS__);
+
+/**
+ * @brief assert that lyd_node_term structure members are correct
+ * @param[in] NODE             pointer to lyd_node_term variable
+ * @param[in] FLAGS            expected [data node flags](@ref dnodeflags)
+ * @param[in] META             0 -> meta is not prezent, 1 -> meta is prezent
+ * @param[in] NEXT             0 -> next node is not prezent, 1 -> next node is prezent
+ * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
+ *                     part of text reprezenting LY_DATA_TYPE.
+ * @param[in] ...              ::CHECK_LYD_VALUE
+ */
+#define CHECK_LYD_NODE_TERM(NODE, FLAGS, META, NEXT, PARENT, SCHEMA, VALUE_TYPE, ...) \
+    assert_non_null(NODE); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_POINTER((NODE)->meta, META); \
+    CHECK_POINTER((NODE)->next, NEXT); \
+    CHECK_POINTER((NODE)->parent, PARENT); \
+    assert_non_null((NODE)->prev); \
+    CHECK_POINTER((NODE)->schema, SCHEMA); \
+    CHECK_LYD_VALUE((NODE)->value, VALUE_TYPE, ##__VA_ARGS__);
+
+/**
+ * @brief assert that lyd_node_any structure members are correct
+ * @param[in] NODE       pointer to lyd_node_term variable
+ * @param[in] FLAGS      expected [data node flags](@ref dnodeflags)
+ * @param[in] META       0 meta isnt present , 1 meta is present
+ * @param[in] PARENT     0 it is root node , 1 node have parent
+ * @param[in] VALUE_TYPE value type ::lyd_node_any.value
+ */
+#define CHECK_LYD_NODE_ANY(NODE, FLAGS, META, PARENT, VALUE_TYPE) \
+    assert_non_null(NODE); \
+    assert_int_equal((NODE)->flags, FLAGS); \
+    CHECK_POINTER((NODE)->meta, META); \
+    CHECK_POINTER((NODE)->meta, PARENT); \
+    assert_non_null((NODE)->prev); \
+    assert_non_null((NODE)->schema); \
+    assert_int_equal((NODE)->value_type, VALUE_TYPE);
+
+/**
+ * @brief assert that lyd_node_opaq structure members are correct
+ * @param[in] NODE     pointer to lyd_node_opaq variable
+ * @param[in] ATTR     0 if pointer is null ,1 if pointer is not null
+ * @param[in] CHILD    0 if pointer is null ,1 if pointer is not null
+ * @param[in] FORMAT   LY_PREF_XML or LY_PREF_JSON
+ * @param[in] VAL_PREFS 0 if pointer is null ,1 if pointer is not null
+ * @param[in] NAME     expected name
+ * @param[in] value    expected orignal value
+ */
+#define CHECK_LYD_NODE_OPAQ(NODE, ATTR, CHILD, FORMAT, NAME, NEXT, PARENT, PREFIX, VAL_PREFS, VALUE) \
+    assert_non_null(NODE); \
+    CHECK_POINTER((NODE)->attr, ATTR); \
+    CHECK_POINTER((NODE)->child, CHILD); \
+    assert_ptr_equal((NODE)->ctx, UTEST_LYCTX); \
+    assert_int_equal((NODE)->flags, 0); \
+    assert_true((NODE)->format == FORMAT); \
+    assert_int_equal((NODE)->hash, 0); \
+    assert_string_equal((NODE)->name.name, NAME); \
+    assert_non_null((NODE)->prev); \
+    assert_null((NODE)->schema); \
+    CHECK_POINTER((NODE)->val_prefix_data, VAL_PREFS); \
+    assert_string_equal((NODE)->value, VALUE);
+
+/**
+ * @brief assert that lyd_value structure members are correct
+ * @param[in] NODE     lyd_value
+ * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
+ *                     part of text reprezenting LY_DATA_TYPE.
+ * @param[in] ...      Unspecified parameters. Type and numbers of parameters are specified
+ *                     by type of value. These parameters are passed to macro
+ *                     CHECK_LYD_VALUE_ ## TYPE_VAL.
+ */
+#define CHECK_LYD_VALUE(NODE, TYPE_VAL, ...) \
+    CHECK_LYD_VALUE_ ## TYPE_VAL (NODE, ##__VA_ARGS__);
+
+/*
+ * LYD VALUES CHECKING SPECIALIZATION
+ */
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type EMPTY
+ *        Example CHECK_LYD_VALUE(node->value, EMPTY, "");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ */
+#define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UNION
+ *        Example CHECK_LYD_VALUE(node->value, UNION, "12", INT8, "12", 12);
+ * @warning   type of subvalue cannot be UNION. Example of calling
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
+ * @param[in] ...      Unspecified parameters. Type and numbers of parameters are specified
+ *                     by type of value. These parameters are passed to macro
+ *                     CHECK_LYD_VALUE_ ## TYPE_VAL.
+ */
+#define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \
+    assert_non_null((NODE).subvalue); \
+    assert_non_null((NODE).subvalue->prefix_data); \
+    CHECK_LYD_VALUE_ ## TYPE_VAL ((NODE).subvalue->value, ## __VA_ARGS__)
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BITS
+ *        Example arr[] = {"a", "b"}; CHECK_LYD_VALUE(node->value, BITS, "a b", arr);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected array of bits names
+ */
+#define CHECK_LYD_VALUE_BITS(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \
+    { \
+    	LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
+        assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).bits_items)); \
+        for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
+            assert_string_equal(VALUE[it], (NODE).bits_items[it]->name); \
+        } \
+    }
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INST
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected array of enum ly_path_pred_type
+ * @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr);
+ */
+#define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \
+    { \
+    	LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
+        assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \
+        for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
+            assert_int_equal(VALUE[it], (NODE).target[it].pred_type); \
+        } \
+    }
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type ENUM.
+ *        Example CHECK_LYD_VALUE(node->value, ENUM, "item_name", "item_name");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected enum item name
+ */
+#define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \
+    assert_string_equal(VALUE, (NODE).enum_item->name);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT8
+ *        Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected inteager value (-128 to 127).
+ */
+#define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \
+    assert_int_equal(VALUE, (NODE).int8);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT16
+ *        Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected inteager value.
+ */
+#define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \
+    assert_int_equal(VALUE, (NODE).int16);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT8.
+ *        Example CHECK_LYD_VALUE(node->value, UINT8, "12", 12);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected inteager (0 to 255).
+ */
+#define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \
+    assert_int_equal(VALUE, (NODE).uint8);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type STRING.
+ *        Example CHECK_LYD_VALUE(node->value, STRING, "text");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ */
+#define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type LEAFREF
+ * @brief Example CHECK_LYD_VALUE(node->value, LEAFREF, "");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ */
+#define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \
+    assert_non_null((NODE).ptr)
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type DEC64
+ *        Example CHECK_LYD_VALUE(node->value, DEC64, "125", 125);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected value 64bit inteager
+*/
+#define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \
+    assert_int_equal(VALUE, (NODE).dec64);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BINARY.
+ *        Example CHECK_LYD_VALUE(node->value, BINARY, "aGVs\nbG8=");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+*/
+#define CHECK_LYD_VALUE_BINARY(NODE, CANNONICAL_VAL) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BOOL.
+ *        Example CHECK_LYD_VALUE(node->value, BOOL, "true", 1);
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected boolean value 0,1
+*/
+#define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \
+    assert_int_equal(VALUE, (NODE).boolean);
+
+/**
+ * @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type IDENT.
+ *        Example CHECK_LYD_VALUE(node->value, IDENT, "types:gigabit-ethernet", "gigabit-ethernet");
+ * @param[in] NODE           lyd_value variable
+ * @param[in] CANNONICAL_VAL expected cannonical value
+ * @param[in] VALUE          expected ident name
+*/
+#define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \
+    assert_non_null((NODE).canonical); \
+    assert_string_equal((NODE).canonical, CANNONICAL_VAL); \
+    assert_non_null((NODE).realtype); \
+    assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \
+    assert_string_equal(VALUE, (NODE).ident->name);
+
+/**
+ * @brief Add module (from a string) into the used libyang context.
+ * @param[in] DATA     String storing the schema module representation.
+ * @param[in] FORMAT   Schema format of the @p DATA
+ * @param[in] FEATURES Array of module's features to enable
+ * @param[out] MOD     Optional parameter as a pointer to variable to store the resulting module.
+ */
+#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
+    assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
+    assert_int_equal(LY_SUCCESS, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, MOD)); \
+    ly_in_free(_UC->in, 0); \
+    _UC->in = NULL
+
+/**
+ * @brief Internal macro to compare error info record with the expected error message and path.
+ * If NULL is provided as MSG, no error info record (NULL) is expected.
+ * @param[in] ERR Error information record from libyang context.
+ * @param[in] MSG Expected error message.
+ * @param[in] PATH Expected error path.
+ *
+ */
+#define _CHECK_LOG_CTX(ERR, MSG, PATH) \
+    if (!MSG) { \
+        assert_null(ERR); \
+    } else { \
+        assert_non_null(ERR); \
+        CHECK_STRING((ERR)->msg, MSG); \
+        CHECK_STRING((ERR)->path, PATH); \
+    }
+
+/**`
+ * @brief Internal macro to check the last libyang's context error.
+ */
+#define _CHECK_LOG_CTX1(MSG, PATH) \
+    _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG, PATH)
+
+/**
+ * @brief Internal macro to check the last two libyang's context error.
+ */
+#define _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2) \
+        _CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG1, PATH1); \
+        _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev, MSG2, PATH2)
+
+/**
+ * @brief Internal macro to check the last three libyang's context error.
+ */
+#define _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3) \
+        _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2); \
+        _CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev, MSG3, PATH3)
+
+/**
+ * @brief Internal helper macro to select _CHECK_LOG_CTX* macro according to the provided parameters.
+ */
+#define _GET_CHECK_LOG_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
+
+/**
+ * @brief Check expected error(s) in libyang context.
+ *
+ * Macro has variadic parameters expected to be provided in pairs of error message and error path starting
+ * from the latest error. Current limit is checking at most 3 last errors. After checking, macro cleans up
+ * all the errors from the libyang context.
+ *
+ * @param[in] MSG Expected error message.
+ * @param[in] PATH Expected error path.
+ */
+#define CHECK_LOG_CTX(...) \
+    _GET_CHECK_LOG_MACRO(__VA_ARGS__, _CHECK_LOG_CTX3, _INVAL, _CHECK_LOG_CTX2, _INVAL, _CHECK_LOG_CTX1)(__VA_ARGS__); \
+    ly_err_clean(_UC->ctx, NULL)
+
+/**
+ * @brief Clean up the logging callback's storage.
+ */
+#define UTEST_LOG_CLEAN \
+    free(_UC->err_msg); \
+    free(_UC->err_path); \
+    _UC->err_msg = NULL; \
+    _UC->err_path = NULL;
+
+/**
+ * @brief Check expected error directly logged via logging callback.
+ * Useful mainly for messages logged by functions without access to libyang context.
+ * @param[in] MSG Expected error message.
+ * @param[in] PATH Expected error path.
+ */
+#define CHECK_LOG(MSG, PATH) \
+    CHECK_STRING(_UC->err_msg, MSG); \
+    CHECK_STRING(_UC->err_path, PATH); \
+    UTEST_LOG_CLEAN
+
+#ifdef _UTEST_MAIN_
+/*
+ * Functions inlined into each C source file including this header with _UTEST_MAIN_ defined
+ */
+
+/**
+ * @brief Global variable holding the tests context to simplify access to it.
+ */
+struct utest_context *current_utest_context;
+
+/* set to 0 to printing error messages to stderr instead of checking them in code */
+#define ENABLE_LOGGER_CHECKING 1
+
+/**
+ * @brief Logging callback for libyang.
+ */
+static void
+_utest_logger(LY_LOG_LEVEL level, const char *msg, const char *path)
+{
+    (void) level; /* unused */
+
+    if (ENABLE_LOGGER_CHECKING == 0) {
+        printf("ERROR:\n\tMESSAGE: %s\n\tPATH: %s\n\tLEVEL: %i\n", msg, path, level);
+    } else {
+        free(current_utest_context->err_msg);
+        current_utest_context->err_msg = msg ? strdup(msg) : NULL;
+        free(current_utest_context->err_path);
+        current_utest_context->err_path = path ? strdup(path) : NULL;
+    }
+}
+
+/**
+ * @brief Generic utest's setup
+ */
+static int
+utest_setup(void **state)
+{
+    /* setup the logger */
+    ly_set_log_clb(_utest_logger, 1);
+    ly_log_options(LY_LOLOG | LY_LOSTORE);
+
+    current_utest_context = calloc(1, sizeof *current_utest_context);
+    assert_non_null(current_utest_context);
+    *state = current_utest_context;
+
+    /* libyang context */
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &current_utest_context->ctx));
+
+    return 0;
+}
+
+/**
+ * @brief macro to include generic utest's setup into the test-specific setup.
+ *
+ * Place at the beginning of the test-specific setup
+ */
+#define UTEST_SETUP \
+    assert_int_equal(0, utest_setup(state))
+
+/**
+ * @brief Generic utest's teardown
+ */
+static int
+utest_teardown(void **state)
+{
+    *state = NULL;
+
+    /* libyang context */
+    ly_ctx_destroy(current_utest_context->ctx, NULL);
+
+    /* utest context */
+    ly_in_free(current_utest_context->in, 0);
+    free(current_utest_context->err_msg);
+    free(current_utest_context->err_path);
+    free(current_utest_context);
+    current_utest_context = NULL;
+
+    return 0;
+}
+
+/**
+ * @brief macro to include generic utest's teardown into the test-specific teardown.
+ *
+ * Place at the end of the test-specific teardown
+ */
+#define UTEST_TEARDOWN \
+    assert_int_equal(0, utest_teardown(state))
+
+/**
+ * @brief Internal macro for utest setup with test-specific setup and teardown
+ */
+#define _UTEST_SETUP_TEARDOWN(FUNC, SETUP, TEARDOWN) \
+    cmocka_unit_test_setup_teardown(FUNC, SETUP, TEARDOWN)
+
+/**
+ * @brief Internal macro for utest setup with test-specific setup and generic teardown
+ */
+#define _UTEST_SETUP(FUNC, SETUP) \
+    cmocka_unit_test_setup_teardown(FUNC, SETUP, utest_teardown)
+
+/**
+ * @brief Internal macro for utest setup with generic setup and teardown
+ */
+#define _UTEST(FUNC) \
+    cmocka_unit_test_setup_teardown(FUNC, utest_setup, utest_teardown)
+
+/**
+ * @brief Internal helper macro to select _UTEST* macro according to the provided parameters.
+ */
+#define _GET_UTEST_MACRO(_1, _2, _3, NAME, ...) NAME
+
+/**
+ * @brief Macro to specify test function using utest environment. Macro has variadic parameters
+ * to provide test-specific setup/teardown functions:
+ *
+ * UTEST(test_func) - only implicit setup and teardown functions are used
+ * UTEST(test_func, setup) - implicit teardown but own setup
+ * UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
+ */
+#define UTEST(...) \
+    _GET_UTEST_MACRO(__VA_ARGS__, _UTEST_SETUP_TEARDOWN, _UTEST_SETUP, _UTEST)(__VA_ARGS__)
+
+#else /* _UTEST_MAIN_ */
+
+extern struct utest_context *current_utest_context;
+
+#endif /* _UTEST_MAIN_ */
+
+#endif /* _UTESTS_H_ */