Compare commits

..

No commits in common. "master" and "v1.4" have entirely different histories.
master ... v1.4

174 changed files with 6316 additions and 10142 deletions

17
.gitattributes vendored
View file

@ -1,17 +0,0 @@
* text=auto
*.h text
*.cpp text
# VS 20xx files
*.sln text eol=crlf
*.vcproj text eol=crlf
*.vcxproj text eol=crlf
*.vcxproj.filters text eol=crlf
# VC6 files
*.dsw text eol=crlf
*.dsp text eol=crlf
# Other 'windows-specific' files
*.bat text eol=crlf

44
.gitignore vendored
View file

@ -1,44 +0,0 @@
*.o
*.a
*.lo
*.la
# Visual Studio temp/user files
*.user
*.suo
*.sdf
*.opensdf
*.ncb
# Build output directories
Release
Debug
MinSizeRel
RelWithDebInfo
ipch
# files generated by autotools
/aclocal.m4
/autom4te.cache
/config.guess
/config.h
/config.h.in
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/m4
/missing
/stamp-h*
/test-driver
/UnitTest++/TestUnitTest++
Makefile
Makefile.in
.deps
.libs
*.log
*.trs
*.pc

4
.gitmodules vendored
View file

@ -1,4 +0,0 @@
[submodule "docs"]
path = docs
url = https://github.com/unittest-cpp/unittest-cpp.wiki.git
ignore = dirty

View file

@ -1,21 +0,0 @@
language: cpp
# Build with gcc and clang.
compiler:
- gcc
- clang
# Build both debug and release configurations, through use of an environment variable in the build matrix.
env:
- CONFIGURATION=Debug
- CONFIGURATION=Release
# Run cmake to generate makefiles in 'builds' directory.
# No need to create it because it's part of the repo.
# Pass along configuration type to cmake.
before_script:
- cd builds && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$CONFIGURATION ../ && cd ..
# Run make in the directory containing generated makefiles.
script:
- make -C builds

View file

@ -1,488 +0,0 @@
# Uncrustify 0.61
newlines = auto
input_tab_size = 4
output_tab_size = 3
string_escape_char = 92
string_escape_char2 = 0
tok_split_gte = false
utf8_bom = remove
utf8_byte = false
utf8_force = false
indent_columns = 3
indent_continue = 0
indent_with_tabs = 0
indent_cmt_with_tabs = false
indent_align_string = false
indent_xml_string = 0
indent_brace = 0
indent_braces = false
indent_braces_no_func = false
indent_braces_no_class = false
indent_braces_no_struct = false
indent_brace_parent = false
indent_paren_open_brace = false
indent_namespace = true
indent_namespace_single_indent = false
indent_namespace_level = 0
indent_namespace_limit = 0
indent_extern = false
indent_class = true
indent_class_colon = false
indent_constr_colon = false
indent_ctor_init_leading = 1
indent_ctor_init = 0
indent_else_if = false
indent_var_def_blk = 0
indent_var_def_cont = false
indent_func_def_force_col1 = false
indent_func_call_param = false
indent_func_def_param = false
indent_func_proto_param = false
indent_func_class_param = false
indent_func_ctor_var_param = false
indent_template_param = false
indent_func_param_double = false
indent_func_const = 0
indent_func_throw = 0
indent_member = indent_columns
indent_sing_line_comments = 0
indent_relative_single_line_comments = true
indent_switch_case = 0
indent_case_shift = 0
indent_case_brace = 0
indent_col1_comment = false
indent_label = 1
indent_access_spec = -3
indent_access_spec_body = false
indent_paren_nl = false
indent_paren_close = 0
indent_comma_paren = false
indent_bool_paren = false
indent_first_bool_expr = false
indent_square_nl = false
indent_preserve_sql = false
indent_align_assign = true
indent_oc_block = false
indent_oc_block_msg = 0
indent_oc_msg_colon = 0
indent_oc_msg_prioritize_first_colon = true
indent_oc_block_msg_xcode_style = false
indent_oc_block_msg_from_keyword = false
indent_oc_block_msg_from_colon = false
indent_oc_block_msg_from_caret = false
indent_oc_block_msg_from_brace = false
sp_arith = ignore
sp_assign = ignore
sp_cpp_lambda_assign = ignore
sp_cpp_lambda_paren = ignore
sp_assign_default = ignore
sp_before_assign = ignore
sp_after_assign = ignore
sp_enum_paren = ignore
sp_enum_assign = ignore
sp_enum_before_assign = ignore
sp_enum_after_assign = ignore
sp_pp_concat = add
sp_pp_stringify = ignore
sp_before_pp_stringify = ignore
sp_bool = ignore
sp_compare = ignore
sp_inside_paren = ignore
sp_paren_paren = ignore
sp_cparen_oparen = ignore
sp_balance_nested_parens = false
sp_paren_brace = ignore
sp_before_ptr_star = ignore
sp_before_unnamed_ptr_star = ignore
sp_between_ptr_star = ignore
sp_after_ptr_star = ignore
sp_after_ptr_star_qualifier = ignore
sp_after_ptr_star_func = ignore
sp_ptr_star_paren = ignore
sp_before_ptr_star_func = ignore
sp_before_byref = ignore
sp_before_unnamed_byref = ignore
sp_after_byref = ignore
sp_after_byref_func = ignore
sp_before_byref_func = ignore
sp_after_type = force
sp_before_template_paren = ignore
sp_template_angle = ignore
sp_before_angle = ignore
sp_inside_angle = ignore
sp_after_angle = ignore
sp_angle_paren = ignore
sp_angle_word = ignore
sp_angle_shift = add
sp_permit_cpp11_shift = false
sp_before_sparen = ignore
sp_inside_sparen = ignore
sp_inside_sparen_close = ignore
sp_inside_sparen_open = ignore
sp_after_sparen = ignore
sp_sparen_brace = ignore
sp_invariant_paren = ignore
sp_after_invariant_paren = ignore
sp_special_semi = ignore
sp_before_semi = remove
sp_before_semi_for = ignore
sp_before_semi_for_empty = ignore
sp_after_semi = add
sp_after_semi_for = force
sp_after_semi_for_empty = ignore
sp_before_square = ignore
sp_before_squares = ignore
sp_inside_square = ignore
sp_after_comma = ignore
sp_before_comma = remove
sp_paren_comma = force
sp_before_ellipsis = ignore
sp_after_class_colon = ignore
sp_before_class_colon = ignore
sp_after_constr_colon = ignore
sp_before_constr_colon = ignore
sp_before_case_colon = remove
sp_after_operator = ignore
sp_after_operator_sym = ignore
sp_after_cast = ignore
sp_inside_paren_cast = ignore
sp_cpp_cast_paren = ignore
sp_sizeof_paren = ignore
sp_after_tag = ignore
sp_inside_braces_enum = ignore
sp_inside_braces_struct = ignore
sp_inside_braces = ignore
sp_inside_braces_empty = ignore
sp_type_func = ignore
sp_func_proto_paren = ignore
sp_func_def_paren = ignore
sp_inside_fparens = ignore
sp_inside_fparen = ignore
sp_inside_tparen = ignore
sp_after_tparen_close = ignore
sp_square_fparen = ignore
sp_fparen_brace = ignore
sp_fparen_dbrace = ignore
sp_func_call_paren = ignore
sp_func_call_paren_empty = ignore
sp_func_call_user_paren = ignore
sp_func_class_paren = ignore
sp_return_paren = ignore
sp_attribute_paren = ignore
sp_defined_paren = ignore
sp_throw_paren = ignore
sp_after_throw = ignore
sp_catch_paren = ignore
sp_version_paren = ignore
sp_scope_paren = ignore
sp_macro = ignore
sp_macro_func = ignore
sp_else_brace = ignore
sp_brace_else = ignore
sp_brace_typedef = ignore
sp_catch_brace = ignore
sp_brace_catch = ignore
sp_finally_brace = ignore
sp_brace_finally = ignore
sp_try_brace = ignore
sp_getset_brace = ignore
sp_word_brace = add
sp_word_brace_ns = add
sp_before_dc = ignore
sp_after_dc = ignore
sp_d_array_colon = ignore
sp_not = remove
sp_inv = remove
sp_addr = remove
sp_member = remove
sp_deref = remove
sp_sign = remove
sp_incdec = remove
sp_before_nl_cont = add
sp_after_oc_scope = ignore
sp_after_oc_colon = ignore
sp_before_oc_colon = ignore
sp_after_oc_dict_colon = ignore
sp_before_oc_dict_colon = ignore
sp_after_send_oc_colon = ignore
sp_before_send_oc_colon = ignore
sp_after_oc_type = ignore
sp_after_oc_return_type = ignore
sp_after_oc_at_sel = ignore
sp_after_oc_at_sel_parens = ignore
sp_inside_oc_at_sel_parens = ignore
sp_before_oc_block_caret = ignore
sp_after_oc_block_caret = ignore
sp_after_oc_msg_receiver = ignore
sp_after_oc_property = ignore
sp_cond_colon = ignore
sp_cond_colon_before = ignore
sp_cond_colon_after = ignore
sp_cond_question = ignore
sp_cond_question_before = ignore
sp_cond_question_after = ignore
sp_cond_ternary_short = ignore
sp_case_label = ignore
sp_range = ignore
sp_after_for_colon = ignore
sp_before_for_colon = ignore
sp_extern_paren = ignore
sp_cmt_cpp_start = ignore
sp_endif_cmt = ignore
sp_after_new = ignore
sp_before_tr_emb_cmt = ignore
sp_num_before_tr_emb_cmt = 0
sp_annotation_paren = ignore
align_keep_tabs = false
align_with_tabs = false
align_on_tabstop = false
align_number_left = false
align_keep_extra_space = false
align_func_params = false
align_same_func_call_params = false
align_var_def_span = 0
align_var_def_star_style = 0
align_var_def_amp_style = 0
align_var_def_thresh = 0
align_var_def_gap = 0
align_var_def_colon = false
align_var_def_attribute = false
align_var_def_inline = false
align_assign_span = 0
align_assign_thresh = 0
align_enum_equ_span = 0
align_enum_equ_thresh = 0
align_var_struct_span = 0
align_var_struct_thresh = 0
align_var_struct_gap = 0
align_struct_init_span = 0
align_typedef_gap = 0
align_typedef_span = 0
align_typedef_func = 0
align_typedef_star_style = 0
align_typedef_amp_style = 0
align_right_cmt_span = 0
align_right_cmt_mix = false
align_right_cmt_gap = 0
align_right_cmt_at_col = 0
align_func_proto_span = 0
align_func_proto_gap = 0
align_on_operator = false
align_mix_var_proto = false
align_single_line_func = false
align_single_line_brace = false
align_single_line_brace_gap = 0
align_oc_msg_spec_span = 0
align_nl_cont = true
align_pp_define_together = false
align_pp_define_gap = 0
align_pp_define_span = 0
align_left_shift = true
align_oc_msg_colon_span = 0
align_oc_msg_colon_first = false
align_oc_decl_colon = false
nl_collapse_empty_body = true
nl_assign_leave_one_liners = false
nl_class_leave_one_liners = false
nl_enum_leave_one_liners = false
nl_getset_leave_one_liners = false
nl_func_leave_one_liners = false
nl_cpp_lambda_leave_one_liners = false
nl_if_leave_one_liners = false
nl_oc_msg_leave_one_liner = false
nl_start_of_file = ignore
nl_start_of_file_min = 0
nl_end_of_file = ignore
nl_end_of_file_min = 0
nl_assign_brace = ignore
nl_assign_square = ignore
nl_after_square_assign = ignore
nl_func_var_def_blk = 0
nl_typedef_blk_start = 0
nl_typedef_blk_end = 0
nl_typedef_blk_in = 0
nl_var_def_blk_start = 0
nl_var_def_blk_end = 0
nl_var_def_blk_in = 0
nl_fcall_brace = ignore
nl_enum_brace = ignore
nl_struct_brace = ignore
nl_union_brace = ignore
nl_if_brace = ignore
nl_brace_else = ignore
nl_elseif_brace = ignore
nl_else_brace = ignore
nl_else_if = ignore
nl_brace_finally = ignore
nl_finally_brace = ignore
nl_try_brace = ignore
nl_getset_brace = ignore
nl_for_brace = ignore
nl_catch_brace = ignore
nl_brace_catch = ignore
nl_brace_square = ignore
nl_brace_fparen = ignore
nl_while_brace = ignore
nl_scope_brace = ignore
nl_unittest_brace = ignore
nl_version_brace = ignore
nl_using_brace = ignore
nl_brace_brace = ignore
nl_do_brace = ignore
nl_brace_while = ignore
nl_switch_brace = ignore
nl_multi_line_cond = false
nl_multi_line_define = false
nl_before_case = false
nl_before_throw = ignore
nl_after_case = false
nl_case_colon_brace = ignore
nl_namespace_brace = ignore
nl_template_class = ignore
nl_class_brace = ignore
nl_class_init_args = ignore
nl_constr_init_args = ignore
nl_func_type_name = ignore
nl_func_type_name_class = ignore
nl_func_scope_name = ignore
nl_func_proto_type_name = ignore
nl_func_paren = ignore
nl_func_def_paren = ignore
nl_func_decl_start = ignore
nl_func_def_start = ignore
nl_func_decl_start_single = ignore
nl_func_def_start_single = ignore
nl_func_decl_args = ignore
nl_func_def_args = ignore
nl_func_decl_end = ignore
nl_func_def_end = ignore
nl_func_decl_end_single = ignore
nl_func_def_end_single = ignore
nl_func_decl_empty = ignore
nl_func_def_empty = ignore
nl_oc_msg_args = false
nl_fdef_brace = ignore
nl_cpp_ldef_brace = ignore
nl_return_expr = ignore
nl_after_semicolon = false
nl_paren_dbrace_open = ignore
nl_after_brace_open = false
nl_after_brace_open_cmt = false
nl_after_vbrace_open = false
nl_after_vbrace_open_empty = false
nl_after_brace_close = false
nl_after_vbrace_close = false
nl_brace_struct_var = ignore
nl_define_macro = false
nl_squeeze_ifdef = false
nl_before_if = ignore
nl_after_if = ignore
nl_before_for = ignore
nl_after_for = ignore
nl_before_while = ignore
nl_after_while = ignore
nl_before_switch = ignore
nl_after_switch = ignore
nl_before_do = ignore
nl_after_do = ignore
nl_ds_struct_enum_cmt = false
nl_ds_struct_enum_close_brace = false
nl_class_colon = ignore
nl_constr_colon = ignore
nl_create_if_one_liner = false
nl_create_for_one_liner = false
nl_create_while_one_liner = false
pos_arith = ignore
pos_assign = ignore
pos_bool = ignore
pos_compare = ignore
pos_conditional = ignore
pos_comma = ignore
pos_class_comma = ignore
pos_constr_comma = ignore
pos_class_colon = ignore
pos_constr_colon = ignore
code_width = 0
ls_for_split_full = false
ls_func_split_full = false
ls_code_width = false
nl_max = 0
nl_after_func_proto = 0
nl_after_func_proto_group = 0
nl_after_func_body = 0
nl_after_func_body_class = 0
nl_after_func_body_one_liner = 0
nl_before_block_comment = 0
nl_before_c_comment = 0
nl_before_cpp_comment = 0
nl_after_multiline_comment = false
nl_after_struct = 0
nl_after_class = 0
nl_before_access_spec = 0
nl_after_access_spec = 0
nl_comment_func_def = 0
nl_after_try_catch_finally = 0
nl_around_cs_property = 0
nl_between_get_set = 0
nl_property_brace = ignore
eat_blanks_after_open_brace = false
eat_blanks_before_close_brace = false
nl_remove_extra_newlines = 0
nl_before_return = false
nl_after_return = false
nl_after_annotation = ignore
nl_between_annotation = ignore
mod_full_brace_do = ignore
mod_full_brace_for = ignore
mod_full_brace_function = ignore
mod_full_brace_if = ignore
mod_full_brace_if_chain = false
mod_full_brace_nl = 0
mod_full_brace_while = ignore
mod_full_brace_using = ignore
mod_paren_on_return = ignore
mod_pawn_semicolon = false
mod_full_paren_if_bool = false
mod_remove_extra_semicolon = false
mod_add_long_function_closebrace_comment = 0
mod_add_long_namespace_closebrace_comment = 0
mod_add_long_switch_closebrace_comment = 0
mod_add_long_ifdef_endif_comment = 0
mod_add_long_ifdef_else_comment = 0
mod_sort_import = false
mod_sort_using = false
mod_sort_include = false
mod_move_case_break = false
mod_case_brace = ignore
mod_remove_empty_return = false
cmt_width = 0
cmt_reflow_mode = 0
cmt_convert_tab_to_spaces = false
cmt_indent_multi = true
cmt_c_group = false
cmt_c_nl_start = false
cmt_c_nl_end = false
cmt_cpp_group = false
cmt_cpp_nl_start = false
cmt_cpp_nl_end = false
cmt_cpp_to_c = false
cmt_star_cont = false
cmt_sp_before_star_cont = 0
cmt_sp_after_star_cont = 0
cmt_multi_check_last = true
cmt_insert_file_header = ""
cmt_insert_file_footer = ""
cmt_insert_func_header = ""
cmt_insert_class_header = ""
cmt_insert_oc_msg_header = ""
cmt_insert_before_preproc = false
pp_indent = ignore
pp_indent_at_level = false
pp_indent_count = 3
pp_space = ignore
pp_space_count = 0
pp_indent_region = 0
pp_region_indent_code = false
pp_indent_if = 0
pp_if_indent_code = false
pp_define_at_level = true

View file

@ -1,3 +0,0 @@
See README.md for the historic contributor list.
The maintainer of UnitTest++ is Patrick Johnmeyer (pjohnmeyer@gmail.com).

View file

@ -1,145 +0,0 @@
cmake_minimum_required(VERSION 3.0)
project(UnitTest++ VERSION 2.1.0)
option(UTPP_USE_PLUS_SIGN
"Set this to OFF if you wish to use '-cpp' instead of '++' in lib/include paths"
ON)
option(UTPP_INCLUDE_TESTS_IN_BUILD
"Set this to OFF if you do not wish to automatically build or run unit tests as part of the default cmake --build"
ON)
option(UTPP_AMPLIFY_WARNINGS
"Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler"
ON)
set(LIB_SUFFIX "" CACHE STRING "Identifier to add to end of lib directory name e.g. 64 for lib64")
if (MSVC)
# CHECK_CXX_COMPILER_FLAG could be used
# but MSVC version is preferred for feature requirements
if (MSVC14 OR MSVC12)
# has the support we need
else()
message(STATUS "The MSVC compiler version does not support UnitTest++ C++11 features.")
endif()
else()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
endif()
# up warning level for project
if (${UTPP_AMPLIFY_WARNINGS})
# instead of getting compiler specific, we're going to try making an assumption that an existing /W# means
# we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
endif()
# get the main sources
file(GLOB headers_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.h)
file(GLOB sources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/*.cpp)
source_group("" FILES ${headers_} ${sources_})
# get platform specific sources
if (WIN32)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
set(platformDir_ Win32)
else()
set(platformDir_ Posix)
endif(WIN32)
file(GLOB platformHeaders_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.h)
file(GLOB platformSources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.cpp)
source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_})
# create the lib
add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${platformSources_})
add_library(UnitTest++::UnitTest++ ALIAS UnitTest++)
if(${UTPP_USE_PLUS_SIGN})
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
endif()
# build the test runner
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
source_group( "" FILES ${TEST_SRCS})
add_executable(TestUnitTest++ ${TEST_SRCS})
if(${UTPP_USE_PLUS_SIGN})
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
endif()
target_link_libraries(TestUnitTest++
PUBLIC
UnitTest++::UnitTest++
)
# run unit tests as post build step
add_custom_command(TARGET TestUnitTest++
POST_BUILD COMMAND TestUnitTest++
COMMENT "Running unit tests")
if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
# add install targets
# need a custom install path?
# define CMAKE_INSTALL_PREFIX to change root folder
if(${UTPP_USE_PLUS_SIGN})
set (UTPP_INSTALL_DESTINATION "include/UnitTest++")
else()
set (UTPP_INSTALL_DESTINATION "include/UnitTestPP")
endif()
target_include_directories( UnitTest++
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/UnitTest++>
)
set_target_properties(UnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
set_target_properties(TestUnitTest++ PROPERTIES DEBUG_POSTFIX "-d")
set(config_install_dir_ lib${LIB_SUFFIX}/cmake/${PROJECT_NAME})
set(targets_export_name_ "${PROJECT_NAME}Targets")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
cmake/UnitTest++ConfigVersion.cmake
VERSION ${UnitTest++_VERSION}
COMPATIBILITY SameMajorVersion
)
install(TARGETS UnitTest++ EXPORT "${targets_export_name_}" DESTINATION lib${LIB_SUFFIX})
install(FILES ${headers_} DESTINATION ${UTPP_INSTALL_DESTINATION})
install(FILES ${platformHeaders_} DESTINATION ${UTPP_INSTALL_DESTINATION}/${platformDir_})
install(FILES
cmake/UnitTest++Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/UnitTest++ConfigVersion.cmake
DESTINATION "${config_install_dir_}")
install(EXPORT "${targets_export_name_}" NAMESPACE "UnitTest++::" DESTINATION "${config_install_dir_}")
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
set(libdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set(includedir ${CMAKE_INSTALL_PREFIX}/include/UnitTest++)
configure_file("UnitTest++.pc.in" "UnitTest++.pc" @ONLY)
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig)
else()
set(pkgconfdir ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig)
endif()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UnitTest++.pc"
DESTINATION "${pkgconfdir}")

View file

@ -1,20 +1,20 @@
Copyright (c) 2006 Noel Llopis and Charles Nicholson
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.
Copyright (c) 2006 Noel Llopis and Charles Nicholson
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.

376
INSTALL
View file

@ -1,376 +0,0 @@
Preamble: If you are installing UnitTest++ from source, or from a
release prior to 1.6.1, you will need to have autotools installed and
run `autoreconf -i; autoconf` prior to following the standard
instructions below.
Installation Instructions
*************************
Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without warranty of any kind.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this
`INSTALL' file but do not implement all of the features documented
below. The lack of an optional feature in a given package is not
necessarily a bug. More recommendations for GNU packages can be found
in *note Makefile Conventions: (standards)Makefile Conventions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package, generally using the just-built uninstalled binaries.
4. Type `make install' to install the programs and any data files and
documentation. When installing into a prefix owned by root, it is
recommended that the package be configured and built as a regular
user, and only the `make install' phase executed with root
privileges.
5. Optionally, type `make installcheck' to repeat any self-tests, but
this time using the binaries in their final installed location.
This target does not install anything. Running this target as a
regular user, particularly if the prior `make install' required
root privileges, verifies that the installation completed
correctly.
6. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
7. Often, you can also type `make uninstall' to remove the installed
files again. In practice, not all packages have tested that
uninstallation works correctly, even though it is required by the
GNU Coding Standards.
8. Some packages, particularly those that use Automake, provide `make
distcheck', which can by used by developers to test that all other
targets like `make install' and `make uninstall' work correctly.
This target is generally not run by end users.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'. This
is known as a "VPATH" build.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX', where PREFIX must be an
absolute file name.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them. In general, the
default for these options is expressed in terms of `${prefix}', so that
specifying just `--prefix' will affect all of the other directory
specifications that were not explicitly provided.
The most portable way to affect installation locations is to pass the
correct locations to `configure'; however, many packages provide one or
both of the following shortcuts of passing variable assignments to the
`make install' command line to change installation locations without
having to reconfigure or recompile.
The first method involves providing an override variable for each
affected directory. For example, `make install
prefix=/alternate/directory' will choose an alternate location for all
directory configuration variables that were expressed in terms of
`${prefix}'. Any directories that were specified during `configure',
but not in terms of `${prefix}', must each be overridden at install
time for the entire installation to be relocated. The approach of
makefile variable overrides for each directory variable is required by
the GNU Coding Standards, and ideally causes no recompilation.
However, some platforms have known limitations with the semantics of
shared libraries that end up requiring recompilation when using this
method, particularly noticeable in packages that use GNU Libtool.
The second method involves providing the `DESTDIR' variable. For
example, `make install DESTDIR=/alternate/directory' will prepend
`/alternate/directory' before all installation names. The approach of
`DESTDIR' overrides is not required by the GNU Coding Standards, and
does not work on platforms that have drive letters. On the other hand,
it does better at avoiding recompilation issues, and works well even
when some directory options were not specified in terms of `${prefix}'
at `configure' time.
Optional Features
=================
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Some packages offer the ability to configure how verbose the
execution of `make' will be. For these packages, running `./configure
--enable-silent-rules' sets the default to minimal output, which can be
overridden with `make V=1'; while running `./configure
--disable-silent-rules' sets the default to verbose, which can be
overridden with `make V=0'.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
HP-UX `make' updates targets which have the same time stamps as
their prerequisites, which makes it generally unusable when shipped
generated files such as `configure' are involved. Use GNU `make'
instead.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
directory contains several dysfunctional programs; working variants of
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
in your `PATH', put it _after_ `/usr/bin'.
On Haiku, software installed for all users goes in `/boot/common',
not `/usr/local'. It is recommended to use the following options:
./configure --prefix=/boot/common
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS
KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf limitation. Until the limitation is lifted, you can use
this workaround:
CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

96
Makefile Normal file
View file

@ -0,0 +1,96 @@
CXX = g++
CXXFLAGS ?= -g -Wall -W -ansi # -pedantic
LDFLAGS ?=
SED = sed
MV = mv
RM = rm
.SUFFIXES: .o .cpp
lib = libUnitTest++.a
test = TestUnitTest++
src = src/AssertException.cpp \
src/Test.cpp \
src/Checks.cpp \
src/TestRunner.cpp \
src/TestResults.cpp \
src/TestReporter.cpp \
src/TestReporterStdout.cpp \
src/ReportAssert.cpp \
src/TestList.cpp \
src/TimeConstraint.cpp \
src/TestDetails.cpp \
src/MemoryOutStream.cpp \
src/DeferredTestReporter.cpp \
src/DeferredTestResult.cpp \
src/XmlTestReporter.cpp \
src/CurrentTest.cpp
ifeq ($(MSYSTEM), MINGW32)
src += src/Win32/TimeHelpers.cpp
else
src += src/Posix/SignalTranslator.cpp \
src/Posix/TimeHelpers.cpp
endif
test_src = src/tests/Main.cpp \
src/tests/TestAssertHandler.cpp \
src/tests/TestChecks.cpp \
src/tests/TestUnitTest++.cpp \
src/tests/TestTest.cpp \
src/tests/TestTestResults.cpp \
src/tests/TestTestRunner.cpp \
src/tests/TestCheckMacros.cpp \
src/tests/TestTestList.cpp \
src/tests/TestTestMacros.cpp \
src/tests/TestTimeConstraint.cpp \
src/tests/TestTimeConstraintMacro.cpp \
src/tests/TestMemoryOutStream.cpp \
src/tests/TestDeferredTestReporter.cpp \
src/tests/TestXmlTestReporter.cpp \
src/tests/TestCurrentTest.cpp
objects = $(patsubst %.cpp, %.o, $(src))
test_objects = $(patsubst %.cpp, %.o, $(test_src))
dependencies = $(subst .o,.d,$(objects))
test_dependencies = $(subst .o,.d,$(test_objects))
define make-depend
$(CXX) $(CXXFLAGS) -M $1 | \
$(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp
$(SED) -e 's/#.*//' \
-e 's/^[^:]*: *//' \
-e 's/ *\\$$//' \
-e '/^$$/ d' \
-e 's/$$/ :/' $3.tmp >> $3.tmp
$(MV) $3.tmp $3
endef
all: $(test)
$(lib): $(objects)
@echo Creating $(lib) library...
@ar cr $(lib) $(objects)
$(test): $(lib) $(test_objects)
@echo Linking $(test)...
@$(CXX) $(LDFLAGS) -o $(test) $(test_objects) $(lib)
@echo Running unit tests...
@./$(test)
clean:
-@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null
%.o : %.cpp
@echo $<
@$(call make-depend,$<,$@,$(subst .o,.d,$@))
@$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<)
ifneq "$(MAKECMDGOALS)" "clean"
-include $(dependencies)
-include $(test_dependencies)
endif

View file

@ -1,8 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = docs
include UnitTest++/Makefile.am
include tests/Makefile.am
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = UnitTest++.pc

68
README Normal file
View file

@ -0,0 +1,68 @@
UnitTest++ README
Version: v1.4
Last update: 2008-10-30
UnitTest++ is free software. You may copy, distribute, and modify it under
the terms of the License contained in the file COPYING distributed
with this package. This license is the same as the MIT/X Consortium
license.
See src/tests/TestUnitTest++.cpp for usage.
Authors:
Noel Llopis (llopis@convexhull.com)
Charles Nicholson (charles.nicholson@gmail.com)
Contributors:
Jim Tilander
Kim Grasman
Jonathan Jansson
Dirck Blaskey
Rory Driscoll
Dan Lind
Matt Kimmel -- Submitted with permission from Blue Fang Games
Anthony Moralez
Jeff Dixon
Randy Coulman
Lieven van der Heide
Release notes:
--------------
Version 1.4 (2008-10-30)
- CHECK macros work at arbitrary stack depth from inside TESTs.
- Remove obsolete TEST_UTILITY macros
- Predicated test execution (via TestRunner::RunTestsIf)
- Better exception handling for fixture ctors/dtors.
- VC6/7/8/9 support
Version 1.3 (2007-4-22)
- Removed dynamic memory allocations (other than streams)
- MinGW support
- Consistent (native) line endings
- Minor bug fixing
Version 1.2 (2006-10-29)
- First pass at documentation.
- More detailed error crash catching in fixtures.
- Standard streams used for printing objects under check. This should allow the
use of standard class types such as std::string or other custom classes with
stream operators to ostream.
- Standard streams can be optionally compiled off by defining UNITTEST_USE_CUSTOM_STREAMS
in Config.h
- Added named test suites
- Added CHECK_ARRAY2D_CLOSE
- Posix library name is libUnitTest++.a now
- Floating point numbers are postfixed with f in the failure reports
Version 1.1 (2006-04-18)
- CHECK macros do not have side effects even if one of the parameters changes state
- Removed CHECK_ARRAY_EQUAL (too similar to CHECK_ARRAY_CLOSE)
- Added local and global time constraints
- Removed dependencies on strstream
- Improved Posix signal to exception translator
- Failing tests are added to Visual Studio's error list
- Fixed Visual Studio projects to work with spaces in directories
Version 1.0 (2006-03-15)
- Initial release

141
README.md
View file

@ -1,141 +0,0 @@
> ### Maintenance of UnitTest++, recently sporadic, is officially on hiatus until 26 November 2020. Subscribe to https://github.com/unittest-cpp/unittest-cpp/issues/180 for updates.
[![Build Status](https://travis-ci.org/unittest-cpp/unittest-cpp.svg?branch=master)](https://travis-ci.org/unittest-cpp/unittest-cpp)
[![Build status](https://ci.appveyor.com/api/projects/status/ffs2k8dddts5cyok/branch/master?svg=true)](https://ci.appveyor.com/project/pjohnmeyer/unittest-cpp/branch/master)
UnitTest++
===========
UnitTest++ is a lightweight unit testing framework for C++. It was designed to do test-driven development on a wide variety of platforms. Simplicity, portability, speed, and small footprint are all very important aspects of UnitTest++. UnitTest++ is mostly standard C++ and makes minimal use of advanced library and language features, which means it should be easily portable to just about any platform. Out of the box, the following platforms are supported:
* Windows
* Linux
* Mac OS X
Documentation
--------------
The full documentation for building and using UnitTest++ can be found on the [GitHub wiki page](https://github.com/unittest-cpp/unittest-cpp/wiki). The contents of this wiki are also included as a git submodule under the `docs` folder, so version-specific Markdown documentation is always available along with the download.
Pre-requisites
---------------
While there are currently some bundled automake files, UnitTest++ is primarily built and supported using [CMake](http://cmake.org).
Downloading
------------
### Latest (HEAD) ###
Via git:
git clone https://github.com/unittest-cpp/unittest-cpp
Via svn:
svn checkout https://github.com/unittest-cpp/unittest-cpp/trunk unittest-cpp
### Latest release (v2.0.0) ###
Via git:
git clone https://github.com/unittest-cpp/unittest-cpp
cd unittest-cpp
git checkout v2.0.0
Via svn:
svn checkout https://github.com/unittest-cpp/unittest-cpp/tags/v2.0.0 unittest-cpp
License
---------
*UnitTest++ is free software. You may copy, distribute, and modify it under
the terms of the License contained in the file LICENSE distributed
with this package. This license is the same as the MIT/X Consortium
license.*
Contributors
--------------
### [GitHub Contributor Graph](https://github.com/unittest-cpp/unittest-cpp/contributors) ###
### Current Maintainers: ###
* Patrick Johnmeyer (pjohnmeyer@gmail.com) @pjohnmeyer
* Charles Nicholson (charles.nicholson@gmail.com) @charlesnicholson
### Original Authors: ###
* Noel Llopis (llopis@convexhull.com)
* Charles Nicholson (charles.nicholson@gmail.com)
### Contributors not included in github history ###
* Jim Tilander
* Kim Grasman
* Jonathan Jansson
* Dirck Blaskey
* Rory Driscoll
* Dan Lind
* Matt Kimmel -- Submitted with permission from Blue Fang Games
* Anthony Moralez
* Jeff Dixon
* Randy Coulman
* Lieven van der Heide
Historic release notes
----------------------
### Version 2.0.0 (2017-01-13) ###
- Change Check method supporting CHECK macro to accept argument by reference
- Introduce long macro forms (e.g. UNITTEST_CHECK); make short forms optional
- Improved Visual Studio 2015 support
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A2.0.0+)
### Version 1.6.0 (2016-02-29) ###
- Add REQUIRE macro to end tests early when selected checks fail
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A1.6.0+)
### Version 1.5.1 (2016-01-30) ###
- pkg-config support
- Fix for Visual Studio 2010 compilation issue in 1.5.0
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=milestone%3A1.5.1+)
### Version 1.5 (2015-11-04) ###
- Visual Studio 2015 support
- CMake-based build management
- Integration of SourceForge and Google Code versions of the project
- [Full List](https://github.com/unittest-cpp/unittest-cpp/issues?q=is%3Aissue+is%3Aclosed+milestone%3A1.5.0)
### Version 1.4 (2008-10-30) ###
- CHECK macros work at arbitrary stack depth from inside TESTs.
- Remove obsolete TEST_UTILITY macros
- Predicated test execution (via TestRunner::RunTestsIf)
- Better exception handling for fixture ctors/dtors.
- VC6/7/8/9 support
### Version 1.3 (2007-4-22) ###
- Removed dynamic memory allocations (other than streams)
- MinGW support
- Consistent (native) line endings
- Minor bug fixing
### Version 1.2 (2006-10-29) ###
- First pass at documentation.
- More detailed error crash catching in fixtures.
- Standard streams used for printing objects under check. This should allow the
use of standard class types such as std::string or other custom classes with
stream operators to ostream.
- Standard streams can be optionally compiled off by defining UNITTEST_USE_CUSTOM_STREAMS
in Config.h
- Added named test suites
- Added CHECK_ARRAY2D_CLOSE
- Posix library name is libUnitTest++.a now
- Floating point numbers are postfixed with 'f' in the failure reports
### Version 1.1 (2006-04-18) ###
- CHECK macros do not have side effects even if one of the parameters changes state
- Removed CHECK_ARRAY_EQUAL (too similar to CHECK_ARRAY_CLOSE)
- Added local and global time constraints
- Removed dependencies on strstream
- Improved Posix signal to exception translator
- Failing tests are added to Visual Studio's error list
- Fixed Visual Studio projects to work with spaces in directories
### Version 1.0 (2006-03-15) ###
- Initial release

View file

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="TestUnitTest++.vsnet2003"
ProjectGUID="{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/TestUnitTest++.vsnet2003.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/TestUnitTest++.vsnet2003.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="&quot;$(TargetPath)&quot;"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/TestUnitTest++.vsnet2003.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="&quot;$(TargetPath)&quot;"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\src\tests\Main.cpp">
</File>
<File
RelativePath=".\src\tests\RecordingReporter.h">
</File>
<File
RelativePath=".\src\tests\ScopedCurrentTest.h">
</File>
<File
RelativePath=".\src\tests\TestAssertHandler.cpp">
</File>
<File
RelativePath=".\src\tests\TestCheckMacros.cpp">
</File>
<File
RelativePath=".\src\tests\TestChecks.cpp">
</File>
<File
RelativePath=".\src\tests\TestCurrentTest.cpp">
</File>
<File
RelativePath=".\src\tests\TestDeferredTestReporter.cpp">
</File>
<File
RelativePath=".\src\tests\TestMemoryOutStream.cpp">
</File>
<File
RelativePath=".\src\tests\TestTest.cpp">
</File>
<File
RelativePath=".\src\tests\TestTestList.cpp">
</File>
<File
RelativePath=".\src\tests\TestTestMacros.cpp">
</File>
<File
RelativePath=".\src\tests\TestTestResults.cpp">
</File>
<File
RelativePath=".\src\tests\TestTestRunner.cpp">
</File>
<File
RelativePath=".\src\tests\TestTestSuite.cpp">
</File>
<File
RelativePath=".\src\tests\TestTimeConstraint.cpp">
</File>
<File
RelativePath=".\src\tests\TestTimeConstraintMacro.cpp">
</File>
<File
RelativePath=".\src\tests\TestUnitTest++.cpp">
</File>
<File
RelativePath=".\src\tests\TestXmlTestReporter.cpp">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,256 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="TestUnitTest++.vsnet2005"
ProjectGUID="{9CCC3439-309E-4E85-B3B8-CE704D385D48}"
RootNamespace="TestUnitTestvsnet2005"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
ExceptionHandling="2"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="&quot;$(TargetPath)&quot;"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
ExceptionHandling="2"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="&quot;$(TargetPath)&quot;"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\src\tests\Main.cpp"
>
</File>
<File
RelativePath=".\src\tests\RecordingReporter.h"
>
</File>
<File
RelativePath=".\src\tests\ScopedCurrentTest.h"
>
</File>
<File
RelativePath=".\src\tests\TestAssertHandler.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestCheckMacros.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestChecks.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestCurrentTest.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestDeferredTestReporter.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestMemoryOutStream.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTest.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTestList.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTestMacros.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTestResults.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTestRunner.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTestSuite.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTimeConstraint.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestTimeConstraintMacro.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestUnitTest++.cpp"
>
</File>
<File
RelativePath=".\src\tests\TestXmlTestReporter.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: UnitTest++
Description: UnitTest++ is a simple C++ Unit Test Framework
URL: https://github.com/unittest-cpp/unittest-cpp
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lUnitTest++
Cflags: -I${includedir}/

30
UnitTest++.vsnet2003.sln Normal file
View file

@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest++.vsnet2003", "UnitTest++.vsnet2003.vcproj", "{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestUnitTest++.vsnet2003", "TestUnitTest++.vsnet2003.vcproj", "{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}"
ProjectSection(ProjectDependencies) = postProject
{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5} = {7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}.Debug.ActiveCfg = Debug|Win32
{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}.Debug.Build.0 = Debug|Win32
{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}.Release.ActiveCfg = Release|Win32
{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}.Release.Build.0 = Release|Win32
{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}.Debug.ActiveCfg = Debug|Win32
{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}.Debug.Build.0 = Debug|Win32
{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}.Release.ActiveCfg = Release|Win32
{ACDF9A6A-874F-49E5-AB7C-74F8150BB4C7}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

226
UnitTest++.vsnet2003.vcproj Normal file
View file

@ -0,0 +1,226 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="UnitTest++.vsnet2003"
ProjectGUID="{7E5DD804-EC63-4FA5-BB6D-53DA86806EF5}"
RootNamespace="UnitTest++.vsnet2003"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/UnitTest++.vsnet2003.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="4"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/UnitTest++.vsnet2003.lib"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Win32">
<File
RelativePath=".\src\Win32\TimeHelpers.cpp">
</File>
<File
RelativePath=".\src\Win32\TimeHelpers.h">
</File>
</Filter>
<File
RelativePath=".\src\AssertException.cpp">
</File>
<File
RelativePath=".\src\AssertException.h">
</File>
<File
RelativePath=".\src\CheckMacros.h">
</File>
<File
RelativePath=".\src\Checks.cpp">
</File>
<File
RelativePath=".\src\Checks.h">
</File>
<File
RelativePath=".\src\Config.h">
</File>
<File
RelativePath=".\src\CurrentTest.cpp">
</File>
<File
RelativePath=".\src\CurrentTest.h">
</File>
<File
RelativePath=".\src\DeferredTestReporter.cpp">
</File>
<File
RelativePath=".\src\DeferredTestReporter.h">
</File>
<File
RelativePath=".\src\DeferredTestResult.cpp">
</File>
<File
RelativePath=".\src\DeferredTestResult.h">
</File>
<File
RelativePath=".\src\ExecuteTest.h">
</File>
<File
RelativePath=".\src\MemoryOutStream.cpp">
</File>
<File
RelativePath=".\src\MemoryOutStream.h">
</File>
<File
RelativePath=".\src\ReportAssert.cpp">
</File>
<File
RelativePath=".\src\ReportAssert.h">
</File>
<File
RelativePath=".\src\Test.cpp">
</File>
<File
RelativePath=".\src\Test.h">
</File>
<File
RelativePath=".\src\TestDetails.cpp">
</File>
<File
RelativePath=".\src\TestDetails.h">
</File>
<File
RelativePath=".\src\TestList.cpp">
</File>
<File
RelativePath=".\src\TestList.h">
</File>
<File
RelativePath=".\src\TestMacros.h">
</File>
<File
RelativePath=".\src\TestReporter.cpp">
</File>
<File
RelativePath=".\src\TestReporter.h">
</File>
<File
RelativePath=".\src\TestReporterStdout.cpp">
</File>
<File
RelativePath=".\src\TestReporterStdout.h">
</File>
<File
RelativePath=".\src\TestResults.cpp">
</File>
<File
RelativePath=".\src\TestResults.h">
</File>
<File
RelativePath=".\src\TestRunner.cpp">
</File>
<File
RelativePath=".\src\TestRunner.h">
</File>
<File
RelativePath=".\src\TestSuite.h">
</File>
<File
RelativePath=".\src\TimeConstraint.cpp">
</File>
<File
RelativePath=".\src\TimeConstraint.h">
</File>
<File
RelativePath=".\src\TimeHelpers.h">
</File>
<File
RelativePath=".\src\UnitTest++.h">
</File>
<File
RelativePath=".\src\XmlTestReporter.cpp">
</File>
<File
RelativePath=".\src\XmlTestReporter.h">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

29
UnitTest++.vsnet2005.sln Normal file
View file

@ -0,0 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest++.vsnet2005", "UnitTest++.vsnet2005.vcproj", "{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestUnitTest++.vsnet2005", "TestUnitTest++.vsnet2005.vcproj", "{9CCC3439-309E-4E85-B3B8-CE704D385D48}"
ProjectSection(ProjectDependencies) = postProject
{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6} = {64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Debug|Win32.ActiveCfg = Debug|Win32
{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Debug|Win32.Build.0 = Debug|Win32
{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Release|Win32.ActiveCfg = Release|Win32
{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}.Release|Win32.Build.0 = Release|Win32
{9CCC3439-309E-4E85-B3B8-CE704D385D48}.Debug|Win32.ActiveCfg = Debug|Win32
{9CCC3439-309E-4E85-B3B8-CE704D385D48}.Debug|Win32.Build.0 = Debug|Win32
{9CCC3439-309E-4E85-B3B8-CE704D385D48}.Release|Win32.ActiveCfg = Release|Win32
{9CCC3439-309E-4E85-B3B8-CE704D385D48}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

318
UnitTest++.vsnet2005.vcproj Normal file
View file

@ -0,0 +1,318 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="UnitTest++.vsnet2005"
ProjectGUID="{64A4FEFE-0461-4E95-8CC1-91EF5F57DBC6}"
RootNamespace="UnitTestvsnet2005"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
ExceptionHandling="2"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="obj\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="1"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
ExceptionHandling="2"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Win32"
>
<File
RelativePath=".\src\Win32\TimeHelpers.cpp"
>
</File>
<File
RelativePath=".\src\Win32\TimeHelpers.h"
>
</File>
</Filter>
<File
RelativePath=".\src\AssertException.cpp"
>
</File>
<File
RelativePath=".\src\AssertException.h"
>
</File>
<File
RelativePath=".\src\CheckMacros.h"
>
</File>
<File
RelativePath=".\src\Checks.cpp"
>
</File>
<File
RelativePath=".\src\Checks.h"
>
</File>
<File
RelativePath=".\src\Config.h"
>
</File>
<File
RelativePath=".\src\CurrentTest.cpp"
>
</File>
<File
RelativePath=".\src\CurrentTest.h"
>
</File>
<File
RelativePath=".\src\DeferredTestReporter.cpp"
>
</File>
<File
RelativePath=".\src\DeferredTestReporter.h"
>
</File>
<File
RelativePath=".\src\DeferredTestResult.cpp"
>
</File>
<File
RelativePath=".\src\DeferredTestResult.h"
>
</File>
<File
RelativePath=".\src\ExecuteTest.h"
>
</File>
<File
RelativePath=".\src\MemoryOutStream.cpp"
>
</File>
<File
RelativePath=".\src\MemoryOutStream.h"
>
</File>
<File
RelativePath=".\src\ReportAssert.cpp"
>
</File>
<File
RelativePath=".\src\ReportAssert.h"
>
</File>
<File
RelativePath=".\src\Test.cpp"
>
</File>
<File
RelativePath=".\src\Test.h"
>
</File>
<File
RelativePath=".\src\TestDetails.cpp"
>
</File>
<File
RelativePath=".\src\TestDetails.h"
>
</File>
<File
RelativePath=".\src\TestList.cpp"
>
</File>
<File
RelativePath=".\src\TestList.h"
>
</File>
<File
RelativePath=".\src\TestMacros.h"
>
</File>
<File
RelativePath=".\src\TestReporter.cpp"
>
</File>
<File
RelativePath=".\src\TestReporter.h"
>
</File>
<File
RelativePath=".\src\TestReporterStdout.cpp"
>
</File>
<File
RelativePath=".\src\TestReporterStdout.h"
>
</File>
<File
RelativePath=".\src\TestResults.cpp"
>
</File>
<File
RelativePath=".\src\TestResults.h"
>
</File>
<File
RelativePath=".\src\TestRunner.cpp"
>
</File>
<File
RelativePath=".\src\TestRunner.h"
>
</File>
<File
RelativePath=".\src\TestSuite.h"
>
</File>
<File
RelativePath=".\src\TimeConstraint.cpp"
>
</File>
<File
RelativePath=".\src\TimeConstraint.h"
>
</File>
<File
RelativePath=".\src\TimeHelpers.h"
>
</File>
<File
RelativePath=".\src\UnitTest++.h"
>
</File>
<File
RelativePath=".\src\XmlTestReporter.cpp"
>
</File>
<File
RelativePath=".\src\XmlTestReporter.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -1,15 +0,0 @@
#include "AssertException.h"
#ifndef UNITTEST_NO_EXCEPTIONS
namespace UnitTest {
AssertException::AssertException()
{}
AssertException::~AssertException() throw()
{}
}
#endif

View file

@ -1,23 +0,0 @@
#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

View file

@ -1,216 +0,0 @@
#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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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_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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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, e, \
{ \
UnitTest::MemoryOutStream UnitTest_message; \
UnitTest_message << "Unhandled exception (" << e.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 UNITTEST_CHECK
#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 UNITTEST_CHECK_EQUAL
#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 UNITTEST_CHECK_CLOSE
#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 UNITTEST_CHECK_ARRAY_EQUAL
#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 UNITTEST_CHECK_ARRAY_CLOSE
#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 UNITTEST_CHECK_ARRAY2D_CLOSE
#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_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_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
#endif

View file

@ -1,50 +0,0 @@
#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);
}
}

View file

@ -1,158 +0,0 @@
#ifndef UNITTEST_CHECKS_H
#define UNITTEST_CHECKS_H
#include "Config.h"
#include "TestResults.h"
#include "MemoryOutStream.h"
namespace UnitTest {
template< typename Value >
bool Check(Value const& value)
{
return !!value; // doing double negative to avoid silly VS warnings
}
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 " << expected << " but was " << actual;
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 >
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 << expected[expectedIndex] << " ";
stream << "] 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 >
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());
}
}
}
#endif

View file

@ -1,66 +0,0 @@
#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);
}
}

View file

@ -1,34 +0,0 @@
#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

View file

@ -1,84 +0,0 @@
#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

View file

@ -1,18 +0,0 @@
#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;
}
}

View file

@ -1,19 +0,0 @@
#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

View file

@ -1,35 +0,0 @@
#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

View file

@ -1,43 +0,0 @@
#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

View file

@ -1,52 +0,0 @@
#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

View file

@ -1,20 +0,0 @@
#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

View file

@ -1,61 +0,0 @@
#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, e, { (void)e; })
UNITTEST_IMPL_CATCH(AssertException, e, { (void)e; })
UNITTEST_IMPL_CATCH(std::exception, e,
{
MemoryOutStream stream;
stream << "Unhandled exception: " << e.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

View file

@ -1,52 +0,0 @@
#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

View file

@ -1,17 +0,0 @@
lib_LTLIBRARIES = UnitTest++/libUnitTest++.la
pkgincludedir = $(includedir)
nobase_pkginclude_HEADERS = UnitTest++/AssertException.h UnitTest++/CheckMacros.h UnitTest++/Checks.h UnitTest++/CompositeTestReporter.h UnitTest++/Config.h UnitTest++/CurrentTest.h UnitTest++/DeferredTestReporter.h UnitTest++/DeferredTestResult.h UnitTest++/ExceptionMacros.h UnitTest++/ExecuteTest.h UnitTest++/HelperMacros.h UnitTest++/MemoryOutStream.h UnitTest++/ReportAssert.h UnitTest++/ReportAssertImpl.h UnitTest++/RequireMacros.h UnitTest++/RequiredCheckException.h UnitTest++/RequiredCheckTestReporter.h UnitTest++/Test.h UnitTest++/TestDetails.h UnitTest++/TestList.h UnitTest++/TestMacros.h UnitTest++/TestReporter.h UnitTest++/TestReporterStdout.h UnitTest++/TestResults.h UnitTest++/TestRunner.h UnitTest++/TestSuite.h UnitTest++/ThrowingTestReporter.h UnitTest++/TimeConstraint.h UnitTest++/TimeHelpers.h UnitTest++/UnitTest++.h UnitTest++/UnitTestPP.h UnitTest++/XmlTestReporter.h
UnitTest___libUnitTest___la_SOURCES = UnitTest++/AssertException.cpp UnitTest++/Checks.cpp UnitTest++/CompositeTestReporter.cpp UnitTest++/CurrentTest.cpp UnitTest++/DeferredTestReporter.cpp UnitTest++/DeferredTestResult.cpp UnitTest++/MemoryOutStream.cpp UnitTest++/ReportAssert.cpp UnitTest++/RequiredCheckException.cpp UnitTest++/RequiredCheckTestReporter.cpp UnitTest++/Test.cpp UnitTest++/TestDetails.cpp UnitTest++/TestList.cpp UnitTest++/TestReporter.cpp UnitTest++/TestReporterStdout.cpp UnitTest++/TestResults.cpp UnitTest++/TestRunner.cpp UnitTest++/ThrowingTestReporter.cpp UnitTest++/TimeConstraint.cpp UnitTest++/XmlTestReporter.cpp
if WINDOWS
nobase_pkginclude_HEADERS += UnitTest++/Win32/TimeHelpers.h
UnitTest___libUnitTest___la_SOURCES += UnitTest++/Win32/TimeHelpers.cpp
else
nobase_pkginclude_HEADERS += UnitTest++/Posix/SignalTranslator.h UnitTest++/Posix/TimeHelpers.h
UnitTest___libUnitTest___la_SOURCES += UnitTest++/Posix/SignalTranslator.cpp UnitTest++/Posix/TimeHelpers.cpp
endif
UnitTest___libUnitTest___la_LDFLAGS = -version-number @LIBUNITTEST_SO_VERSION@

View file

@ -1,218 +0,0 @@
#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

View file

@ -1,87 +0,0 @@
#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

View file

@ -1,46 +0,0 @@
#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;
}
}

View file

@ -1,41 +0,0 @@
#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

View file

@ -1,33 +0,0 @@
#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(&currentTime, 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));
}
}

View file

@ -1,28 +0,0 @@
#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

View file

@ -1,71 +0,0 @@
#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();
}
}
}

View file

@ -1,12 +0,0 @@
#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

View file

@ -1,46 +0,0 @@
#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

View file

@ -1,16 +0,0 @@
#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

View file

@ -1,17 +0,0 @@
#include "RequiredCheckException.h"
#ifndef UNITTEST_NO_EXCEPTIONS
namespace UnitTest {
RequiredCheckException::RequiredCheckException()
{
}
RequiredCheckException::~RequiredCheckException() throw()
{
}
}
#endif

View file

@ -1,23 +0,0 @@
#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

View file

@ -1,26 +0,0 @@
#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;
}
}

View file

@ -1,33 +0,0 @@
#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

View file

@ -1,38 +0,0 @@
#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
{}
}

View file

@ -1,35 +0,0 @@
#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

View file

@ -1,22 +0,0 @@
#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)
{}
}

View file

@ -1,27 +0,0 @@
#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

View file

@ -1,38 +0,0 @@
#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);
}
}

View file

@ -1,33 +0,0 @@
#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

View file

@ -1,126 +0,0 @@
#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 UNITTEST_SUITE
#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 UNITTEST_TEST
#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 UNITTEST_TEST_FIXTURE
#endif
#endif
#endif

View file

@ -1,22 +0,0 @@
#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

View file

@ -1,44 +0,0 @@
#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);
}
}

View file

@ -1,19 +0,0 @@
#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

View file

@ -1,59 +0,0 @@
#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;
}
}

View file

@ -1,41 +0,0 @@
#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

View file

@ -1,82 +0,0 @@
#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));
}
}

View file

@ -1,61 +0,0 @@
#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

View file

@ -1,12 +0,0 @@
#ifndef UNITTEST_TESTSUITE_H
#define UNITTEST_TESTSUITE_H
namespace UnitTestSuite
{
inline char const* GetSuiteName ()
{
return "DefaultSuite";
}
}
#endif

View file

@ -1,61 +0,0 @@
#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);
}
}
}

View file

@ -1,26 +0,0 @@
#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

View file

@ -1,29 +0,0 @@
#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());
}
}
}

View file

@ -1,37 +0,0 @@
#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

View file

@ -1,7 +0,0 @@
#include "Config.h"
#if defined UNITTEST_POSIX
#include "Posix/TimeHelpers.h"
#else
#include "Win32/TimeHelpers.h"
#endif

View file

@ -1 +0,0 @@
#include "UnitTestPP.h"

View file

@ -1,12 +0,0 @@
#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

View file

@ -1,49 +0,0 @@
#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);
}
}

View file

@ -1,45 +0,0 @@
#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

View file

@ -1,130 +0,0 @@
#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, '&', "&amp;");
ReplaceChar(escaped, '<', "&lt;");
ReplaceChar(escaped, '>', "&gt;");
ReplaceChar(escaped, '\'', "&apos;");
ReplaceChar(escaped, '\"', "&quot;");
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

View file

@ -1,38 +0,0 @@
#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

View file

@ -1,30 +0,0 @@
version: 2.1.0.{build}
os:
- Windows Server 2012 R2
environment:
matrix:
- CMAKE_GENERATOR: Visual Studio 9 2008
- CMAKE_GENERATOR: Visual Studio 10 2010
- CMAKE_GENERATOR: Visual Studio 11 2012
- CMAKE_GENERATOR: Visual Studio 12 2013
- CMAKE_GENERATOR: Visual Studio 14 2015
before_build:
# Generate solution files using cmake, in 'builds' directory.
# No need to create it because it's part of the repo.
- pushd builds && cmake -G "%CMAKE_GENERATOR%" ..\ && popd
configuration:
- Debug
- Release
build_script:
- pushd builds && cmake --build . && popd
matrix:
fast_finish: true

View file

@ -1,9 +0,0 @@
#!/bin/sh
test -e ./.autotools_aux || mkdir .autotools_aux
libtoolize -cq
aclocal -I m4 --install # Generate aclocal
autoconf # Generate configure script
autoheader # Generate config.h
automake --add-missing --copy # Generate Makefile.in and other scripts

4
builds/.gitignore vendored
View file

@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View file

@ -1,2 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/UnitTest++Targets.cmake")
get_filename_component(UTPP_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../../include/" ABSOLUTE)

View file

@ -1,48 +0,0 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([UnitTest++],
m4_esyscmd_s([git describe --tags | cut -c2-]),
[pjohnmeyer@gmail.com],
[unittest-cpp])
AC_CONFIG_SRCDIR([UnitTest++/TestDetails.cpp])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([UnitTest++.pc])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_SILENT_RULES([yes])
AC_CANONICAL_HOST
dnl Detect Windows, as it doesn't implement UNIX signals and requires special code
AM_CONDITIONAL([WINDOWS],
[test "${host//mingw/}" != "${host}" -o "${host//msvc/}" != "${host}"])
LT_INIT()
AC_SUBST([LIBUNITTEST_SO_VERSION], [2:1:0])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AX_CXX_COMPILE_STDCXX_11(noext, optional)
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([sys/time.h unistd.h setjmp.h signal.h cassert cstddef cstdio cstring exception iosfwd iostream sstream string vector])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([gettimeofday strstr])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

1
docs

@ -1 +0,0 @@
Subproject commit a6963b798400df760e148a6e15e9c13db965a3ec

260
docs/UnitTest++.html Normal file
View file

@ -0,0 +1,260 @@
<html>
<head>
<title>UnitTest++ in brief</title>
</head>
<body>
<h1>UnitTest++ in brief</h1>
<h2>Introduction</h2>
<p>This little document serves as bare-bones documentation for UnitTest++.</p>
<p>For background, goals and license details, see:</p>
<ul>
<li><a href="http://unittest-cpp.sourceforge.net/">The UnitTest++ home page</a></li>
<li><a href="http://www.gamesfromwithin.com/articles/0603/000108.html">Noel Llopis' announcement</a></li>
</ul>
<p>The documentation, while sparse, aims to be practical, so it should give you enough info to get started using UnitTest++ as fast as possible.</p>
<h2>Building UnitTest++</h2>
<p>Building UnitTest++ will be specific to each platform and build environment, but it should be straightforward.</p>
<h3>Building with Visual Studio</h3>
<p>If you are using Visual Studio, go for either of the provided .sln files, depending on version. There are no prefabricated solutions for versions earlier than VS.NET 2003, but we have had reports of people building UnitTest++ with at least VS.NET 2002.</p>
<h3>Building with Make</h3>
<p>The bundled makefile is written to build with g++. It also needs <code>sed</code> installed in the path, and to be able to use the <code>mv</code> and <code>rm</code> shell commands. The makefile should be usable on most Posix-like platforms.</p>
<p>Do "make all" to generate a library and test executable. A final build step runs all unit tests to make sure that the result works as expected.</p>
<h3>Packaging</h3>
<p>You'll probably want to keep the generated library in a shared space in source control, so you can reuse it for multiple test projects. A redistributable package of UnitTest++ would consist of the generated library file, and all of the header files in <code>UnitTest++/src/</code> and its per-platform subfolders. The <code>tests</code> directory only contains the unit tests for the library, and need not be included.</p>
<h2>Using UnitTest++</h2>
<p>The source code for UnitTest++ comes with a full test suite written <em>using</em> UnitTest++. This is a great place to learn techniques for testing. There is one sample .cpp file: <code>UnitTest++/src/tests/TestUnitTest++.cpp</code>. It covers most of UnitTest++'s features in an easy-to-grasp context, so start there if you want a quick overview of typical usage.</p>
<h3>Getting started</h3>
<p>Listed below is a minimal C++ program to run a failing test through UnitTest++.</p>
<pre>
// test.cpp
#include &lt;UnitTest++.h&gt;
TEST(FailSpectacularly)
{
CHECK(false);
}
int main()
{
return UnitTest::RunAllTests();
}
</pre>
<p><code>UnitTest++.h</code> is a facade header for UnitTest++, so including that should get you all features of the library. All classes and free functions are placed in namespace <code>UnitTest</code>, so you need to either qualify their full names (as with <code>RunAllTests()</code> in the example) or add a <code>using namespace UnitTest;</code> statement in your .cpp files. Note that any mention of UnitTest++ functions and classes in this document assume that the <code>UnitTest</code> namespace has been opened.</p>
<p>Compiling and linking this program with UnitTest++'s static library into an executable, and running it, will produce the following output (details may vary):</p>
<pre>
.\test.cpp(5): error: Failure in FailSpectacularly: false
FAILED: 1 out of 1 tests failed (1 failures).
Test time: 0.00 seconds.
</pre>
<p>UnitTest++ attempts to report every failure in an IDE-friendly format, depending on platform (e.g. you can double-click it in Visual Studio's error list.) The exit code will be the number of failed tests, so that a failed test run always returns a non-zero exit code.</p>
<h3>Test macros</h3>
<p>To add a test, simply put the following code in a .cpp file of your choice:</p>
<pre>
TEST(YourTestName)
{
}
</pre>
<p>The <code>TEST</code> macro contains enough machinery to turn this slightly odd-looking syntax into legal C++, and automatically register the test in a global list. This test list forms the basis of what is executed by <code>RunAllTests()</code>.</p>
<p>If you want to re-use a set of test data for more than one test, or provide setup/teardown for tests, you can use the <code>TEST_FIXTURE</code> macro instead. The macro requires that you pass it a class name that it will instantiate, so any setup and teardown code should be in its constructor and destructor.</p>
<pre>
struct SomeFixture
{
SomeFixture() { /* some setup */ }
~SomeFixture() { /* some teardown */ }
int testData;
};
TEST_FIXTURE(SomeFixture, YourTestName)
{
int temp = testData;
}
</pre>
<p>Note how members of the fixture are used as if they are a part of the test, since the macro-generated test class derives from the provided fixture class.</p>
<h3>Suite macros</h3>
<p>Tests can be grouped into suites, using the <code>SUITE</code> macro. A suite serves as a namespace for test names, so that the same test name can be used in two difference contexts.</p>
<pre>
SUITE(YourSuiteName)
{
TEST(YourTestName)
{
}
TEST(YourOtherTestName)
{
}
}
</pre>
<p>This will place the tests into a C++ namespace called <code>YourSuiteName</code>, and make the suite name available to UnitTest++. <code>RunAllTests()</code> can be called for a specific suite name, so you can use this to build named groups of tests to be run together.</p>
<h3>Simple check macros</h3>
<p>In test cases, we want to check the results of our system under test. UnitTest++ provides a number of check macros that handle comparison and proper failure reporting.</p>
<p>The most basic variety is the boolean <code>CHECK</code> macro:</p>
<pre>
CHECK(false); // fails
</pre>
<p>It will fail if the boolean expression evaluates to false.</p>
<p>For equality checks, it's generally better to use <code>CHECK_EQUAL</code>:</p>
<pre>
CHECK_EQUAL(10, 20); // fails
CHECK_EQUAL("foo", "bar"); // fails
</pre>
<p>Note how <code>CHECK_EQUAL</code> is overloaded for C strings, so you don't have to resort to <code>strcmp</code> or similar. There is no facility for case-insensitive comparison or string searches, so you may have to drop down to a plain boolean <code>CHECK</code> with help from the CRT:</p>
<pre>
CHECK(std::strstr("zaza", "az") != 0); // succeeds
</pre>
<p>For floating-point comparison, equality <a href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm">isn't necessarily well-defined</a>, so you should prefer the <code>CHECK_CLOSE</code> macro:</p>
<pre>
CHECK_CLOSE(3.14, 3.1415, 0.01); // succeeds
</pre>
<p>All of the macros are tailored to avoid unintended side-effects, for example:</p>
<pre>
TEST(CheckMacrosHaveNoSideEffects)
{
int i = 4;
CHECK_EQUAL(5, ++i); // succeeds
CHECK_EQUAL(5, i); // succeeds
}
</pre>
<p>The check macros guarantee that the <code>++i</code> expression isn't repeated internally, as demonstrated above.</p>
<h3>Array check macros</h3>
<p>There is a set of check macros for array comparison as well:</p>
<pre>
const float oned[2] = { 10, 20 };
CHECK_ARRAY_EQUAL(oned, oned, 2); // succeeds
CHECK_ARRAY_CLOSE(oned, oned, 2, 0.00); // succeeds
const float twod[2][3] = { {0, 1, 2}, {2, 3, 4} };
CHECK_ARRAY2D_CLOSE(twod, twod, 2, 3, 0.00); // succeeds
</pre>
<p>The array equal macro compares elements using <code>operator==</code>, so <code>CHECK_ARRAY_EQUAL</code> won't work for an array of C strings, for example.</p>
<p>The array close macros are similar to the regular CHECK_CLOSE macro, and are really only useful for scalar types, that can be compared in terms of a difference between two array elements.</p>
<p>Note that the one-dimensional array macros work for <code>std::vector</code> as well, as it can be indexed just as a C array.</p>
<h3>Exception check macros</h3>
<p>Finally, there's a <code>CHECK_THROW</code> macro, which asserts that its enclosed expression throws the specified type:</p>
<pre>
struct TestException {};
CHECK_THROW(throw TestException(), TestException); // succeeds
</pre>
<p>UnitTest++ natively catches exceptions if your test code doesn't. So if your code under test throws any exception UnitTest++ will fail the test and report either using the <code>what()</code> method for <code>std::exception</code> derivatives or just a plain message for unknown exception types.</p>
<p>Should your test or code raise an irrecoverable error (an Access Violation on Win32, for example, or a signal on Linux), UnitTest++ will attempt to map them to an exception and fail the test, just as for other unhandled exceptions.</p>
<h3>Time constraints</h3>
<p>UnitTest++ can fail a test if it takes too long to complete, using so-called time constraints.</p>
<p>They come in two flavors; <em>local</em> and <em>global</em> time constraints.</p>
<p>Local time constraints are limited to the current scope, like so:</p>
<pre>
TEST(YourTimedTest)
{
// Lengthy setup...
{
UNITTEST_TIME_CONSTRAINT(50);
// Do time-critical stuff
}
// Lengthy teardown...
}
</pre>
<p>The test will fail if the "Do time-critical stuff" block takes longer than 50 ms to complete. The time-consuming setup and teardown are not measured, since the time constraint is scope-bound. It's perfectly valid to have multiple local time constraints in the same test, as long as there is only one per block.</p>
<p>A global time constraint, on the other hand, requires that all of the tests in a test run are faster than a specified amount of time. This allows you, when you run a suite of tests, to ask UnitTest++ to fail it entirely if any test exceeds the global constraint. The max time is passed as a parameter to an overload of <code>RunAllTests()</code>.</p>
<p>If you want to use a global time constraint, but have one test that is notoriously slow, you can exempt it from inspection by using the <code>UNITTEST_TIME_CONSTRAINT_EXEMPT</code> macro anywhere inside the test body.</p>
<pre>
TEST(NotoriouslySlowTest)
{
UNITTEST_TIME_CONSTRAINT_EXEMPT();
// Oh boy, this is going to take a while
...
}
</pre>
<h3>Test runners</h3>
<p>The <code>RunAllTests()</code> function has an overload that lets you customize the behavior of the runner, such as global time constraints, custom reporters, which suite to run, etc.</p>
<pre>
int RunAllTests(TestReporter& reporter, TestList const& list, char const* suiteName, int const maxTestTimeInMs);
</pre>
<p>If you attempt to pass custom parameters to <code>RunAllTests()</code>, note that the <code>list</code> parameter should have the value <code>Test::GetTestList()</code>.</p>
<p>The parameterless <code>RunAllTests()</code> is a simple wrapper for this one, with sensible defaults.</p>
<h3>Example setup</h3>
<p>How to create a new test project varies depending on your environment, but here are some directions on common file structure and usage.</p>
<p>The general idea is that you keep one <code>Main.cpp</code> file with the entry-point which calls <code>RunAllTests()</code>.</p>
<p>Then you can simply compile and link new .cpp files at will, typically one per test suite.</p>
<pre>
+ ShaverTests/
|
+- Main.cpp
|
+- TestBrush.cpp
+- TestEngine.cpp
+- TestRazor.cpp
</pre>
<p>Each of the <code>Test*.cpp</code> files will contain one or more <code>TEST</code> macro incantations with the associated test code. There are no source-level dependencies between <code>Main.cpp</code> and <code>Test*.cpp</code>, as the <code>TEST</code> macro handles the registration and setup necessary for <code>RunAllTests()</code> to find all tests compiled into the same final executable.</p>
<p>UnitTest++ does not require this structure, even if this is how the library itself does it. As long as your test project contains one or more <code>TESTs</code> and calls <code>RunAllTests()</code> at one point or another, it will be handled by UnitTest++.</p>
<p>It's common to make the generated executable start as a post-build step, so that merely building your test project will run the tests as well. Since the exit code is the count of failures, a failed test will generally break the build, as most build engines will fail a build if any step returns a non-zero exit code.</p>
</body>
</html>

View file

@ -1,558 +0,0 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the specified
# version of the C++ standard. If necessary, add switches to CXXFLAGS to
# enable support. VERSION may be '11' (for the C++11 standard) or '14'
# (for the C++14 standard).
#
# The second argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The third argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline support for the specified C++ standard is
# required and that the macro should error out if no mode with that
# support is found. If specified 'optional', then configuration proceeds
# regardless, after defining HAVE_CXX${VERSION} if and only if a
# supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [],
[$1], [14], [],
[$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
[$2], [noext], [],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
[$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
[$3], [optional], [ax_cxx_compile_cxx$1_required=false],
[m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
ax_cv_cxx_compile_cxx$1,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[ax_cv_cxx_compile_cxx$1=yes],
[ax_cv_cxx_compile_cxx$1=no])])
if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
ac_success=yes
fi
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++$1 -std=gnu++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$2], [ext], [], [dnl
if test x$ac_success = xno; then
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
dnl Cray's crayCC needs "-h std=c++11"
for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx$1_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX$1=0
AC_MSG_NOTICE([No compiler with C++$1 support was found])
else
HAVE_CXX$1=1
AC_DEFINE(HAVE_CXX$1,1,
[define if the compiler supports basic C++$1 syntax])
fi
AC_SUBST(HAVE_CXX$1)
fi
])
dnl Test body for checking C++11 support
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
)
dnl Test body for checking C++14 support
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)
dnl Tests for new features in C++11
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
// If the compiler admits that it is not ready for C++11, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
#error "This is not a C++11 compiler"
#else
namespace cxx11
{
namespace test_static_assert
{
template <typename T>
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
}
namespace test_final_override
{
struct Base
{
virtual void f() {}
};
struct Derived : public Base
{
virtual void f() override {}
};
}
namespace test_double_right_angle_brackets
{
template < typename T >
struct check {};
typedef check<void> single_type;
typedef check<check<void>> double_type;
typedef check<check<check<void>>> triple_type;
typedef check<check<check<check<void>>>> quadruple_type;
}
namespace test_decltype
{
int
f()
{
int a = 1;
decltype(a) b = 2;
return a + b;
}
}
namespace test_type_deduction
{
template < typename T1, typename T2 >
struct is_same
{
static const bool value = false;
};
template < typename T >
struct is_same<T, T>
{
static const bool value = true;
};
template < typename T1, typename T2 >
auto
add(T1 a1, T2 a2) -> decltype(a1 + a2)
{
return a1 + a2;
}
int
test(const int c, volatile int v)
{
static_assert(is_same<int, decltype(0)>::value == true, "");
static_assert(is_same<int, decltype(c)>::value == false, "");
static_assert(is_same<int, decltype(v)>::value == false, "");
auto ac = c;
auto av = v;
auto sumi = ac + av + 'x';
auto sumf = ac + av + 1.0;
static_assert(is_same<int, decltype(ac)>::value == true, "");
static_assert(is_same<int, decltype(av)>::value == true, "");
static_assert(is_same<int, decltype(sumi)>::value == true, "");
static_assert(is_same<int, decltype(sumf)>::value == false, "");
static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
return (sumf > 0.0) ? sumi : add(c, v);
}
}
namespace test_noexcept
{
int f() { return 0; }
int g() noexcept { return 0; }
static_assert(noexcept(f()) == false, "");
static_assert(noexcept(g()) == true, "");
}
namespace test_constexpr
{
template < typename CharT >
unsigned long constexpr
strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
{
return *s ? strlen_c_r(s + 1, acc + 1) : acc;
}
template < typename CharT >
unsigned long constexpr
strlen_c(const CharT *const s) noexcept
{
return strlen_c_r(s, 0UL);
}
static_assert(strlen_c("") == 0UL, "");
static_assert(strlen_c("1") == 1UL, "");
static_assert(strlen_c("example") == 7UL, "");
static_assert(strlen_c("another\0example") == 7UL, "");
}
namespace test_rvalue_references
{
template < int N >
struct answer
{
static constexpr int value = N;
};
answer<1> f(int&) { return answer<1>(); }
answer<2> f(const int&) { return answer<2>(); }
answer<3> f(int&&) { return answer<3>(); }
void
test()
{
int i = 0;
const int c = 0;
static_assert(decltype(f(i))::value == 1, "");
static_assert(decltype(f(c))::value == 2, "");
static_assert(decltype(f(0))::value == 3, "");
}
}
namespace test_uniform_initialization
{
struct test
{
static const int zero {};
static const int one {1};
};
static_assert(test::zero == 0, "");
static_assert(test::one == 1, "");
}
namespace test_lambdas
{
void
test1()
{
auto lambda1 = [](){};
auto lambda2 = lambda1;
lambda1();
lambda2();
}
int
test2()
{
auto a = [](int i, int j){ return i + j; }(1, 2);
auto b = []() -> int { return '0'; }();
auto c = [=](){ return a + b; }();
auto d = [&](){ return c; }();
auto e = [a, &b](int x) mutable {
const auto identity = [](int y){ return y; };
for (auto i = 0; i < a; ++i)
a += b--;
return x + identity(a + b);
}(0);
return a + b + c + d + e;
}
int
test3()
{
const auto nullary = [](){ return 0; };
const auto unary = [](int x){ return x; };
using nullary_t = decltype(nullary);
using unary_t = decltype(unary);
const auto higher1st = [](nullary_t f){ return f(); };
const auto higher2nd = [unary](nullary_t f1){
return [unary, f1](unary_t f2){ return f2(unary(f1())); };
};
return higher1st(nullary) + higher2nd(nullary)(unary);
}
}
namespace test_variadic_templates
{
template <int...>
struct sum;
template <int N0, int... N1toN>
struct sum<N0, N1toN...>
{
static constexpr auto value = N0 + sum<N1toN...>::value;
};
template <>
struct sum<>
{
static constexpr auto value = 0;
};
static_assert(sum<>::value == 0, "");
static_assert(sum<1>::value == 1, "");
static_assert(sum<23>::value == 23, "");
static_assert(sum<1, 2>::value == 3, "");
static_assert(sum<5, 5, 11>::value == 21, "");
static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
}
// http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
// Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
// because of this.
namespace test_template_alias_sfinae
{
struct foo {};
template<typename T>
using member = typename T::member_type;
template<typename T>
void func(...) {}
template<typename T>
void func(member<T>*) {}
void test();
void test() { func<foo>(0); }
}
} // namespace cxx11
#endif // __cplusplus >= 201103L
]])
dnl Tests for new features in C++14
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
// If the compiler admits that it is not ready for C++14, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201402L
#error "This is not a C++14 compiler"
#else
namespace cxx14
{
namespace test_polymorphic_lambdas
{
int
test()
{
const auto lambda = [](auto&&... args){
const auto istiny = [](auto x){
return (sizeof(x) == 1UL) ? 1 : 0;
};
const int aretiny[] = { istiny(args)... };
return aretiny[0];
};
return lambda(1, 1L, 1.0f, '1');
}
}
namespace test_binary_literals
{
constexpr auto ivii = 0b0000000000101010;
static_assert(ivii == 42, "wrong value");
}
namespace test_generalized_constexpr
{
template < typename CharT >
constexpr unsigned long
strlen_c(const CharT *const s) noexcept
{
auto length = 0UL;
for (auto p = s; *p; ++p)
++length;
return length;
}
static_assert(strlen_c("") == 0UL, "");
static_assert(strlen_c("x") == 1UL, "");
static_assert(strlen_c("test") == 4UL, "");
static_assert(strlen_c("another\0test") == 7UL, "");
}
namespace test_lambda_init_capture
{
int
test()
{
auto x = 0;
const auto lambda1 = [a = x](int b){ return a + b; };
const auto lambda2 = [a = lambda1(x)](){ return a; };
return lambda2();
}
}
namespace test_digit_seperators
{
constexpr auto ten_million = 100'000'000;
static_assert(ten_million == 100000000, "");
}
namespace test_return_type_deduction
{
auto f(int& x) { return x; }
decltype(auto) g(int& x) { return x; }
template < typename T1, typename T2 >
struct is_same
{
static constexpr auto value = false;
};
template < typename T >
struct is_same<T, T>
{
static constexpr auto value = true;
};
int
test()
{
auto x = 0;
static_assert(is_same<int, decltype(f(x))>::value, "");
static_assert(is_same<int&, decltype(g(x))>::value, "");
return x;
}
}
} // namespace cxx14
#endif // __cplusplus >= 201402L
]])

View file

@ -1,39 +0,0 @@
# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXXFLAGS to enable support.
#
# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
# macro with the version set to C++11. The two optional arguments are
# forwarded literally as the second and third argument respectively.
# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
# more information. If you want to use this macro, you also need to
# download the ax_cxx_compile_stdcxx.m4 file.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 14
include([ax_cxx_compile_stdcxx.m4])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])])

34
src/AssertException.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "AssertException.h"
#include <cstring>
namespace UnitTest {
AssertException::AssertException(char const* description, char const* filename, int lineNumber)
: m_lineNumber(lineNumber)
{
using namespace std;
strcpy(m_description, description);
strcpy(m_filename, filename);
}
AssertException::~AssertException() throw()
{
}
char const* AssertException::what() const throw()
{
return m_description;
}
char const* AssertException::Filename() const
{
return m_filename;
}
int AssertException::LineNumber() const
{
return m_lineNumber;
}
}

28
src/AssertException.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef UNITTEST_ASSERTEXCEPTION_H
#define UNITTEST_ASSERTEXCEPTION_H
#include <exception>
namespace UnitTest {
class AssertException : public std::exception
{
public:
AssertException(char const* description, char const* filename, int lineNumber);
virtual ~AssertException() throw();
virtual char const* what() const throw();
char const* Filename() const;
int LineNumber() const;
private:
char m_description[512];
char m_filename[256];
int m_lineNumber;
};
}
#endif

122
src/CheckMacros.h Normal file
View file

@ -0,0 +1,122 @@
#ifndef UNITTEST_CHECKMACROS_H
#define UNITTEST_CHECKMACROS_H
#include "Checks.h"
#include "AssertException.h"
#include "MemoryOutStream.h"
#include "TestDetails.h"
#include "CurrentTest.h"
#ifdef CHECK
#error UnitTest++ redefines CHECK
#endif
#ifdef CHECK_EQUAL
#error UnitTest++ redefines CHECK_EQUAL
#endif
#ifdef CHECK_CLOSE
#error UnitTest++ redefines CHECK_CLOSE
#endif
#ifdef CHECK_ARRAY_EQUAL
#error UnitTest++ redefines CHECK_ARRAY_EQUAL
#endif
#ifdef CHECK_ARRAY_CLOSE
#error UnitTest++ redefines CHECK_ARRAY_CLOSE
#endif
#ifdef CHECK_ARRAY2D_CLOSE
#error UnitTest++ redefines CHECK_ARRAY2D_CLOSE
#endif
#define CHECK(value) \
do \
{ \
try { \
if (!UnitTest::Check(value)) \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), #value); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK(" #value ")"); \
} \
} while (0)
#define CHECK_EQUAL(expected, actual) \
do \
{ \
try { \
UnitTest::CheckEqual(*UnitTest::CurrentTest::Results(), expected, actual, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_EQUAL(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_CLOSE(expected, actual, tolerance) \
do \
{ \
try { \
UnitTest::CheckClose(*UnitTest::CurrentTest::Results(), expected, actual, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY_EQUAL(expected, actual, count) \
do \
{ \
try { \
UnitTest::CheckArrayEqual(*UnitTest::CurrentTest::Results(), expected, actual, count, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_EQUAL(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY_CLOSE(expected, actual, count, tolerance) \
do \
{ \
try { \
UnitTest::CheckArrayClose(*UnitTest::CurrentTest::Results(), expected, actual, count, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_ARRAY2D_CLOSE(expected, actual, rows, columns, tolerance) \
do \
{ \
try { \
UnitTest::CheckArray2DClose(*UnitTest::CurrentTest::Results(), expected, actual, rows, columns, tolerance, UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__)); \
} \
catch (...) { \
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), \
"Unhandled exception in CHECK_ARRAY_CLOSE(" #expected ", " #actual ")"); \
} \
} while (0)
#define CHECK_THROW(expression, ExpectedExceptionType) \
do \
{ \
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"); \
} while(0)
#define CHECK_ASSERT(expression) \
CHECK_THROW(expression, UnitTest::AssertException);
#endif

50
src/Checks.cpp Normal file
View 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 (strcmp(expected, actual))
{
UnitTest::MemoryOutStream stream;
stream << "Expected " << expected << " but was " << actual;
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);
}
}

158
src/Checks.h Normal file
View file

@ -0,0 +1,158 @@
#ifndef UNITTEST_CHECKS_H
#define UNITTEST_CHECKS_H
#include "Config.h"
#include "TestResults.h"
#include "MemoryOutStream.h"
namespace UnitTest {
template< typename Value >
bool Check(Value const value)
{
return !!value; // doing double negative to avoid silly VS warnings
}
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 " << expected << " but was " << actual;
results.OnTestFailure(details, stream.GetText());
}
}
void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details);
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 >
void CheckArrayEqual(TestResults& results, Expected const& expected, Actual const& actual,
int const count, TestDetails const& details)
{
bool equal = true;
for (int i = 0; i < count; ++i)
equal &= (expected[i] == actual[i]);
if (!equal)
{
UnitTest::MemoryOutStream stream;
stream << "Expected [ ";
for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex)
stream << expected[expectedIndex] << " ";
stream << "] but was [ ";
for (int actualIndex = 0; actualIndex < count; ++actualIndex)
stream << actual[actualIndex] << " ";
stream << "]";
results.OnTestFailure(details, stream.GetText());
}
}
template< typename Expected, typename Actual, typename Tolerance >
bool ArrayAreClose(Expected const& expected, Actual const& actual, int const count, Tolerance const& tolerance)
{
bool equal = true;
for (int 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,
int const count, Tolerance const& tolerance, TestDetails const& details)
{
bool equal = ArrayAreClose(expected, actual, count, tolerance);
if (!equal)
{
UnitTest::MemoryOutStream stream;
stream << "Expected [ ";
for (int expectedIndex = 0; expectedIndex < count; ++expectedIndex)
stream << expected[expectedIndex] << " ";
stream << "] +/- " << tolerance << " but was [ ";
for (int 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,
int const rows, int const columns, Tolerance const& tolerance, TestDetails const& details)
{
bool equal = true;
for (int i = 0; i < rows; ++i)
equal &= ArrayAreClose(expected[i], actual[i], columns, tolerance);
if (!equal)
{
UnitTest::MemoryOutStream stream;
stream << "Expected [ ";
for (int expectedRow = 0; expectedRow < rows; ++expectedRow)
{
stream << "[ ";
for (int expectedColumn = 0; expectedColumn < columns; ++expectedColumn)
stream << expected[expectedRow][expectedColumn] << " ";
stream << "] ";
}
stream << "] +/- " << tolerance << " but was [ ";
for (int actualRow = 0; actualRow < rows; ++actualRow)
{
stream << "[ ";
for (int actualColumn = 0; actualColumn < columns; ++actualColumn)
stream << actual[actualRow][actualColumn] << " ";
stream << "] ";
}
stream << "]";
results.OnTestFailure(details, stream.GetText());
}
}
}
#endif

31
src/Config.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef UNITTEST_CONFIG_H
#define UNITTEST_CONFIG_H
// Standard defines documented here: http://predef.sourceforge.net
#if defined(_MSC_VER)
#pragma warning(disable:4127) // conditional expression is constant
#pragma warning(disable:4702) // unreachable code
#pragma warning(disable:4722) // destructor never returns, potential memory leak
#if (_MSC_VER == 1200) // VC6
#pragma warning(disable:4786)
#pragma warning(disable:4290)
#endif
#endif
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#define UNITTEST_POSIX
#endif
#if defined(__MINGW32__)
#define UNITTEST_MINGW
#endif
// by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive.
// uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
//#define UNITTEST_USE_CUSTOM_STREAMS
#endif

18
src/CurrentTest.cpp Normal file
View file

@ -0,0 +1,18 @@
#include "CurrentTest.h"
#include <cstddef>
namespace UnitTest {
TestResults*& CurrentTest::Results()
{
static TestResults* testResults = NULL;
return testResults;
}
const TestDetails*& CurrentTest::Details()
{
static const TestDetails* testDetails = NULL;
return testDetails;
}
}

17
src/CurrentTest.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef UNITTEST_CURRENTTESTRESULTS_H
#define UNITTEST_CURRENTTESTRESULTS_H
namespace UnitTest {
class TestResults;
class TestDetails;
namespace CurrentTest
{
TestResults*& Results();
const TestDetails*& Details();
}
}
#endif

View file

@ -1,33 +1,29 @@
#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
#include "DeferredTestReporter.h"
#include "TestDetails.h"
#include "Config.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(DeferredTestResult::Failure(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;
}

View file

@ -0,0 +1,28 @@
#ifndef UNITTEST_DEFERREDTESTREPORTER_H
#define UNITTEST_DEFERREDTESTREPORTER_H
#include "TestReporter.h"
#include "DeferredTestResult.h"
#include <vector>
namespace UnitTest
{
class 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

View file

@ -0,0 +1,25 @@
#include "DeferredTestResult.h"
#include "Config.h"
namespace UnitTest
{
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)
{
}
}

29
src/DeferredTestResult.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef UNITTEST_DEFERREDTESTRESULT_H
#define UNITTEST_DEFERREDTESTRESULT_H
#include <string>
#include <vector>
namespace UnitTest
{
struct DeferredTestResult
{
DeferredTestResult();
DeferredTestResult(char const* suite, char const* test);
std::string suiteName;
std::string testName;
std::string failureFile;
typedef std::pair< int, std::string > Failure;
typedef std::vector< Failure > FailureVec;
FailureVec failures;
float timeElapsed;
bool failed;
};
}
#endif //UNITTEST_DEFERREDTESTRESULT_H

46
src/ExecuteTest.h Normal file
View file

@ -0,0 +1,46 @@
#ifndef UNITTEST_EXECUTE_TEST_H
#define UNITTEST_EXECUTE_TEST_H
#include "TestDetails.h"
#include "MemoryOutStream.h"
#include "AssertException.h"
#include "CurrentTest.h"
#ifdef UNITTEST_POSIX
#include "Posix/SignalTranslator.h"
#endif
namespace UnitTest {
template< typename T >
void ExecuteTest(T& testObject, TestDetails const& details)
{
CurrentTest::Details() = &details;
try
{
#ifdef UNITTEST_POSIX
UNITTEST_THROW_SIGNALS
#endif
testObject.RunImpl();
}
catch (AssertException const& e)
{
CurrentTest::Results()->OnTestFailure(
TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what());
}
catch (std::exception const& e)
{
MemoryOutStream stream;
stream << "Unhandled exception: " << e.what();
CurrentTest::Results()->OnTestFailure(details, stream.GetText());
}
catch (...)
{
CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!");
}
}
}
#endif

149
src/MemoryOutStream.cpp Normal file
View file

@ -0,0 +1,149 @@
#include "MemoryOutStream.h"
#ifndef UNITTEST_USE_CUSTOM_STREAMS
namespace UnitTest {
char const* MemoryOutStream::GetText() const
{
m_text = this->str();
return m_text.c_str();
}
}
#else
#include <cstring>
#include <cstdio>
namespace UnitTest {
namespace {
template<typename ValueType>
void FormatToStream(MemoryOutStream& stream, char const* format, ValueType const& value)
{
using namespace std;
char txt[32];
sprintf(txt, 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;
}
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;
}
MemoryOutStream& MemoryOutStream::operator << (float const f)
{
FormatToStream(*this, "%ff", 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, "%f", 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

Some files were not shown because too many files have changed in this diff Show more