git subrepo clone --branch=20.41.6 git@github.com:ETLCPP/etl.git components/etl
subrepo: subdir: "components/etl" merged: "be5537ec" upstream: origin: "git@github.com:ETLCPP/etl.git" branch: "20.41.6" commit: "be5537ec" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
This commit is contained in:
parent
931c4def56
commit
11c24647ea
1296 changed files with 801882 additions and 0 deletions
1
components/etl/test/.gitattributes
vendored
Normal file
1
components/etl/test/.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.tar filter=lfs diff=lfs merge=lfs -text
|
487
components/etl/test/CMakeLists.txt
Normal file
487
components/etl/test/CMakeLists.txt
Normal file
|
@ -0,0 +1,487 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(etl_unit_tests LANGUAGES CXX)
|
||||
|
||||
#include(FetchContent)
|
||||
#FetchContent_Declare(
|
||||
# googletest
|
||||
# URL https://github.com/google/googletest/archive/refs/heads/main.zip
|
||||
#)
|
||||
|
||||
#set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
#FetchContent_MakeAvailable(googletest)
|
||||
|
||||
add_executable(etl_tests
|
||||
main.cpp
|
||||
murmurhash3.cpp
|
||||
test_algorithm.cpp
|
||||
test_alignment.cpp
|
||||
test_array.cpp
|
||||
test_array_view.cpp
|
||||
test_array_wrapper.cpp
|
||||
test_atomic.cpp
|
||||
test_base64_RFC2152_decoder.cpp
|
||||
test_base64_RFC2152_encoder.cpp
|
||||
test_base64_RFC3501_decoder.cpp
|
||||
test_base64_RFC3501_encoder.cpp
|
||||
test_base64_RFC4648_decoder_with_no_padding.cpp
|
||||
test_base64_RFC4648_decoder_with_padding.cpp
|
||||
test_base64_RFC4648_encoder_with_no_padding.cpp
|
||||
test_base64_RFC4648_encoder_with_padding.cpp
|
||||
test_base64_RFC4648_URL_decoder_with_no_padding.cpp
|
||||
test_base64_RFC4648_URL_decoder_with_padding.cpp
|
||||
test_base64_RFC4648_URL_encoder_with_no_padding.cpp
|
||||
test_base64_RFC4648_URL_encoder_with_padding.cpp
|
||||
test_binary.cpp
|
||||
test_bip_buffer_spsc_atomic.cpp
|
||||
test_bit.cpp
|
||||
test_bitset_legacy.cpp
|
||||
test_bitset_new_comparisons.cpp
|
||||
test_bitset_new_default_element_type.cpp
|
||||
test_bitset_new_explicit_single_element_type.cpp
|
||||
test_bitset_new_ext_default_element_type.cpp
|
||||
test_bitset_new_ext_explicit_single_element_type.cpp
|
||||
test_bit_stream.cpp
|
||||
test_bit_stream_reader_big_endian.cpp
|
||||
test_bit_stream_reader_little_endian.cpp
|
||||
test_bit_stream_writer_big_endian.cpp
|
||||
test_bit_stream_writer_little_endian.cpp
|
||||
test_bloom_filter.cpp
|
||||
test_bresenham_line.cpp
|
||||
test_bsd_checksum.cpp
|
||||
test_buffer_descriptors.cpp
|
||||
test_byte.cpp
|
||||
test_byte_stream.cpp
|
||||
test_callback_service.cpp
|
||||
test_callback_timer.cpp
|
||||
test_callback_timer_atomic.cpp
|
||||
test_callback_timer_interrupt.cpp
|
||||
test_callback_timer_locked.cpp
|
||||
test_char_traits.cpp
|
||||
test_checksum.cpp
|
||||
test_chrono_clocks.cpp
|
||||
test_chrono_day.cpp
|
||||
test_chrono_duration.cpp
|
||||
test_chrono_hh_mm_ss.cpp
|
||||
test_chrono_literals.cpp
|
||||
test_chrono_month.cpp
|
||||
test_chrono_month_day.cpp
|
||||
test_chrono_month_day_last.cpp
|
||||
test_chrono_month_weekday.cpp
|
||||
test_chrono_month_weekday_last.cpp
|
||||
test_chrono_operators.cpp
|
||||
test_chrono_time_point.cpp
|
||||
test_chrono_weekday.cpp
|
||||
test_chrono_weekday_indexed.cpp
|
||||
test_chrono_weekday_last.cpp
|
||||
test_chrono_year.cpp
|
||||
test_chrono_year_month.cpp
|
||||
test_chrono_year_month_day.cpp
|
||||
test_chrono_year_month_day_last.cpp
|
||||
test_chrono_year_month_weekday.cpp
|
||||
test_chrono_year_month_weekday_last.cpp
|
||||
test_circular_buffer.cpp
|
||||
test_circular_buffer_external_buffer.cpp
|
||||
test_circular_iterator.cpp
|
||||
test_compare.cpp
|
||||
test_constant.cpp
|
||||
test_container.cpp
|
||||
test_correlation.cpp
|
||||
test_covariance.cpp
|
||||
test_crc1.cpp
|
||||
test_crc16.cpp
|
||||
test_crc16_a.cpp
|
||||
test_crc16_arc.cpp
|
||||
test_crc16_aug_ccitt.cpp
|
||||
test_crc16_buypass.cpp
|
||||
test_crc16_ccitt.cpp
|
||||
test_crc16_cdma2000.cpp
|
||||
test_crc16_dds110.cpp
|
||||
test_crc16_dectr.cpp
|
||||
test_crc16_dectx.cpp
|
||||
test_crc16_dnp.cpp
|
||||
test_crc16_en13757.cpp
|
||||
test_crc16_genibus.cpp
|
||||
test_crc16_kermit.cpp
|
||||
test_crc16_m17.cpp
|
||||
test_crc16_maxim.cpp
|
||||
test_crc16_mcrf4xx.cpp
|
||||
test_crc16_modbus.cpp
|
||||
test_crc16_profibus.cpp
|
||||
test_crc16_riello.cpp
|
||||
test_crc16_t10dif.cpp
|
||||
test_crc16_teledisk.cpp
|
||||
test_crc16_tms37157.cpp
|
||||
test_crc16_usb.cpp
|
||||
test_crc16_x25.cpp
|
||||
test_crc16_xmodem.cpp
|
||||
test_crc32.cpp
|
||||
test_crc32_bzip2.cpp
|
||||
test_crc32_c.cpp
|
||||
test_crc32_d.cpp
|
||||
test_crc32_jamcrc.cpp
|
||||
test_crc32_mpeg2.cpp
|
||||
test_crc32_posix.cpp
|
||||
test_crc32_q.cpp
|
||||
test_crc32_xfer.cpp
|
||||
test_crc64_ecma.cpp
|
||||
test_crc8_ccitt.cpp
|
||||
test_crc8_cdma2000.cpp
|
||||
test_crc8_darc.cpp
|
||||
test_crc8_dvbs2.cpp
|
||||
test_crc8_ebu.cpp
|
||||
test_crc8_icode.cpp
|
||||
test_crc8_itu.cpp
|
||||
test_crc8_j1850.cpp
|
||||
test_crc8_j1850_zero.cpp
|
||||
test_crc8_maxim.cpp
|
||||
test_crc8_rohc.cpp
|
||||
test_crc8_wcdma.cpp
|
||||
test_cyclic_value.cpp
|
||||
test_debounce.cpp
|
||||
test_delegate.cpp
|
||||
test_delegate_cpp03.cpp
|
||||
test_delegate_service.cpp
|
||||
test_delegate_service_compile_time.cpp
|
||||
test_delegate_service_cpp03.cpp
|
||||
test_deque.cpp
|
||||
test_endian.cpp
|
||||
test_enum_type.cpp
|
||||
test_error_handler.cpp
|
||||
test_etl_traits.cpp
|
||||
test_exception.cpp
|
||||
test_expected.cpp
|
||||
test_fixed_iterator.cpp
|
||||
test_fixed_sized_memory_block_allocator.cpp
|
||||
test_flags.cpp
|
||||
test_flat_map.cpp
|
||||
test_flat_multimap.cpp
|
||||
test_flat_multiset.cpp
|
||||
test_flat_set.cpp
|
||||
test_fnv_1.cpp
|
||||
test_format_spec.cpp
|
||||
test_forward_list.cpp
|
||||
test_forward_list_shared_pool.cpp
|
||||
test_fsm.cpp
|
||||
test_function.cpp
|
||||
test_functional.cpp
|
||||
test_function_traits.cpp
|
||||
test_gamma.cpp
|
||||
test_hash.cpp
|
||||
test_hfsm.cpp
|
||||
test_hfsm_recurse_to_inner_state_on_start.cpp
|
||||
test_histogram.cpp
|
||||
test_index_of_type.cpp
|
||||
test_indirect_vector.cpp
|
||||
test_indirect_vector_external_buffer.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_invert.cpp
|
||||
test_io_port.cpp
|
||||
test_iterator.cpp
|
||||
test_jenkins.cpp
|
||||
test_largest.cpp
|
||||
test_limiter.cpp
|
||||
test_limits.cpp
|
||||
test_list.cpp
|
||||
test_list_shared_pool.cpp
|
||||
test_macros.cpp
|
||||
test_make_string.cpp
|
||||
test_map.cpp
|
||||
test_math.cpp
|
||||
test_math_functions.cpp
|
||||
test_mean.cpp
|
||||
test_memory.cpp
|
||||
test_mem_cast.cpp
|
||||
test_mem_cast_ptr.cpp
|
||||
test_message.cpp
|
||||
test_message_broker.cpp
|
||||
test_message_bus.cpp
|
||||
test_message_packet.cpp
|
||||
test_message_router.cpp
|
||||
test_message_router_registry.cpp
|
||||
test_message_timer.cpp
|
||||
test_message_timer_atomic.cpp
|
||||
test_message_timer_interrupt.cpp
|
||||
test_message_timer_locked.cpp
|
||||
test_multimap.cpp
|
||||
test_multiset.cpp
|
||||
test_multi_array.cpp
|
||||
test_multi_range.cpp
|
||||
test_multi_span.cpp
|
||||
test_multi_vector.cpp
|
||||
test_murmur3.cpp
|
||||
test_nth_type.cpp
|
||||
test_numeric.cpp
|
||||
test_observer.cpp
|
||||
test_optional.cpp
|
||||
test_overload.cpp
|
||||
test_packet.cpp
|
||||
test_parameter_pack.cpp
|
||||
test_parameter_type.cpp
|
||||
test_parity_checksum.cpp
|
||||
test_pearson.cpp
|
||||
test_poly_span_dynamic_extent.cpp
|
||||
test_poly_span_fixed_extent.cpp
|
||||
test_pool.cpp
|
||||
test_pool_external_buffer.cpp
|
||||
test_priority_queue.cpp
|
||||
test_pseudo_moving_average.cpp
|
||||
test_quantize.cpp
|
||||
test_queue.cpp
|
||||
test_queue_lockable.cpp
|
||||
test_queue_lockable_small.cpp
|
||||
test_queue_memory_model_small.cpp
|
||||
test_queue_mpmc_mutex.cpp
|
||||
test_queue_mpmc_mutex_small.cpp
|
||||
test_queue_spsc_atomic.cpp
|
||||
test_queue_spsc_atomic_small.cpp
|
||||
test_queue_spsc_isr.cpp
|
||||
test_queue_spsc_isr_small.cpp
|
||||
test_queue_spsc_locked.cpp
|
||||
test_queue_spsc_locked_small.cpp
|
||||
test_random.cpp
|
||||
test_ratio.cpp
|
||||
test_reference_flat_map.cpp
|
||||
test_reference_flat_multimap.cpp
|
||||
test_reference_flat_multiset.cpp
|
||||
test_reference_flat_set.cpp
|
||||
test_rescale.cpp
|
||||
test_result.cpp
|
||||
test_rms.cpp
|
||||
test_scaled_rounding.cpp
|
||||
test_set.cpp
|
||||
test_shared_message.cpp
|
||||
test_singleton.cpp
|
||||
test_singleton_base.cpp
|
||||
test_smallest.cpp
|
||||
test_span_dynamic_extent.cpp
|
||||
test_span_fixed_extent.cpp
|
||||
test_stack.cpp
|
||||
test_standard_deviation.cpp
|
||||
test_state_chart.cpp
|
||||
test_state_chart_compile_time.cpp
|
||||
test_state_chart_compile_time_with_data_parameter.cpp
|
||||
test_state_chart_with_data_parameter.cpp
|
||||
test_state_chart_with_rvalue_data_parameter.cpp
|
||||
test_string_char.cpp
|
||||
test_string_char_external_buffer.cpp
|
||||
test_string_stream.cpp
|
||||
test_string_stream_u16.cpp
|
||||
test_string_stream_u32.cpp
|
||||
test_string_stream_u8.cpp
|
||||
test_string_stream_wchar_t.cpp
|
||||
test_string_u16.cpp
|
||||
test_string_u16_external_buffer.cpp
|
||||
test_string_u32.cpp
|
||||
test_string_u32_external_buffer.cpp
|
||||
test_string_u8.cpp
|
||||
test_string_u8_external_buffer.cpp
|
||||
test_string_utilities.cpp
|
||||
test_string_utilities_std.cpp
|
||||
test_string_utilities_std_u16.cpp
|
||||
test_string_utilities_std_u32.cpp
|
||||
test_string_utilities_std_u8.cpp
|
||||
test_string_utilities_std_wchar_t.cpp
|
||||
test_string_utilities_u16.cpp
|
||||
test_string_utilities_u32.cpp
|
||||
test_string_utilities_u8.cpp
|
||||
test_string_utilities_wchar_t.cpp
|
||||
test_string_view.cpp
|
||||
test_string_wchar_t.cpp
|
||||
test_string_wchar_t_external_buffer.cpp
|
||||
test_successor.cpp
|
||||
test_task_scheduler.cpp
|
||||
test_threshold.cpp
|
||||
test_to_arithmetic.cpp
|
||||
test_to_arithmetic_u16.cpp
|
||||
test_to_arithmetic_u32.cpp
|
||||
test_to_arithmetic_u8.cpp
|
||||
test_to_arithmetic_wchar_t.cpp
|
||||
test_to_string.cpp
|
||||
test_to_u16string.cpp
|
||||
test_to_u32string.cpp
|
||||
test_to_u8string.cpp
|
||||
test_to_wstring.cpp
|
||||
test_tuple.cpp
|
||||
test_type_def.cpp
|
||||
test_type_list.cpp
|
||||
test_type_lookup.cpp
|
||||
test_type_select.cpp
|
||||
test_type_traits.cpp
|
||||
test_unaligned_type.cpp
|
||||
test_unaligned_type_ext.cpp
|
||||
test_uncopyable.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_variance.cpp
|
||||
test_variant_legacy.cpp
|
||||
test_variant_pool.cpp
|
||||
test_variant_pool_external_buffer.cpp
|
||||
test_variant_variadic.cpp
|
||||
test_vector.cpp
|
||||
test_vector_external_buffer.cpp
|
||||
test_vector_non_trivial.cpp
|
||||
test_vector_pointer.cpp
|
||||
test_vector_pointer_external_buffer.cpp
|
||||
test_visitor.cpp
|
||||
test_xor_checksum.cpp
|
||||
test_xor_rotate_checksum.cpp
|
||||
)
|
||||
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_DEBUG)
|
||||
|
||||
option(ETL_NO_STL "No STL" OFF)
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++03 (C++98)")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
if (NO_STL OR ETL_NO_STL)
|
||||
message(STATUS "Compiling for No STL")
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_NO_STL)
|
||||
else()
|
||||
message(STATUS "Compiling for STL")
|
||||
endif()
|
||||
|
||||
if (ETL_USE_TYPE_TRAITS_BUILTINS)
|
||||
message(STATUS "Compiling for built-in type traits")
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_USE_TYPE_TRAITS_BUILTINS)
|
||||
endif()
|
||||
|
||||
if (ETL_USER_DEFINED_TYPE_TRAITS)
|
||||
message(STATUS "Compiling for user defined type traits")
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_USER_DEFINED_TYPE_TRAITS)
|
||||
endif()
|
||||
|
||||
if (ETL_MESSAGES_ARE_NOT_VIRTUAL)
|
||||
message(STATUS "Compiling for non-virtual messages")
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_MESSAGES_ARE_NOT_VIRTUAL)
|
||||
endif()
|
||||
|
||||
if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
message(STATUS "Compiling for C++03 tests")
|
||||
target_compile_definitions(etl_tests PRIVATE -DETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
|
||||
message(STATUS "Using MSVC compiler")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
/Zc:__cplusplus
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
-g
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
-g
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/../include)
|
||||
|
||||
add_subdirectory(UnitTest++)
|
||||
target_link_libraries(etl_tests PRIVATE UnitTestpp)
|
||||
|
||||
# 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)
|
||||
|
426
components/etl/test/Deprecated/test_embedded_compile.cpp
Normal file
426
components/etl/test/Deprecated/test_embedded_compile.cpp
Normal file
|
@ -0,0 +1,426 @@
|
|||
|
||||
|
||||
#include "etl/algorithm.h"
|
||||
#include "etl/alignment.h"
|
||||
#include "etl/array.h"
|
||||
#include "etl/bitset.h"
|
||||
#include "etl/container.h"
|
||||
#include "etl/crc8_ccitt.h"
|
||||
#include "etl/crc16.h"
|
||||
#include "etl/crc16_ccitt.h"
|
||||
#include "etl/crc16_kermit.h"
|
||||
#include "etl/crc32.h"
|
||||
#include "etl/crc64_ecma.h"
|
||||
#include "etl/cyclic_value.h"
|
||||
#include "etl/deque.h"
|
||||
#include "etl/io_port.h"
|
||||
#include "etl/vector.h"
|
||||
#include "etl/variant.h"
|
||||
#include "etl/list.h"
|
||||
#include "etl/map.h"
|
||||
#include "etl/integral_limits.h"
|
||||
#include "etl/constant.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#if !defined(ETL_COMPILER_IAR) & !defined(ETL_COMPILER_TI)
|
||||
#include "etl/stm32f4xx.h"
|
||||
#endif
|
||||
|
||||
#if defined(COMPILER_KEIL)
|
||||
#pragma diag_suppress 550
|
||||
#pragma diag_suppress 177
|
||||
#endif
|
||||
|
||||
#if defined(COMPILER_IAR)
|
||||
#pragma diag_suppress = pe177
|
||||
#endif
|
||||
|
||||
struct Test
|
||||
{
|
||||
Test(int i, double d)
|
||||
: i(i),
|
||||
d(d)
|
||||
{
|
||||
}
|
||||
|
||||
int i;
|
||||
double d;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// algorithm
|
||||
//*****************************************************************************
|
||||
void test_algorithm()
|
||||
{
|
||||
int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int data2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
int data3[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
std::pair<int*, int*> result1;
|
||||
std::pair<int, int> result2;
|
||||
int x = 0;
|
||||
int y = 1;
|
||||
int* p;
|
||||
bool b;
|
||||
|
||||
// minmax_element
|
||||
result1 = etl::minmax_element(etl::begin(data), etl::end(data));
|
||||
result1 = etl::minmax_element(etl::begin(data), etl::end(data), std::greater<int>());
|
||||
|
||||
// minmax
|
||||
result2 = etl::minmax(x, y);
|
||||
result2 = etl::minmax(x, y, std::greater<int>());
|
||||
|
||||
// is_sorted_until
|
||||
p = etl::is_sorted_until(etl::begin(data), etl::end(data));
|
||||
p = etl::is_sorted_until(etl::begin(data), etl::end(data), std::greater<int>());
|
||||
|
||||
// is_sorted
|
||||
b = etl::is_sorted(etl::begin(data), etl::end(data));
|
||||
b = etl::is_sorted(etl::begin(data), etl::end(data), std::greater<int>());
|
||||
|
||||
// copy_n
|
||||
p = etl::copy_n(etl::begin(data), 5, etl::begin(data2));
|
||||
|
||||
// copy_if
|
||||
p = etl::copy_if(etl::begin(data), etl::end(data), etl::begin(data2), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// find_if_not
|
||||
p = etl::find_if_not(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// all_of
|
||||
b = etl::all_of(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// any_of
|
||||
b = etl::any_of(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// none_of
|
||||
b = etl::none_of(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// is_permutation
|
||||
b = etl::is_permutation(etl::begin(data), etl::end(data), etl::begin(data2));
|
||||
b = etl::is_permutation(etl::begin(data), etl::end(data), etl::begin(data2), std::equal_to<int>());
|
||||
b = etl::is_permutation(etl::begin(data), etl::end(data), etl::begin(data2), etl::end(data2));
|
||||
b = etl::is_permutation(etl::begin(data), etl::end(data), etl::begin(data2), etl::end(data2), std::equal_to<int>());
|
||||
|
||||
// is_partitioned
|
||||
b = etl::is_partitioned(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// partition_point
|
||||
p = etl::partition_point(etl::begin(data), etl::end(data), std::bind2nd(std::greater<int>(), 4));
|
||||
|
||||
// partition_copy
|
||||
result1 = etl::partition_copy(etl::begin(data), etl::end(data), etl::begin(data2), etl::begin(data3), std::bind2nd(std::greater<int>(), 4));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// alignment
|
||||
//*****************************************************************************
|
||||
etl::aligned_storage<100, 8>::type data9;
|
||||
etl::aligned_storage_as<100, double>::type data10;
|
||||
|
||||
void test_alignment()
|
||||
{
|
||||
int a = static_cast<int&>(data9);
|
||||
|
||||
etl::aligned_storage<1, 1>::type data1;
|
||||
etl::aligned_storage<1, 2>::type data2;
|
||||
etl::aligned_storage<1, 4>::type data3;
|
||||
etl::aligned_storage<1, 8>::type data4;
|
||||
|
||||
etl::aligned_storage_as<1, char>::type data5;
|
||||
etl::aligned_storage_as<1, short>::type data6;
|
||||
etl::aligned_storage_as<1, int>::type data7;
|
||||
etl::aligned_storage_as<1, double>::type data8;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// array
|
||||
//*****************************************************************************
|
||||
void test_array()
|
||||
{
|
||||
etl::array<int, 10> a;
|
||||
|
||||
int i = a[4];
|
||||
int s = a.size();
|
||||
a.fill(45);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// bitset
|
||||
//*****************************************************************************
|
||||
void test_bitset()
|
||||
{
|
||||
etl::bitset<7> b7;
|
||||
etl::bitset<8> b8;
|
||||
etl::bitset<9> b9;
|
||||
etl::bitset<15> b15;
|
||||
etl::bitset<16> b16;
|
||||
etl::bitset<17> b17;
|
||||
etl::bitset<31> b31;
|
||||
etl::bitset<32> b32;
|
||||
etl::bitset<33> b33;
|
||||
etl::bitset<63> b63;
|
||||
etl::bitset<64> b64;
|
||||
etl::bitset<65> b65;
|
||||
|
||||
b65.set();
|
||||
b65.set(4, true);
|
||||
b65.reset();
|
||||
b65.reset(37);
|
||||
b65 = ~b65;
|
||||
bool b = b65[4];
|
||||
b = b65[64];
|
||||
b65.flip();
|
||||
b65.flip(5);
|
||||
|
||||
etl::ibitset& ib = b65;
|
||||
|
||||
ib.set();
|
||||
ib.set(4, true);
|
||||
ib.reset();
|
||||
ib.reset(37);
|
||||
b = ib[4];
|
||||
b = ib[64];
|
||||
ib.flip();
|
||||
ib.flip(5);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// crc
|
||||
//*****************************************************************************
|
||||
void test_crc()
|
||||
{
|
||||
char data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
uint8_t crc1 = etl::crc8_ccitt(etl::begin(data), etl::end(data));
|
||||
uint8_t crc2 = etl::crc8_ccitt(etl::begin(data), etl::end(data));
|
||||
|
||||
uint16_t crc3 = etl::crc16(etl::begin(data), etl::end(data));
|
||||
uint16_t crc4 = etl::crc16(etl::begin(data), etl::end(data));
|
||||
|
||||
uint16_t crc5 = etl::crc16_ccitt(etl::begin(data), etl::end(data));
|
||||
uint16_t crc6 = etl::crc16_ccitt(etl::begin(data), etl::end(data));
|
||||
|
||||
uint16_t crc7 = etl::crc16_kermit(etl::begin(data), etl::end(data));
|
||||
uint16_t crc8 = etl::crc16_kermit(etl::begin(data), etl::end(data));
|
||||
|
||||
uint32_t crc9 = etl::crc32(etl::begin(data), etl::end(data));
|
||||
uint32_t crc10 = etl::crc32(etl::begin(data), etl::end(data));
|
||||
|
||||
uint64_t crc11 = etl::crc64_ecma(etl::begin(data), etl::end(data));
|
||||
uint64_t crc12 = etl::crc64_ecma(etl::begin(data), etl::end(data));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// deque
|
||||
//*****************************************************************************
|
||||
void test_cyclic_value()
|
||||
{
|
||||
etl::cyclic_value<int, 1, 10> cv1;
|
||||
|
||||
etl::cyclic_value<int> cv2;
|
||||
cv2.set(3, 8);
|
||||
|
||||
cv1.advance(3);
|
||||
cv1.to_first();
|
||||
cv1.to_last();
|
||||
|
||||
--cv1;
|
||||
++cv1;
|
||||
int f = cv1.first();
|
||||
int l = cv1.last();
|
||||
|
||||
int v = cv1;
|
||||
cv1 = v;
|
||||
cv1 = cv2;
|
||||
|
||||
bool b;
|
||||
b = cv1 == cv2;
|
||||
b = cv1 != cv2;
|
||||
}
|
||||
|
||||
template <uintptr_t ADDRESS>
|
||||
struct serial_port
|
||||
{
|
||||
etl::io_port_ro<uint8_t, ADDRESS> rxdata;
|
||||
etl::io_port_wo<uint8_t, ADDRESS + 1> txdata;
|
||||
etl::io_port_rw<uint16_t, ADDRESS + 2> control;
|
||||
etl::io_port_ro<uint16_t, ADDRESS + 4> status;
|
||||
etl::io_port_wos<uint8_t, ADDRESS + 6> control2;
|
||||
};
|
||||
|
||||
struct dynamic_serial_port
|
||||
{
|
||||
dynamic_serial_port(uint8_t* base)
|
||||
: rxdata(base),
|
||||
txdata(base + 1),
|
||||
control(base + 2),
|
||||
status(base + 4),
|
||||
control2(base + 6)
|
||||
{
|
||||
}
|
||||
|
||||
etl::io_port_ro<uint8_t> rxdata;
|
||||
etl::io_port_wo<uint8_t> txdata;
|
||||
etl::io_port_rw<uint16_t> control;
|
||||
etl::io_port_ro<uint16_t> status;
|
||||
etl::io_port_wos<uint8_t> control2;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// io_port
|
||||
//*****************************************************************************
|
||||
void test_io_port()
|
||||
{
|
||||
serial_port<0x1234U> port1;
|
||||
|
||||
uint8_t rxdata = port1.rxdata;
|
||||
port1.txdata = 0x34U;
|
||||
port1.control = 0x5678U; // Little endian.
|
||||
uint16_t status = port1.status;
|
||||
port1.control2 = 0xDEU;
|
||||
int control2 = port1.control2;
|
||||
|
||||
uint8_t memory[7];
|
||||
dynamic_serial_port port2(memory);
|
||||
|
||||
uint8_t rxdata2 = port2.rxdata;
|
||||
port2.txdata = 0x34U;
|
||||
port2.control = 0x5678U; // Little endian.
|
||||
uint16_t status2 = port2.status;
|
||||
port2.control2 = 0xDEU;
|
||||
int control22 = port2.control2;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// variant
|
||||
//*****************************************************************************
|
||||
void test_variant()
|
||||
{
|
||||
typedef etl::variant<int, double, Test> Data;
|
||||
|
||||
Data data;
|
||||
|
||||
data = int(1);
|
||||
int i = data;
|
||||
|
||||
data = double(2.2);
|
||||
double d = data;
|
||||
|
||||
data = Test(3, 3.3);
|
||||
Test test(data);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// deque
|
||||
//*****************************************************************************
|
||||
void test_deque()
|
||||
{
|
||||
typedef etl::deque<Test, 10> Data;
|
||||
|
||||
Data data;
|
||||
|
||||
data.push_back(Test(1, 1.1));
|
||||
data.push_back(Test(2, 2.2));
|
||||
|
||||
Data::iterator it = data.begin();
|
||||
data.erase(it);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// vector
|
||||
//*****************************************************************************
|
||||
void test_vector()
|
||||
{
|
||||
typedef etl::vector<Test, 10> Data;
|
||||
|
||||
Data data;
|
||||
|
||||
data.push_back(Test(1, 1.1));
|
||||
data.push_back(Test(2, 2.2));
|
||||
|
||||
Data::iterator it = data.begin();
|
||||
data.erase(it);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// list
|
||||
//*****************************************************************************
|
||||
void test_list()
|
||||
{
|
||||
typedef etl::list<Test, 10> Data;
|
||||
typedef etl::list<int, 10> Data2;
|
||||
|
||||
Data data;
|
||||
Data2 data2;
|
||||
|
||||
data.push_back(Test(1, 1.1));
|
||||
data.push_front(Test(3, 3.3));
|
||||
data.reverse();
|
||||
|
||||
Data::iterator it = data.begin();
|
||||
data.erase(it);
|
||||
|
||||
data2.push_back(1);
|
||||
data2.push_front(3);
|
||||
data2.reverse();
|
||||
|
||||
Data2::iterator it2 = data2.begin();
|
||||
data2.erase(it2);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// map
|
||||
//*****************************************************************************
|
||||
void test_map()
|
||||
{
|
||||
typedef etl::map<int, int, 10> Data;
|
||||
|
||||
Data data;
|
||||
|
||||
data.insert(std::pair<int, int>(1, 2));
|
||||
data.insert(std::pair<int, int>(3, 4));
|
||||
|
||||
Data::iterator it = data.begin();
|
||||
data.erase(it);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// integral_limits
|
||||
//*****************************************************************************
|
||||
void test_integral_limits()
|
||||
{
|
||||
static unsigned int imax = etl::integral_limits<unsigned int>::max;
|
||||
static unsigned int cmin = etl::integral_limits<char>::min;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// constant
|
||||
//*****************************************************************************
|
||||
void test_constant()
|
||||
{
|
||||
typedef etl::constant<unsigned int, 0x12345678UL> C1;
|
||||
|
||||
unsigned int i1 = C1::value;
|
||||
|
||||
C1 c1;
|
||||
unsigned int i2 = c1.value;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// main
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
test_algorithm();
|
||||
test_alignment();
|
||||
test_array();
|
||||
test_bitset();
|
||||
test_crc();
|
||||
test_cyclic_value();
|
||||
test_deque();
|
||||
test_vector();
|
||||
test_list();
|
||||
test_io_port();
|
||||
}
|
355
components/etl/test/Deprecated/test_factory.cpp
Normal file
355
components/etl/test/Deprecated/test_factory.cpp
Normal file
|
@ -0,0 +1,355 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
http://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "UnitTest++.h"
|
||||
#include "ExtraCheckMacros.h"
|
||||
|
||||
#include "etl/factory.h"
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool destructor;
|
||||
|
||||
//***********************************
|
||||
struct Base
|
||||
{
|
||||
Base()
|
||||
{
|
||||
destructor = false;
|
||||
}
|
||||
|
||||
virtual ~Base()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Set() = 0;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Derived1 : public Base
|
||||
{
|
||||
int i;
|
||||
|
||||
Derived1()
|
||||
: i(0)
|
||||
{
|
||||
}
|
||||
|
||||
~Derived1()
|
||||
{
|
||||
destructor = true;
|
||||
}
|
||||
|
||||
void Set()
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Derived2 : public Base
|
||||
{
|
||||
double d;
|
||||
|
||||
Derived2()
|
||||
: d(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
~Derived2()
|
||||
{
|
||||
destructor = true;
|
||||
}
|
||||
|
||||
void Set()
|
||||
{
|
||||
d = 1.2;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct Derived3 : public Base
|
||||
{
|
||||
std::string s;
|
||||
|
||||
Derived3()
|
||||
: s("constructed")
|
||||
{
|
||||
}
|
||||
|
||||
Derived3(const char* p1)
|
||||
: s("constructed")
|
||||
{
|
||||
s.append(p1);
|
||||
}
|
||||
|
||||
Derived3(const char* p1, const std::string& p2)
|
||||
: s("constructed")
|
||||
{
|
||||
s.append(p1);
|
||||
s.append(p2);
|
||||
}
|
||||
|
||||
Derived3(const char* p1, const std::string& p2, const char* p3)
|
||||
: s("constructed")
|
||||
{
|
||||
s.append(p1);
|
||||
s.append(p2);
|
||||
s.append(p3);
|
||||
}
|
||||
|
||||
Derived3(const char* p1, const std::string& p2, const char* p3, const std::string& p4)
|
||||
: s("constructed")
|
||||
{
|
||||
s.append(p1);
|
||||
s.append(p2);
|
||||
s.append(p3);
|
||||
s.append(p4);
|
||||
}
|
||||
|
||||
~Derived3()
|
||||
{
|
||||
destructor = true;
|
||||
}
|
||||
|
||||
void Set()
|
||||
{
|
||||
s = "set";
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
struct NonDerived
|
||||
{
|
||||
NonDerived()
|
||||
: s("constructed")
|
||||
{
|
||||
}
|
||||
|
||||
~NonDerived()
|
||||
{
|
||||
destructor = true;
|
||||
}
|
||||
|
||||
void Set()
|
||||
{
|
||||
s = "set";
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
DERIVED1,
|
||||
DERIVED2,
|
||||
DERIVED3,
|
||||
NONDERIVED,
|
||||
INTEGRAL
|
||||
};
|
||||
|
||||
typedef etl::type_id_pair<Derived1, DERIVED1> D1_Type;
|
||||
typedef etl::type_id_pair<Derived2, DERIVED2> D2_Type;
|
||||
typedef etl::type_id_pair<Derived3, DERIVED3> D3_Type;
|
||||
typedef etl::type_id_pair<NonDerived, NONDERIVED> ND_Type;
|
||||
typedef etl::type_id_pair<int, INTEGRAL> I_Type;
|
||||
|
||||
const size_t SIZE = 5UL;
|
||||
|
||||
// Notice that the type declaration order is not important.
|
||||
typedef etl::factory<SIZE, D1_Type, ND_Type, D3_Type, D2_Type, I_Type> Factory;
|
||||
|
||||
SUITE(test_factory)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_sizes)
|
||||
{
|
||||
Factory factory;
|
||||
|
||||
size_t ms = Factory::MAX_SIZE;
|
||||
CHECK_EQUAL(SIZE, ms);
|
||||
CHECK_EQUAL(SIZE, factory.max_size());
|
||||
CHECK_EQUAL(SIZE, factory.available());
|
||||
CHECK_EQUAL(0U, factory.size());
|
||||
CHECK(factory.empty());
|
||||
CHECK(!factory.full());
|
||||
|
||||
factory.create_from_type<Derived1>();
|
||||
CHECK_EQUAL(SIZE - 1U, factory.available());
|
||||
CHECK_EQUAL(1U, factory.size());
|
||||
CHECK(!factory.empty());
|
||||
CHECK(!factory.full());
|
||||
|
||||
factory.create_from_type<Derived1>();
|
||||
factory.create_from_type<Derived1>();
|
||||
factory.create_from_type<Derived1>();
|
||||
factory.create_from_type<Derived1>();
|
||||
CHECK_EQUAL(0U, factory.available());
|
||||
CHECK_EQUAL(SIZE, factory.size());
|
||||
CHECK(!factory.empty());
|
||||
CHECK(factory.full());
|
||||
|
||||
CHECK_THROW(factory.create_from_type<Derived1>(), etl::factory_cannot_create);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_create_release)
|
||||
{
|
||||
Factory factory;
|
||||
|
||||
Base* p;
|
||||
|
||||
// Derived 1
|
||||
p = factory.create_from_type<Derived1>();
|
||||
Derived1* pd1 = static_cast<Derived1*>(p);
|
||||
CHECK_EQUAL(0, pd1->i);
|
||||
p->Set();
|
||||
CHECK_EQUAL(1, pd1->i);
|
||||
factory.destroy(p);
|
||||
CHECK(destructor);
|
||||
|
||||
// Derived 2
|
||||
destructor = false;
|
||||
p = factory.create_from_type<Derived2>();
|
||||
Derived2* pd2 = static_cast<Derived2*>(p);
|
||||
CHECK_EQUAL(0.0, pd2->d);
|
||||
p->Set();
|
||||
CHECK_EQUAL(1.2, pd2->d);
|
||||
factory.destroy(p);
|
||||
CHECK(destructor);
|
||||
|
||||
// Derived 3
|
||||
destructor = false;
|
||||
p = factory.create_from_type<Derived3>();
|
||||
Derived3* pd3 = static_cast<Derived3*>(p);
|
||||
CHECK_EQUAL("constructed", pd3->s);
|
||||
p->Set();
|
||||
CHECK_EQUAL("set", pd3->s);
|
||||
factory.destroy(p);
|
||||
CHECK(destructor);
|
||||
|
||||
// Non Derived
|
||||
destructor = false;
|
||||
NonDerived* pnd = factory.create_from_type<NonDerived>();
|
||||
CHECK_EQUAL("constructed", pnd->s);
|
||||
pnd->Set();
|
||||
CHECK_EQUAL("set", pnd->s);
|
||||
factory.destroy(pnd);
|
||||
CHECK(destructor);
|
||||
|
||||
// Integral
|
||||
int* pi = factory.create_from_type<int>();
|
||||
factory.destroy(pi);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_create_release_const)
|
||||
{
|
||||
Factory factory;
|
||||
|
||||
const Derived1& d = *factory.create_from_type<Derived1>();
|
||||
|
||||
CHECK_EQUAL(0, d.i);
|
||||
factory.destroy(&d);
|
||||
CHECK(destructor);
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_create_emplace)
|
||||
{
|
||||
Factory factory;
|
||||
|
||||
Base* p;
|
||||
Derived3* pd3;
|
||||
|
||||
p = factory.create_from_type<Derived3>("1");
|
||||
pd3 = static_cast<Derived3*>(p);
|
||||
CHECK_EQUAL("constructed1", pd3->s);
|
||||
factory.destroy(p);
|
||||
|
||||
p = factory.create_from_type<Derived3>("1", "2");
|
||||
pd3 = static_cast<Derived3*>(p);
|
||||
CHECK_EQUAL("constructed12", pd3->s);
|
||||
factory.destroy(p);
|
||||
|
||||
p = factory.create_from_type<Derived3>("1", "2", "3");
|
||||
pd3 = static_cast<Derived3*>(p);
|
||||
CHECK_EQUAL("constructed123", pd3->s);
|
||||
factory.destroy(p);
|
||||
|
||||
p = factory.create_from_type<Derived3>("1", "2", "3", "4");
|
||||
pd3 = static_cast<Derived3*>(p);
|
||||
CHECK_EQUAL("constructed1234", pd3->s);
|
||||
factory.destroy(p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_did_not_create)
|
||||
{
|
||||
Factory factory1;
|
||||
Factory factory2;
|
||||
|
||||
Base* p;
|
||||
|
||||
p = factory1.create_from_type<Derived1>();
|
||||
CHECK_NO_THROW(factory1.destroy(p));
|
||||
|
||||
p = factory2.create_from_type<Derived1>();
|
||||
CHECK_THROW(factory1.destroy(p), etl::factory_did_not_create);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_create_from_index)
|
||||
{
|
||||
Factory factory;
|
||||
Derived1* p1;
|
||||
Derived2* p2;
|
||||
Derived3* p3;
|
||||
|
||||
CHECK_NO_THROW(p1 = factory.create_from_id<DERIVED1>());
|
||||
CHECK_EQUAL(0, p1->i);
|
||||
factory.destroy(p1);
|
||||
|
||||
CHECK_NO_THROW(p2 = factory.create_from_id<DERIVED2>());
|
||||
CHECK_EQUAL(0.0, p2->d);
|
||||
factory.destroy(p2);
|
||||
|
||||
CHECK_NO_THROW(p3 = factory.create_from_id<DERIVED3>());
|
||||
CHECK_EQUAL("constructed", p3->s);
|
||||
factory.destroy(p3);
|
||||
|
||||
CHECK_NO_THROW(p3 = factory.create_from_id<DERIVED3>("1"));
|
||||
CHECK_EQUAL("constructed1", p3->s);
|
||||
factory.destroy(p3);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_map", "unordered_map\unordered_map.vcxproj", "{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x64.Build.0 = Debug|x64
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x86.Build.0 = Debug|Win32
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x64.ActiveCfg = Release|x64
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x64.Build.0 = Release|x64
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x86.ActiveCfg = Release|Win32
|
||||
{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,40 @@
|
|||
========================================================================
|
||||
CONSOLE APPLICATION : unordered_map Project Overview
|
||||
========================================================================
|
||||
|
||||
AppWizard has created this unordered_map application for you.
|
||||
|
||||
This file contains a summary of what you will find in each of the files that
|
||||
make up your unordered_map application.
|
||||
|
||||
|
||||
unordered_map.vcxproj
|
||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the version of Visual C++ that generated the file, and
|
||||
information about the platforms, configurations, and project features selected with the
|
||||
Application Wizard.
|
||||
|
||||
unordered_map.vcxproj.filters
|
||||
This is the filters file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the association between the files in your project
|
||||
and the filters. This association is used in the IDE to show grouping of files with
|
||||
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
|
||||
"Source Files" filter).
|
||||
|
||||
unordered_map.cpp
|
||||
This is the main application source file.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other standard files:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
These files are used to build a precompiled header (PCH) file
|
||||
named unordered_map.pch and a precompiled types file named StdAfx.obj.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other notes:
|
||||
|
||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
||||
should add to or customize.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1,8 @@
|
|||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// unordered_map.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
|
@ -0,0 +1,15 @@
|
|||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||
|
||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
|
@ -0,0 +1,82 @@
|
|||
// unordered_map.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <unordered_map>
|
||||
#include "../../../../src/unordered_map.h"
|
||||
|
||||
LARGE_INTEGER frequency;
|
||||
LARGE_INTEGER begin;
|
||||
|
||||
void StartTimer()
|
||||
{
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
QueryPerformanceCounter(&begin);
|
||||
|
||||
frequency.QuadPart /= 1000;
|
||||
}
|
||||
|
||||
uint64_t StopTimer()
|
||||
{
|
||||
LARGE_INTEGER end;
|
||||
|
||||
QueryPerformanceCounter(&end);
|
||||
|
||||
return (end.QuadPart - begin.QuadPart) / frequency.QuadPart;
|
||||
}
|
||||
|
||||
const size_t TESTSIZE = 10000000UL;
|
||||
const size_t TESTINTERATIONS = 16UL;
|
||||
|
||||
typedef std::unordered_map<uint64_t, uint16_t> Stdmap;
|
||||
typedef etl::unordered_map<uint64_t, uint16_t, TESTSIZE> Etlmap;
|
||||
|
||||
Stdmap stdmap;
|
||||
Etlmap etlmap;
|
||||
|
||||
int main()
|
||||
{
|
||||
StartTimer();
|
||||
|
||||
for (size_t i = 0UL; i < TESTINTERATIONS; ++i)
|
||||
{
|
||||
for (size_t j = 0UL; j < TESTSIZE; ++j)
|
||||
{
|
||||
std::pair<Stdmap::iterator, bool> ok = stdmap.insert(std::make_pair(uint64_t(j), uint16_t(j)));
|
||||
}
|
||||
|
||||
for (size_t j = 0UL; j < TESTSIZE; ++j)
|
||||
{
|
||||
stdmap.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t time;
|
||||
|
||||
time = StopTimer();
|
||||
std::cout << "STD Time = " << time << "ms\n";
|
||||
|
||||
StartTimer();
|
||||
|
||||
for (size_t i = 0UL; i < TESTINTERATIONS; ++i)
|
||||
{
|
||||
for (size_t j = 0UL; j < TESTSIZE; ++j)
|
||||
{
|
||||
std::pair<Etlmap::iterator, bool> ok = etlmap.insert(std::make_pair(uint64_t(j), uint16_t(j)));
|
||||
}
|
||||
|
||||
for (size_t j = 0UL; j < TESTSIZE; ++j)
|
||||
{
|
||||
etlmap.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
time = StopTimer();
|
||||
std::cout << "ETL Time = " << time << "ms\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>unordered_map</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../../../../src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\..\..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<FullProgramDatabaseFile>true</FullProgramDatabaseFile>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\..\src\ipool.h" />
|
||||
<ClInclude Include="..\..\..\..\src\iunordered_map.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
<ClCompile Include="unordered_map.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\ipool.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\..\src\iunordered_map.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="unordered_map.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
15
components/etl/test/UnitTest++/AssertException.cpp
Normal file
15
components/etl/test/UnitTest++/AssertException.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "AssertException.h"
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
AssertException::AssertException()
|
||||
{}
|
||||
|
||||
AssertException::~AssertException() throw()
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
23
components/etl/test/UnitTest++/AssertException.h
Normal file
23
components/etl/test/UnitTest++/AssertException.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef UNITTEST_ASSERTEXCEPTION_H
|
||||
#define UNITTEST_ASSERTEXCEPTION_H
|
||||
|
||||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include <exception>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE AssertException : public std::exception
|
||||
{
|
||||
public:
|
||||
AssertException();
|
||||
virtual ~AssertException() throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
51
components/etl/test/UnitTest++/CMakeLists.txt
Normal file
51
components/etl/test/UnitTest++/CMakeLists.txt
Normal file
|
@ -0,0 +1,51 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(UnitTestpp LANGUAGES CXX)
|
||||
|
||||
add_library(UnitTestpp
|
||||
AssertException.cpp
|
||||
Checks.cpp
|
||||
CompositeTestReporter.cpp
|
||||
CurrentTest.cpp
|
||||
DeferredTestReporter.cpp
|
||||
DeferredTestResult.cpp
|
||||
MemoryOutStream.cpp
|
||||
ReportAssert.cpp
|
||||
RequiredCheckException.cpp
|
||||
RequiredCheckTestReporter.cpp
|
||||
Test.cpp
|
||||
TestDetails.cpp
|
||||
TestList.cpp
|
||||
TestReporter.cpp
|
||||
TestReporterStdout.cpp
|
||||
TestResults.cpp
|
||||
TestRunner.cpp
|
||||
ThrowingTestReporter.cpp
|
||||
TimeConstraint.cpp
|
||||
XmlTestReporter.cpp
|
||||
)
|
||||
|
||||
target_include_directories(UnitTestpp SYSTEM INTERFACE ..)
|
||||
|
||||
if (WIN32)
|
||||
target_sources(UnitTestpp PRIVATE Win32/TimeHelpers.cpp)
|
||||
else ()
|
||||
target_sources(UnitTestpp PRIVATE
|
||||
Posix/SignalTranslator.cpp
|
||||
Posix/TimeHelpers.cpp
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
target_compile_options(UnitTestpp PRIVATE -fexceptions)
|
||||
endif ()
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
# atomic is need on Linux with Clang
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(UnitTestpp PRIVATE atomic Threads::Threads)
|
||||
elseif (NOT UNIX AND APPLE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(UnitTestpp PRIVATE Threads::Threads)
|
||||
endif ()
|
410
components/etl/test/UnitTest++/CheckMacros.h
Normal file
410
components/etl/test/UnitTest++/CheckMacros.h
Normal file
|
@ -0,0 +1,410 @@
|
|||
#ifndef UNITTEST_CHECKMACROS_H
|
||||
#define UNITTEST_CHECKMACROS_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include "ExceptionMacros.h"
|
||||
#include "Checks.h"
|
||||
#include "AssertException.h"
|
||||
#include "RequiredCheckException.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "TestDetails.h"
|
||||
#include "CurrentTest.h"
|
||||
#include "ReportAssertImpl.h"
|
||||
|
||||
#define UNITTEST_CHECK(value) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
if (!UnitTest::Check(value)) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK(" #value ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK(" #value ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FALSE(value) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
if (!UnitTest::CheckFalse(value)) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK(" #value ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK(" #value ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_EQUAL(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_EQUAL_HEX(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckEqualHex(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_NOT_EQUAL(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckNotEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FALSE_EQUAL_HEX(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckNotEqualHex(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_CLOSE(expected, actual, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FLOAT_SAME(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, 0, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_FLOAT_SAME(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_FLOAT_SAME(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_FLOAT_DIFFERENT(expected, actual) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckNotClose(*UnitTest::CurrentTest::Results(), expected, actual, 0, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_FLOAT_DIFFERENT(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_FLOAT_DIFFERENT(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_ARRAY_EQUAL(expected, actual, count) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
|
||||
}) \
|
||||
UNITTEST_IMPL_RETHROW (UnitTest::RequiredCheckException) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, exc, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream UnitTest_message; \
|
||||
UnitTest_message << "Unhandled exception (" << exc.what() << ") in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"; \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
UnitTest_message.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
|
||||
"Unhandled exception in CHECK_ARRAY2D_CLOSE(" #expected ", " #actual ")"); \
|
||||
}) \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#ifndef UNITTEST_DISABLE_SHORT_MACROS
|
||||
#ifdef CHECK
|
||||
#error CHECK already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK instead
|
||||
#else
|
||||
#define CHECK(value) UNITTEST_CHECK((value))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_TRUE
|
||||
#error CHECK_TRUE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_TRUE instead
|
||||
#else
|
||||
#define CHECK_TRUE(value) UNITTEST_CHECK((value))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FALSE
|
||||
#error CHECK_FALSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FALSE instead
|
||||
#else
|
||||
#define CHECK_FALSE(value) UNITTEST_CHECK_FALSE((value))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_EQUAL
|
||||
#error CHECK_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL instead
|
||||
#else
|
||||
#define CHECK_EQUAL(expected, actual) UNITTEST_CHECK_EQUAL((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_EQUAL_HEX
|
||||
#error CHECK_EQUAL_HEX already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_EQUAL_HEX instead
|
||||
#else
|
||||
#define CHECK_EQUAL_HEX(expected, actual) UNITTEST_CHECK_EQUAL_HEX((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_NOT_EQUAL
|
||||
#error CHECK_NOT_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NOT_EQUAL instead
|
||||
#else
|
||||
#define CHECK_NOT_EQUAL(expected, actual) UNITTEST_CHECK_NOT_EQUAL((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_NOT_EQUAL_HEX
|
||||
#error CHECK_NOT_EQUAL_HEX already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NOT_EQUAL_HEX instead
|
||||
#else
|
||||
#define CHECK_NOT_EQUAL_HEX(expected, actual) UNITTEST_CHECK_NOT_EQUAL_HEX((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_CLOSE
|
||||
#error CHECK_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_CLOSE instead
|
||||
#else
|
||||
#define CHECK_CLOSE(expected, actual, tolerance) UNITTEST_CHECK_CLOSE((expected), (actual), (tolerance))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FLOAT_SAME
|
||||
#error CHECK_FLOAT_SAME already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FLOAT_SAME instead
|
||||
#else
|
||||
#define CHECK_FLOAT_SAME(expected, actual) UNITTEST_CHECK_FLOAT_SAME((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FLOAT_DIFFERENT
|
||||
#error CHECK_FLOAT_DIFFERENT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FLOAT_DIFFERENT instead
|
||||
#else
|
||||
#define CHECK_FLOAT_DIFFERENT(expected, actual) UNITTEST_CHECK_FLOAT_DIFFERENT((expected), (actual))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_ARRAY_EQUAL
|
||||
#error CHECK_ARRAY_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_EQUAL instead
|
||||
#else
|
||||
#define CHECK_ARRAY_EQUAL(expected, actual, count) UNITTEST_CHECK_ARRAY_EQUAL((expected), (actual), (count))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_ARRAY_CLOSE
|
||||
#error CHECK_ARRAY_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY_CLOSE instead
|
||||
#else
|
||||
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) UNITTEST_CHECK_ARRAY_CLOSE((expected), (actual), (count), (tolerance))
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_ARRAY2D_CLOSE
|
||||
#error CHECK_ARRAY2D_CLOSE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ARRAY2D_CLOSE instead
|
||||
#else
|
||||
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) UNITTEST_CHECK_ARRAY2D_CLOSE((expected), (actual), (rows), (columns), (tolerance))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// CHECK_THROW and CHECK_ASSERT only exist when UNITTEST_NO_EXCEPTIONS isn't defined (see config.h)
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
#define UNITTEST_CHECK_THROW(expression, ExpectedExceptionType) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
bool caught_ = false; \
|
||||
try { expression; } \
|
||||
catch (ExpectedExceptionType const&) { caught_ = true; } \
|
||||
catch (...) {} \
|
||||
if (!caught_) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_NO_THROW(expression) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
bool caught_ = false; \
|
||||
try { expression; } \
|
||||
catch (...) { caught_ = true; } \
|
||||
if (caught_) \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Unexpected exception thrown"); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
#define UNITTEST_CHECK_ASSERT(expression) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
UnitTest::Detail::ExpectAssert(true); \
|
||||
CHECK_THROW(expression, UnitTest::AssertException); \
|
||||
UnitTest::Detail::ExpectAssert(false); \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
#endif
|
||||
|
||||
#ifndef UNITTEST_DISABLE_SHORT_MACROS
|
||||
#ifdef CHECK_THROW
|
||||
#error CHECK_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_THROW instead
|
||||
#else
|
||||
#define CHECK_THROW UNITTEST_CHECK_THROW
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_NO_THROW
|
||||
#error CHECK_NO_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NO_THROW instead
|
||||
#else
|
||||
#define CHECK_NO_THROW UNITTEST_CHECK_NO_THROW
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_ASSERT
|
||||
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
|
||||
#else
|
||||
#define CHECK_ASSERT UNITTEST_CHECK_ASSERT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CHECK_MESSAGE(m1) std::cerr << (m1) << "\n";
|
||||
#define CHECK_MESSAGE1(m1) std::cerr << (m1) << "\n";
|
||||
#define CHECK_MESSAGE2(m1, m2) std::cerr << (m1) << (m2) << "\n";
|
||||
#define CHECK_MESSAGE3(m1, m2, m3) std::cerr << (m1) << (m2) << (m3) << "\n";
|
||||
#define CHECK_MESSAGE4(m1, m2, m3, m4) std::cerr << (m1) << (m2) << (m3) << (m4) << "\n";
|
||||
|
||||
#define CHECK_MESSAGE_IF(b, m1) { if (b) std::cerr << (m1) << "\n"; }
|
||||
#define CHECK_MESSAGE1_IF(m1) { if (b) std::cerr << (m1) << "\n"; }
|
||||
#define CHECK_MESSAGE2_IF(m1, m2) { if (b) std::cerr << (m1) << (m2) << "\n"; }
|
||||
#define CHECK_MESSAGE3_IF(m1, m2, m3) { if (b) std::cerr << (m1) << (m2) << (m3) << "\n"; }
|
||||
#define CHECK_MESSAGE4_IF(m1, m2, m3, m4) { if (b) std::cerr << (m1) << (m2) << (m3) << (m4) << "\n"; }
|
||||
#endif
|
||||
|
50
components/etl/test/UnitTest++/Checks.cpp
Normal file
50
components/etl/test/UnitTest++/Checks.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "Checks.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
namespace {
|
||||
|
||||
void CheckStringsEqual(TestResults& results, char const* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if ((expected && actual) ? strcmp(expected, actual) : (expected || actual))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected " << (expected ? expected : "<NULLPTR>") << " but was " << (actual ? actual : "<NULLPTR>");
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CheckEqual(TestResults& results, char const* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char* expected, char* actual,
|
||||
TestDetails const& details)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char* expected, char const* actual,
|
||||
TestDetails const& details)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
}
|
||||
|
||||
void CheckEqual(TestResults& results, char const* expected, char* actual,
|
||||
TestDetails const& details)
|
||||
{
|
||||
CheckStringsEqual(results, expected, actual, details);
|
||||
}
|
||||
|
||||
|
||||
}
|
389
components/etl/test/UnitTest++/Checks.h
Normal file
389
components/etl/test/UnitTest++/Checks.h
Normal file
|
@ -0,0 +1,389 @@
|
|||
#ifndef UNITTEST_CHECKS_H
|
||||
#define UNITTEST_CHECKS_H
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__) && !defined(__llvm__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || defined(__llvm__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wsign-compare"
|
||||
#pragma clang diagnostic ignored "-Wfloat-equal"
|
||||
#endif
|
||||
|
||||
#include "Config.h"
|
||||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include<iomanip>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::is_pointer<T>::value, std::string>::type
|
||||
DisplayValue(const T& c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << c;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const char& c)
|
||||
{
|
||||
typedef std::char_traits<char>::int_type type;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << type(c) << " ('" << c << "')";
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#if (__cplusplus >= 202002L)
|
||||
template <>
|
||||
inline std::string DisplayValue(const char8_t& c)
|
||||
{
|
||||
typedef std::char_traits<char8_t>::int_type type;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << type(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const wchar_t& c)
|
||||
{
|
||||
typedef std::char_traits<wchar_t>::int_type type;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << type(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#if (__cplusplus >= 201103L)
|
||||
template <>
|
||||
inline std::string DisplayValue(const char16_t& c)
|
||||
{
|
||||
typedef std::char_traits<char16_t>::int_type type;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << type(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const char32_t& c)
|
||||
{
|
||||
typedef std::char_traits<char32_t>::int_type type;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << type(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
std::string DisplayValue(const T* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << c;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const char* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << c;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#if (__cplusplus >= 202002L)
|
||||
template <>
|
||||
inline std::string DisplayValue(const char8_t* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << static_cast<const void*>(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const wchar_t* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << static_cast<const void*>(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#if (__cplusplus >= 201103L)
|
||||
template <>
|
||||
inline std::string DisplayValue(const char16_t* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << static_cast<const void*>(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline std::string DisplayValue(const char32_t* c)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << static_cast<const void*>(c);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename Value >
|
||||
bool Check(Value const& value)
|
||||
{
|
||||
return !!value; // doing double negative to avoid silly VS warnings
|
||||
}
|
||||
|
||||
template< typename Value >
|
||||
bool CheckFalse(Value const& value)
|
||||
{
|
||||
return !value;
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckEqual(TestResults& results, Expected&& expected, Actual&& actual, TestDetails const& details)
|
||||
{
|
||||
if (!(expected == actual))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected "
|
||||
<< DisplayValue(expected) << " but was " << DisplayValue(actual);
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
#else
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckEqual(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
{
|
||||
if (!(expected == actual))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected "
|
||||
<< DisplayValue(expected) << " but was " << DisplayValue(actual);
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckEqualHex(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
{
|
||||
if (!(expected == actual))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << std::hex << std::uppercase << std::setfill('0')
|
||||
<< "Expected 0x" << std::setw(2 * sizeof(Expected)) << (expected & ~(typename std::make_unsigned<Expected>::type(0)))
|
||||
<< " but was 0x" << std::setw(2 * sizeof(Actual)) << (actual & ~(typename std::make_unsigned<Actual>::type(0)));
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckNotEqual(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
{
|
||||
if (expected == actual)
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected not equal, but both values are" << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckNotEqualHex(TestResults& results, Expected const& expected, Actual const& actual, TestDetails const& details)
|
||||
{
|
||||
if (expected == actual)
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(2 * sizeof(Actual))
|
||||
<< "Expected not equal, but both values are " << (actual & ~(typename std::make_unsigned<Actual>::type(0)));
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details);
|
||||
|
||||
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details);
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
bool AreClose(Expected const& expected, Actual const& actual, Tolerance const& tolerance)
|
||||
{
|
||||
return (actual >= (expected - tolerance)) && (actual <= (expected + tolerance));
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckClose(TestResults& results, Expected const& expected, Actual const& actual, Tolerance const& tolerance,
|
||||
TestDetails const& details)
|
||||
{
|
||||
if (!AreClose(expected, actual, tolerance))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckNotClose(TestResults& results, Expected const& expected, Actual const& actual, Tolerance const& tolerance,
|
||||
TestDetails const& details)
|
||||
{
|
||||
if (AreClose(expected, actual, tolerance))
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual >
|
||||
void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
size_t const count, TestDetails const& details)
|
||||
{
|
||||
bool equal = true;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
equal &= (expected[i] == actual[i]);
|
||||
|
||||
if (!equal)
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
|
||||
stream << "Expected [ ";
|
||||
|
||||
for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex)
|
||||
stream << DisplayValue(expected[expectedIndex]) << " ";
|
||||
|
||||
stream << "] but was [ ";
|
||||
|
||||
for (size_t actualIndex = 0; actualIndex < count; ++actualIndex)
|
||||
stream << DisplayValue(actual[actualIndex]) << " ";
|
||||
|
||||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
bool ArrayAreClose(Expected const& expected, Actual const& actual, size_t const count, Tolerance const& tolerance)
|
||||
{
|
||||
bool equal = true;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
equal &= AreClose(expected[i], actual[i], tolerance);
|
||||
return equal;
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckArrayClose(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
size_t const count, Tolerance const& tolerance, TestDetails const& details)
|
||||
{
|
||||
bool equal = ArrayAreClose(expected, actual, count, tolerance);
|
||||
|
||||
if (!equal)
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
|
||||
stream << "Expected [ ";
|
||||
for (size_t expectedIndex = 0; expectedIndex < count; ++expectedIndex)
|
||||
stream << expected[expectedIndex] << " ";
|
||||
stream << "] +/- " << tolerance << " but was [ ";
|
||||
|
||||
for (size_t actualIndex = 0; actualIndex < count; ++actualIndex)
|
||||
stream << actual[actualIndex] << " ";
|
||||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Expected, typename Actual, typename Tolerance >
|
||||
void CheckArray2DClose(TestResults& results, Expected const& expected, Actual const& actual,
|
||||
size_t const rows, size_t const columns, Tolerance const& tolerance, TestDetails const& details)
|
||||
{
|
||||
bool equal = true;
|
||||
for (size_t i = 0; i < rows; ++i)
|
||||
equal &= ArrayAreClose(expected[i], actual[i], columns, tolerance);
|
||||
|
||||
if (!equal)
|
||||
{
|
||||
UnitTest::MemoryOutStream stream;
|
||||
|
||||
stream << "Expected [ ";
|
||||
|
||||
for (size_t expectedRow = 0; expectedRow < rows; ++expectedRow)
|
||||
{
|
||||
stream << "[ ";
|
||||
for (size_t expectedColumn = 0; expectedColumn < columns; ++expectedColumn)
|
||||
stream << expected[expectedRow][expectedColumn] << " ";
|
||||
stream << "] ";
|
||||
}
|
||||
|
||||
stream << "] +/- " << tolerance << " but was [ ";
|
||||
|
||||
for (size_t actualRow = 0; actualRow < rows; ++actualRow)
|
||||
{
|
||||
stream << "[ ";
|
||||
for (size_t actualColumn = 0; actualColumn < columns; ++actualColumn)
|
||||
stream << actual[actualRow][actualColumn] << " ";
|
||||
stream << "] ";
|
||||
}
|
||||
|
||||
stream << "]";
|
||||
|
||||
results.OnTestFailure(details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__) && !defined(__llvm__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || defined(__llvm__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif
|
66
components/etl/test/UnitTest++/CompositeTestReporter.cpp
Normal file
66
components/etl/test/UnitTest++/CompositeTestReporter.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "CompositeTestReporter.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
CompositeTestReporter::CompositeTestReporter()
|
||||
: m_reporterCount(0)
|
||||
{}
|
||||
|
||||
int CompositeTestReporter::GetReporterCount() const
|
||||
{
|
||||
return m_reporterCount;
|
||||
}
|
||||
|
||||
bool CompositeTestReporter::AddReporter(TestReporter* reporter)
|
||||
{
|
||||
if (m_reporterCount == kMaxReporters)
|
||||
return false;
|
||||
|
||||
m_reporters[m_reporterCount++] = reporter;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompositeTestReporter::RemoveReporter(TestReporter* reporter)
|
||||
{
|
||||
for (int index = 0; index < m_reporterCount; ++index)
|
||||
{
|
||||
if (m_reporters[index] == reporter)
|
||||
{
|
||||
m_reporters[index] = m_reporters[m_reporterCount - 1];
|
||||
--m_reporterCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CompositeTestReporter::ReportFailure(TestDetails const& details, char const* failure)
|
||||
{
|
||||
for (int index = 0; index < m_reporterCount; ++index)
|
||||
m_reporters[index]->ReportFailure(details, failure);
|
||||
}
|
||||
|
||||
void CompositeTestReporter::ReportTestStart(TestDetails const& test)
|
||||
{
|
||||
for (int index = 0; index < m_reporterCount; ++index)
|
||||
m_reporters[index]->ReportTestStart(test);
|
||||
}
|
||||
|
||||
void CompositeTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed)
|
||||
{
|
||||
for (int index = 0; index < m_reporterCount; ++index)
|
||||
m_reporters[index]->ReportTestFinish(test, secondsElapsed);
|
||||
}
|
||||
|
||||
void CompositeTestReporter::ReportSummary(int totalTestCount,
|
||||
int failedTestCount,
|
||||
int failureCount,
|
||||
float secondsElapsed)
|
||||
{
|
||||
for (int index = 0; index < m_reporterCount; ++index)
|
||||
m_reporters[index]->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed);
|
||||
}
|
||||
|
||||
}
|
34
components/etl/test/UnitTest++/CompositeTestReporter.h
Normal file
34
components/etl/test/UnitTest++/CompositeTestReporter.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef UNITTEST_COMPOSITETESTREPORTER_H
|
||||
#define UNITTEST_COMPOSITETESTREPORTER_H
|
||||
|
||||
#include "TestReporter.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE CompositeTestReporter : public TestReporter
|
||||
{
|
||||
public:
|
||||
CompositeTestReporter();
|
||||
|
||||
int GetReporterCount() const;
|
||||
bool AddReporter(TestReporter* reporter);
|
||||
bool RemoveReporter(TestReporter* reporter);
|
||||
|
||||
virtual void ReportTestStart(TestDetails const& test);
|
||||
virtual void ReportFailure(TestDetails const& test, char const* failure);
|
||||
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
|
||||
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
|
||||
|
||||
private:
|
||||
enum { kMaxReporters = 16 };
|
||||
TestReporter* m_reporters[kMaxReporters];
|
||||
int m_reporterCount;
|
||||
|
||||
// revoked
|
||||
CompositeTestReporter(const CompositeTestReporter&);
|
||||
CompositeTestReporter& operator =(const CompositeTestReporter&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
84
components/etl/test/UnitTest++/Config.h
Normal file
84
components/etl/test/UnitTest++/Config.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
#ifndef UNITTEST_CONFIG_H
|
||||
#define UNITTEST_CONFIG_H
|
||||
|
||||
// Standard defines documented here: http://predef.sourceforge.net
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable:4702)// unreachable code
|
||||
#pragma warning(disable:4722)// destructor never returns, potential memory leak
|
||||
|
||||
#if (_MSC_VER == 1200) // VC6
|
||||
#define UNITTEST_COMPILER_IS_MSVC6
|
||||
#pragma warning(disable:4786)
|
||||
#pragma warning(disable:4290)
|
||||
#endif
|
||||
|
||||
#ifdef _USRDLL
|
||||
#define UNITTEST_WIN32_DLL
|
||||
#endif
|
||||
|
||||
#define UNITTEST_WIN32
|
||||
#endif
|
||||
|
||||
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
|
||||
defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) \
|
||||
|| defined (__HAIKU__) || defined(_AIX)
|
||||
#define UNITTEST_POSIX
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
#define UNITTEST_MINGW
|
||||
#endif
|
||||
|
||||
|
||||
// By default, MemoryOutStream is implemented in terms of std::ostringstream.
|
||||
// This is useful if you are using the CHECK macros on objects that have something like this defined:
|
||||
// std::ostringstream& operator<<(std::ostringstream& s, const YourObject& value)
|
||||
//
|
||||
// On the other hand, it can be more expensive.
|
||||
// Un-comment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
|
||||
|
||||
// #define UNITTEST_USE_CUSTOM_STREAMS
|
||||
|
||||
// Developer note: This dual-macro setup is to preserve compatibility with UnitTest++ 1.4 users
|
||||
// who may have used or defined UNITTEST_USE_CUSTOM_STREAMS outside of this configuration file, as
|
||||
// well as Google Code HEAD users that may have used or defined
|
||||
// UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM outside of this configuration file.
|
||||
#ifndef UNITTEST_USE_CUSTOM_STREAMS
|
||||
#define UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
|
||||
#endif
|
||||
|
||||
// DeferredTestReporter uses the STL to collect test results for subsequent export by reporters like
|
||||
// XmlTestReporter. If you don't want to use this functionality, uncomment this line and no STL
|
||||
// headers or code will be compiled into UnitTest++
|
||||
|
||||
//#define UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
|
||||
// By default, asserts that you report via UnitTest::ReportAssert() abort the current test and
|
||||
// continue to the next one by throwing an exception, which unwinds the stack naturally, destroying
|
||||
// all auto variables on its way back down. If you don't want to (or can't) use exceptions for your
|
||||
// platform/compiler, uncomment this line. All exception code will be removed from UnitTest++,
|
||||
// assert recovery will be done via setjmp/longjmp, and NO correct stack unwinding will happen!
|
||||
|
||||
//#define UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
|
||||
// std namespace qualification: used for functions like strcpy that
|
||||
// may live in std:: namespace (cstring header).
|
||||
#if defined( UNITTEST_COMPILER_IS_MSVC6 )
|
||||
#define UNIITEST_NS_QUAL_STD(x) x
|
||||
#else
|
||||
#define UNIITEST_NS_QUAL_STD(x) ::std::x
|
||||
#endif
|
||||
|
||||
// By default, UnitTest++ will attempt to define "short" macro names like CHECK and CHECK_EQUAL
|
||||
// for "public" interface macros etc. Defining UNITTEST_DISABLE_SHORT_MACROS in your project
|
||||
// will disable this behavior, leaving only the longer macros "namespaced" with the UNITTEST_
|
||||
// prefix.
|
||||
//
|
||||
// "Internal" utility macros will only have the UNITTEST_IMPL_ prefix.
|
||||
|
||||
// #define UNITTEST_DISABLE_SHORT_MACROS
|
||||
|
||||
#endif
|
18
components/etl/test/UnitTest++/CurrentTest.cpp
Normal file
18
components/etl/test/UnitTest++/CurrentTest.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "CurrentTest.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
UNITTEST_LINKAGE TestResults*& CurrentTest::Results()
|
||||
{
|
||||
static TestResults* testResults = NULL;
|
||||
return testResults;
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE const TestDetails*& CurrentTest::Details()
|
||||
{
|
||||
static const TestDetails* testDetails = NULL;
|
||||
return testDetails;
|
||||
}
|
||||
|
||||
}
|
19
components/etl/test/UnitTest++/CurrentTest.h
Normal file
19
components/etl/test/UnitTest++/CurrentTest.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef UNITTEST_CURRENTTESTRESULTS_H
|
||||
#define UNITTEST_CURRENTTESTRESULTS_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestResults;
|
||||
class TestDetails;
|
||||
|
||||
namespace CurrentTest
|
||||
{
|
||||
UNITTEST_LINKAGE TestResults*& Results();
|
||||
UNITTEST_LINKAGE const TestDetails*& Details();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
components/etl/test/UnitTest++/DeferredTestReporter.cpp
Normal file
33
components/etl/test/UnitTest++/DeferredTestReporter.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "DeferredTestReporter.h"
|
||||
#include "TestDetails.h"
|
||||
|
||||
using namespace UnitTest;
|
||||
|
||||
void DeferredTestReporter::ReportTestStart(TestDetails const& details)
|
||||
{
|
||||
m_results.push_back(DeferredTestResult(details.suiteName, details.testName));
|
||||
}
|
||||
|
||||
void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure)
|
||||
{
|
||||
DeferredTestResult& r = m_results.back();
|
||||
r.failed = true;
|
||||
r.failures.push_back(DeferredTestFailure(details.lineNumber, failure));
|
||||
r.failureFile = details.filename;
|
||||
}
|
||||
|
||||
void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed)
|
||||
{
|
||||
DeferredTestResult& r = m_results.back();
|
||||
r.timeElapsed = secondsElapsed;
|
||||
}
|
||||
|
||||
DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults()
|
||||
{
|
||||
return m_results;
|
||||
}
|
||||
|
||||
#endif
|
35
components/etl/test/UnitTest++/DeferredTestReporter.h
Normal file
35
components/etl/test/UnitTest++/DeferredTestReporter.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef UNITTEST_DEFERREDTESTREPORTER_H
|
||||
#define UNITTEST_DEFERREDTESTREPORTER_H
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "TestReporter.h"
|
||||
#include "DeferredTestResult.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestResult);
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE DeferredTestReporter : public TestReporter
|
||||
{
|
||||
public:
|
||||
virtual void ReportTestStart(TestDetails const& details);
|
||||
virtual void ReportFailure(TestDetails const& details, char const* failure);
|
||||
virtual void ReportTestFinish(TestDetails const& details, float secondsElapsed);
|
||||
|
||||
typedef std::vector< DeferredTestResult > DeferredTestResultList;
|
||||
DeferredTestResultList& GetResults();
|
||||
|
||||
private:
|
||||
DeferredTestResultList m_results;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
43
components/etl/test/UnitTest++/DeferredTestResult.cpp
Normal file
43
components/etl/test/UnitTest++/DeferredTestResult.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "DeferredTestResult.h"
|
||||
#include <cstring>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
DeferredTestFailure::DeferredTestFailure()
|
||||
: lineNumber(-1)
|
||||
{
|
||||
failureStr[0] = '\0';
|
||||
}
|
||||
|
||||
DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr_)
|
||||
: lineNumber(lineNumber_)
|
||||
{
|
||||
UNIITEST_NS_QUAL_STD(strcpy)(failureStr, failureStr_);
|
||||
}
|
||||
|
||||
DeferredTestResult::DeferredTestResult()
|
||||
: suiteName("")
|
||||
, testName("")
|
||||
, failureFile("")
|
||||
, timeElapsed(0.0f)
|
||||
, failed(false)
|
||||
{}
|
||||
|
||||
DeferredTestResult::DeferredTestResult(char const* suite, char const* test)
|
||||
: suiteName(suite)
|
||||
, testName(test)
|
||||
, failureFile("")
|
||||
, timeElapsed(0.0f)
|
||||
, failed(false)
|
||||
{}
|
||||
|
||||
DeferredTestResult::~DeferredTestResult()
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
52
components/etl/test/UnitTest++/DeferredTestResult.h
Normal file
52
components/etl/test/UnitTest++/DeferredTestResult.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef UNITTEST_DEFERREDTESTRESULT_H
|
||||
#define UNITTEST_DEFERREDTESTRESULT_H
|
||||
|
||||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE DeferredTestFailure
|
||||
{
|
||||
public:
|
||||
DeferredTestFailure();
|
||||
DeferredTestFailure(int lineNumber_, const char* failureStr_);
|
||||
|
||||
int lineNumber;
|
||||
char failureStr[1024];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestFailure);
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE DeferredTestResult
|
||||
{
|
||||
public:
|
||||
DeferredTestResult();
|
||||
DeferredTestResult(char const* suite, char const* test);
|
||||
~DeferredTestResult();
|
||||
|
||||
std::string suiteName;
|
||||
std::string testName;
|
||||
std::string failureFile;
|
||||
|
||||
typedef std::vector< DeferredTestFailure > FailureVec;
|
||||
FailureVec failures;
|
||||
|
||||
float timeElapsed;
|
||||
bool failed;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
20
components/etl/test/UnitTest++/ExceptionMacros.h
Normal file
20
components/etl/test/UnitTest++/ExceptionMacros.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef UNITTEST_EXCEPTIONMACROS_H
|
||||
#define UNITTEST_EXCEPTIONMACROS_H
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
#define UNITTEST_IMPL_TRY(x) try x
|
||||
#define UNITTEST_IMPL_THROW(x) throw x
|
||||
#define UNITTEST_IMPL_RETHROW(ExceptionType) catch(ExceptionType&) { throw; }
|
||||
#define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody) catch(ExceptionType& ExceptionName) CatchBody
|
||||
#define UNITTEST_IMPL_CATCH_ALL(CatchBody) catch(...) CatchBody
|
||||
#else
|
||||
#define UNITTEST_IMPL_TRY(x) x
|
||||
#define UNITTEST_IMPL_THROW(x)
|
||||
#define UNITTEST_IMPL_RETHROW(ExceptionType)
|
||||
#define UNITTEST_IMPL_CATCH(ExceptionType, ExceptionName, CatchBody)
|
||||
#define UNITTEST_IMPL_CATCH_ALL(CatchBody)
|
||||
#endif
|
||||
|
||||
#endif
|
61
components/etl/test/UnitTest++/ExecuteTest.h
Normal file
61
components/etl/test/UnitTest++/ExecuteTest.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#ifndef UNITTEST_EXECUTE_TEST_H
|
||||
#define UNITTEST_EXECUTE_TEST_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "ExceptionMacros.h"
|
||||
#include "TestDetails.h"
|
||||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "AssertException.h"
|
||||
#include "RequiredCheckException.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
#include "ReportAssertImpl.h"
|
||||
#endif
|
||||
|
||||
#ifdef UNITTEST_POSIX
|
||||
#include "Posix/SignalTranslator.h"
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
template< typename T >
|
||||
void ExecuteTest(T& testObject, TestDetails const& details, bool isMockTest)
|
||||
{
|
||||
if (isMockTest == false)
|
||||
CurrentTest::Details() = &details;
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
if (UNITTEST_SET_ASSERT_JUMP_TARGET() == 0)
|
||||
{
|
||||
#endif
|
||||
#ifndef UNITTEST_POSIX
|
||||
UNITTEST_IMPL_TRY({ testObject.RunImpl(); })
|
||||
#else
|
||||
UNITTEST_IMPL_TRY
|
||||
({
|
||||
UNITTEST_THROW_SIGNALS_POSIX_ONLY
|
||||
testObject.RunImpl();
|
||||
})
|
||||
#endif
|
||||
UNITTEST_IMPL_CATCH(RequiredCheckException, exc, { (void)exc; })
|
||||
UNITTEST_IMPL_CATCH(AssertException, exc, { (void)exc; })
|
||||
UNITTEST_IMPL_CATCH(std::exception, exc,
|
||||
{
|
||||
MemoryOutStream stream;
|
||||
stream << "Unhandled exception: " << exc.what();
|
||||
CurrentTest::Results()->OnTestFailure(details, stream.GetText());
|
||||
})
|
||||
UNITTEST_IMPL_CATCH_ALL
|
||||
({
|
||||
CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: test crashed");
|
||||
})
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
52
components/etl/test/UnitTest++/HelperMacros.h
Normal file
52
components/etl/test/UnitTest++/HelperMacros.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef UNITTEST_HELPERMACROS_H
|
||||
#define UNITTEST_HELPERMACROS_H
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#define UNITTEST_MULTILINE_MACRO_BEGIN do {
|
||||
|
||||
#if defined(UNITTEST_WIN32) && !defined(UNITTEST_COMPILER_IS_MSVC6)
|
||||
#define UNITTEST_MULTILINE_MACRO_END \
|
||||
} __pragma(warning(push)) __pragma(warning(disable: 4127)) while (0) __pragma(warning(pop))
|
||||
#else
|
||||
#define UNITTEST_MULTILINE_MACRO_END } while(0)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UNITTEST_WIN32_DLL
|
||||
#define UNITTEST_IMPORT __declspec(dllimport)
|
||||
#define UNITTEST_EXPORT __declspec(dllexport)
|
||||
|
||||
#ifdef UNITTEST_DLL_EXPORT
|
||||
#define UNITTEST_LINKAGE UNITTEST_EXPORT
|
||||
#define UNITTEST_IMPEXP_TEMPLATE
|
||||
#else
|
||||
#define UNITTEST_LINKAGE UNITTEST_IMPORT
|
||||
#define UNITTEST_IMPEXP_TEMPLATE extern
|
||||
#endif
|
||||
|
||||
#define UNITTEST_STDVECTOR_LINKAGE(T) \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4231)) \
|
||||
UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::allocator< T >; \
|
||||
UNITTEST_IMPEXP_TEMPLATE template class UNITTEST_LINKAGE std::vector< T >; \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
#define UNITTEST_IMPORT
|
||||
#define UNITTEST_EXPORT
|
||||
#define UNITTEST_LINKAGE
|
||||
#define UNITTEST_IMPEXP_TEMPLATE
|
||||
#define UNITTEST_STDVECTOR_LINKAGE(T)
|
||||
#endif
|
||||
|
||||
#ifdef UNITTEST_WIN32
|
||||
#define UNITTEST_JMPBUF jmp_buf
|
||||
#define UNITTEST_SETJMP setjmp
|
||||
#define UNITTEST_LONGJMP longjmp
|
||||
#elif defined UNITTEST_POSIX
|
||||
#define UNITTEST_JMPBUF std::jmp_buf
|
||||
#define UNITTEST_SETJMP setjmp
|
||||
#define UNITTEST_LONGJMP std::longjmp
|
||||
#endif
|
||||
|
||||
#endif
|
218
components/etl/test/UnitTest++/MemoryOutStream.cpp
Normal file
218
components/etl/test/UnitTest++/MemoryOutStream.cpp
Normal file
|
@ -0,0 +1,218 @@
|
|||
#include "MemoryOutStream.h"
|
||||
|
||||
#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
char const* MemoryOutStream::GetText() const
|
||||
{
|
||||
m_text = this->str();
|
||||
return m_text.c_str();
|
||||
}
|
||||
|
||||
void MemoryOutStream::Clear()
|
||||
{
|
||||
this->str(std::string());
|
||||
m_text = this->str();
|
||||
}
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
|
||||
#define snprintf _snprintf
|
||||
|
||||
template<typename ValueType>
|
||||
std::ostream& FormatToStream(std::ostream& stream, char const* format, ValueType const& value)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
const size_t BUFFER_SIZE=32;
|
||||
char txt[BUFFER_SIZE];
|
||||
snprintf(txt, BUFFER_SIZE, format, value);
|
||||
return stream << txt;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, __int64 const n)
|
||||
{
|
||||
return FormatToStream(stream, "%I64d", n);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n)
|
||||
{
|
||||
return FormatToStream(stream, "%I64u", n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#if _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename ValueType>
|
||||
void FormatToStream(MemoryOutStream& stream, char const* format, ValueType const& value)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
const size_t BUFFER_SIZE=32;
|
||||
char txt[BUFFER_SIZE];
|
||||
snprintf(txt, BUFFER_SIZE, format, value);
|
||||
stream << txt;
|
||||
}
|
||||
|
||||
int RoundUpToMultipleOfPow2Number (int n, int pow2Number)
|
||||
{
|
||||
return (n + (pow2Number - 1)) & ~(pow2Number - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MemoryOutStream::MemoryOutStream(int const size)
|
||||
: m_capacity (0)
|
||||
, m_buffer (0)
|
||||
|
||||
{
|
||||
GrowBuffer(size);
|
||||
}
|
||||
|
||||
MemoryOutStream::~MemoryOutStream()
|
||||
{
|
||||
delete [] m_buffer;
|
||||
}
|
||||
|
||||
void MemoryOutStream::Clear()
|
||||
{
|
||||
m_buffer[0] = '\0';
|
||||
}
|
||||
|
||||
char const* MemoryOutStream::GetText() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(char const* txt)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
int const bytesLeft = m_capacity - (int)strlen(m_buffer);
|
||||
int const bytesRequired = (int)strlen(txt) + 1;
|
||||
|
||||
if (bytesRequired > bytesLeft)
|
||||
{
|
||||
int const requiredCapacity = bytesRequired + m_capacity - bytesLeft;
|
||||
GrowBuffer(requiredCapacity);
|
||||
}
|
||||
|
||||
strcat(m_buffer, txt);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(int const n)
|
||||
{
|
||||
FormatToStream(*this, "%i", n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(long const n)
|
||||
{
|
||||
FormatToStream(*this, "%li", n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(unsigned long const n)
|
||||
{
|
||||
FormatToStream(*this, "%lu", n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
MemoryOutStream& MemoryOutStream::operator <<(__int64 const n)
|
||||
#else
|
||||
MemoryOutStream& MemoryOutStream::operator <<(long long const n)
|
||||
#endif
|
||||
{
|
||||
#ifdef UNITTEST_WIN32
|
||||
FormatToStream(*this, "%I64d", n);
|
||||
#else
|
||||
FormatToStream(*this, "%lld", n);
|
||||
#endif
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
MemoryOutStream& MemoryOutStream::operator <<(unsigned __int64 const n)
|
||||
#else
|
||||
MemoryOutStream& MemoryOutStream::operator <<(unsigned long long const n)
|
||||
#endif
|
||||
{
|
||||
#ifdef UNITTEST_WIN32
|
||||
FormatToStream(*this, "%I64u", n);
|
||||
#else
|
||||
FormatToStream(*this, "%llu", n);
|
||||
#endif
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(float const f)
|
||||
{
|
||||
FormatToStream(*this, "%0.6f", f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(void const* p)
|
||||
{
|
||||
FormatToStream(*this, "%p", p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(unsigned int const s)
|
||||
{
|
||||
FormatToStream(*this, "%u", s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MemoryOutStream& MemoryOutStream::operator <<(double const d)
|
||||
{
|
||||
FormatToStream(*this, "%0.6f", d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
int MemoryOutStream::GetCapacity() const
|
||||
{
|
||||
return m_capacity;
|
||||
}
|
||||
|
||||
|
||||
void MemoryOutStream::GrowBuffer(int const desiredCapacity)
|
||||
{
|
||||
int const newCapacity = RoundUpToMultipleOfPow2Number(desiredCapacity, GROW_CHUNK_SIZE);
|
||||
|
||||
using namespace std;
|
||||
|
||||
char* buffer = new char[newCapacity];
|
||||
if (m_buffer)
|
||||
strcpy(buffer, m_buffer);
|
||||
else
|
||||
strcpy(buffer, "");
|
||||
|
||||
delete [] m_buffer;
|
||||
m_buffer = buffer;
|
||||
m_capacity = newCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
87
components/etl/test/UnitTest++/MemoryOutStream.h
Normal file
87
components/etl/test/UnitTest++/MemoryOutStream.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
#ifndef UNITTEST_MEMORYOUTSTREAM_H
|
||||
#define UNITTEST_MEMORYOUTSTREAM_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "HelperMacros.h"
|
||||
|
||||
#ifdef UNITTEST_MEMORYOUTSTREAM_IS_STD_OSTRINGSTREAM
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream
|
||||
{
|
||||
public:
|
||||
MemoryOutStream() {}
|
||||
~MemoryOutStream() {}
|
||||
void Clear();
|
||||
char const* GetText() const;
|
||||
|
||||
private:
|
||||
MemoryOutStream(MemoryOutStream const&);
|
||||
void operator =(MemoryOutStream const&);
|
||||
|
||||
mutable std::string m_text;
|
||||
};
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
std::ostream& operator<<(std::ostream& stream, __int64 const n);
|
||||
std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
namespace std {}
|
||||
#endif
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE MemoryOutStream
|
||||
{
|
||||
public:
|
||||
explicit MemoryOutStream(int const size = 256);
|
||||
~MemoryOutStream();
|
||||
|
||||
void Clear();
|
||||
char const* GetText() const;
|
||||
|
||||
MemoryOutStream& operator <<(char const* txt);
|
||||
MemoryOutStream& operator <<(int n);
|
||||
MemoryOutStream& operator <<(long n);
|
||||
MemoryOutStream& operator <<(unsigned long n);
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
MemoryOutStream& operator <<(__int64 n);
|
||||
MemoryOutStream& operator <<(unsigned __int64 n);
|
||||
#else
|
||||
MemoryOutStream& operator <<(long long n);
|
||||
MemoryOutStream& operator <<(unsigned long long n);
|
||||
#endif
|
||||
MemoryOutStream& operator <<(float f);
|
||||
MemoryOutStream& operator <<(double d);
|
||||
MemoryOutStream& operator <<(void const* p);
|
||||
MemoryOutStream& operator <<(unsigned int s);
|
||||
|
||||
enum { GROW_CHUNK_SIZE = 32 };
|
||||
int GetCapacity() const;
|
||||
|
||||
private:
|
||||
void operator= (MemoryOutStream const&);
|
||||
void GrowBuffer(int capacity);
|
||||
|
||||
int m_capacity;
|
||||
char* m_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
46
components/etl/test/UnitTest++/Posix/SignalTranslator.cpp
Normal file
46
components/etl/test/UnitTest++/Posix/SignalTranslator.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "SignalTranslator.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
sigjmp_buf* SignalTranslator::s_jumpTarget = 0;
|
||||
|
||||
namespace {
|
||||
|
||||
void SignalHandler(int sig)
|
||||
{
|
||||
siglongjmp(*SignalTranslator::s_jumpTarget, sig );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
SignalTranslator::SignalTranslator()
|
||||
{
|
||||
m_oldJumpTarget = s_jumpTarget;
|
||||
s_jumpTarget = &m_currentJumpTarget;
|
||||
|
||||
struct sigaction action;
|
||||
action.sa_flags = 0;
|
||||
action.sa_handler = SignalHandler;
|
||||
sigemptyset( &action.sa_mask );
|
||||
|
||||
sigaction( SIGSEGV, &action, &m_old_SIGSEGV_action );
|
||||
sigaction( SIGFPE, &action, &m_old_SIGFPE_action );
|
||||
sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action );
|
||||
sigaction( SIGBUS, &action, &m_old_SIGBUS_action );
|
||||
sigaction( SIGILL, &action, &m_old_SIGILL_action );
|
||||
}
|
||||
|
||||
SignalTranslator::~SignalTranslator()
|
||||
{
|
||||
sigaction( SIGILL, &m_old_SIGILL_action, 0 );
|
||||
sigaction( SIGBUS, &m_old_SIGBUS_action, 0 );
|
||||
sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 );
|
||||
sigaction( SIGFPE, &m_old_SIGFPE_action, 0 );
|
||||
sigaction( SIGSEGV, &m_old_SIGSEGV_action, 0 );
|
||||
|
||||
s_jumpTarget = m_oldJumpTarget;
|
||||
}
|
||||
|
||||
|
||||
}
|
41
components/etl/test/UnitTest++/Posix/SignalTranslator.h
Normal file
41
components/etl/test/UnitTest++/Posix/SignalTranslator.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef UNITTEST_SIGNALTRANSLATOR_H
|
||||
#define UNITTEST_SIGNALTRANSLATOR_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class SignalTranslator
|
||||
{
|
||||
public:
|
||||
SignalTranslator();
|
||||
~SignalTranslator();
|
||||
|
||||
static sigjmp_buf* s_jumpTarget;
|
||||
|
||||
private:
|
||||
sigjmp_buf m_currentJumpTarget;
|
||||
sigjmp_buf* m_oldJumpTarget;
|
||||
|
||||
struct sigaction m_old_SIGFPE_action;
|
||||
struct sigaction m_old_SIGTRAP_action;
|
||||
struct sigaction m_old_SIGSEGV_action;
|
||||
struct sigaction m_old_SIGBUS_action;
|
||||
struct sigaction m_old_SIGILL_action;
|
||||
};
|
||||
|
||||
#if !defined (__GNUC__)
|
||||
#define UNITTEST_EXTENSION
|
||||
#else
|
||||
#define UNITTEST_EXTENSION __extension__
|
||||
#endif
|
||||
|
||||
#define UNITTEST_THROW_SIGNALS_POSIX_ONLY \
|
||||
UnitTest::SignalTranslator sig; \
|
||||
if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \
|
||||
throw ("Unhandled system exception");
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
components/etl/test/UnitTest++/Posix/TimeHelpers.cpp
Normal file
33
components/etl/test/UnitTest++/Posix/TimeHelpers.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "TimeHelpers.h"
|
||||
#include <unistd.h>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
Timer::Timer()
|
||||
{
|
||||
m_startTime.tv_sec = 0;
|
||||
m_startTime.tv_usec = 0;
|
||||
}
|
||||
|
||||
void Timer::Start()
|
||||
{
|
||||
gettimeofday(&m_startTime, 0);
|
||||
}
|
||||
|
||||
double Timer::GetTimeInMs() const
|
||||
{
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
|
||||
double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
|
||||
double const dus = currentTime.tv_usec - m_startTime.tv_usec;
|
||||
|
||||
return (dsecs * 1000.0) + (dus / 1000.0);
|
||||
}
|
||||
|
||||
void TimeHelpers::SleepMs(int ms)
|
||||
{
|
||||
usleep(static_cast<useconds_t>(ms * 1000));
|
||||
}
|
||||
|
||||
}
|
28
components/etl/test/UnitTest++/Posix/TimeHelpers.h
Normal file
28
components/etl/test/UnitTest++/Posix/TimeHelpers.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef UNITTEST_TIMEHELPERS_H
|
||||
#define UNITTEST_TIMEHELPERS_H
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
void Start();
|
||||
double GetTimeInMs() const;
|
||||
|
||||
private:
|
||||
struct timeval m_startTime;
|
||||
};
|
||||
|
||||
|
||||
namespace TimeHelpers
|
||||
{
|
||||
void SleepMs(int ms);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
71
components/etl/test/UnitTest++/ReportAssert.cpp
Normal file
71
components/etl/test/UnitTest++/ReportAssert.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "ReportAssert.h"
|
||||
#include "ReportAssertImpl.h"
|
||||
#include "AssertException.h"
|
||||
#include "CurrentTest.h"
|
||||
#include "TestResults.h"
|
||||
#include "TestDetails.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
#include "ReportAssertImpl.h"
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
namespace
|
||||
{
|
||||
bool& AssertExpectedFlag()
|
||||
{
|
||||
static bool s_assertExpected = false;
|
||||
return s_assertExpected;
|
||||
}
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename, int lineNumber)
|
||||
{
|
||||
Detail::ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(),
|
||||
description, filename, lineNumber);
|
||||
}
|
||||
|
||||
namespace Detail {
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
UNITTEST_JMPBUF* GetAssertJmpBuf()
|
||||
{
|
||||
static UNITTEST_JMPBUF s_jmpBuf;
|
||||
return &s_jmpBuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults,
|
||||
const TestDetails* testDetails,
|
||||
char const* description,
|
||||
char const* filename,
|
||||
int lineNumber)
|
||||
{
|
||||
if (AssertExpectedFlag() == false)
|
||||
{
|
||||
TestDetails assertDetails(testDetails->testName, testDetails->suiteName, filename, lineNumber);
|
||||
testResults->OnTestFailure(assertDetails, description);
|
||||
}
|
||||
|
||||
ExpectAssert(false);
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
throw AssertException();
|
||||
#else
|
||||
UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET();
|
||||
#endif
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE void ExpectAssert(bool expected)
|
||||
{
|
||||
AssertExpectedFlag() = expected;
|
||||
}
|
||||
|
||||
UNITTEST_LINKAGE bool AssertExpected()
|
||||
{
|
||||
return AssertExpectedFlag();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
12
components/etl/test/UnitTest++/ReportAssert.h
Normal file
12
components/etl/test/UnitTest++/ReportAssert.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef UNITTEST_ASSERT_H
|
||||
#define UNITTEST_ASSERT_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
UNITTEST_LINKAGE void ReportAssert(char const* description, char const* filename, int lineNumber);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
46
components/etl/test/UnitTest++/ReportAssertImpl.h
Normal file
46
components/etl/test/UnitTest++/ReportAssertImpl.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef UNITTEST_REPORTASSERTIMPL_H
|
||||
#define UNITTEST_REPORTASSERTIMPL_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "HelperMacros.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
#include <csetjmp>
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestResults;
|
||||
class TestDetails;
|
||||
|
||||
namespace Detail {
|
||||
|
||||
UNITTEST_LINKAGE void ExpectAssert(bool expected);
|
||||
|
||||
UNITTEST_LINKAGE void ReportAssertEx(TestResults* testResults,
|
||||
const TestDetails* testDetails,
|
||||
char const* description,
|
||||
char const* filename,
|
||||
int lineNumber);
|
||||
|
||||
UNITTEST_LINKAGE bool AssertExpected();
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
UNITTEST_LINKAGE UNITTEST_JMPBUF* GetAssertJmpBuf();
|
||||
|
||||
#ifdef UNITTEST_WIN32
|
||||
#define UNITTEST_SET_ASSERT_JUMP_TARGET() \
|
||||
__pragma(warning(push)) __pragma(warning(disable: 4611)) \
|
||||
UNITTEST_SETJMP(*UnitTest::Detail::GetAssertJmpBuf()) \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
#define UNITTEST_SET_ASSERT_JUMP_TARGET() UNITTEST_SETJMP(*UnitTest::Detail::GetAssertJmpBuf())
|
||||
#endif
|
||||
|
||||
#define UNITTEST_JUMP_TO_ASSERT_JUMP_TARGET() UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), 1)
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
16
components/etl/test/UnitTest++/RequireMacros.h
Normal file
16
components/etl/test/UnitTest++/RequireMacros.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef UNITTEST_REQUIREMACROS_H
|
||||
#define UNITTEST_REQUIREMACROS_H
|
||||
|
||||
#include "RequiredCheckTestReporter.h"
|
||||
|
||||
#define UNITTEST_REQUIRE for(UnitTest::RequiredCheckTestReporter decoratedReporter(*UnitTest::CurrentTest::Results()); decoratedReporter.Next(); )
|
||||
|
||||
#ifndef UNITTEST_DISABLE_SHORT_MACROS
|
||||
#ifdef REQUIRE
|
||||
#error REQUIRE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_REQUIRE instead
|
||||
#else
|
||||
#define REQUIRE UNITTEST_REQUIRE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
17
components/etl/test/UnitTest++/RequiredCheckException.cpp
Normal file
17
components/etl/test/UnitTest++/RequiredCheckException.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "RequiredCheckException.h"
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
RequiredCheckException::RequiredCheckException()
|
||||
{
|
||||
}
|
||||
|
||||
RequiredCheckException::~RequiredCheckException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
23
components/etl/test/UnitTest++/RequiredCheckException.h
Normal file
23
components/etl/test/UnitTest++/RequiredCheckException.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef UNITTEST_REQUIREDCHECKEXCEPTION_H
|
||||
#define UNITTEST_REQUIREDCHECKEXCEPTION_H
|
||||
|
||||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include <exception>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE RequiredCheckException : public std::exception
|
||||
{
|
||||
public:
|
||||
RequiredCheckException();
|
||||
virtual ~RequiredCheckException() throw();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
26
components/etl/test/UnitTest++/RequiredCheckTestReporter.cpp
Normal file
26
components/etl/test/UnitTest++/RequiredCheckTestReporter.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "RequiredCheckTestReporter.h"
|
||||
|
||||
#include "CurrentTest.h"
|
||||
#include "TestResults.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
RequiredCheckTestReporter::RequiredCheckTestReporter(TestResults& results)
|
||||
: m_results(results)
|
||||
, m_originalTestReporter(results.m_testReporter)
|
||||
, m_throwingReporter(results.m_testReporter)
|
||||
, m_continue(0)
|
||||
{
|
||||
m_results.m_testReporter = &m_throwingReporter;
|
||||
}
|
||||
|
||||
RequiredCheckTestReporter::~RequiredCheckTestReporter()
|
||||
{
|
||||
m_results.m_testReporter = m_originalTestReporter;
|
||||
}
|
||||
|
||||
bool RequiredCheckTestReporter::Next()
|
||||
{
|
||||
return m_continue++ == 0;
|
||||
}
|
||||
}
|
33
components/etl/test/UnitTest++/RequiredCheckTestReporter.h
Normal file
33
components/etl/test/UnitTest++/RequiredCheckTestReporter.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef UNITTEST_REQUIRED_CHECK_TEST_REPORTER_H
|
||||
#define UNITTEST_REQUIRED_CHECK_TEST_REPORTER_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
#include "ThrowingTestReporter.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestResults;
|
||||
|
||||
// This RAII class decorates the current TestReporter with
|
||||
// a version that throws after reporting a failure.
|
||||
class UNITTEST_LINKAGE RequiredCheckTestReporter
|
||||
{
|
||||
public:
|
||||
explicit RequiredCheckTestReporter(TestResults& results);
|
||||
~RequiredCheckTestReporter();
|
||||
|
||||
bool Next();
|
||||
|
||||
private:
|
||||
RequiredCheckTestReporter(RequiredCheckTestReporter const&);
|
||||
RequiredCheckTestReporter& operator =(RequiredCheckTestReporter const&);
|
||||
|
||||
TestResults& m_results;
|
||||
TestReporter* m_originalTestReporter;
|
||||
ThrowingTestReporter m_throwingReporter;
|
||||
int m_continue;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
38
components/etl/test/UnitTest++/Test.cpp
Normal file
38
components/etl/test/UnitTest++/Test.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "Config.h"
|
||||
#include "Test.h"
|
||||
#include "TestList.h"
|
||||
#include "TestResults.h"
|
||||
#include "AssertException.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "ExecuteTest.h"
|
||||
|
||||
#ifdef UNITTEST_POSIX
|
||||
#include "Posix/SignalTranslator.h"
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
TestList& Test::GetTestList()
|
||||
{
|
||||
static TestList s_list;
|
||||
return s_list;
|
||||
}
|
||||
|
||||
Test::Test(char const* testName, char const* suiteName, char const* filename, int lineNumber)
|
||||
: m_details(testName, suiteName, filename, lineNumber)
|
||||
, m_nextTest(0)
|
||||
, m_isMockTest(false)
|
||||
{}
|
||||
|
||||
Test::~Test()
|
||||
{}
|
||||
|
||||
void Test::Run()
|
||||
{
|
||||
ExecuteTest(*this, m_details, m_isMockTest);
|
||||
}
|
||||
|
||||
void Test::RunImpl() const
|
||||
{}
|
||||
|
||||
}
|
35
components/etl/test/UnitTest++/Test.h
Normal file
35
components/etl/test/UnitTest++/Test.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef UNITTEST_TEST_H
|
||||
#define UNITTEST_TEST_H
|
||||
|
||||
#include "TestDetails.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestResults;
|
||||
class TestList;
|
||||
|
||||
class UNITTEST_LINKAGE Test
|
||||
{
|
||||
public:
|
||||
explicit Test(char const* testName, char const* suiteName = "DefaultSuite", char const* filename = "", int lineNumber = 0);
|
||||
virtual ~Test();
|
||||
void Run();
|
||||
|
||||
TestDetails const m_details;
|
||||
Test* m_nextTest;
|
||||
|
||||
mutable bool m_isMockTest;
|
||||
|
||||
static TestList& GetTestList();
|
||||
|
||||
virtual void RunImpl() const;
|
||||
|
||||
private:
|
||||
Test(Test const&);
|
||||
Test& operator =(Test const&);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
22
components/etl/test/UnitTest++/TestDetails.cpp
Normal file
22
components/etl/test/UnitTest++/TestDetails.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "TestDetails.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
TestDetails::TestDetails(char const* testName_, char const* suiteName_, char const* filename_, int lineNumber_)
|
||||
: suiteName(suiteName_)
|
||||
, testName(testName_)
|
||||
, filename(filename_)
|
||||
, lineNumber(lineNumber_)
|
||||
, timeConstraintExempt(false)
|
||||
{}
|
||||
|
||||
TestDetails::TestDetails(const TestDetails& details, int lineNumber_)
|
||||
: suiteName(details.suiteName)
|
||||
, testName(details.testName)
|
||||
, filename(details.filename)
|
||||
, lineNumber(lineNumber_)
|
||||
, timeConstraintExempt(details.timeConstraintExempt)
|
||||
{}
|
||||
|
||||
|
||||
}
|
27
components/etl/test/UnitTest++/TestDetails.h
Normal file
27
components/etl/test/UnitTest++/TestDetails.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef UNITTEST_TESTDETAILS_H
|
||||
#define UNITTEST_TESTDETAILS_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE TestDetails
|
||||
{
|
||||
public:
|
||||
TestDetails(char const* testName, char const* suiteName, char const* filename, int lineNumber);
|
||||
TestDetails(const TestDetails& details, int lineNumber);
|
||||
|
||||
char const* const suiteName;
|
||||
char const* const testName;
|
||||
char const* const filename;
|
||||
int const lineNumber;
|
||||
mutable bool timeConstraintExempt;
|
||||
|
||||
TestDetails(TestDetails const&); // Why is it public? --> http://gcc.gnu.org/bugs.html#cxx_rvalbind
|
||||
private:
|
||||
TestDetails& operator=(TestDetails const&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
38
components/etl/test/UnitTest++/TestList.cpp
Normal file
38
components/etl/test/UnitTest++/TestList.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "TestList.h"
|
||||
#include "Test.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
TestList::TestList()
|
||||
: m_head(0)
|
||||
, m_tail(0)
|
||||
{}
|
||||
|
||||
void TestList::Add(Test* test)
|
||||
{
|
||||
if (m_tail == 0)
|
||||
{
|
||||
assert(m_head == 0);
|
||||
m_head = test;
|
||||
m_tail = test;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tail->m_nextTest = test;
|
||||
m_tail = test;
|
||||
}
|
||||
}
|
||||
|
||||
Test* TestList::GetHead() const
|
||||
{
|
||||
return m_head;
|
||||
}
|
||||
|
||||
ListAdder::ListAdder(TestList& list, Test* test)
|
||||
{
|
||||
list.Add(test);
|
||||
}
|
||||
|
||||
}
|
33
components/etl/test/UnitTest++/TestList.h
Normal file
33
components/etl/test/UnitTest++/TestList.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef UNITTEST_TESTLIST_H
|
||||
#define UNITTEST_TESTLIST_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class Test;
|
||||
|
||||
class UNITTEST_LINKAGE TestList
|
||||
{
|
||||
public:
|
||||
TestList();
|
||||
void Add (Test* test);
|
||||
|
||||
Test* GetHead() const;
|
||||
|
||||
private:
|
||||
Test* m_head;
|
||||
Test* m_tail;
|
||||
};
|
||||
|
||||
|
||||
class UNITTEST_LINKAGE ListAdder
|
||||
{
|
||||
public:
|
||||
ListAdder(TestList& list, Test* test);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
126
components/etl/test/UnitTest++/TestMacros.h
Normal file
126
components/etl/test/UnitTest++/TestMacros.h
Normal file
|
@ -0,0 +1,126 @@
|
|||
#ifndef UNITTEST_TESTMACROS_H
|
||||
#define UNITTEST_TESTMACROS_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "TestSuite.h"
|
||||
#include "ExceptionMacros.h"
|
||||
#include "ExecuteTest.h"
|
||||
#include "AssertException.h"
|
||||
#include "TestDetails.h"
|
||||
#include "MemoryOutStream.h"
|
||||
|
||||
#ifndef UNITTEST_POSIX
|
||||
#define UNITTEST_THROW_SIGNALS_POSIX_ONLY
|
||||
#else
|
||||
#include "Posix/SignalTranslator.h"
|
||||
#endif
|
||||
|
||||
#define UNITTEST_SUITE(Name) \
|
||||
namespace Suite ## Name { \
|
||||
namespace UnitTestSuite { \
|
||||
inline char const* GetSuiteName () { \
|
||||
return #Name; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
namespace Suite ## Name
|
||||
|
||||
#define UNITTEST_IMPL_TEST(Name, List) \
|
||||
class Test ## Name : public UnitTest::Test \
|
||||
{ \
|
||||
public: \
|
||||
Test ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \
|
||||
private: \
|
||||
virtual void RunImpl() const; \
|
||||
} static test ## Name ## Instance; \
|
||||
\
|
||||
static UnitTest::ListAdder adder ## Name (List, &test ## Name ## Instance); \
|
||||
\
|
||||
void Test ## Name::RunImpl() const
|
||||
|
||||
|
||||
#define UNITTEST_TEST(Name) UNITTEST_IMPL_TEST(Name, UnitTest::Test::GetTestList())
|
||||
|
||||
|
||||
#define UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, List) \
|
||||
class Fixture ## Name ## Helper : public Fixture \
|
||||
{ \
|
||||
public: \
|
||||
explicit Fixture ## Name ## Helper(UnitTest::TestDetails const& details) : m_details(details) {} \
|
||||
void RunImpl(); \
|
||||
UnitTest::TestDetails const& m_details; \
|
||||
virtual ~Fixture ## Name ## Helper(); \
|
||||
private: \
|
||||
Fixture ## Name ## Helper(Fixture ## Name ## Helper const&); \
|
||||
Fixture ## Name ## Helper& operator =(Fixture ## Name ## Helper const&); \
|
||||
}; \
|
||||
Fixture ## Name ## Helper::~Fixture ## Name ## Helper(){} \
|
||||
\
|
||||
class Test ## Fixture ## Name : public UnitTest::Test \
|
||||
{ \
|
||||
public: \
|
||||
Test ## Fixture ## Name() : Test(#Name, UnitTestSuite::GetSuiteName(), __FILE__, __LINE__) {} \
|
||||
private: \
|
||||
virtual void RunImpl() const; \
|
||||
} static test ## Fixture ## Name ## Instance; \
|
||||
\
|
||||
static UnitTest::ListAdder adder ## Fixture ## Name (List, &test ## Fixture ## Name ## Instance); \
|
||||
\
|
||||
void Test ## Fixture ## Name::RunImpl() const \
|
||||
{ \
|
||||
volatile bool ctorOk = false; \
|
||||
UNITTEST_IMPL_TRY \
|
||||
({ \
|
||||
Fixture ## Name ## Helper fixtureHelper(m_details); \
|
||||
ctorOk = true; \
|
||||
UnitTest::ExecuteTest(fixtureHelper, m_details, false); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH (UnitTest::AssertException, e, \
|
||||
{ \
|
||||
(void)e; \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH (std::exception, e, \
|
||||
{ \
|
||||
UnitTest::MemoryOutStream stream; \
|
||||
stream << "Unhandled exception: " << e.what(); \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); \
|
||||
}) \
|
||||
UNITTEST_IMPL_CATCH_ALL \
|
||||
({ \
|
||||
if (ctorOk) \
|
||||
{ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
|
||||
"Unhandled exception while destroying fixture " #Fixture); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
|
||||
"Unhandled exception while constructing fixture " #Fixture); \
|
||||
} \
|
||||
}) \
|
||||
} \
|
||||
void Fixture ## Name ## Helper::RunImpl()
|
||||
|
||||
#define UNITTEST_TEST_FIXTURE(Fixture,Name) UNITTEST_IMPL_TEST_FIXTURE(Fixture, Name, UnitTest::Test::GetTestList())
|
||||
|
||||
#ifndef UNITTEST_DISABLE_SHORT_MACROS
|
||||
#ifdef SUITE
|
||||
#error SUITE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_SUITE instead
|
||||
#else
|
||||
#define SUITE(name) UNITTEST_SUITE(name)
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
#error TEST already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST instead
|
||||
#else
|
||||
#define TEST(Name) UNITTEST_TEST(Name)
|
||||
#endif
|
||||
|
||||
#ifdef TEST_FIXTURE
|
||||
#error TEST_FIXTURE already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_TEST_FIXTURE instead
|
||||
#else
|
||||
#define TEST_FIXTURE(Fixture,Name) UNITTEST_TEST_FIXTURE(Fixture,Name)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
8
components/etl/test/UnitTest++/TestReporter.cpp
Normal file
8
components/etl/test/UnitTest++/TestReporter.cpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "TestReporter.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
TestReporter::~TestReporter()
|
||||
{}
|
||||
|
||||
}
|
22
components/etl/test/UnitTest++/TestReporter.h
Normal file
22
components/etl/test/UnitTest++/TestReporter.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef UNITTEST_TESTREPORTER_H
|
||||
#define UNITTEST_TESTREPORTER_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestDetails;
|
||||
|
||||
class UNITTEST_LINKAGE TestReporter
|
||||
{
|
||||
public:
|
||||
virtual ~TestReporter();
|
||||
|
||||
virtual void ReportTestStart(TestDetails const& test) = 0;
|
||||
virtual void ReportFailure(TestDetails const& test, char const* failure) = 0;
|
||||
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed) = 0;
|
||||
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
44
components/etl/test/UnitTest++/TestReporterStdout.cpp
Normal file
44
components/etl/test/UnitTest++/TestReporterStdout.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "TestReporterStdout.h"
|
||||
#include <cstdio>
|
||||
|
||||
#include "TestDetails.h"
|
||||
|
||||
// cstdio doesn't pull in namespace std on VC6, so we do it here.
|
||||
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200)
|
||||
namespace std {}
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure)
|
||||
{
|
||||
using namespace std;
|
||||
#if defined(__APPLE__) || defined(__GNUG__)
|
||||
char const* const errorFormat = "%s:%d:%d: error: Failure in %s: %s\n";
|
||||
fprintf(stderr, errorFormat, details.filename, details.lineNumber, 1, details.testName, failure);
|
||||
#else
|
||||
char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n";
|
||||
fprintf(stderr, errorFormat, details.filename, details.lineNumber, details.testName, failure);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TestReporterStdout::ReportTestStart(TestDetails const& /*test*/)
|
||||
{}
|
||||
|
||||
void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float)
|
||||
{}
|
||||
|
||||
void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount,
|
||||
int const failureCount, float const secondsElapsed)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if (failureCount > 0)
|
||||
printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount);
|
||||
else
|
||||
printf("Success: %d tests passed.\n", totalTestCount);
|
||||
|
||||
printf("Test time: %.2f seconds.\n", secondsElapsed);
|
||||
}
|
||||
|
||||
}
|
19
components/etl/test/UnitTest++/TestReporterStdout.h
Normal file
19
components/etl/test/UnitTest++/TestReporterStdout.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef UNITTEST_TESTREPORTERSTDOUT_H
|
||||
#define UNITTEST_TESTREPORTERSTDOUT_H
|
||||
|
||||
#include "TestReporter.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE TestReporterStdout : public TestReporter
|
||||
{
|
||||
private:
|
||||
virtual void ReportTestStart(TestDetails const& test);
|
||||
virtual void ReportFailure(TestDetails const& test, char const* failure);
|
||||
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
|
||||
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
59
components/etl/test/UnitTest++/TestResults.cpp
Normal file
59
components/etl/test/UnitTest++/TestResults.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "TestResults.h"
|
||||
#include "TestReporter.h"
|
||||
|
||||
#include "TestDetails.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
TestResults::TestResults(TestReporter* testReporter)
|
||||
: m_testReporter(testReporter)
|
||||
, m_totalTestCount(0)
|
||||
, m_failedTestCount(0)
|
||||
, m_failureCount(0)
|
||||
, m_currentTestFailed(false)
|
||||
{}
|
||||
|
||||
void TestResults::OnTestStart(TestDetails const& test)
|
||||
{
|
||||
++m_totalTestCount;
|
||||
m_currentTestFailed = false;
|
||||
if (m_testReporter)
|
||||
m_testReporter->ReportTestStart(test);
|
||||
}
|
||||
|
||||
void TestResults::OnTestFailure(TestDetails const& test, char const* failure)
|
||||
{
|
||||
++m_failureCount;
|
||||
if (!m_currentTestFailed)
|
||||
{
|
||||
++m_failedTestCount;
|
||||
m_currentTestFailed = true;
|
||||
}
|
||||
|
||||
if (m_testReporter)
|
||||
m_testReporter->ReportFailure(test, failure);
|
||||
}
|
||||
|
||||
void TestResults::OnTestFinish(TestDetails const& test, float secondsElapsed)
|
||||
{
|
||||
if (m_testReporter)
|
||||
m_testReporter->ReportTestFinish(test, secondsElapsed);
|
||||
}
|
||||
|
||||
int TestResults::GetTotalTestCount() const
|
||||
{
|
||||
return m_totalTestCount;
|
||||
}
|
||||
|
||||
int TestResults::GetFailedTestCount() const
|
||||
{
|
||||
return m_failedTestCount;
|
||||
}
|
||||
|
||||
int TestResults::GetFailureCount() const
|
||||
{
|
||||
return m_failureCount;
|
||||
}
|
||||
|
||||
|
||||
}
|
41
components/etl/test/UnitTest++/TestResults.h
Normal file
41
components/etl/test/UnitTest++/TestResults.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef UNITTEST_TESTRESULTS_H
|
||||
#define UNITTEST_TESTRESULTS_H
|
||||
|
||||
#include "HelperMacros.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class RequiredCheckTestReporter;
|
||||
class TestReporter;
|
||||
class TestDetails;
|
||||
|
||||
class UNITTEST_LINKAGE TestResults
|
||||
{
|
||||
public:
|
||||
explicit TestResults(TestReporter* reporter = 0);
|
||||
|
||||
void OnTestStart(TestDetails const& test);
|
||||
void OnTestFailure(TestDetails const& test, char const* failure);
|
||||
void OnTestFinish(TestDetails const& test, float secondsElapsed);
|
||||
|
||||
int GetTotalTestCount() const;
|
||||
int GetFailedTestCount() const;
|
||||
int GetFailureCount() const;
|
||||
|
||||
private:
|
||||
friend class RequiredCheckTestReporter;
|
||||
|
||||
TestReporter* m_testReporter;
|
||||
int m_totalTestCount;
|
||||
int m_failedTestCount;
|
||||
int m_failureCount;
|
||||
|
||||
bool m_currentTestFailed;
|
||||
|
||||
TestResults(TestResults const&);
|
||||
TestResults& operator =(TestResults const&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
82
components/etl/test/UnitTest++/TestRunner.cpp
Normal file
82
components/etl/test/UnitTest++/TestRunner.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "TestRunner.h"
|
||||
#include "TestResults.h"
|
||||
#include "TestReporter.h"
|
||||
#include "TestReporterStdout.h"
|
||||
#include "TimeHelpers.h"
|
||||
#include "MemoryOutStream.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
int RunAllTests()
|
||||
{
|
||||
TestReporterStdout reporter;
|
||||
TestRunner runner(reporter);
|
||||
return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0);
|
||||
}
|
||||
|
||||
|
||||
TestRunner::TestRunner(TestReporter& reporter)
|
||||
: m_reporter(&reporter)
|
||||
, m_result(new TestResults(&reporter))
|
||||
, m_timer(new Timer)
|
||||
{
|
||||
m_timer->Start();
|
||||
}
|
||||
|
||||
TestRunner::~TestRunner()
|
||||
{
|
||||
delete m_result;
|
||||
delete m_timer;
|
||||
}
|
||||
|
||||
TestResults* TestRunner::GetTestResults()
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
int TestRunner::Finish() const
|
||||
{
|
||||
float const secondsElapsed = static_cast<float>(m_timer->GetTimeInMs() / 1000.0);
|
||||
m_reporter->ReportSummary(m_result->GetTotalTestCount(),
|
||||
m_result->GetFailedTestCount(),
|
||||
m_result->GetFailureCount(),
|
||||
secondsElapsed);
|
||||
|
||||
return m_result->GetFailureCount();
|
||||
}
|
||||
|
||||
bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const
|
||||
{
|
||||
using namespace std;
|
||||
return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName);
|
||||
}
|
||||
|
||||
void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const
|
||||
{
|
||||
if (curTest->m_isMockTest == false)
|
||||
CurrentTest::Results() = result;
|
||||
|
||||
Timer testTimer;
|
||||
testTimer.Start();
|
||||
|
||||
result->OnTestStart(curTest->m_details);
|
||||
|
||||
curTest->Run();
|
||||
|
||||
double const testTimeInMs = testTimer.GetTimeInMs();
|
||||
if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_details.timeConstraintExempt)
|
||||
{
|
||||
MemoryOutStream stream;
|
||||
stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
|
||||
"ms but took " << testTimeInMs << "ms.";
|
||||
|
||||
result->OnTestFailure(curTest->m_details, stream.GetText());
|
||||
}
|
||||
|
||||
result->OnTestFinish(curTest->m_details, static_cast< float >(testTimeInMs / 1000.0));
|
||||
}
|
||||
|
||||
}
|
61
components/etl/test/UnitTest++/TestRunner.h
Normal file
61
components/etl/test/UnitTest++/TestRunner.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
#ifndef UNITTEST_TESTRUNNER_H
|
||||
#define UNITTEST_TESTRUNNER_H
|
||||
|
||||
#include "Test.h"
|
||||
#include "TestList.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestReporter;
|
||||
class TestResults;
|
||||
class Timer;
|
||||
|
||||
UNITTEST_LINKAGE int RunAllTests();
|
||||
|
||||
struct True
|
||||
{
|
||||
bool operator()(const Test* const) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class UNITTEST_LINKAGE TestRunner
|
||||
{
|
||||
public:
|
||||
explicit TestRunner(TestReporter& reporter);
|
||||
~TestRunner();
|
||||
|
||||
template< class Predicate >
|
||||
int RunTestsIf(TestList const& list, char const* suiteName,
|
||||
const Predicate& predicate, int maxTestTimeInMs) const
|
||||
{
|
||||
Test* curTest = list.GetHead();
|
||||
|
||||
while (curTest != 0)
|
||||
{
|
||||
if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
|
||||
RunTest(m_result, curTest, maxTestTimeInMs);
|
||||
|
||||
curTest = curTest->m_nextTest;
|
||||
}
|
||||
|
||||
return Finish();
|
||||
}
|
||||
|
||||
TestResults* GetTestResults();
|
||||
|
||||
private:
|
||||
TestReporter* m_reporter;
|
||||
TestResults* m_result;
|
||||
Timer* m_timer;
|
||||
|
||||
int Finish() const;
|
||||
bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
|
||||
void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
12
components/etl/test/UnitTest++/TestSuite.h
Normal file
12
components/etl/test/UnitTest++/TestSuite.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef UNITTEST_TESTSUITE_H
|
||||
#define UNITTEST_TESTSUITE_H
|
||||
|
||||
namespace UnitTestSuite
|
||||
{
|
||||
inline char const* GetSuiteName ()
|
||||
{
|
||||
return "DefaultSuite";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
61
components/etl/test/UnitTest++/ThrowingTestReporter.cpp
Normal file
61
components/etl/test/UnitTest++/ThrowingTestReporter.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "ThrowingTestReporter.h"
|
||||
#include "RequiredCheckException.h"
|
||||
|
||||
#ifdef UNITTEST_NO_EXCEPTIONS
|
||||
#include "ReportAssertImpl.h"
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
ThrowingTestReporter::ThrowingTestReporter(TestReporter* decoratedReporter)
|
||||
: m_decoratedReporter(decoratedReporter)
|
||||
{}
|
||||
|
||||
//virtual
|
||||
ThrowingTestReporter::~ThrowingTestReporter()
|
||||
{}
|
||||
|
||||
//virtual
|
||||
void ThrowingTestReporter::ReportTestStart(TestDetails const& test)
|
||||
{
|
||||
if(m_decoratedReporter)
|
||||
{
|
||||
m_decoratedReporter->ReportTestStart(test);
|
||||
}
|
||||
}
|
||||
|
||||
//virtual
|
||||
void ThrowingTestReporter::ReportFailure(TestDetails const& test, char const* failure)
|
||||
{
|
||||
if(m_decoratedReporter)
|
||||
{
|
||||
m_decoratedReporter->ReportFailure(test, failure);
|
||||
}
|
||||
|
||||
#ifndef UNITTEST_NO_EXCEPTIONS
|
||||
throw RequiredCheckException();
|
||||
#else
|
||||
static const int stopTest = 1;
|
||||
UNITTEST_LONGJMP(*UnitTest::Detail::GetAssertJmpBuf(), stopTest);
|
||||
#endif
|
||||
}
|
||||
|
||||
//virtual
|
||||
void ThrowingTestReporter::ReportTestFinish(TestDetails const& test, float secondsElapsed)
|
||||
{
|
||||
if(m_decoratedReporter)
|
||||
{
|
||||
m_decoratedReporter->ReportTestFinish(test, secondsElapsed);
|
||||
}
|
||||
}
|
||||
|
||||
//virtual
|
||||
void ThrowingTestReporter::ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed)
|
||||
{
|
||||
if(m_decoratedReporter)
|
||||
{
|
||||
m_decoratedReporter->ReportSummary(totalTestCount, failedTestCount, failureCount, secondsElapsed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
26
components/etl/test/UnitTest++/ThrowingTestReporter.h
Normal file
26
components/etl/test/UnitTest++/ThrowingTestReporter.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef UNITTEST_THROWINGTESTREPORTER_H
|
||||
#define UNITTEST_THROWINGTESTREPORTER_H
|
||||
|
||||
#include "TestReporter.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
// A TestReporter that throws when ReportFailure is called. Otherwise it
|
||||
// forwards the calls to a decorated TestReporter
|
||||
class ThrowingTestReporter : public TestReporter
|
||||
{
|
||||
public:
|
||||
explicit ThrowingTestReporter(TestReporter* reporter);
|
||||
|
||||
virtual ~ThrowingTestReporter();
|
||||
virtual void ReportTestStart(TestDetails const& test);
|
||||
virtual void ReportFailure(TestDetails const& test, char const* failure);
|
||||
virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
|
||||
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
|
||||
|
||||
private:
|
||||
TestReporter* m_decoratedReporter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
29
components/etl/test/UnitTest++/TimeConstraint.cpp
Normal file
29
components/etl/test/UnitTest++/TimeConstraint.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "TimeConstraint.h"
|
||||
#include "TestResults.h"
|
||||
#include "MemoryOutStream.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
|
||||
TimeConstraint::TimeConstraint(int ms, TestDetails const& details, int lineNumber)
|
||||
: m_details(details, lineNumber)
|
||||
, m_maxMs(ms)
|
||||
{
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
TimeConstraint::~TimeConstraint()
|
||||
{
|
||||
double const totalTimeInMs = m_timer.GetTimeInMs();
|
||||
if (totalTimeInMs > m_maxMs)
|
||||
{
|
||||
MemoryOutStream stream;
|
||||
stream << "Time constraint failed. Expected to run test under " << m_maxMs <<
|
||||
"ms but took " << totalTimeInMs << "ms.";
|
||||
|
||||
CurrentTest::Results()->OnTestFailure(m_details, stream.GetText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
37
components/etl/test/UnitTest++/TimeConstraint.h
Normal file
37
components/etl/test/UnitTest++/TimeConstraint.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef UNITTEST_TIMECONSTRAINT_H
|
||||
#define UNITTEST_TIMECONSTRAINT_H
|
||||
|
||||
#include "TimeHelpers.h"
|
||||
#include "HelperMacros.h"
|
||||
#include "TestDetails.h"
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class TestResults;
|
||||
|
||||
class UNITTEST_LINKAGE TimeConstraint
|
||||
{
|
||||
public:
|
||||
TimeConstraint(int ms, TestDetails const& details, int lineNumber);
|
||||
~TimeConstraint();
|
||||
|
||||
private:
|
||||
void operator=(TimeConstraint const&);
|
||||
TimeConstraint(TimeConstraint const&);
|
||||
|
||||
Timer m_timer;
|
||||
TestDetails const m_details;
|
||||
int const m_maxMs;
|
||||
};
|
||||
|
||||
#define UNITTEST_TIME_CONSTRAINT(ms) \
|
||||
UnitTest::TimeConstraint unitTest__timeConstraint__(ms, m_details, __LINE__)
|
||||
|
||||
#define UNITTEST_TIME_CONSTRAINT_EXEMPT() \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
m_details.timeConstraintExempt = true; \
|
||||
UNITTEST_MULTILINE_MACRO_END
|
||||
|
||||
}
|
||||
|
||||
#endif
|
7
components/etl/test/UnitTest++/TimeHelpers.h
Normal file
7
components/etl/test/UnitTest++/TimeHelpers.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "Config.h"
|
||||
|
||||
#if defined UNITTEST_POSIX
|
||||
#include "Posix/TimeHelpers.h"
|
||||
#else
|
||||
#include "Win32/TimeHelpers.h"
|
||||
#endif
|
1
components/etl/test/UnitTest++/UnitTest++.h
Normal file
1
components/etl/test/UnitTest++/UnitTest++.h
Normal file
|
@ -0,0 +1 @@
|
|||
#include "UnitTestPP.h"
|
12
components/etl/test/UnitTest++/UnitTestPP.h
Normal file
12
components/etl/test/UnitTest++/UnitTestPP.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef UNITTESTPP_H
|
||||
#define UNITTESTPP_H
|
||||
|
||||
#include "Config.h"
|
||||
#include "TestMacros.h"
|
||||
#include "CheckMacros.h"
|
||||
#include "RequireMacros.h"
|
||||
#include "TestRunner.h"
|
||||
#include "TimeConstraint.h"
|
||||
#include "ReportAssert.h"
|
||||
|
||||
#endif
|
49
components/etl/test/UnitTest++/Win32/TimeHelpers.cpp
Normal file
49
components/etl/test/UnitTest++/Win32/TimeHelpers.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "TimeHelpers.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
Timer::Timer()
|
||||
: m_threadHandle(::GetCurrentThread())
|
||||
, m_startTime(0)
|
||||
{
|
||||
#if defined(UNITTEST_WIN32) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
|
||||
typedef unsigned long DWORD_PTR;
|
||||
#endif
|
||||
|
||||
DWORD_PTR systemMask;
|
||||
::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask);
|
||||
::SetThreadAffinityMask(m_threadHandle, 1);
|
||||
::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency));
|
||||
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
|
||||
}
|
||||
|
||||
void Timer::Start()
|
||||
{
|
||||
m_startTime = GetTime();
|
||||
}
|
||||
|
||||
double Timer::GetTimeInMs() const
|
||||
{
|
||||
__int64 const elapsedTime = GetTime() - m_startTime;
|
||||
double const seconds = double(elapsedTime) / double(m_frequency);
|
||||
return seconds * 1000.0;
|
||||
}
|
||||
|
||||
__int64 Timer::GetTime() const
|
||||
{
|
||||
LARGE_INTEGER curTime;
|
||||
::SetThreadAffinityMask(m_threadHandle, 1);
|
||||
::QueryPerformanceCounter(&curTime);
|
||||
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
|
||||
return curTime.QuadPart;
|
||||
}
|
||||
|
||||
void TimeHelpers::SleepMs(int ms)
|
||||
{
|
||||
::Sleep(ms);
|
||||
}
|
||||
|
||||
}
|
45
components/etl/test/UnitTest++/Win32/TimeHelpers.h
Normal file
45
components/etl/test/UnitTest++/Win32/TimeHelpers.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef UNITTEST_TIMEHELPERS_H
|
||||
#define UNITTEST_TIMEHELPERS_H
|
||||
|
||||
#include "../Config.h"
|
||||
#include "../HelperMacros.h"
|
||||
|
||||
#ifdef UNITTEST_MINGW
|
||||
#ifndef __int64
|
||||
#define __int64 long long
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
class UNITTEST_LINKAGE Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
void Start();
|
||||
double GetTimeInMs() const;
|
||||
|
||||
private:
|
||||
__int64 GetTime() const;
|
||||
|
||||
void* m_threadHandle;
|
||||
|
||||
#if defined(_WIN64)
|
||||
unsigned __int64 m_processAffinityMask;
|
||||
#else
|
||||
unsigned long m_processAffinityMask;
|
||||
#endif
|
||||
|
||||
__int64 m_startTime;
|
||||
__int64 m_frequency;
|
||||
};
|
||||
|
||||
|
||||
namespace TimeHelpers
|
||||
{
|
||||
UNITTEST_LINKAGE void SleepMs(int ms);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
130
components/etl/test/UnitTest++/XmlTestReporter.cpp
Normal file
130
components/etl/test/UnitTest++/XmlTestReporter.cpp
Normal file
|
@ -0,0 +1,130 @@
|
|||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "XmlTestReporter.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using std::ostringstream;
|
||||
using std::ostream;
|
||||
|
||||
namespace {
|
||||
|
||||
void ReplaceChar(string& str, char c, string const& replacement)
|
||||
{
|
||||
for (size_t pos = str.find(c); pos != string::npos; pos = str.find(c, pos + 1))
|
||||
str.replace(pos, 1, replacement);
|
||||
}
|
||||
|
||||
string XmlEscape(string const& value)
|
||||
{
|
||||
string escaped = value;
|
||||
|
||||
ReplaceChar(escaped, '&', "&");
|
||||
ReplaceChar(escaped, '<', "<");
|
||||
ReplaceChar(escaped, '>', ">");
|
||||
ReplaceChar(escaped, '\'', "'");
|
||||
ReplaceChar(escaped, '\"', """);
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
||||
string BuildFailureMessage(string const& file, int line, string const& message)
|
||||
{
|
||||
ostringstream failureMessage;
|
||||
failureMessage << file << "(" << line << ") : " << message;
|
||||
return failureMessage.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
XmlTestReporter::XmlTestReporter(ostream& ostream)
|
||||
: m_ostream(ostream)
|
||||
{}
|
||||
|
||||
void XmlTestReporter::ReportSummary(int totalTestCount, int failedTestCount,
|
||||
int failureCount, float secondsElapsed)
|
||||
{
|
||||
AddXmlElement(m_ostream, NULL);
|
||||
|
||||
BeginResults(m_ostream, totalTestCount, failedTestCount, failureCount, secondsElapsed);
|
||||
|
||||
DeferredTestResultList const& results = GetResults();
|
||||
for (DeferredTestResultList::const_iterator i = results.begin(); i != results.end(); ++i)
|
||||
{
|
||||
BeginTest(m_ostream, *i);
|
||||
|
||||
if (i->failed)
|
||||
AddFailure(m_ostream, *i);
|
||||
|
||||
EndTest(m_ostream, *i);
|
||||
}
|
||||
|
||||
EndResults(m_ostream);
|
||||
}
|
||||
|
||||
void XmlTestReporter::AddXmlElement(ostream& os, char const* encoding)
|
||||
{
|
||||
os << "<?xml version=\"1.0\"";
|
||||
|
||||
if (encoding != NULL)
|
||||
os << " encoding=\"" << encoding << "\"";
|
||||
|
||||
os << "?>";
|
||||
}
|
||||
|
||||
void XmlTestReporter::BeginResults(std::ostream& os, int totalTestCount, int failedTestCount,
|
||||
int failureCount, float secondsElapsed)
|
||||
{
|
||||
os << "<unittest-results"
|
||||
<< " tests=\"" << totalTestCount << "\""
|
||||
<< " failedtests=\"" << failedTestCount << "\""
|
||||
<< " failures=\"" << failureCount << "\""
|
||||
<< " time=\"" << secondsElapsed << "\""
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void XmlTestReporter::EndResults(std::ostream& os)
|
||||
{
|
||||
os << "</unittest-results>";
|
||||
}
|
||||
|
||||
void XmlTestReporter::BeginTest(std::ostream& os, DeferredTestResult const& result)
|
||||
{
|
||||
os << "<test"
|
||||
<< " suite=\"" << result.suiteName << "\""
|
||||
<< " name=\"" << result.testName << "\""
|
||||
<< " time=\"" << result.timeElapsed << "\"";
|
||||
}
|
||||
|
||||
void XmlTestReporter::EndTest(std::ostream& os, DeferredTestResult const& result)
|
||||
{
|
||||
if (result.failed)
|
||||
os << "</test>";
|
||||
else
|
||||
os << "/>";
|
||||
}
|
||||
|
||||
void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& result)
|
||||
{
|
||||
os << ">"; // close <test> element
|
||||
|
||||
for (DeferredTestResult::FailureVec::const_iterator it = result.failures.begin();
|
||||
it != result.failures.end();
|
||||
++it)
|
||||
{
|
||||
string const escapedMessage = XmlEscape(std::string(it->failureStr));
|
||||
string const message = BuildFailureMessage(result.failureFile, it->lineNumber, escapedMessage);
|
||||
|
||||
os << "<failure" << " message=\"" << message << "\"" << "/>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
38
components/etl/test/UnitTest++/XmlTestReporter.h
Normal file
38
components/etl/test/UnitTest++/XmlTestReporter.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef UNITTEST_XMLTESTREPORTER_H
|
||||
#define UNITTEST_XMLTESTREPORTER_H
|
||||
|
||||
#include "Config.h"
|
||||
#ifndef UNITTEST_NO_DEFERRED_REPORTER
|
||||
|
||||
#include "DeferredTestReporter.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
|
||||
class UNITTEST_LINKAGE XmlTestReporter : public DeferredTestReporter
|
||||
{
|
||||
public:
|
||||
explicit XmlTestReporter(std::ostream& ostream);
|
||||
|
||||
virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
|
||||
|
||||
private:
|
||||
XmlTestReporter(XmlTestReporter const&);
|
||||
XmlTestReporter& operator=(XmlTestReporter const&);
|
||||
|
||||
void AddXmlElement(std::ostream& os, char const* encoding);
|
||||
void BeginResults(std::ostream& os, int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
|
||||
void EndResults(std::ostream& os);
|
||||
void BeginTest(std::ostream& os, DeferredTestResult const& result);
|
||||
void AddFailure(std::ostream& os, DeferredTestResult const& result);
|
||||
void EndTest(std::ostream& os, DeferredTestResult const& result);
|
||||
|
||||
std::ostream& m_ostream;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
5
components/etl/test/cppcheck_macro_definitions.txt
Normal file
5
components/etl/test/cppcheck_macro_definitions.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
ETL_CONSTEXPR constexpr
|
||||
ETL_CONSTEXPR14
|
||||
ETL_CONSTEXPR17
|
||||
ETL_CONSTEXPR20
|
||||
ETL_IF_CONSTEXPR20
|
291
components/etl/test/data.h
Normal file
291
components/etl/test/data.h
Normal file
|
@ -0,0 +1,291 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2014 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_TEST_DATA_INCLUDED
|
||||
#define ETL_TEST_DATA_INCLUDED
|
||||
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
#include "etl/instance_count.h"
|
||||
|
||||
//*****************************************************************************
|
||||
// Default constructor.
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
class TestDataDC : public etl::instance_count<TestDataDC<T>>
|
||||
{
|
||||
public:
|
||||
|
||||
TestDataDC()
|
||||
: value(T()),
|
||||
index(0)
|
||||
{
|
||||
}
|
||||
|
||||
explicit TestDataDC(const T& value_, int index_ = 0)
|
||||
: value(value_),
|
||||
index(index_)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~TestDataDC()
|
||||
{
|
||||
}
|
||||
|
||||
bool operator < (const TestDataDC& other) const
|
||||
{
|
||||
return value < other.value;
|
||||
}
|
||||
|
||||
bool operator > (const TestDataDC& other) const
|
||||
{
|
||||
return value > other.value;
|
||||
}
|
||||
|
||||
bool operator <= (const TestDataDC& other) const
|
||||
{
|
||||
return !(value > other.value);
|
||||
}
|
||||
|
||||
bool operator >= (const TestDataDC& other) const
|
||||
{
|
||||
return !(value < other.value);
|
||||
}
|
||||
|
||||
static bool are_identical(const TestDataDC& lhs, const TestDataDC& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return (lhs.value == rhs.value) && (lhs.index == rhs.index);
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
T value;
|
||||
int index;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator == (const TestDataDC<T>& lhs, const TestDataDC<T>& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return lhs.value == rhs.value;
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator != (const TestDataDC<T>& lhs, const TestDataDC<T>& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return lhs.value != rhs.value;
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator << (std::ostream& s, const TestDataDC<T>& rhs)
|
||||
{
|
||||
s << rhs.value;
|
||||
return s;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// No default constructor.
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
class TestDataNDC : public etl::instance_count<TestDataNDC<T>>
|
||||
{
|
||||
public:
|
||||
|
||||
explicit TestDataNDC(const T& value_, int index_ = 0)
|
||||
: value(value_),
|
||||
index(index_)
|
||||
{}
|
||||
|
||||
virtual ~TestDataNDC()
|
||||
{
|
||||
}
|
||||
|
||||
TestDataNDC(const TestDataNDC&) = default;
|
||||
TestDataNDC& operator =(const TestDataNDC&) = default;
|
||||
|
||||
bool operator < (const TestDataNDC& other) const
|
||||
{
|
||||
return value < other.value;
|
||||
}
|
||||
|
||||
bool operator > (const TestDataNDC& other) const
|
||||
{
|
||||
return value > other.value;
|
||||
}
|
||||
|
||||
bool operator <= (const TestDataNDC& other) const
|
||||
{
|
||||
return !(value > other.value);
|
||||
}
|
||||
|
||||
bool operator >= (const TestDataNDC& other) const
|
||||
{
|
||||
return !(value < other.value);
|
||||
}
|
||||
|
||||
static bool are_identical(const TestDataNDC& lhs, const TestDataNDC& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return (lhs.value == rhs.value) && (lhs.index == rhs.index);
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
T value;
|
||||
int index;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator == (const TestDataNDC<T>& lhs, const TestDataNDC<T>& rhs)
|
||||
{
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator != (const TestDataNDC<T>& lhs, const TestDataNDC<T>& rhs)
|
||||
{
|
||||
return lhs.value != rhs.value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator << (std::ostream& s, const TestDataNDC<T>& rhs)
|
||||
{
|
||||
s << rhs.value;
|
||||
return s;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Movable.
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
class TestDataM : public etl::instance_count<TestDataM<T>>
|
||||
{
|
||||
public:
|
||||
|
||||
explicit TestDataM(const T& value_)
|
||||
: value(value_)
|
||||
, valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
explicit TestDataM(T&& value_)
|
||||
: value(std::move(value_))
|
||||
, valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
TestDataM(TestDataM&& other) noexcept
|
||||
: value(std::move(other.value))
|
||||
, valid(true)
|
||||
{
|
||||
other.valid = false;
|
||||
}
|
||||
|
||||
TestDataM(const TestDataM&& other) noexcept
|
||||
: value(std::move(other.value))
|
||||
, valid(true)
|
||||
{
|
||||
other.valid = false;
|
||||
}
|
||||
|
||||
virtual ~TestDataM()
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
TestDataM& operator =(TestDataM&& other) noexcept
|
||||
{
|
||||
value = std::move(other.value);
|
||||
valid = true;
|
||||
|
||||
other.valid = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator < (const TestDataM& other) const
|
||||
{
|
||||
return value < other.value;
|
||||
}
|
||||
|
||||
bool operator > (const TestDataM& other) const
|
||||
{
|
||||
return other.value < value;
|
||||
}
|
||||
|
||||
bool operator <= (const TestDataM& other) const
|
||||
{
|
||||
return !(other.value < value);
|
||||
}
|
||||
|
||||
bool operator >= (const TestDataM& other) const
|
||||
{
|
||||
return !(value < other.value);
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
T value;
|
||||
mutable bool valid;
|
||||
|
||||
private:
|
||||
|
||||
TestDataM(const TestDataM& other) = delete;
|
||||
TestDataM& operator =(const TestDataM& other) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator == (const TestDataM<T>& lhs, const TestDataM<T>& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return lhs.value == rhs.value;
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator != (const TestDataM<T>& lhs, const TestDataM<T>& rhs)
|
||||
{
|
||||
#include "etl/private/diagnostic_float_equal_push.h"
|
||||
return lhs.value != rhs.value;
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator << (std::ostream& s, const TestDataM<T>& rhs)
|
||||
{
|
||||
s << rhs.value;
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,126 @@
|
|||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_error_handler_unit_tests)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
add_definitions(-DETL_USE_ASSERT_FUNCTION)
|
||||
add_definitions(-DETL_VERBOSE_ERRORS)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/../../../include)
|
||||
|
||||
set(TEST_SOURCE_FILES
|
||||
assert_function.cpp
|
||||
test_error_handler.cpp
|
||||
)
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
)
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wno-deprecated-declarations
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wno-deprecated-declarations
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_error_handler_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)
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
#include "etl/exception.h"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#include "etl/exception.h"
|
||||
|
||||
extern void AssertFunction(const etl::exception& /*e*/);
|
||||
|
||||
#define ETL_ASSERT_FUNCTION AssertFunction
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,167 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/std
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2022 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/error_handler.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "assert_function.h"
|
||||
|
||||
int assert_return_count = 0;
|
||||
int assert_count = 0;
|
||||
|
||||
//*****************************************************************************
|
||||
void assert_function(const etl::exception& e)
|
||||
{
|
||||
std::cout << "Exception " << e.what() << " raised\n";
|
||||
|
||||
++assert_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception_1 : public test_exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception_1(string_type file_name_, numeric_type line_number_)
|
||||
: test_exception(ETL_ERROR_TEXT("Test Exception 1", "1A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
void Assert(bool state)
|
||||
{
|
||||
ETL_ASSERT(state, ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFail()
|
||||
{
|
||||
ETL_ASSERT_FAIL(ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertAndReturn(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN(state, ETL_ERROR(test_exception_1));
|
||||
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFailAndReturn()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN(ETL_ERROR(test_exception_1));
|
||||
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertAndReturnValue(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(state, ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++assert_return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertFailAndReturnValue()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++assert_return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::set_assert_function(assert_function);
|
||||
|
||||
Assert(false);
|
||||
Assert(true);
|
||||
AssertFail();
|
||||
|
||||
AssertAndReturn(false);
|
||||
AssertAndReturn(true);
|
||||
AssertFailAndReturn();
|
||||
|
||||
if (AssertAndReturnValue(false))
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
if (AssertAndReturnValue(true))
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
if (AssertFailAndReturnValue())
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
bool assert_count_passed = (assert_count == 6);
|
||||
|
||||
if (assert_count_passed)
|
||||
{
|
||||
std::cout << "Log Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Log Count Failed\n";
|
||||
}
|
||||
|
||||
bool return_count_passed = (assert_return_count == 4);
|
||||
|
||||
if (return_count_passed)
|
||||
{
|
||||
std::cout << "Return Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Return Count Failed\n";
|
||||
}
|
||||
|
||||
return (assert_count_passed && return_count_passed) ? 0 : 1;
|
||||
}
|
||||
|
122
components/etl/test/etl_error_handler/exceptions/CMakeLists.txt
Normal file
122
components/etl/test/etl_error_handler/exceptions/CMakeLists.txt
Normal file
|
@ -0,0 +1,122 @@
|
|||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_error_handler_unit_tests)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
add_definitions(-DETL_THROW_EXCEPTIONS)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/../../../include)
|
||||
|
||||
set(TEST_SOURCE_FILES
|
||||
test_error_handler.cpp
|
||||
)
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
)
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_error_handler_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)
|
||||
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/std
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2022 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/error_handler.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
//*****************************************************************************
|
||||
int exception_count = 0;
|
||||
int return_count = 0;
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception_1 : public test_exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception_1(string_type file_name_, numeric_type line_number_)
|
||||
: test_exception(ETL_ERROR_TEXT("Test Exception 1", "1A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
void Assert(bool state)
|
||||
{
|
||||
ETL_ASSERT(state, ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFail()
|
||||
{
|
||||
ETL_ASSERT_FAIL(ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertAndReturn(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN(state, ETL_ERROR(test_exception_1));
|
||||
|
||||
++return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFailAndReturn()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN(ETL_ERROR(test_exception_1));
|
||||
|
||||
++return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertAndReturnValue(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(state, ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertFailAndReturnValue()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Assert(false);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Assert(true);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertFail();
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturn(false);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturn(true);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertFailAndReturn();
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (AssertAndReturnValue(false))
|
||||
{
|
||||
++return_count;
|
||||
}
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (AssertAndReturnValue(true))
|
||||
{
|
||||
++return_count;
|
||||
}
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (AssertFailAndReturnValue())
|
||||
{
|
||||
++return_count;
|
||||
}
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
bool exception_count_passed = (exception_count == 6);
|
||||
|
||||
if (exception_count_passed)
|
||||
{
|
||||
std::cout << "Exception Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Exception Count Failed\n";
|
||||
}
|
||||
|
||||
bool return_count_passed = (return_count == 2);
|
||||
|
||||
if (return_count_passed)
|
||||
{
|
||||
std::cout << "Return Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Return Count Failed\n";
|
||||
}
|
||||
|
||||
return (exception_count_passed && return_count_passed) ? 0 : 1;
|
||||
}
|
||||
|
127
components/etl/test/etl_error_handler/log_errors/CMakeLists.txt
Normal file
127
components/etl/test/etl_error_handler/log_errors/CMakeLists.txt
Normal file
|
@ -0,0 +1,127 @@
|
|||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_error_handler_unit_tests)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
add_definitions(-DETL_LOG_ERRORS)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/../../../include)
|
||||
|
||||
set(TEST_SOURCE_FILES
|
||||
test_error_handler.cpp
|
||||
)
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
)
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-fno-exceptions
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-fno-exceptions
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_error_handler_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)
|
||||
|
||||
|
||||
#RSG
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/std
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2022 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/error_handler.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
//*****************************************************************************
|
||||
struct ErrorLog
|
||||
{
|
||||
ErrorLog()
|
||||
: log_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Log(const etl::exception& /*e*/)
|
||||
{
|
||||
++log_count;
|
||||
}
|
||||
|
||||
int log_count;
|
||||
};
|
||||
|
||||
int assert_return_count = 0;
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception_1 : public test_exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception_1(string_type file_name_, numeric_type line_number_)
|
||||
: test_exception(ETL_ERROR_TEXT("Test Exception 1", "1A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
void Assert(bool state)
|
||||
{
|
||||
ETL_ASSERT(state, ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFail()
|
||||
{
|
||||
ETL_ASSERT_FAIL(ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertAndReturn(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN(state, ETL_ERROR(test_exception_1));
|
||||
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFailAndReturn()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN(ETL_ERROR(test_exception_1));
|
||||
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertAndReturnValue(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(state, ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++assert_return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertFailAndReturnValue()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++assert_return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
static ErrorLog error_log;
|
||||
|
||||
etl::error_handler::set_callback<ErrorLog, error_log, &ErrorLog::Log>();
|
||||
|
||||
Assert(false);
|
||||
Assert(true);
|
||||
AssertFail();
|
||||
|
||||
AssertAndReturn(false);
|
||||
AssertAndReturn(true);
|
||||
AssertFailAndReturn();
|
||||
|
||||
if (AssertAndReturnValue(false))
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
if (AssertAndReturnValue(true))
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
if (AssertFailAndReturnValue())
|
||||
{
|
||||
++assert_return_count;
|
||||
}
|
||||
|
||||
bool log_count_passed = (error_log.log_count == 6);
|
||||
|
||||
if (log_count_passed)
|
||||
{
|
||||
std::cout << "Log Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Log Count Failed\n";
|
||||
}
|
||||
|
||||
bool return_count_passed = (assert_return_count == 4);
|
||||
|
||||
if (return_count_passed)
|
||||
{
|
||||
std::cout << "Return Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Return Count Failed\n";
|
||||
}
|
||||
|
||||
return (log_count_passed && return_count_passed) ? 0 : 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_error_handler_unit_tests)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
add_definitions(-DETL_THROW_EXCEPTIONS)
|
||||
add_definitions(-DETL_LOG_ERRORS)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/../../../include)
|
||||
|
||||
set(TEST_SOURCE_FILES
|
||||
test_error_handler.cpp
|
||||
)
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
)
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_error_handler_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)
|
||||
|
||||
|
||||
#RSG
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/std
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2022 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/error_handler.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
//*****************************************************************************
|
||||
struct ErrorLog
|
||||
{
|
||||
ErrorLog()
|
||||
: log_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Log(const etl::exception& /*e*/)
|
||||
{
|
||||
++log_count;
|
||||
}
|
||||
|
||||
int log_count;
|
||||
};
|
||||
|
||||
int exception_count = 0;
|
||||
int return_count = 0;
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class test_exception_1 : public test_exception
|
||||
{
|
||||
public:
|
||||
|
||||
test_exception_1(string_type file_name_, numeric_type line_number_)
|
||||
: test_exception(ETL_ERROR_TEXT("Test Exception 1", "1A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
void Assert(bool state)
|
||||
{
|
||||
ETL_ASSERT(state, ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFail()
|
||||
{
|
||||
ETL_ASSERT_FAIL(ETL_ERROR(test_exception_1));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertAndReturn(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN(state, ETL_ERROR(test_exception_1));
|
||||
|
||||
++return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
void AssertFailAndReturn()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN(ETL_ERROR(test_exception_1));
|
||||
|
||||
++return_count;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertAndReturnValue(bool state)
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(state, ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
bool AssertFailAndReturnValue()
|
||||
{
|
||||
ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(test_exception_1), true);
|
||||
|
||||
++return_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
ErrorLog error_log;
|
||||
|
||||
etl::error_handler::set_callback<ErrorLog, &ErrorLog::Log>(error_log);
|
||||
|
||||
try
|
||||
{
|
||||
Assert(false);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Assert(true);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertFail();
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturn(false);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturn(true);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertFailAndReturn();
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturnValue(false);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertAndReturnValue(true);
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AssertFailAndReturnValue();
|
||||
}
|
||||
catch (test_exception_1 e)
|
||||
{
|
||||
++exception_count;
|
||||
}
|
||||
|
||||
bool log_count_passed = (error_log.log_count == 6);
|
||||
|
||||
if (log_count_passed)
|
||||
{
|
||||
std::cout << "Log Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Log Count Failed\n";
|
||||
}
|
||||
|
||||
bool return_count_passed = (return_count == 2);
|
||||
|
||||
if (return_count_passed)
|
||||
{
|
||||
std::cout << "Return Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Return Count Failed\n";
|
||||
}
|
||||
|
||||
bool exception_count_passed = (exception_count == 6);
|
||||
|
||||
if (exception_count_passed)
|
||||
{
|
||||
std::cout << "Exception Count Passed\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Exception Count Failed\n";
|
||||
}
|
||||
|
||||
return (log_count_passed && return_count_passed && exception_count_passed) ? 0 : 1;
|
||||
}
|
||||
|
123
components/etl/test/etl_initializer_list/CMakeLists.txt
Normal file
123
components/etl/test/etl_initializer_list/CMakeLists.txt
Normal file
|
@ -0,0 +1,123 @@
|
|||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_initializer_list_unit_tests)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
add_definitions(-DETL_NO_STL)
|
||||
add_definitions(-DETL_FORCE_ETL_INITIALIZER_LIST)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(TEST_SOURCE_FILES
|
||||
test_initializer_list.cpp
|
||||
)
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
)
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O1")
|
||||
message(STATUS "Compiling with -O1 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O2")
|
||||
message(STATUS "Compiling with -O2 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if (ETL_OPTIMISATION MATCHES "-O3")
|
||||
message(STATUS "Compiling with -O3 optimisations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
endif()
|
||||
|
||||
if (ETL_CXX_STANDARD MATCHES "98")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "03")
|
||||
message(STATUS "Compiling for C++98")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 98)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "11")
|
||||
message(STATUS "Compiling for C++11")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 11)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "14")
|
||||
message(STATUS "Compiling for C++14")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 14)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "17")
|
||||
message(STATUS "Compiling for C++17")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||
elseif (ETL_CXX_STANDARD MATCHES "20")
|
||||
message(STATUS "Compiling for C++20")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 20)
|
||||
else()
|
||||
message(STATUS "Compiling for C++23")
|
||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
message(STATUS "Using GCC compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(STATUS "Using Clang compiler")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fno-omit-frame-pointer
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
-Wfloat-equal
|
||||
-Wshadow
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif ()
|
||||
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
if (ETL_ENABLE_SANITIZER MATCHES "ON")
|
||||
message(STATUS "Compiling with Sanitizer enabled")
|
||||
# MinGW doesn't presently support sanitization
|
||||
if (NOT MINGW)
|
||||
target_compile_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
|
||||
target_link_options(etl_tests
|
||||
PRIVATE
|
||||
-fsanitize=address,undefined,bounds
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_initializer_list_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)
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32126.315
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "etl_initializer_list", "etl_initializer_list.vcxproj", "{E22E8381-71AD-4EE0-9238-7277E343FC8B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Debug|x64.Build.0 = Debug|x64
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Release|x64.ActiveCfg = Release|x64
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Release|x64.Build.0 = Release|x64
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{E22E8381-71AD-4EE0-9238-7277E343FC8B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F34563DE-EC62-4A92-B873-FBD0AD24C7AD}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,157 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\etl\initializer_list.h" />
|
||||
<ClInclude Include="..\..\include\etl\placement_new.h" />
|
||||
<ClInclude Include="..\..\include\etl\utility.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="test_initializer_list.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{e22e8381-71ad-4ee0-9238-7277e343fc8b}</ProjectGuid>
|
||||
<RootNamespace>etlinitializerlist</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ETL_FORCE_ETL_INITIALIZER_LIST;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../include</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
0
components/etl/test/etl_initializer_list/etl_profile.h
Normal file
0
components/etl/test/etl_initializer_list/etl_profile.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/std
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2022 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/initializer_list.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
template <typename T>
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
|
||||
//#if ETL_USING_INITIALIZER_LIST
|
||||
ETL_CONSTEXPR14 Container(std::initializer_list<T> init)
|
||||
: length(init.size())
|
||||
, buffer()
|
||||
{
|
||||
typename std::initializer_list<T>::const_iterator itr = std::begin(init);
|
||||
T* p = buffer;
|
||||
|
||||
while (itr != std::end(init))
|
||||
{
|
||||
*p++ = *itr++;
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
|
||||
const T& operator [](int i) const
|
||||
{
|
||||
return buffer[i];
|
||||
}
|
||||
|
||||
const size_t length;
|
||||
|
||||
private:
|
||||
|
||||
T buffer[10];
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
Container<int> c = { 1, 2, 3, 4, 5 };
|
||||
|
||||
if (c[0] != 1) result = 1;
|
||||
if (c[1] != 2) result = 2;
|
||||
if (c[2] != 3) result = 3;
|
||||
if (c[3] != 4) result = 4;
|
||||
if (c[4] != 5) result = 5;
|
||||
|
||||
if (c.length != 5) result = 6;
|
||||
|
||||
ETL_CONSTEXPR14 Container<int> cc = { 1, 2, 3, 4, 5 };
|
||||
|
||||
if (cc[0] != 1) result = 7;
|
||||
if (cc[1] != 2) result = 8;
|
||||
if (cc[2] != 3) result = 9;
|
||||
if (cc[3] != 4) result = 10;
|
||||
if (cc[4] != 5) result = 11;
|
||||
|
||||
if (cc.length != 5) result = 12;
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
printf("**** All tests passed ****\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">>>> Tests failed at #%d <<<<\n", result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
143
components/etl/test/etl_profile.h
Normal file
143
components/etl/test/etl_profile.h
Normal file
|
@ -0,0 +1,143 @@
|
|||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_PROFILE_H_INCLUDED
|
||||
#define ETL_PROFILE_H_INCLUDED
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
#define ETL_ISTRING_REPAIR_ENABLE
|
||||
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||
#define ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE
|
||||
#define ETL_IN_UNIT_TEST
|
||||
#define ETL_DEBUG_COUNT
|
||||
#define ETL_ARRAY_VIEW_IS_MUTABLE
|
||||
|
||||
#define ETL_MESSAGE_TIMER_USE_ATOMIC_LOCK
|
||||
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||
|
||||
#define ETL_POLYMORPHIC_RANDOM
|
||||
|
||||
#define ETL_POLYMORPHIC_BITSET
|
||||
#define ETL_POLYMORPHIC_DEQUE
|
||||
#define ETL_POLYMORPHIC_FLAT_MAP
|
||||
#define ETL_POLYMORPHIC_FLAT_MULTIMAP
|
||||
#define ETL_POLYMORPHIC_FLAT_SET
|
||||
#define ETL_POLYMORPHIC_FLAT_MULTISET
|
||||
#define ETL_POLYMORPHIC_FORWARD_LIST
|
||||
#define ETL_POLYMORPHIC_LIST
|
||||
#define ETL_POLYMORPHIC_MAP
|
||||
#define ETL_POLYMORPHIC_MULTIMAP
|
||||
#define ETL_POLYMORPHIC_SET
|
||||
#define ETL_POLYMORPHIC_MULTISET
|
||||
#define ETL_POLYMORPHIC_QUEUE
|
||||
#define ETL_POLYMORPHIC_STACK
|
||||
#define ETL_POLYMORPHIC_REFERENCE_FLAT_MAP
|
||||
#define ETL_POLYMORPHIC_REFERENCE_FLAT_MULTIMAP
|
||||
#define ETL_POLYMORPHIC_REFERENCE_FLAT_SET
|
||||
#define ETL_POLYMORPHIC_REFERENCE_FLAT_MULTISET
|
||||
#define ETL_POLYMORPHIC_UNORDERED_MAP
|
||||
#define ETL_POLYMORPHIC_UNORDERED_MULTIMAP
|
||||
#define ETL_POLYMORPHIC_UNORDERED_SET
|
||||
#define ETL_POLYMORPHIC_UNORDERED_MULTISET
|
||||
#define ETL_POLYMORPHIC_STRINGS
|
||||
#define ETL_POLYMORPHIC_POOL
|
||||
#define ETL_POLYMORPHIC_VECTOR
|
||||
#define ETL_POLYMORPHIC_INDIRECT_VECTOR
|
||||
|
||||
#if defined(ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
#define ETL_FUNCTION_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_PRIORITY_QUEUE_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_QUEUE_ATOMIC_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_VARIANT_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_QUEUE_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_QUEUE_ISR_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_QUEUE_LOCKED_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_CRC_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_MEM_CAST_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_FSM_FORCE_CPP03_IMPLEMENTATION
|
||||
//#define ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION // C++03 implementation is tested at the same time as the C++11 and above.
|
||||
#define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_BYTE_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_LIST_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_FLAT_SET_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_FLAT_MULTISET_FORCE_CPP03_IMPLEMENTATION
|
||||
#define ETL_VARIANT_POOL_FORCE_CPP03_IMPLEMENTATION
|
||||
#endif
|
||||
|
||||
#if defined(ETL_FORCE_TEST_CPP11)
|
||||
#define ETL_OVERLOAD_FORCE_CPP11
|
||||
#define ETL_VARIANT_FORCE_CPP11
|
||||
#endif
|
||||
|
||||
#include "../include/etl/profiles/determine_compiler_language_support.h"
|
||||
#include "../include/etl/profiles/determine_compiler_version.h"
|
||||
#include "../include/etl/profiles/determine_development_os.h"
|
||||
|
||||
#if defined(ETL_COMPILER_GCC)
|
||||
#if (ETL_COMPILER_VERSION < 8)
|
||||
#define ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define ETL_CHRONO_SYSTEM_CLOCK_DURATION etl::chrono::milliseconds
|
||||
#define ETL_CHRONO_HIGH_RESOLUTION_CLOCK_DURATION etl::chrono::nanoseconds
|
||||
#define ETL_CHRONO_STEADY_CLOCK_DURATION etl::chrono::seconds
|
||||
|
||||
#define ETL_CHRONO_SYSTEM_CLOCK_IS_STEADY false
|
||||
|
||||
#define ETL_USE_VERBOSE_CHRONO_LITERALS
|
||||
|
||||
#if defined(ETL_DEVELOPMENT_OS_WINDOWS)
|
||||
#define ETL_TARGET_OS_WINDOWS
|
||||
#elif defined(ETL_DEVELOPMENT_OS_LINUX)
|
||||
#define ETL_TARGET_OS_LINUX
|
||||
#else
|
||||
#define ETL_TARGET_OS_GENERIC
|
||||
#endif
|
||||
|
||||
#if !((ETL_CPP20_SUPPORTED && !defined(ETL_NO_STL)) || defined(__BYTE_ORDER__))
|
||||
#define ETL_ENDIAN_NATIVE 0
|
||||
#endif
|
||||
|
||||
#endif
|
219
components/etl/test/iterators_for_unit_tests.h
Normal file
219
components/etl/test/iterators_for_unit_tests.h
Normal file
|
@ -0,0 +1,219 @@
|
|||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2018 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_NO_STL_TEST_ITERATORS_INCLUDED
|
||||
#define ETL_NO_STL_TEST_ITERATORS_INCLUDED
|
||||
|
||||
#include "etl/platform.h"
|
||||
#include "etl/iterator.h"
|
||||
|
||||
template <typename T>
|
||||
struct non_random_iterator : public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, T>
|
||||
{
|
||||
non_random_iterator()
|
||||
: ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
non_random_iterator(T* v)
|
||||
: ptr(v)
|
||||
{
|
||||
}
|
||||
|
||||
non_random_iterator(const non_random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
}
|
||||
|
||||
non_random_iterator& operator =(const non_random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& operator *()
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
const T& operator *() const
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
non_random_iterator& operator ++()
|
||||
{
|
||||
++ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
non_random_iterator operator ++(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
++ptr;
|
||||
return non_random_iterator(temp);
|
||||
}
|
||||
|
||||
non_random_iterator& operator --()
|
||||
{
|
||||
--ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
non_random_iterator operator --(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
--ptr;
|
||||
return non_random_iterator(temp);
|
||||
}
|
||||
|
||||
non_random_iterator& operator =(T* other)
|
||||
{
|
||||
ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
operator const T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator !=(const non_random_iterator<T>& lhs, const non_random_iterator<T>& rhs)
|
||||
{
|
||||
return lhs.ptr != rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct random_iterator : public etl::iterator<ETL_OR_STD::random_access_iterator_tag, T>
|
||||
{
|
||||
random_iterator()
|
||||
: ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
random_iterator(T* v)
|
||||
: ptr(v)
|
||||
{
|
||||
}
|
||||
|
||||
random_iterator(const random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
}
|
||||
|
||||
random_iterator& operator =(const random_iterator& other)
|
||||
{
|
||||
ptr = other.ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& operator *()
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
const T& operator *() const
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
random_iterator& operator ++()
|
||||
{
|
||||
++ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator operator ++(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
++ptr;
|
||||
return random_iterator(temp);
|
||||
}
|
||||
|
||||
random_iterator& operator --()
|
||||
{
|
||||
--ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator operator --(int)
|
||||
{
|
||||
T* temp = ptr;
|
||||
--ptr;
|
||||
return random_iterator(temp);
|
||||
}
|
||||
|
||||
random_iterator& operator +=(int n)
|
||||
{
|
||||
ptr += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator& operator -=(int n)
|
||||
{
|
||||
ptr -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
random_iterator& operator =(T* other)
|
||||
{
|
||||
ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
operator const T*()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
ptrdiff_t operator -(const random_iterator<T>& lhs, const random_iterator<T>& rhs)
|
||||
{
|
||||
return lhs.ptr - rhs.ptr;
|
||||
}
|
||||
|
||||
#endif
|
14
components/etl/test/list_header_files.bat
Normal file
14
components/etl/test/list_header_files.bat
Normal file
|
@ -0,0 +1,14 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
cd ../include/etl
|
||||
|
||||
> header_file_list.txt (
|
||||
for %%f in (*.h) do (
|
||||
echo %%~nxf
|
||||
)
|
||||
)
|
||||
|
||||
cd ../../test
|
||||
|
||||
endlocal
|
10
components/etl/test/list_test_files.bat
Normal file
10
components/etl/test/list_test_files.bat
Normal file
|
@ -0,0 +1,10 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
> test_file_list.txt (
|
||||
for %%f in (test_*.cpp) do (
|
||||
echo %%~nxf
|
||||
)
|
||||
)
|
||||
|
||||
endlocal
|
1
components/etl/test/list_test_files.ps1
Normal file
1
components/etl/test/list_test_files.ps1
Normal file
|
@ -0,0 +1 @@
|
|||
Get-ChildItem -Path "./test_*.cpp" | Select-Object -ExpandProperty Name
|
3
components/etl/test/list_test_files.sh
Normal file
3
components/etl/test/list_test_files.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
cd ../test
|
||||
ls -1 test_*.cpp > test_file_list.txt
|
||||
cd ../scripts
|
33
components/etl/test/main.cpp
Normal file
33
components/etl/test/main.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2014 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return UnitTest::RunAllTests();
|
||||
}
|
169
components/etl/test/maincpp03check.cpp
Normal file
169
components/etl/test/maincpp03check.cpp
Normal file
|
@ -0,0 +1,169 @@
|
|||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://www.etlcpp.com
|
||||
https://github.com/ETLCPP/etl
|
||||
|
||||
Copyright(c) 2019 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
|
||||
#include "etl/absolute.h"
|
||||
#include "etl/algorithm.h"
|
||||
#include "etl/alignment.h"
|
||||
#include "etl/array.h"
|
||||
#include "etl/array_view.h"
|
||||
#include "etl/array_wrapper.h"
|
||||
#include "etl/atomic.h"
|
||||
#include "etl/basic_string.h"
|
||||
#include "etl/binary.h"
|
||||
#include "etl/bitset.h"
|
||||
#include "etl/bit_stream.h"
|
||||
#include "etl/bloom_filter.h"
|
||||
#include "etl/callback.h"
|
||||
#include "etl/callback_service.h"
|
||||
#include "etl/callback_timer.h"
|
||||
#include "etl/char_traits.h"
|
||||
#include "etl/checksum.h"
|
||||
#include "etl/combinations.h"
|
||||
#include "etl/compare.h"
|
||||
#include "etl/constant.h"
|
||||
#include "etl/container.h"
|
||||
#include "etl/crc16.h"
|
||||
#include "etl/crc16_ccitt.h"
|
||||
#include "etl/crc16_kermit.h"
|
||||
#include "etl/crc16_modbus.h"
|
||||
#include "etl/crc32.h"
|
||||
#include "etl/crc32_c.h"
|
||||
#include "etl/crc64_ecma.h"
|
||||
#include "etl/crc8_ccitt.h"
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/cumulative_moving_average.h"
|
||||
#include "etl/cyclic_value.h"
|
||||
#include "etl/debounce.h"
|
||||
#include "etl/debug_count.h"
|
||||
#include "etl/deque.h"
|
||||
#include "etl/endianness.h"
|
||||
#include "etl/enum_type.h"
|
||||
#include "etl/error_handler.h"
|
||||
#include "etl/exception.h"
|
||||
#include "etl/factorial.h"
|
||||
#include "etl/fibonacci.h"
|
||||
#include "etl/fixed_iterator.h"
|
||||
#include "etl/flat_map.h"
|
||||
#include "etl/flat_multimap.h"
|
||||
#include "etl/flat_multiset.h"
|
||||
#include "etl/flat_set.h"
|
||||
#include "etl/fnv_1.h"
|
||||
#include "etl/forward_list.h"
|
||||
#include "etl/frame_check_sequence.h"
|
||||
#include "etl/fsm.h"
|
||||
#include "etl/function.h"
|
||||
#include "etl/functional.h"
|
||||
#include "etl/hash.h"
|
||||
#include "etl/ihash.h"
|
||||
#include "etl/instance_count.h"
|
||||
#include "etl/integral_limits.h"
|
||||
#include "etl/intrusive_forward_list.h"
|
||||
#include "etl/intrusive_links.h"
|
||||
#include "etl/intrusive_list.h"
|
||||
#include "etl/intrusive_queue.h"
|
||||
#include "etl/intrusive_stack.h"
|
||||
#include "etl/io_port.h"
|
||||
#include "etl/iterator.h"
|
||||
#include "etl/jenkins.h"
|
||||
#include "etl/largest.h"
|
||||
#include "etl/list.h"
|
||||
#include "etl/log.h"
|
||||
#include "etl/macros.h"
|
||||
#include "etl/map.h"
|
||||
#include "etl/math_constants.h"
|
||||
#include "etl/memory.h"
|
||||
#include "etl/memory_model.h"
|
||||
#include "etl/message.h"
|
||||
#include "etl/message_bus.h"
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/message_timer.h"
|
||||
#include "etl/message_types.h"
|
||||
#include "etl/multimap.h"
|
||||
#include "etl/multiset.h"
|
||||
#include "etl/murmur3.h"
|
||||
#include "etl/mutex.h"
|
||||
#include "etl/nullptr.h"
|
||||
#include "etl/null_type.h"
|
||||
#include "etl/numeric.h"
|
||||
#include "etl/observer.h"
|
||||
#include "etl/optional.h"
|
||||
#include "etl/packet.h"
|
||||
#include "etl/parameter_type.h"
|
||||
#include "etl/pearson.h"
|
||||
#include "etl/permutations.h"
|
||||
#include "etl/platform.h"
|
||||
#include "etl/pool.h"
|
||||
#include "etl/power.h"
|
||||
#include "etl/priority_queue.h"
|
||||
#include "etl/queue.h"
|
||||
#include "etl/queue_mpmc_mutex.h"
|
||||
#include "etl/queue_spsc_atomic.h"
|
||||
#include "etl/queue_spsc_isr.h"
|
||||
#include "etl/radix.h"
|
||||
#include "etl/random.h"
|
||||
#include "etl/ratio.h"
|
||||
#include "etl/reference_flat_map.h"
|
||||
#include "etl/reference_flat_multimap.h"
|
||||
#include "etl/reference_flat_multiset.h"
|
||||
#include "etl/reference_flat_set.h"
|
||||
#include "etl/scaled_rounding.h"
|
||||
#include "etl/scheduler.h"
|
||||
#include "etl/set.h"
|
||||
#include "etl/smallest.h"
|
||||
#include "etl/sqrt.h"
|
||||
#include "etl/stack.h"
|
||||
#include "etl/state_chart.h"
|
||||
#include "etl/static_assert.h"
|
||||
#include "etl/string_view.h"
|
||||
#include "etl/task.h"
|
||||
#include "etl/timer.h"
|
||||
#include "etl/type_def.h"
|
||||
#include "etl/type_lookup.h"
|
||||
#include "etl/type_select.h"
|
||||
#include "etl/type_traits.h"
|
||||
#include "etl/u16string.h"
|
||||
#include "etl/u32string.h"
|
||||
#include "etl/unordered_map.h"
|
||||
#include "etl/unordered_multimap.h"
|
||||
#include "etl/unordered_multiset.h"
|
||||
#include "etl/unordered_set.h"
|
||||
#include "etl/user_type.h"
|
||||
#include "etl/utility.h"
|
||||
#include "etl/variant.h"
|
||||
#include "etl/variant_pool.h"
|
||||
#include "etl/vector.h"
|
||||
#include "etl/version.h"
|
||||
#include "etl/visitor.h"
|
||||
#include "etl/wstring.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return UnitTest::RunAllTests();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue