diff --git a/.gitmodules b/.gitmodules index a144f126..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "unittest-cpp"] - path = unittest-cpp - url = https://github.com/unittest-cpp/unittest-cpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3456c7be..61c57638 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,14 @@ project(etl) set(ETL_PROFILE "DEFAULT" CACHE STRING "Defines what profile header to include. See https://www.etlcpp.com/setup.html" ) +option(BUILD_TESTS "Build unit tests" ON) + + +# Note: this will not compile src/c/ecl_timer.c as that c file has a dependence +# on ecl_user.h which is provided by clients of this library add_library(etl src/binary.cpp + src/crc16.cpp src/crc16_ccitt.cpp src/crc16_kermit.cpp src/crc32.cpp @@ -28,7 +34,7 @@ add_library(etl ) target_include_directories(etl PUBLIC - include/etl/ + include/etl include/etl/atomic include/etl/profiles PRIVATE @@ -63,3 +69,9 @@ target_compile_definitions(etl ${ETL_PROFILE} ) + + +if (BUILD_TESTS) + enable_testing() + add_subdirectory(test) +endif() diff --git a/include/etl/debug_count.h b/include/etl/debug_count.h index e3672d32..b603b00c 100644 --- a/include/etl/debug_count.h +++ b/include/etl/debug_count.h @@ -122,6 +122,7 @@ namespace etl int32_t count; }; + } #else diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..9fb4fb86 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,157 @@ +cmake_minimum_required(VERSION 3.5.0) +project(etl_unit_tests) + +# Bring in the UnitTest++ include directories and libraries +find_package(UnitTest++) + +if(NOT UnitTest++_FOUND) + # Add unittest-cpp as an ExternalProject + include(cmake/unit-test_external_project.cmake) + add_unittest_cpp() +else() + include(${UnitTest++_CONFIG}) + # The CMake install of UnitTest++ puts the include directory to ${CMAKE_INSTALL_PREFIX}/include + # under the assumptions that clients will consume the headers via + # #include + # However the tests in etl include the headers directly, e.g. + # #include "UnitTest++.h" + # Therefore we update the provide UTPP_INCLUDE_DIRS here + set(UTPP_INCLUDE_DIRS "${UTPP_INCLUDE_DIRS}/UnitTest++") +endif() +include_directories(${UTPP_INCLUDE_DIRS}) + +set(TEST_SOURCE_FILES + main.cpp + murmurhash3.cpp + test_algorithm.cpp + test_alignment.cpp + test_array.cpp + test_array_view.cpp + test_array_wrapper.cpp + test_binary.cpp + test_bitset.cpp + test_bloom_filter.cpp + test_bsd_checksum.cpp + test_callback_timer.cpp + test_checksum.cpp + test_compare.cpp + test_constant.cpp + test_container.cpp + test_crc.cpp + test_c_timer_framework.cpp + test_cyclic_value.cpp + test_debounce.cpp + test_deque.cpp + test_endian.cpp + test_enum_type.cpp + test_error_handler.cpp + test_exception.cpp + test_factory.cpp + test_fixed_iterator.cpp + test_flat_map.cpp + test_flat_multimap.cpp + test_flat_multiset.cpp + test_flat_set.cpp + test_fnv_1.cpp + test_forward_list.cpp + test_fsm.cpp + test_functional.cpp + test_function.cpp + test_hash.cpp + test_instance_count.cpp + test_integral_limits.cpp + test_intrusive_forward_list.cpp + test_intrusive_links.cpp + test_intrusive_list.cpp + test_intrusive_queue.cpp + test_intrusive_stack.cpp + test_io_port.cpp + test_iterator.cpp + test_jenkins.cpp + test_largest.cpp + test_list.cpp + test_map.cpp + test_maths.cpp + test_memory.cpp + test_message_bus.cpp + test_message_router.cpp + test_message_timer.cpp + test_multimap.cpp + test_multiset.cpp + test_murmur3.cpp + test_numeric.cpp + test_observer.cpp + test_optional.cpp + test_packet.cpp + test_parameter_type.cpp + test_pearson.cpp + test_pool.cpp + test_priority_queue.cpp + test_queue.cpp + test_random.cpp + test_reference_flat_map.cpp + test_reference_flat_multimap.cpp + test_reference_flat_multiset.cpp + test_reference_flat_set.cpp + test_set.cpp + test_smallest.cpp + test_stack.cpp + test_string_char.cpp + test_string_u16.cpp + test_string_u32.cpp + test_string_wchar_t.cpp + test_task_scheduler.cpp + test_type_def.cpp + test_type_lookup.cpp + test_type_traits.cpp + test_unordered_map.cpp + test_unordered_multimap.cpp + test_unordered_multiset.cpp + test_unordered_set.cpp + test_user_type.cpp + test_utility.cpp + test_variant.cpp + test_variant_pool.cpp + test_vector.cpp + test_vector_non_trivial.cpp + test_vector_pointer.cpp + test_visitor.cpp + test_xor_checksum.cpp + test_xor_rotate_checksum.cpp + + # Compile the source level ecl_timer here as test has provided a ecl_user.h file + ${CMAKE_SOURCE_DIR}/src/c/ecl_timer.c + ) + +if (WIN32) + # test_error_handler.cpp uses windows APIs that assume the microsoft project + # is setup for unicode support. Note: This may have adverse effects on client + # projects and the tests should be updated to be independent of project setup + ADD_DEFINITIONS(-DUNICODE) + ADD_DEFINITIONS(-D_UNICODE) +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + list(APPEND TEST_SOURCE_FILES "test_atomic_gcc.cpp") +endif() +add_executable(etl_tests + ${TEST_SOURCE_FILES} + ) +target_link_libraries(etl_tests etl UnitTest++) +target_include_directories(etl_tests + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ) + +# Enable the 'make test' CMake target using the executable defined above +add_test(etl_unit_tests etl_tests) + +# Since ctest will only show you the results of the single executable +# define a target that will output all of the failing or passing tests +# as they appear from UnitTest++ +add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose) + + +# Remaining Tests to be implemented: +#1. Enable embedded compile target testing +# - test_embedded_compile.cpp diff --git a/test/ExtraCheckMacros.h b/test/ExtraCheckMacros.h index b8051f6a..17fcd51a 100644 --- a/test/ExtraCheckMacros.h +++ b/test/ExtraCheckMacros.h @@ -1,14 +1,14 @@ #ifndef UNITTEST_EXTRA_CHECKMACROS_H #define UNITTEST_EXTRA_CHECKMACROS_H -#include "../unittest-cpp/UnitTest++/HelperMacros.h" -#include "../unittest-cpp/UnitTest++/ExceptionMacros.h" -#include "../unittest-cpp/UnitTest++/Checks.h" -#include "../unittest-cpp/UnitTest++/AssertException.h" -#include "../unittest-cpp/UnitTest++/MemoryOutStream.h" -#include "../unittest-cpp/UnitTest++/TestDetails.h" -#include "../unittest-cpp/UnitTest++/CurrentTest.h" -#include "../unittest-cpp/UnitTest++/ReportAssertImpl.h" +#include "HelperMacros.h" +#include "ExceptionMacros.h" +#include "Checks.h" +#include "AssertException.h" +#include "MemoryOutStream.h" +#include "TestDetails.h" +#include "CurrentTest.h" +#include "ReportAssertImpl.h" #ifndef CHECK_NO_THROW #define CHECK_NO_THROW(expression) \ diff --git a/test/cmake/unit-test_external_project.cmake b/test/cmake/unit-test_external_project.cmake new file mode 100644 index 00000000..119c64ee --- /dev/null +++ b/test/cmake/unit-test_external_project.cmake @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.5.0) +find_package(Git REQUIRED) +include(ExternalProject) + + +##### +# \breif Function used to add UnitTest++ as an External Project, install it into the +# binary location of the CMake build, add its header directories in the +# include_directories, and finally add the built static library as an imported +# CMake target +##### +function (add_unittest_cpp) + + set(UTPP_INSATLL_DIR "${CMAKE_CURRENT_BINARY_DIR}/unittest++/install") + if (WIN32) + set(UTPP_LIB_NAME "UnitTest++.lib") + else() + set(UTPP_LIB_NAME "libUnitTest++.a") + endif() + + + ExternalProject_Add(unittest-cpp + GIT_REPOSITORY https://github.com/unittest-cpp/unittest-cpp.git + GIT_TAG v2.0.0 + GIT_SHALLOW TRUE # Don't require downloading the entire history + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/unittest++/src" + INSTALL_DIR "${UTPP_INSATLL_DIR}" + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + TEST_EXCLUDE_FROM_MAIN TRUE # Don't run UnitTest++'s tests by default + ) + + set(UTPP_INCLUDE_DIRS "${UTPP_INSATLL_DIR}/include/UnitTest++" PARENT_SCOPE) + add_library(UnitTest++ STATIC IMPORTED) + set_target_properties(UnitTest++ PROPERTIES IMPORTED_LOCATION "${UTPP_INSATLL_DIR}/lib/${UTPP_LIB_NAME}" ) + # Require the ExternalProject target to complete before importing the library + add_dependencies(UnitTest++ unittest-cpp) + +endfunction(add_unittest_cpp) diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index b4758871..20b6dfb2 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -61,19 +61,90 @@ - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -248,76 +319,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index eee0ad5c..4c47ec11 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -161,7 +161,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test + ../../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test false @@ -203,7 +203,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test + ../../../unittest-cpp\UnitTest++;../../include/etl;../../include/etl/c;../../test false @@ -245,7 +245,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - ../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test + ../../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test @@ -323,6 +323,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -379,35 +411,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -428,7 +431,6 @@ - @@ -488,8 +490,6 @@ - - @@ -505,12 +505,31 @@ - - + + + + + + + + + + + + + + + + + + + + + @@ -524,24 +543,6 @@ - - - - - - - - - - - - - - - - - - @@ -725,7 +726,6 @@ - diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 7ba6c7d5..d8a39e36 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -75,9 +75,6 @@ - - Header Files - ETL\Utilities @@ -156,9 +153,6 @@ ETL\Containers - - Header Files - ETL\Containers @@ -216,9 +210,6 @@ ETL\Maths - - Header Files - ETL\Containers @@ -297,12 +288,6 @@ ETL\Containers - - Header Files - - - Header Files - ETL\Utilities @@ -366,93 +351,6 @@ ETL\Containers - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - ETL\Frameworks @@ -633,6 +531,102 @@ ETL\Maths + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -908,60 +902,6 @@ Source Files - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - - - UnitTest++ - Source Files @@ -1037,11 +977,71 @@ ETL\Maths + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++ + + + UnitTest++\Win32 + - - Header Files - Resource Files diff --git a/unittest-cpp b/unittest-cpp deleted file mode 160000 index bc5d87f4..00000000 --- a/unittest-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bc5d87f484cac2959b0a0eafbde228e69e828d74