tests CHANGE redesign mechanism to add particular tests

Define cmake function to add a test into the ctest instead of adding
particular parameters of each test into several lists.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 631f577..0726dce 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -13,41 +13,43 @@
 include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})
 include_directories(${PROJECT_BINARY_DIR})
 
-set(tests)
-set(tests_wraps)
-add_subdirectory(utests)
+function(ly_add_utest)
+    cmake_parse_arguments(ADDTEST "" "NAME;WRAP" "SOURCES" ${ARGN})
+    set(TEST_NAME utest_${ADDTEST_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>)
+    add_executable(${TEST_NAME} ${TEST_SOURCES} $<TARGET_OBJECTS:yangobj>)
+    foreach(TEST_SOURCE ${ADDTEST_SOURCES})
+        message(STATUS "SRC: ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SOURCE}")
+        target_sources(${TEST_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SOURCE})
+    endforeach()
 
-	# Set common attributes of all tests
-    target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} m)
+    # Set common attributes of all tests
+    set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/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)
-        set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${test_wrap}")
-        list(REMOVE_AT tests_wraps 0)
+        if (ADDTEST_WRAP)
+            set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${ADDTEST_WRAP}")
+        endif()
     endif()
-    add_test(NAME ${test_name} COMMAND ${test_name})
+
+    add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
 #    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")
+    set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3")
 
     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})
+            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})
 #            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")
         else(VALGRIND_FOUND)
             message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
         endif(VALGRIND_FOUND)
     endif(ENABLE_VALGRIND_TESTS)
-endforeach()
+endfunction(ly_add_utest)
+
+add_subdirectory(utests)
 
 if(ENABLE_COVERAGE)
     # Destination
diff --git a/tests/utests/CMakeLists.txt b/tests/utests/CMakeLists.txt
index 9a5905a..19b3950 100644
--- a/tests/utests/CMakeLists.txt
+++ b/tests/utests/CMakeLists.txt
@@ -1,48 +1,22 @@
-set(local_tests
-    utest:test_common
-    utest:test_set
-    utest:test_hash_table
-    utest:test_inout
-    utest:test_context
-    utest:test_xml
-    utest:test_xpath
-    utest:test_yanglib
-    utest:schema/test_schema
-    utest:schema/test_parser_yang
-    utest:schema/test_parser_yin
-    utest:schema/test_tree_schema_compile
-    utest:schema/test_printer_yang
-    utest:schema/test_printer_yin
-    utest:data/test_tree_data
-    utest:data/test_new
-    utest:data/test_parser_xml
-    utest:data/test_printer_xml
-    utest:data/test_validation
-    utest:data/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)
+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 xpath SOURCES test_xpath.c)
+ly_add_utest(NAME yanglib SOURCES 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 parses_yang SOURCES schema/test_parser_yang.c)
+ly_add_utest(NAME parses_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)
+ly_add_utest(NAME printer_xml SOURCES data/test_printer_xml.c)
+ly_add_utest(NAME validation SOURCES data/test_validation.c)
+ly_add_utest(NAME types SOURCES data/test_types.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/schema/test_schema.c b/tests/utests/schema/test_schema.c
index 559b193..ffb7195 100644
--- a/tests/utests/schema/test_schema.c
+++ b/tests/utests/schema/test_schema.c
@@ -12,6 +12,8 @@
  *     https://opensource.org/licenses/BSD-3-Clause
  */
 
+#include "test_schema.h"
+
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -20,23 +22,17 @@
 
 #include <string.h>
 
-#include "../../../src/common.h"
-#include "../../../src/context.h"
-#include "../../../src/log.h"
-#include "../../../src/parser_yin.h"
-#include "../../../src/tree_schema.h"
-#include "../../../src/tree_schema_internal.h"
-#include "../../../src/xml.h"
+#include "config.h"
+#include "log.h"
+#include "parser_schema.h"
+#include "tree_schema.h"
 
+#if ENABLE_LOGGER_CHECKING
 
 #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)
 {
@@ -82,20 +78,34 @@
 void
 logbuf_clean(void)
 {
+#if ENABLE_LOGGER_CHECKING
     logbuf[0] = '\0';
+#endif
 }
 
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+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;
+}
 
 /**
- * INCLUDE OTHER SCHEMA TESTS
+ * DECLARE OTHER SCHEMA TESTS
  */
-#include "test_schema_common.c"
-#include "test_schema_stmts.c"
+/* test_schema_common.c */
+void test_getnext(void **state);
+void test_date(void **state);
+void test_revisions(void **state);
+void test_typedef(void **state);
+
+/* test_schema_stmts.c */
+void test_identity(void **state);
+void test_feature(void **state);
 
 int main(void)
 {
diff --git a/tests/utests/schema/macros.h b/tests/utests/schema/test_schema.h
similarity index 78%
rename from tests/utests/schema/macros.h
rename to tests/utests/schema/test_schema.h
index 4a0424f..b6f1929 100644
--- a/tests/utests/schema/macros.h
+++ b/tests/utests/schema/test_schema.h
@@ -11,8 +11,29 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-#ifndef TESTS_UTESTS_SCHEMA_MACROS_H_
-#define TESTS_UTESTS_SCHEMA_MACROS_H_
+#ifndef TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
+#define TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
+
+#include "config.h"
+#include "log.h"
+#include "parser_schema.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));
+
 
 #define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
     "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
@@ -69,4 +90,4 @@
 #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.");
 
-#endif /* TESTS_UTESTS_SCHEMA_MACROS_H_ */
+#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 9b2bc6b..1623905 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -20,7 +20,14 @@
 
 #include <string.h>
 
-static void
+#include "context.h"
+#include "log.h"
+#include "tree_schema.h"
+#include "tree_schema_internal.h"
+
+#include "test_schema.h"
+
+void
 test_getnext(void **state)
 {
     *state = test_getnext;
@@ -138,7 +145,7 @@
     *state = NULL;
     ly_ctx_destroy(ctx, NULL);
 }
-static void
+void
 test_date(void **state)
 {
     *state = test_date;
@@ -169,7 +176,7 @@
     *state = NULL;
 }
 
-static void
+void
 test_revisions(void **state)
 {
     (void) state; /* unused */
@@ -198,17 +205,7 @@
     LY_ARRAY_FREE(revs);
 }
 
-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
+void
 test_typedef(void **state)
 {
     *state = test_typedef;
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
index eab21c9..a588e42 100644
--- a/tests/utests/schema/test_schema_stmts.c
+++ b/tests/utests/schema/test_schema_stmts.c
@@ -20,10 +20,14 @@
 
 #include <string.h>
 
-#include "macros.h"
+#include "log.h"
+#include "context.h"
+#include "test_schema.h"
+#include "tree_schema.h"
 
+#include "test_schema.h"
 
-static void
+void
 test_identity(void **state)
 {
     *state = test_identity;
@@ -136,7 +140,7 @@
 }
 
 
-static void
+void
 test_feature(void **state)
 {
     *state = test_feature;