Kaynağa Gözat

use cmake tests for unit tests

Julius Pfrommer 10 yıl önce
ebeveyn
işleme
1d0c0e9165
3 değiştirilmiş dosya ile 47 ekleme ve 11 silme
  1. 12 1
      CMakeLists.txt
  2. 32 7
      tests/CMakeLists.txt
  3. 3 3
      tests/check_base64.c

+ 12 - 1
CMakeLists.txt

@@ -5,7 +5,11 @@ project(open62541)
 set(open62541_VERSION_MAJOR 0)
 set(open62541_VERSION_MINOR 1)
 
-set(CMAKE_VERBOSE_MAKEFILE on )
+# set(CMAKE_VERBOSE_MAKEFILE on )
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules")
+
+# compiler options
 if(CMAKE_COMPILER_IS_GNUCC)
 add_definitions(-std=c99 -pedantic -pipe -fstack-protector -Wall -Wextra
                  -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
@@ -151,3 +155,10 @@ if(GENERATE_DOCUMENTATION)
                       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
                       COMMENT "Generating API documentation with Doxygen")
 endif(GENERATE_DOCUMENTATION)
+
+# run unit tests
+option(UNIT_TESTS "Run unit tests after building" OFF)
+if(UNIT_TESTS)
+    enable_testing()
+    add_subdirectory(tests)
+endif(UNIT_TESTS)

+ 32 - 7
tests/CMakeLists.txt

@@ -1,8 +1,33 @@
-enable_testing()
 find_package(Check REQUIRED)
-include_directories(${CHECK_INCLUDE_DIRS})
-set(LIBS ${LIBS} ${CHECK_LIBRARIES} isti_clib)
-include_directories(. ../src)
-add_executable(test_isti_str test_isti_str.c)
-target_link_libraries(test_isti_str ${LIBS})
-add_test(test_isti_str ${CMAKE_CURRENT_BINARY_DIR}/test_isti_str)
+
+add_executable(check_builtin check_builtin.c)
+target_link_libraries(check_builtin open62541 check)
+add_test(builtin ${CMAKE_CURRENT_BINARY_DIR}/check_builtin)
+
+add_executable(check_memory check_memory.c)
+target_link_libraries(check_memory open62541 check)
+add_test(memory ${CMAKE_CURRENT_BINARY_DIR}/check_memory)
+
+add_executable(check_stack check_stack.c)
+target_link_libraries(check_stack open62541 check)
+add_test(stack ${CMAKE_CURRENT_BINARY_DIR}/check_stack)
+
+add_executable(check_list check_list.c)
+target_link_libraries(check_list open62541 check)
+add_test(list ${CMAKE_CURRENT_BINARY_DIR}/check_list)
+
+add_executable(check_indexedList check_indexedList.c)
+target_link_libraries(check_indexedList open62541 check)
+add_test(indexedList ${CMAKE_CURRENT_BINARY_DIR}/check_indexedList)
+
+add_executable(check_base64 check_base64.c)
+target_link_libraries(check_base64 open62541 check)
+add_test(base64 ${CMAKE_CURRENT_BINARY_DIR}/check_base64)
+
+add_executable(check_services_view check_services_view.c)
+target_link_libraries(check_services_view open62541 check)
+add_test(services_view ${CMAKE_CURRENT_BINARY_DIR}/check_services_view)
+
+add_executable(check_namespace check_namespace.c)
+target_link_libraries(check_namespace open62541 check)
+add_test(namespace ${CMAKE_CURRENT_BINARY_DIR}/check_namespace)

+ 3 - 3
tests/check_base64.c

@@ -5,7 +5,7 @@
 START_TEST(base64_test_2padding)
 {
 	//this is base64'd ASCII string "open62541!"
-	UA_String encodedString = UA_STRING_STATIC("b3BlbjYyNTQxIQ==");
+	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQxIQ==");
 
 	//assure that we allocate exactly 10 bytes
 	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 10);
@@ -34,7 +34,7 @@ START_TEST(base64_test_1padding)
 {
 
 	//this is base64'd ASCII string "open62541!!"
-	UA_String encodedString = UA_STRING_STATIC("b3BlbjYyNTQxISE=");
+	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQxISE=");
 
 	//assure that we allocate exactly 11 bytes
 	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 11);
@@ -64,7 +64,7 @@ START_TEST(base64_test_0padding)
 {
 
 	//this is base64'd ASCII string "open62541"
-	UA_String encodedString = UA_STRING_STATIC("b3BlbjYyNTQx");
+	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQx");
 
 	//assure that we allocate exactly 9 bytes
 	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 9);