tests CHANGE move tests from source view to a units view

Focus of the tests is supposed to be on the libyang's parts/mechanisms,
so move the tests structure from source view to a units view.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 01cb370..631f577 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -15,18 +15,17 @@
 
 set(tests)
 set(tests_wraps)
-add_subdirectory(src)
-add_subdirectory(features)
+add_subdirectory(utests)
 
-foreach(test_name IN LISTS tests)
-    message(STATUS ${test_name})
-    string(REGEX REPLACE "[a-z]*_(.*)" "\\1" name "${test_name}")
-    string(REGEX REPLACE "([a-z]*)_.*" "\\1" prefix "${test_name}")
-    add_executable(${test_name} ${prefix}/test_${name}.c $<TARGET_OBJECTS:yangobj>)
-endforeach(test_name)
+foreach(test_id IN LISTS tests)
+    message(STATUS ${test_id})
+    string(REGEX REPLACE "([a-z]*):.*" "\\1" category "${test_id}")
+    string(REGEX REPLACE "[a-z]*:(.*)" "\\1" path "${test_id}")
+    string(REGEX REPLACE "[a-z:/]*test_(.*)" "\\1" name "${test_id}")
+    set(test_name ${category}_${name})
+    add_executable(${test_name} ${category}s/${path}.c $<TARGET_OBJECTS:yangobj>)
 
-# Set common attributes of all tests
-foreach(test_name IN LISTS tests)
+	# Set common attributes of all tests
     target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} m)
     if (NOT APPLE)
         list(GET tests_wraps 0 test_wrap)
@@ -37,20 +36,18 @@
 #    set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions")
 #    set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types")
     set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3")
-endforeach(test_name)
 
-if(ENABLE_VALGRIND_TESTS)
-    if(VALGRIND_FOUND)
-        foreach(test_name IN LISTS tests)
+    if(ENABLE_VALGRIND_TESTS)
+        if(VALGRIND_FOUND)
             add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1
-                 ${CMAKE_BINARY_DIR}/tests/${test_name})
+               ${CMAKE_BINARY_DIR}/tests/${test_name})
 #            set_property(TEST ${test_name}_valgrind PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions")
 #            set_property(TEST ${test_name}_valgrind APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types")
-        endforeach(test_name)
-    else(VALGRIND_FOUND)
-        message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
-    endif(VALGRIND_FOUND)
-endif()
+        else(VALGRIND_FOUND)
+            message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
+        endif(VALGRIND_FOUND)
+    endif(ENABLE_VALGRIND_TESTS)
+endforeach()
 
 if(ENABLE_COVERAGE)
     # Destination
diff --git a/tests/features/CMakeLists.txt b/tests/features/CMakeLists.txt
deleted file mode 100644
index 6e4a366..0000000
--- a/tests/features/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-set(local_tests
-    features_types
-    features_metadata
-    features_nacm)
-set(local_tests_wraps
-    " "
-    " "
-    " ")
-set(tests ${tests} ${local_tests} PARENT_SCOPE)
-set(tests_wraps ${tests_wraps} ${local_tests_wraps} PARENT_SCOPE)
diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt
deleted file mode 100644
index 00bf835..0000000
--- a/tests/src/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-set(local_tests
-    src_set
-    src_common
-    src_context
-    src_hash_table
-    src_xml
-    src_parser_yang
-    src_parser_yin
-    src_tree_schema
-    src_tree_schema_compile
-    src_tree_schema_helpers
-    src_printer_yang
-    src_printer_yin
-    src_tree_data
-    src_parser_xml
-    src_printer_xml
-    src_validation)
-set(local_tests_wraps
-    " "
-    "-Wl,--wrap=realloc"
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " "
-    " ")
-set(tests ${tests} ${local_tests} PARENT_SCOPE)
-set(tests_wraps ${tests_wraps} ${local_tests_wraps} PARENT_SCOPE)
diff --git a/tests/utests/CMakeLists.txt b/tests/utests/CMakeLists.txt
new file mode 100644
index 0000000..1a758a1
--- /dev/null
+++ b/tests/utests/CMakeLists.txt
@@ -0,0 +1,42 @@
+set(local_tests
+    utest:test_common
+    utest:test_set
+    utest:test_hash_table
+    utest:test_context
+    utest:test_xml
+    utest:test_parser_yang
+    utest:test_parser_yin
+    utest:test_tree_schema
+    utest:test_tree_schema_compile
+    utest:test_tree_schema_helpers
+    utest:test_printer_yang
+    utest:test_printer_yin
+    utest:test_tree_data
+    utest:test_parser_xml
+    utest:test_printer_xml
+    utest:test_validation
+    utest:test_types
+    utest:extensions/test_metadata
+    utest:extensions/test_nacm)
+set(local_tests_wraps
+    "-Wl,--wrap=realloc"
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "
+    " "	
+    " "
+    " "
+    " "
+    " "
+    " ")
+set(tests ${tests} ${local_tests} PARENT_SCOPE)
+set(tests_wraps ${tests_wraps} ${local_tests_wraps} PARENT_SCOPE)
diff --git a/tests/features/test_metadata.c b/tests/utests/extensions/test_metadata.c
similarity index 100%
rename from tests/features/test_metadata.c
rename to tests/utests/extensions/test_metadata.c
diff --git a/tests/features/test_nacm.c b/tests/utests/extensions/test_nacm.c
similarity index 100%
rename from tests/features/test_nacm.c
rename to tests/utests/extensions/test_nacm.c
diff --git a/tests/src/test_common.c b/tests/utests/test_common.c
similarity index 100%
rename from tests/src/test_common.c
rename to tests/utests/test_common.c
diff --git a/tests/src/test_context.c b/tests/utests/test_context.c
similarity index 97%
rename from tests/src/test_context.c
rename to tests/utests/test_context.c
index a70a01a..d9b8e9f 100644
--- a/tests/src/test_context.c
+++ b/tests/utests/test_context.c
@@ -96,8 +96,8 @@
     logbuf_assert("Invalid argument ctx (ly_ctx_unset_searchdirs()).");
 
     /* readable and executable, but not a directory */
-    assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, TESTS_BIN"/src_context"));
-    logbuf_assert("Given search directory \""TESTS_BIN"/src_context\" is 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).");
@@ -110,14 +110,14 @@
     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"/src"));
+    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"/src", ctx->search_paths.objs[0]);
+    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"/src"));
+    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"/src", ctx->search_paths.objs[0]);
+    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"));
@@ -132,7 +132,7 @@
     /* get searchpaths */
     list = ly_ctx_get_searchdirs(ctx);
     assert_non_null(list);
-    assert_string_equal(TESTS_BIN"/src", list[0]);
+    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]);
@@ -144,8 +144,8 @@
     assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdirs(ctx, "/nonexistingfile"));
     logbuf_assert("Invalid argument value (ly_ctx_unset_searchdirs()).");
     /* first */
-    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, TESTS_BIN"/src"));
-    assert_string_not_equal(TESTS_BIN"/src", list[0]);
+    assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, TESTS_BIN"/utests"));
+    assert_string_not_equal(TESTS_BIN"/utests", list[0]);
     assert_int_equal(7, ctx->search_paths.count);
     /* middle */
     assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, TESTS_SRC));
diff --git a/tests/src/test_hash_table.c b/tests/utests/test_hash_table.c
similarity index 100%
rename from tests/src/test_hash_table.c
rename to tests/utests/test_hash_table.c
diff --git a/tests/src/test_parser_xml.c b/tests/utests/test_parser_xml.c
similarity index 100%
rename from tests/src/test_parser_xml.c
rename to tests/utests/test_parser_xml.c
diff --git a/tests/src/test_parser_yang.c b/tests/utests/test_parser_yang.c
similarity index 100%
rename from tests/src/test_parser_yang.c
rename to tests/utests/test_parser_yang.c
diff --git a/tests/src/test_parser_yin.c b/tests/utests/test_parser_yin.c
similarity index 100%
rename from tests/src/test_parser_yin.c
rename to tests/utests/test_parser_yin.c
diff --git a/tests/src/test_printer_xml.c b/tests/utests/test_printer_xml.c
similarity index 100%
rename from tests/src/test_printer_xml.c
rename to tests/utests/test_printer_xml.c
diff --git a/tests/src/test_printer_yang.c b/tests/utests/test_printer_yang.c
similarity index 100%
rename from tests/src/test_printer_yang.c
rename to tests/utests/test_printer_yang.c
diff --git a/tests/src/test_printer_yin.c b/tests/utests/test_printer_yin.c
similarity index 100%
rename from tests/src/test_printer_yin.c
rename to tests/utests/test_printer_yin.c
diff --git a/tests/src/test_set.c b/tests/utests/test_set.c
similarity index 100%
rename from tests/src/test_set.c
rename to tests/utests/test_set.c
diff --git a/tests/src/test_tree_data.c b/tests/utests/test_tree_data.c
similarity index 100%
rename from tests/src/test_tree_data.c
rename to tests/utests/test_tree_data.c
diff --git a/tests/src/test_tree_schema.c b/tests/utests/test_tree_schema.c
similarity index 100%
rename from tests/src/test_tree_schema.c
rename to tests/utests/test_tree_schema.c
diff --git a/tests/src/test_tree_schema_compile.c b/tests/utests/test_tree_schema_compile.c
similarity index 100%
rename from tests/src/test_tree_schema_compile.c
rename to tests/utests/test_tree_schema_compile.c
diff --git a/tests/src/test_tree_schema_helpers.c b/tests/utests/test_tree_schema_helpers.c
similarity index 100%
rename from tests/src/test_tree_schema_helpers.c
rename to tests/utests/test_tree_schema_helpers.c
diff --git a/tests/features/test_types.c b/tests/utests/test_types.c
similarity index 100%
rename from tests/features/test_types.c
rename to tests/utests/test_types.c
diff --git a/tests/src/test_validation.c b/tests/utests/test_validation.c
similarity index 100%
rename from tests/src/test_validation.c
rename to tests/utests/test_validation.c
diff --git a/tests/src/test_xml.c b/tests/utests/test_xml.c
similarity index 100%
rename from tests/src/test_xml.c
rename to tests/utests/test_xml.c