From e544bb9ab4eaea8c007c030559c91b34e7debbd5 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Sat, 1 Jun 2019 10:34:30 +0900 Subject: [PATCH 1/3] stricmp test (#226) --- include/internal/iutest_compiler.hpp | 14 +++ include/internal/iutest_option_message.hpp | 1 + include/internal/iutest_string.hpp | 115 +++++++++++---------- test/unit_string_tests.cpp | 56 ++++++++++ 4 files changed, 130 insertions(+), 56 deletions(-) diff --git a/include/internal/iutest_compiler.hpp b/include/internal/iutest_compiler.hpp index e10d4196f5..389d63ba44 100644 --- a/include/internal/iutest_compiler.hpp +++ b/include/internal/iutest_compiler.hpp @@ -927,6 +927,20 @@ # include #endif +#if !defined(IUTEST_WCHAR_UNSIGNED) +# if defined(__WCHAR_UNSIGNED__) && __WCHAR_UNSIGNED__ +# define IUTEST_WCHAR_UNSIGNED 1 +# elif defined(_MSC_VER) +# if defined(_NATIVE_WCHAR_T_DEFINED) +# define IUTEST_WCHAR_UNSIGNED 1 +# endif +# endif +#endif + +#if !defined(IUTEST_WCHAR_UNSIGNED) +# define IUTEST_WCHAR_UNSIGNED 0 +#endif + //! has 128bit type #if !defined(IUTEST_HAS_INT128) # if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16 diff --git a/include/internal/iutest_option_message.hpp b/include/internal/iutest_option_message.hpp index 57b22e523d..a493a5adf4 100644 --- a/include/internal/iutest_option_message.hpp +++ b/include/internal/iutest_option_message.hpp @@ -234,6 +234,7 @@ inline void iuOptionMessage::ShowSpec() IIUT_SHOW_MACRO(IUTEST_HAS_WANT_SECURE_LIB); IIUT_SHOW_MACRO(IUTEST_USE_OWN_LIST); IIUT_SHOW_MACRO(IUTEST_USE_THROW_ON_ASSERTION_FAILURE); + IIUT_SHOW_MACRO(IUTEST_WCHAR_UNSIGNED); #ifdef IUTEST_LIBSTDCXX_VERSION IIUT_SHOW_MACRO(IUTEST_LIBSTDCXX_VERSION); diff --git a/include/internal/iutest_string.hpp b/include/internal/iutest_string.hpp index 2983a29d5b..621715dce5 100644 --- a/include/internal/iutest_string.hpp +++ b/include/internal/iutest_string.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -45,48 +45,76 @@ namespace detail ::std::string StringFormat(const char* format, ...); -/** - * @internal - * @brief stricmp -*/ -inline int iu_stricmp(const char* str1, const char* str2) +namespace wrapper { -#if defined(__BORLANDC__) - return stricmp(str1, str2); -#elif defined(_MSC_VER) - return _stricmp(str1, str2); -#elif defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW) && !defined(__STRICT_ANSI__) - return _stricmp(str1, str2); -#elif !defined(__MWERKS__) && !defined(IUTEST_OS_WINDOWS) - return strcasecmp(str1, str2); -#else +inline int iu_mbicmp(char l, char r) +{ + const int ul = static_cast(static_cast(toupper(l))); + const int ur = static_cast(static_cast(toupper(r))); + return ul - ur; +} + +inline int iu_stricmp(const char* str1, const char* str2) +{ const char* l = str1; const char* r = str2; while(*l) { - int ul = toupper(*l); - int ur = toupper(*r); - if( ul < ur ) + const int ret = iu_mbicmp(*l, *r); + if( ret != 0 ) { - return -1; - } - if( ul > ur ) - { - return 1; + return ret; } ++l; ++r; } - if( *l < *r ) - { - return -1; - } - if( *l > *r ) + return iu_mbicmp(*l, *r); +} + +inline int iu_wcicmp(wchar_t l, wchar_t r) +{ + const ::std::wint_t ul = towupper(l); + const ::std::wint_t ur = towupper(r); + return ul - ur; +} + +inline int iu_wcsicmp(const wchar_t * str1, const wchar_t * str2) +{ + const wchar_t* l = str1; + const wchar_t* r = str2; + while(*l) { - return 1; + const int ret = iu_wcicmp(*l, *r); + if( ret != 0 ) + { + return ret; + } + ++l; + ++r; } - return 0; + return iu_wcicmp(*l, *r); +} + +} // end of namespace wrapper + +/** + * @internal + * @brief stricmp (unsigned char compare) +*/ +inline int iu_stricmp(const char* str1, const char* str2) +{ +#if defined(__BORLANDC__) + return stricmp(str1, str2); +#elif defined(_MSC_VER) + return _stricmp(str1, str2); +#elif defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW) && !defined(__STRICT_ANSI__) + return _stricmp(str1, str2); +#elif !defined(__MWERKS__) && !defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_CYGWIN) + // NOTE: Cygwin strcasecmp signed compare? + return strcasecmp(str1, str2); +#else + return wrapper::iu_stricmp(str1, str2); #endif } @@ -101,32 +129,7 @@ inline int iu_wcsicmp(const wchar_t * str1, const wchar_t * str2) #elif defined(IUTEST_OS_LINUX) && !defined(IUTEST_OS_LINUX_ANDROID) return wcscasecmp(str1, str2); #else - const wchar_t* l = str1; - const wchar_t* r = str2; - while(*l) - { - wchar_t ul = towupper(*l); - wchar_t ur = towupper(*r); - if( ul < ur ) - { - return -1; - } - if( ul > ur ) - { - return 1; - } - ++l; - ++r; - } - if( *l < *r ) - { - return -1; - } - if( *l > *r ) - { - return 1; - } - return 0; + return wrapper::iu_wcsicmp(str1, str2); #endif } diff --git a/test/unit_string_tests.cpp b/test/unit_string_tests.cpp index e82230581f..90012b9d32 100644 --- a/test/unit_string_tests.cpp +++ b/test/unit_string_tests.cpp @@ -17,6 +17,62 @@ // include #include "iutest.hpp" +IUTEST(UnitStringTest, Stricmp) +{ + const char negative = -1; + const char negative_sample[] = { 'a', 'a', 'a', negative, '\0' }; + IUTEST_EXPECT_EQ(0, ::iutest::detail::iu_stricmp("AAA", "aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::iu_stricmp("AAAa", "aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::iu_stricmp("AAAB", "aaaa")); + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_stricmp("AAAA", "aaab")); + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_stricmp("AAA", negative_sample)); + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_stricmp("AAA", "aaaA")); +} + +IUTEST(UnitStringTest, OwnStricmp) +{ + const char negative = -1; + const char negative_sample[] = { 'a', 'a', 'a', negative, '\0' }; + IUTEST_EXPECT_EQ(0, ::iutest::detail::wrapper::iu_stricmp("AAA", "aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::wrapper::iu_stricmp("AAAa", "aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::wrapper::iu_stricmp("AAAB", "aaaa")); + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_stricmp("AAAA", "aaab")); + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_stricmp("AAA", negative_sample)); + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_stricmp("AAA", "aaaA")); +} + +IUTEST(UnitStringTest, Wcsicmp) +{ + const wchar_t negative = static_cast(-1); + const wchar_t negative_sample[] = { L'a', L'a', L'a', negative, L'\0' }; + IUTEST_EXPECT_EQ(0, ::iutest::detail::iu_wcsicmp(L"AAA", L"aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::iu_wcsicmp(L"AAAa", L"aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::iu_wcsicmp(L"AAAB", L"aaaa")); + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_wcsicmp(L"AAAa", L"aaaB")); +#if IUTEST_WCHAR_UNSIGNED + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_wcsicmp(L"AAA", negative_sample)); +#else + IUTEST_EXPECT_LT(0, ::iutest::detail::iu_wcsicmp(L"AAA", negative_sample)); +#endif + IUTEST_EXPECT_GT(0, ::iutest::detail::iu_wcsicmp(L"AAA", L"aaaA")); +} + +IUTEST(UnitStringTest, OwnWcsicmp) +{ + const wchar_t negative = static_cast(-1); + const wchar_t negative_sample[] = { L'a', L'a', L'a', negative, L'\0' }; + IUTEST_EXPECT_EQ(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAA", L"aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAAa", L"aaa")); + IUTEST_EXPECT_LT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAAB", L"aaaa")); + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAAa", L"aaaB")); +#if IUTEST_WCHAR_UNSIGNED + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAA", negative_sample)); +#else + IUTEST_EXPECT_LT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAA", negative_sample)); +#endif + IUTEST_EXPECT_GT(0, ::iutest::detail::wrapper::iu_wcsicmp(L"AAA", L"aaaA")); +} + IUTEST(UnitStringTest, StringStrip) { ::std::string str = " a1 a2 "; From f91f52244f320f7edbad5efb0baa1195f5afcc78 Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Mon, 3 Jun 2019 10:08:35 +0900 Subject: [PATCH 2/3] add strict warning options (#223) --- appveyor.yml | 4 +- include/gtest/iutest_switch_for_gtest.hpp | 17 +-- include/gtest/iutest_switch_for_iutest.hpp | 6 +- include/gtest/switch/iutest_switch_assert.hpp | 6 +- include/gtest/switch/iutest_switch_assume.hpp | 4 +- include/gtest/switch/iutest_switch_core.hpp | 3 - include/gtest/switch/iutest_switch_expect.hpp | 4 +- include/gtest/switch/iutest_switch_inform.hpp | 4 +- include/gtest/switch/iutest_switch_port.hpp | 8 +- include/impl/iutest_charcode.ipp | 7 +- include/impl/iutest_core_impl.ipp | 18 +-- include/impl/iutest_default_printer.ipp | 13 ++- include/impl/iutest_default_xml_generator.ipp | 6 +- include/impl/iutest_time.ipp | 7 ++ include/internal/iutest_compiler.hpp | 107 ++++++------------ include/internal/iutest_console.hpp | 16 +-- include/internal/iutest_file.hpp | 5 +- include/internal/iutest_log_stream.hpp | 4 +- include/internal/iutest_option_message.hpp | 10 +- include/internal/iutest_platform.hpp | 95 ++++++++++++++++ include/internal/iutest_pragma.hpp | 32 +++++- include/internal/iutest_result_reporter.hpp | 4 +- include/internal/iutest_stdlib.hpp | 24 +++- include/internal/iutest_stream.hpp | 2 +- include/internal/iutest_string.hpp | 50 +++++--- include/internal/iutest_time.hpp | 10 +- include/internal/iutest_type_traits.hpp | 5 + include/iutest_defs.hpp | 5 +- include/iutest_prod.hpp | 2 +- include/listener/iutest_progress_printer.hpp | 11 +- rocro.yml | 1 + samples/assertion.cpp | 8 +- test/GNUmakefile | 6 +- test/assertion_tests.cpp | 2 +- test/floatingpoint_tests.cpp | 20 ++-- test/logger_tests.hpp | 7 +- test/prod_tests1.cpp | 2 +- test/spi_tests.cpp | 35 +++--- test/spi_tests_decl.cpp | 6 +- test/typed_test_tests.cpp | 4 +- test/unit_string_tests.cpp | 5 + 41 files changed, 378 insertions(+), 207 deletions(-) create mode 100644 include/internal/iutest_platform.hpp diff --git a/appveyor.yml b/appveyor.yml index 9a6173e812..631c507b34 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -135,7 +135,7 @@ for: cmd: | cd test g++ --version; clang++ --version; python --version - @echo. > foo.h && g++ -std=c++1z -dM -E -x c++ foo.h + make showcxxmacros uname make -j4 test_script: @@ -154,7 +154,7 @@ for: cmd: | cd test g++ --version - @echo. > foo.h && g++ -std=c++1z -dM -E -x c++ foo.h + mingw32-make showcxxmacros mingw32-make -j4 %MAKE_OPTIONS% test_script: cmd: mingw32-make test %MAKE_OPTIONS% diff --git a/include/gtest/iutest_switch_for_gtest.hpp b/include/gtest/iutest_switch_for_gtest.hpp index c175bb798a..3a9cec31d8 100644 --- a/include/gtest/iutest_switch_for_gtest.hpp +++ b/include/gtest/iutest_switch_for_gtest.hpp @@ -57,8 +57,6 @@ namespace tr1 #include "iutest_gmock_ver.hpp" #endif #include "iutest_gtest_ver.hpp" -#include "../internal/iutest_pragma.hpp" -#include "../internal/iutest_compatible_defs.hpp" #if GTEST_VER < 0x01040000 # error google test 1.3.0 or less is not supported... @@ -182,10 +180,17 @@ namespace tr1 #define IUTEST_HAS_STREAM_BUFFER 0 +#define IUTEST_HAS_VARIADIC_TEMPLATES 0 +#define IUTEST_HAS_VARIADIC_TEMPLATE_TEMPLATES 0 +#define IUTEST_HAS_INITIALIZER_LIST 0 +#define IUTEST_HAS_CHAR16_T 0 +#define IUTEST_HAS_CHAR32_T 0 + #define IUTEST_HAS_EXCEPTIONS GTEST_HAS_EXCEPTIONS #define IUTEST_HAS_RTTI GTEST_HAS_RTTI #define IUTEST_HAS_REGEX GTEST_USES_POSIX_RE #define IUTEST_HAS_SEH GTEST_HAS_SEH +#define IUTEST_HAS_LONG_DOUBLE 0 #if GTEST_VER < 0x01070000 # define IUTEST_NO_RECORDPROPERTY_OUTSIDE_TESTMETHOD_LIFESPAN @@ -193,12 +198,8 @@ namespace tr1 # define IUTEST_NO_TESTCASE_AD_HOC_TEST_RESULT_ACCESSOR #endif -#ifndef IUTEST_CXX_OVERRIDE -# define IUTEST_CXX_OVERRIDE -#endif -#ifndef IUTEST_CXX_DEFAULT_FUNCTION -# define IUTEST_CXX_DEFAULT_FUNCTION {} -#endif +#include "../internal/iutest_compiler.hpp" +#include "../internal/iutest_compatible_defs.hpp" #include "switch/iutest_switch_port.hpp" #include "switch/iutest_switch_core.hpp" diff --git a/include/gtest/iutest_switch_for_iutest.hpp b/include/gtest/iutest_switch_for_iutest.hpp index f20c785de1..f4e1b0b0d6 100644 --- a/include/gtest/iutest_switch_for_iutest.hpp +++ b/include/gtest/iutest_switch_for_iutest.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -110,11 +110,11 @@ inline void IUTEST_ATTRIBUTE_UNUSED_ InitGoogleTest(int* argc, wchar_t** argv) #if defined(GMOCK_INCLUDE_GMOCK_GMOCK_H_) inline void IUTEST_ATTRIBUTE_UNUSED_ InitGoogleMock(int* argc, char** argv) { - testing::InitGoogleMock(argc, argv); + ::testing::InitGoogleMock(argc, argv); } inline void IUTEST_ATTRIBUTE_UNUSED_ InitGoogleMock(int* argc, wchar_t** argv) { - testing::InitGoogleMock(argc, argv); + ::testing::InitGoogleMock(argc, argv); } #endif diff --git a/include/gtest/switch/iutest_switch_assert.hpp b/include/gtest/switch/iutest_switch_assert.hpp index c211393575..e495d52f53 100644 --- a/include/gtest/switch/iutest_switch_assert.hpp +++ b/include/gtest/switch/iutest_switch_assert.hpp @@ -167,8 +167,10 @@ #define IUTEST_ASSERT_GT ASSERT_GT #define IUTEST_ASSERT_GE ASSERT_GE #define IUTEST_ASSERT_NEAR ASSERT_NEAR -#define IUTEST_ASSERT_NULL(...) IUTEST_THROUGH_ANALYSIS_ASSUME((__VA_ARGS__) == NULL, ASSERT_EQ(NULL, (__VA_ARGS__))) -#define IUTEST_ASSERT_NOTNULL(...) IUTEST_THROUGH_ANALYSIS_ASSUME((__VA_ARGS__) != NULL, ASSERT_TRUE(NULL != (__VA_ARGS__))) +#define IUTEST_ASSERT_NULL(...) IUTEST_THROUGH_ANALYSIS_ASSUME((__VA_ARGS__) == IUTEST_NULLPTR \ + , ASSERT_EQ(IUTEST_NULLPTR, (__VA_ARGS__))) +#define IUTEST_ASSERT_NOTNULL(...) IUTEST_THROUGH_ANALYSIS_ASSUME((__VA_ARGS__) != IUTEST_NULLPTR \ + , ASSERT_TRUE(IUTEST_NULLPTR != (__VA_ARGS__))) #define IUTEST_ASSERT_SAME(v1, v2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSame, v1, v2) #define IUTEST_ASSERT_FLOAT_EQ ASSERT_FLOAT_EQ #define IUTEST_ASSERT_DOUBLE_EQ ASSERT_DOUBLE_EQ diff --git a/include/gtest/switch/iutest_switch_assume.hpp b/include/gtest/switch/iutest_switch_assume.hpp index 839b14021a..285e4b0aec 100644 --- a/include/gtest/switch/iutest_switch_assume.hpp +++ b/include/gtest/switch/iutest_switch_assume.hpp @@ -198,8 +198,8 @@ #define IUTEST_ASSUME_LE ASSUME_LE #define IUTEST_ASSUME_GT ASSUME_GT #define IUTEST_ASSUME_GE ASSUME_GE -#define IUTEST_ASSUME_NULL(...) ASSUME_EQ(NULL, (__VA_ARGS__)) -#define IUTEST_ASSUME_NOTNULL(...) ASSUME_TRUE(NULL != (__VA_ARGS__)) +#define IUTEST_ASSUME_NULL(...) ASSUME_EQ(IUTEST_NULLPTR, (__VA_ARGS__)) +#define IUTEST_ASSUME_NOTNULL(...) ASSUME_TRUE(IUTEST_NULLPTR != (__VA_ARGS__)) #define IUTEST_ASSUME_SAME(v1, v2) ASSUME_PRED_FORMAT2(::testing::internal::CmpHelperSame, v1, v2) #define IUTEST_ASSUME_NEAR ASSUME_NEAR #define IUTEST_ASSUME_FLOAT_EQ ASSUME_FLOAT_EQ diff --git a/include/gtest/switch/iutest_switch_core.hpp b/include/gtest/switch/iutest_switch_core.hpp index c6bf479a2a..3105451435 100644 --- a/include/gtest/switch/iutest_switch_core.hpp +++ b/include/gtest/switch/iutest_switch_core.hpp @@ -69,7 +69,6 @@ #define REGISTER_TYPED_TEST_CASE_P IUTEST_REGISTER_TYPED_TEST_CASE_P #define INSTANTIATE_TYPED_TEST_CASE_P IUTEST_INSTANTIATE_TYPED_TEST_CASE_P -#define GTEST_ATTRIBUTE_UNUSED_ IUTEST_ATTRIBUTE_UNUSED_ #define GTEST_AMBIGUOUS_ELSE_BLOCKER_ IUTEST_AMBIGUOUS_ELSE_BLOCKER_ #define GTEST_TEST_CLASS_NAME_ IUTEST_TEST_CLASS_NAME_ @@ -115,7 +114,6 @@ #endif -#undef IUTEST_ATTRIBUTE_UNUSED_ #undef IUTEST_AMBIGUOUS_ELSE_BLOCKER_ #undef IUTEST_TEST_CLASS_NAME_ @@ -166,7 +164,6 @@ #define IUTEST_REGISTER_TYPED_TEST_CASE_P REGISTER_TYPED_TEST_CASE_P #define IUTEST_INSTANTIATE_TYPED_TEST_CASE_P INSTANTIATE_TYPED_TEST_CASE_P -#define IUTEST_ATTRIBUTE_UNUSED_ GTEST_ATTRIBUTE_UNUSED_ #define IUTEST_AMBIGUOUS_ELSE_BLOCKER_ GTEST_AMBIGUOUS_ELSE_BLOCKER_ #define IUTEST_TEST_CLASS_NAME_ GTEST_TEST_CLASS_NAME_ diff --git a/include/gtest/switch/iutest_switch_expect.hpp b/include/gtest/switch/iutest_switch_expect.hpp index b33a25bf4e..3fc2accea8 100644 --- a/include/gtest/switch/iutest_switch_expect.hpp +++ b/include/gtest/switch/iutest_switch_expect.hpp @@ -168,8 +168,8 @@ #define IUTEST_EXPECT_GT EXPECT_GT #define IUTEST_EXPECT_GE EXPECT_GE #define IUTEST_EXPECT_NEAR EXPECT_NEAR -#define IUTEST_EXPECT_NULL(...) EXPECT_EQ(NULL, (__VA_ARGS__)) -#define IUTEST_EXPECT_NOTNULL(...) EXPECT_TRUE(NULL != (__VA_ARGS__)) +#define IUTEST_EXPECT_NULL(...) EXPECT_EQ(IUTEST_NULLPTR, (__VA_ARGS__)) +#define IUTEST_EXPECT_NOTNULL(...) EXPECT_TRUE(IUTEST_NULLPTR != (__VA_ARGS__)) #define IUTEST_EXPECT_SAME(v1, v2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSame, v1, v2) #define IUTEST_EXPECT_FLOAT_EQ EXPECT_FLOAT_EQ #define IUTEST_EXPECT_DOUBLE_EQ EXPECT_DOUBLE_EQ diff --git a/include/gtest/switch/iutest_switch_inform.hpp b/include/gtest/switch/iutest_switch_inform.hpp index 418b2e26cf..2fdf6e3419 100644 --- a/include/gtest/switch/iutest_switch_inform.hpp +++ b/include/gtest/switch/iutest_switch_inform.hpp @@ -205,8 +205,8 @@ #define IUTEST_INFORM_LE INFORM_LE #define IUTEST_INFORM_GT INFORM_GT #define IUTEST_INFORM_GE INFORM_GE -#define IUTEST_INFORM_NULL(...) INFORM_EQ(NULL, (__VA_ARGS__)) -#define IUTEST_INFORM_NOTNULL(...) INFORM_TRUE(NULL != (__VA_ARGS__)) +#define IUTEST_INFORM_NULL(...) INFORM_EQ(IUTEST_NULLPTR, (__VA_ARGS__)) +#define IUTEST_INFORM_NOTNULL(...) INFORM_TRUE(IUTEST_NULLPTR != (__VA_ARGS__)) #define IUTEST_INFORM_SAME(v1, v2) INFORM_PRED_FORMAT2(::testing::internal::CmpHelperSame, v1, v2) #define IUTEST_INFORM_NEAR INFORM_NEAR #define IUTEST_INFORM_FLOAT_EQ INFORM_FLOAT_EQ diff --git a/include/gtest/switch/iutest_switch_port.hpp b/include/gtest/switch/iutest_switch_port.hpp index 32a9a3dce2..8b167b3856 100644 --- a/include/gtest/switch/iutest_switch_port.hpp +++ b/include/gtest/switch/iutest_switch_port.hpp @@ -58,6 +58,8 @@ # undef IUTEST_OS_NACL #endif +#define GTEST_ATTRIBUTE_UNUSED_ IUTEST_ATTRIBUTE_UNUSED_ + #endif //====================================================================== @@ -112,8 +114,6 @@ //====================================================================== // undef -#if defined(INCG_IRIS_IUTEST_HPP_) - #ifdef IUTEST_OS_CYGWIN # undef IUTEST_OS_CYGWIN #endif @@ -157,7 +157,7 @@ # undef IUTEST_OS_NACL #endif -#endif +#undef IUTEST_ATTRIBUTE_UNUSED_ //====================================================================== // define @@ -211,6 +211,8 @@ # define IUTEST_OS_NACL GTEST_OS_NACL #endif +#define IUTEST_ATTRIBUTE_UNUSED_ GTEST_ATTRIBUTE_UNUSED_ + IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN() //====================================================================== diff --git a/include/impl/iutest_charcode.ipp b/include/impl/iutest_charcode.ipp index 37abe5e27d..d24556f7d7 100644 --- a/include/impl/iutest_charcode.ipp +++ b/include/impl/iutest_charcode.ipp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2017, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -102,7 +102,7 @@ IUTEST_IPP_INLINE char* CodePointToUtf8(UInt32 code_point, char* buf, size_t siz } else { - iu_snprintf(buf, size, "(Invalid UTF16 0x%X)", code_point); + iu_snprintf(buf, size, "(Invalid UTF16 0x%s)", ToHexString(code_point).c_str()); } return buf; } @@ -231,7 +231,10 @@ IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN() IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END() return ret; #else +IUTEST_PRAGMA_WARN_PUSH() +IUTEST_PRAGMA_WARN_CAST_ALIGN() return WideStringToUTF8(reinterpret_cast(str), num); +IUTEST_PRAGMA_WARN_POP() #endif } diff --git a/include/impl/iutest_core_impl.ipp b/include/impl/iutest_core_impl.ipp index d7f47823cf..cadd0f728e 100644 --- a/include/impl/iutest_core_impl.ipp +++ b/include/impl/iutest_core_impl.ipp @@ -57,17 +57,14 @@ IUTEST_IPP_INLINE void UnitTestImpl::SkipTest() IUTEST_IPP_INLINE int UnitTestImpl::Listup() const { - detail::iuConsole::output("%d tests from %d testcase\n", m_total_test_num, m_testcases.size() ); + detail::iuConsole::output("%d tests from %" IUPRzu " testcase\n", m_total_test_num, m_testcases.size() ); for( iuTestCases::const_iterator it = m_testcases.begin(), end=m_testcases.end(); it != end; ++it ) { - detail::iuConsole::output((*it)->name()); - detail::iuConsole::output("\n"); + detail::iuConsole::output("%s\n", (*it)->name()); for( TestCase::iuTestInfos::const_iterator it2 = (*it)->begin(), end2=(*it)->end(); it2 != end2; ++it2 ) { - detail::iuConsole::output(" "); - detail::iuConsole::output((*it2)->name()); - detail::iuConsole::output("\n"); + detail::iuConsole::output(" %s\n", (*it2)->name()); } } return 0; @@ -75,17 +72,14 @@ IUTEST_IPP_INLINE int UnitTestImpl::Listup() const IUTEST_IPP_INLINE int UnitTestImpl::ListupWithWhere() const { - detail::iuConsole::output("%d tests from %d testcase\n", m_total_test_num, m_testcases.size() ); + detail::iuConsole::output("%d tests from %" IUPRzu " testcase\n", m_total_test_num, m_testcases.size() ); for( iuTestCases::const_iterator it = m_testcases.begin(), end=m_testcases.end(); it != end; ++it ) { - detail::iuConsole::output((*it)->testcase_name_with_where().c_str()); - detail::iuConsole::output("\n"); + detail::iuConsole::output("%s\n", (*it)->testcase_name_with_where().c_str()); for( TestCase::iuTestInfos::const_iterator it2 = (*it)->begin(), end2=(*it)->end(); it2 != end2; ++it2 ) { - detail::iuConsole::output(" "); - detail::iuConsole::output((*it2)->test_name_with_where().c_str()); - detail::iuConsole::output("\n"); + detail::iuConsole::output(" %s\n", (*it2)->test_name_with_where().c_str()); } } return 0; diff --git a/include/impl/iutest_default_printer.ipp b/include/impl/iutest_default_printer.ipp index aa8e36681e..fbc84313d8 100644 --- a/include/impl/iutest_default_printer.ipp +++ b/include/impl/iutest_default_printer.ipp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -70,10 +70,11 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestStart(const TestInfo& t IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestPartResult(const TestPartResult& test_part_result) { //if( test_part_result.type() == TestPartResult::kSuccess ) return; + const std::string msg = test_part_result.make_newline_message();; #if defined(_MSC_VER) && !defined(IUTEST_OS_WINDOWS_MOBILE) - OutputDebugStringA(test_part_result.make_newline_message().c_str()); + OutputDebugStringA(msg.c_str()); #endif - detail::iuConsole::output(test_part_result.make_newline_message().c_str()); + detail::iuConsole::output("%s", msg.c_str()); } IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestRecordProperty(const TestProperty& test_property) { @@ -104,7 +105,7 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestEnd(const TestInfo& tes #if defined(IUTEST_NOT_SUPPORT_STOPWATCH) detail::iuConsole::output(" (--ms)" ); #else - detail::iuConsole::output(" (%dms)", test_info.elapsed_time()); + detail::iuConsole::output(" (%sms)", detail::FormatTimeInMillisec(test_info.elapsed_time()).c_str()); #endif } detail::iuConsole::output("\n"); @@ -118,7 +119,7 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestCaseEnd(const TestCase& #if defined(IUTEST_NOT_SUPPORT_STOPWATCH) detail::iuConsole::output("(--ms total)"); #else - detail::iuConsole::output("(%dms total)", test_case.elapsed_time() ); + detail::iuConsole::output("(%sms total)", detail::FormatTimeInMillisec(test_case.elapsed_time()).c_str()); #endif } detail::iuConsole::output("\n\n"); @@ -147,7 +148,7 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestIterationEnd(const Unit #if defined(IUTEST_NOT_SUPPORT_STOPWATCH) detail::iuConsole::output(" (--ms total)"); #else - detail::iuConsole::output(" (%dms total)", test.elapsed_time() ); + detail::iuConsole::output(" (%sms total)", detail::FormatTimeInMillisec(test.elapsed_time()).c_str()); #endif } detail::iuConsole::output("\n"); diff --git a/include/impl/iutest_default_xml_generator.ipp b/include/impl/iutest_default_xml_generator.ipp index ed09add53f..ad6183cdf0 100644 --- a/include/impl/iutest_default_xml_generator.ipp +++ b/include/impl/iutest_default_xml_generator.ipp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -32,11 +32,15 @@ IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnTestIterationStart(const U } if( !m_output_path_format.empty() ) { + // FIXME: -Wformat-nonliteral +IUTEST_PRAGMA_WARN_PUSH() +IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() m_output_path = detail::StringFormat(m_output_path_format.c_str(), iteration); if( m_output_path == m_output_path_format) { m_output_path_format.clear(); } +IUTEST_PRAGMA_WARN_POP() if( m_fp != NULL ) { OnReportTest(m_fp, test); diff --git a/include/impl/iutest_time.ipp b/include/impl/iutest_time.ipp index 981a0e76f1..fee05cbc03 100644 --- a/include/impl/iutest_time.ipp +++ b/include/impl/iutest_time.ipp @@ -60,6 +60,13 @@ IUTEST_IPP_INLINE bool Localtime(time_t sec, struct tm* dst) #endif } +IUTEST_IPP_INLINE ::std::string FormatTimeInMillisec(TimeInMillisec msec) +{ + iu_stringstream ss; + ss << msec; + return ss.str(); +} + IUTEST_IPP_INLINE ::std::string FormatTimeInMillisecAsSecond(TimeInMillisec msec) { iu_stringstream ss; diff --git a/include/internal/iutest_compiler.hpp b/include/internal/iutest_compiler.hpp index 389d63ba44..de939c2547 100644 --- a/include/internal/iutest_compiler.hpp +++ b/include/internal/iutest_compiler.hpp @@ -17,6 +17,7 @@ //====================================================================== // include +#include "iutest_platform.hpp" //====================================================================== // define @@ -26,82 +27,7 @@ # endif #endif -// os -#if defined(__CYGWIN__) -# define IUTEST_OS_CYGWIN 1 -# define IUTEST_PLATFORM "CYGWIN" -#elif defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(WINAPI_FAMILY) -# define IUTEST_OS_WINDOWS 1 -# if !defined(WIN32_LEAN_AND_MEAN) -# define WIN32_LEAN_AND_MEAN -# endif -# include -# if defined(_WIN32_WCE) -# define IUTEST_OS_WINDOWS_MOBILE 1 -# define IUTEST_PLATFORM "Windows CE" -# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) -# define IUTEST_OS_WINDOWS_MINGW 1 -# elif defined(__WINE__) -# define IUTEST_OS_WINDOWS_WINE 1 -# define IUTEST_PLATFORM "WINE" -# elif defined(__CUDACC__) -# define IUTEST_OS_WINDOWS_CUDA 1 -# elif defined(WINAPI_FAMILY) -# if defined(WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) -# define IUTEST_OS_WINDOWS_PHONE 1 -# define IUTEST_PLATFORM "Windows Phone" -# elif defined(WINAPI_FAMILY_APP) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define IUTEST_OS_WINDOWS_RT 1 -# define IUTEST_PLATFORM "Windows RT" -# else -# define IUTEST_OS_WINDOWS_DESKTOP 1 -# endif -# else -# define IUTEST_OS_WINDOWS_DESKTOP 1 -# endif -# if !defined(IUTEST_PLATFORM) -# define IUTEST_PLATFORM "Windows" -# endif -#elif defined(__APPLE__) -# include "TargetConditionals.h" -# if TARGET_OS_IPHONE -# define IUTEST_OS_IOS 1 -# define IUTEST_PLATFORM "iOS" -# else -# define IUTEST_OS_MAC 1 -# define IUTEST_PLATFORM "Mac OS" -# endif -#elif defined(__FreeBSD__) -# define IUTEST_OS_FREEBSD 1 -# define IUTEST_PLATFORM "FreeBSD" -#elif defined(sun) || defined(__sun) -# define IUTEST_OS_SOLARIS 1 -# define IUTEST_PLATFORM "Solaris" -#elif defined(__linux__) -# define IUTEST_OS_LINUX 1 -# if defined(ANDROID) || defined(__ANDROID__) -# define IUTEST_OS_LINUX_ANDROID 1 -# define IUTEST_PLATFORM "Android" -# else -# define IUTEST_PLATFORM "LINUX" -# endif -#elif defined(__native_client__) -# define IUTEST_OS_NACL 1 //!< @deprecated native client to eol -# define IUTEST_PLATFORM "Google Native Client" -#elif defined(__AVR32__) || defined(__avr32__) -# define IUTEST_OS_AVR32 1 -# define IUTEST_PLATFORM "AVR32" -#elif defined(__arm__) -# define IUTEST_OS_ARM 1 -# define IUTEST_PLATFORM "ARM" -#endif - -#if defined(IUTEST_OS_LINUX_ANDROID) -# include -#endif - // __cplusplus numbers - #define IUTEST_CPLUSPLUS_CXX11 201103L #define IUTEST_CPLUSPLUS_CXX14 201402L #define IUTEST_CPLUSPLUS_CXX17 201703L @@ -1313,6 +1239,37 @@ # define IUTEST_ATTRIBUTE_INIT_PRIORITY_(n) #endif +//! format +#if !defined(IUTEST_ATTRIBUTE_FORMAT) +# if defined(__has_attribute) +# if __has_attribute(format) +# define IUTEST_ATTRIBUTE_FORMAT(fmt, fi, vi) __attribute__ ((__format__ (fmt, fi, vi))) +# endif +# elif defined(__GNUC__) && !defined(COMPILER_ICC) +# define IUTEST_ATTRIBUTE_FORMAT(fmt, fi, vi) __attribute__ ((__format__ (fmt, fi, vi))) +# endif +#endif + +//! format printf +#if !defined(IUTEST_ATTRIBUTE_FORMAT_PRINTF) && defined(IUTEST_ATTRIBUTE_FORMAT) +# if defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +# if !defined(__MINGW_PRINTF_FORMAT) +# define __MINGW_PRINTF_FORMAT gnu_printf +# endif +# define IUTEST_ATTRIBUTE_FORMAT_PRINTF(fi, vi) IUTEST_ATTRIBUTE_FORMAT(__MINGW_PRINTF_FORMAT, fi, vi) +# else +# define IUTEST_ATTRIBUTE_FORMAT_PRINTF(fi, vi) IUTEST_ATTRIBUTE_FORMAT(__printf__, fi, vi) +# endif +#endif + +#if !defined(IUTEST_ATTRIBUTE_FORMAT) +# define IUTEST_ATTRIBUTE_FORMAT(fmt, fi, vi) +#endif +#if !defined(IUTEST_ATTRIBUTE_FORMAT_PRINTF) +# define IUTEST_ATTRIBUTE_FORMAT_PRINTF(fi, vi) +#endif + + //! MemorySanitizer #if !defined(IUTEST_HAS_MEMORY_SANITIZER) # if defined(__has_feature) diff --git a/include/internal/iutest_console.hpp b/include/internal/iutest_console.hpp index cf7dcb6a0b..28bb1b314f 100644 --- a/include/internal/iutest_console.hpp +++ b/include/internal/iutest_console.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -48,7 +48,7 @@ class iuLogger { public: virtual ~iuLogger() IUTEST_CXX_DEFAULT_FUNCTION - virtual void output(const char* fmt, ...) + virtual void output(const char* fmt, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(2, 3) { va_list va; va_start(va, fmt); @@ -81,31 +81,31 @@ class iuConsole /** * @brief 標準出力 */ - static inline void output(const char *fmt, ...); + static inline void output(const char *fmt, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(1, 2); /** * @brief 標準出力 */ - static inline void voutput(const char* fmt, va_list va); + static inline void voutput(const char* fmt, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(1, 0); /** * @brief 色指定で標準出力 * @param [in] color = 文字色 */ - static inline void color_output(Color color, const char *fmt, ...); + static inline void color_output(Color color, const char *fmt, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(2, 3); public: /** * @brief 標準出力 * @note no logger */ - static inline void nl_output(const char *fmt, ...); + static inline void nl_output(const char *fmt, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(1, 2); /** * @brief 標準出力 * @note no logger */ - static inline void nl_voutput(const char* fmt, va_list va); + static inline void nl_voutput(const char* fmt, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(1, 0); public: //! Logger のセット @@ -155,7 +155,7 @@ class iuConsole } private: - static inline void color_output_impl(Color color, const char* fmt, va_list va); + static inline void color_output_impl(Color color, const char* fmt, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(2, 0); static inline bool IsShouldUseColor(bool use_color); static inline bool HasColorConsole(); static inline bool IsStringEqual(const char* str1, const char* str2) { return strcmp(str1, str2) == 0; } diff --git a/include/internal/iutest_file.hpp b/include/internal/iutest_file.hpp index 5979ee9021..73ee4ce5d0 100644 --- a/include/internal/iutest_file.hpp +++ b/include/internal/iutest_file.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -247,7 +247,8 @@ IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END() { return GetSizeBySeekSet(fp); } - return st.st_size; + // FIXME: https://github.com/srz-zumix/iutest/issues/227 + return static_cast(st.st_size); #else IUTEST_UNUSED_VAR(fp); return 0; diff --git a/include/internal/iutest_log_stream.hpp b/include/internal/iutest_log_stream.hpp index 97ca6c7885..ba9659b14d 100644 --- a/include/internal/iutest_log_stream.hpp +++ b/include/internal/iutest_log_stream.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2014-2018, Takazumi Shirayanagi\n + * Copyright (C) 2014-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -45,7 +45,7 @@ class LogStream : public IOutStream const char* str = static_cast(buf); for( size_t i=0; i < cnt; ++i ) { - iuConsole::output(str); + iuConsole::output("%s", str); } return true; } diff --git a/include/internal/iutest_option_message.hpp b/include/internal/iutest_option_message.hpp index a493a5adf4..ee5c1b272a 100644 --- a/include/internal/iutest_option_message.hpp +++ b/include/internal/iutest_option_message.hpp @@ -48,7 +48,7 @@ class iuOptionMessage inline void iuOptionMessage::ShowHelp() { - const char* readme = + detail::iuConsole::color_output(detail::iuConsole::cyan, "--------------------------------------------------\n" "Name\n" " iutest - iris unit test framework\n" @@ -91,8 +91,8 @@ inline void iuOptionMessage::ShowHelp() " Copyright (c) 2011-2018, Takazumi-Shirayanagi\n" "\n" " This software is released under the new BSD License, see LICENSE\n" - "\n"; - detail::iuConsole::color_output(detail::iuConsole::cyan, readme); + "\n" + ); } inline void iuOptionMessage::ShowVersion() @@ -256,6 +256,10 @@ inline void iuOptionMessage::ShowSpec() IIUT_SHOW_MACRO(__POSIX_VISIBLE); #endif +#ifdef __USE_MINGW_ANSI_STDIO + IIUT_SHOW_MACRO(__USE_MINGW_ANSI_STDIO); +#endif + #undef IIUT_SHOW_MACRO } diff --git a/include/internal/iutest_platform.hpp b/include/internal/iutest_platform.hpp new file mode 100644 index 0000000000..6cfb3c1e31 --- /dev/null +++ b/include/internal/iutest_platform.hpp @@ -0,0 +1,95 @@ +//====================================================================== +//----------------------------------------------------------------------- +/** + * @file iutest_platform.hpp + * @brief iris unit test platform detection + * + * @author t.shirayanagi + * @par copyright + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n + * This software is released under the new BSD License, + * see LICENSE +*/ +//----------------------------------------------------------------------- +//====================================================================== +#ifndef INCG_IRIS_IUTEST_PLATFORM_HPP_38809F61_271D_4B85_A51E_211004A99F5A_ +#define INCG_IRIS_IUTEST_PLATFORM_HPP_38809F61_271D_4B85_A51E_211004A99F5A_ + +//====================================================================== +// define + +// os +#if defined(__CYGWIN__) +# define IUTEST_OS_CYGWIN 1 +# define IUTEST_PLATFORM "CYGWIN" +#elif defined(_WIN32) || defined(WIN32) || defined(__WIN32__) || defined(WINAPI_FAMILY) +# define IUTEST_OS_WINDOWS 1 +# if !defined(WIN32_LEAN_AND_MEAN) +# define WIN32_LEAN_AND_MEAN +# endif +# include +# if defined(_WIN32_WCE) +# define IUTEST_OS_WINDOWS_MOBILE 1 +# define IUTEST_PLATFORM "Windows CE" +# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +# define IUTEST_OS_WINDOWS_MINGW 1 +# elif defined(__WINE__) +# define IUTEST_OS_WINDOWS_WINE 1 +# define IUTEST_PLATFORM "WINE" +# elif defined(__CUDACC__) +# define IUTEST_OS_WINDOWS_CUDA 1 +# elif defined(WINAPI_FAMILY) +# if defined(WINAPI_FAMILY_PHONE_APP) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +# define IUTEST_OS_WINDOWS_PHONE 1 +# define IUTEST_PLATFORM "Windows Phone" +# elif defined(WINAPI_FAMILY_APP) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define IUTEST_OS_WINDOWS_RT 1 +# define IUTEST_PLATFORM "Windows RT" +# else +# define IUTEST_OS_WINDOWS_DESKTOP 1 +# endif +# else +# define IUTEST_OS_WINDOWS_DESKTOP 1 +# endif +# if !defined(IUTEST_PLATFORM) +# define IUTEST_PLATFORM "Windows" +# endif +#elif defined(__APPLE__) +# include "TargetConditionals.h" +# if TARGET_OS_IPHONE +# define IUTEST_OS_IOS 1 +# define IUTEST_PLATFORM "iOS" +# else +# define IUTEST_OS_MAC 1 +# define IUTEST_PLATFORM "Mac OS" +# endif +#elif defined(__FreeBSD__) +# define IUTEST_OS_FREEBSD 1 +# define IUTEST_PLATFORM "FreeBSD" +#elif defined(sun) || defined(__sun) +# define IUTEST_OS_SOLARIS 1 +# define IUTEST_PLATFORM "Solaris" +#elif defined(__linux__) +# define IUTEST_OS_LINUX 1 +# if defined(ANDROID) || defined(__ANDROID__) +# define IUTEST_OS_LINUX_ANDROID 1 +# define IUTEST_PLATFORM "Android" +# else +# define IUTEST_PLATFORM "LINUX" +# endif +#elif defined(__native_client__) +# define IUTEST_OS_NACL 1 //!< @deprecated native client to eol +# define IUTEST_PLATFORM "Google Native Client" +#elif defined(__AVR32__) || defined(__avr32__) +# define IUTEST_OS_AVR32 1 +# define IUTEST_PLATFORM "AVR32" +#elif defined(__arm__) +# define IUTEST_OS_ARM 1 +# define IUTEST_PLATFORM "ARM" +#endif + +#if defined(IUTEST_OS_LINUX_ANDROID) +# include +#endif + +#endif // INCG_IRIS_IUTEST_PLATFORM_HPP_38809F61_271D_4B85_A51E_211004A99F5A_ diff --git a/include/internal/iutest_pragma.hpp b/include/internal/iutest_pragma.hpp index 4c02f42c24..37ca6e261d 100644 --- a/include/internal/iutest_pragma.hpp +++ b/include/internal/iutest_pragma.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2018, Takazumi Shirayanagi\n + * Copyright (C) 2012-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -195,6 +195,36 @@ # define IUTEST_PRAGMA_WARN_DISABLE_EMPTY_BODY() #endif +#if defined(_MSC_VER) +# define IUTEST_PRAGMA_WARN_FLOAT_EQUAL() // IUTEST_PRAGMA_MSC_WARN_DISABLE(4390) +#elif defined(__clang__) +# define IUTEST_PRAGMA_WARN_FLOAT_EQUAL() IUTEST_PRAGMA_CLANG_WARN_DISABLE("-Wfloat-equal") +#elif defined(__GNUC__) +# define IUTEST_PRAGMA_WARN_FLOAT_EQUAL() IUTEST_PRAGMA_GCC_WARN_DISABLE("-Wfloat-equal") +#else +# define IUTEST_PRAGMA_WARN_FLOAT_EQUAL() +#endif + +#if defined(_MSC_VER) +# define IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() // IUTEST_PRAGMA_MSC_WARN_DISABLE(4390) +#elif defined(__clang__) +# define IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() IUTEST_PRAGMA_CLANG_WARN_DISABLE("-Wformat-nonliteral") +#elif defined(__GNUC__) +# define IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() IUTEST_PRAGMA_GCC_WARN_DISABLE("-Wformat-nonliteral") +#else +# define IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL() +#endif + +#if defined(_MSC_VER) +# define IUTEST_PRAGMA_WARN_CAST_ALIGN() // IUTEST_PRAGMA_MSC_WARN_DISABLE(4390) +#elif defined(__clang__) +# define IUTEST_PRAGMA_WARN_CAST_ALIGN() IUTEST_PRAGMA_CLANG_WARN_DISABLE("-Wcast-align") +#elif defined(__GNUC__) +# define IUTEST_PRAGMA_WARN_CAST_ALIGN() IUTEST_PRAGMA_GCC_WARN_DISABLE("-Wcast-align") +#else +# define IUTEST_PRAGMA_WARN_CAST_ALIGN() +#endif + #if defined(_MSC_VER) # define IUTEST_PRAGMA_WARN_DISABLE_DANGLING_ELSE() #elif defined(__clang__) diff --git a/include/internal/iutest_result_reporter.hpp b/include/internal/iutest_result_reporter.hpp index 47cb973bd6..8220ee4c0f 100644 --- a/include/internal/iutest_result_reporter.hpp +++ b/include/internal/iutest_result_reporter.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -45,7 +45,7 @@ class DefaultGlobalTestPartResultReporter : public TestPartResultReporterInterfa } else { - iuConsole::output(test_part_result.make_newline_message().c_str()); + iuConsole::output("%s", test_part_result.make_newline_message().c_str()); } TestEnv::event_listeners().OnTestPartResult(test_part_result); } diff --git a/include/internal/iutest_stdlib.hpp b/include/internal/iutest_stdlib.hpp index e4dfa5bbcf..c61bd05947 100644 --- a/include/internal/iutest_stdlib.hpp +++ b/include/internal/iutest_stdlib.hpp @@ -17,6 +17,9 @@ //====================================================================== // include +#define __STDC_FORMAT_MACROS 1 +#include + #if defined(IUTEST_USE_GTEST) && defined(__STRICT_ANSI__) # undef __STRICT_ANSI__ # include @@ -679,6 +682,25 @@ using tuples::get; # define IUTEST_HAS_INVALID_PARAMETER_HANDLER 0 #endif +//! size_t format macros +#if !defined(IUPRzu) +# if defined(_MSC_VER) && (_MSC_VER < 1900) +# define IUPRzu "Iu" +# elif defined(IUTEST_OS_WINDOWS_MINGW) +# if !defined(__STRICT_ANSI__) +# if defined(__MINGW64__) +# define IUPRzu PRIu64 +# elif defined(__MINGW32__) +# define IUPRzu PRIu32 +# endif +# endif +# endif +#endif + +#if !defined(IUPRzu) +# define IUPRzu "zu" +#endif + namespace iutest { namespace detail { @@ -751,7 +773,7 @@ struct type_least_t<8> /** * @brief type_fit_t */ -template +template struct type_fit_t {}; /** type_fit_t<1> */ diff --git a/include/internal/iutest_stream.hpp b/include/internal/iutest_stream.hpp index 5b096cd300..0ac089624a 100644 --- a/include/internal/iutest_stream.hpp +++ b/include/internal/iutest_stream.hpp @@ -32,7 +32,7 @@ class IOutStream //! 書き込み virtual bool Write(const void* buf, size_t size, size_t cnt) = 0; public: - virtual int Printf(const char* fmt, ...) + virtual int Printf(const char* fmt, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(2, 3) { IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN() diff --git a/include/internal/iutest_string.hpp b/include/internal/iutest_string.hpp index 621715dce5..76a5c67a82 100644 --- a/include/internal/iutest_string.hpp +++ b/include/internal/iutest_string.hpp @@ -43,7 +43,7 @@ namespace iutest { namespace detail { -::std::string StringFormat(const char* format, ...); +::std::string StringFormat(const char* format, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(1, 2); namespace wrapper { @@ -136,6 +136,8 @@ inline int iu_wcsicmp(const wchar_t * str1, const wchar_t * str2) namespace wrapper { +int iu_vsnprintf(char* dst, size_t size, const char* format, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(3, 0); + inline int iu_vsnprintf(char* dst, size_t size, const char* format, va_list va) { char buffer[4096]; @@ -152,6 +154,9 @@ inline int iu_vsnprintf(char* dst, size_t size, const char* format, va_list va) } // end of namespace wrapper +int iu_vsnprintf(char* dst, size_t size, const char* format, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(3, 0); +int iu_snprintf(char* dst, size_t size, const char* format, ...) IUTEST_ATTRIBUTE_FORMAT_PRINTF(3, 4); + /** * @internal * @brief vsnprintf @@ -323,11 +328,6 @@ inline void StringSplit(const ::std::string& str, char delimiter, ::std::vector< dst.swap(parsed); } -inline IUTEST_CXX_CONSTEXPR char ToOct(unsigned int n) -{ - return '0' + (n & 0x7); -} - template inline ::std::string ToOctString(T value) { @@ -335,10 +335,12 @@ inline ::std::string ToOctString(T value) const size_t kN = (kB + 2) / 3; const size_t kD = kB - (kN - 1) * 3; const size_t kMask = (1u << kD) - 1u; - char buf[kN + 1] = { ToOct(static_cast((value >> ((kN - 1) * 3)) & kMask)), 0 }; + const T head = (value >> ((kN - 1) * 3)) & kMask; + char buf[kN + 1] = { static_cast('0' + (head & 0x7)), 0 }; for(size_t i = 1; i < kN; ++i) { - buf[i] = ToOct(static_cast((value >> ((kN - i - 1) * 3)))); + const T n = (value >> ((kN - i - 1) * 3)); + buf[i] = static_cast('0' + (n & 0x7)); } buf[kN] = '\0'; return buf; @@ -346,7 +348,7 @@ inline ::std::string ToOctString(T value) inline IUTEST_CXX_CONSTEXPR char ToHex(unsigned int n) { - return (n&0xF) >= 0xA ? 'A'+((n&0xF)-0xA) : '0'+(n&0xF); + return static_cast((n&0xF) >= 0xA ? 'A'+((n&0xF)-0xA) : '0'+(n&0xF)); } template @@ -365,11 +367,27 @@ inline ::std::string ToHexString(T value) inline ::std::string FormatIntWidth2(int value) { char buf[3] = "00"; - buf[0] = (value/10)%10 + '0'; - buf[1] = (value )%10 + '0'; + buf[0] = static_cast((value/10)%10 + '0'); + buf[1] = static_cast((value )%10 + '0'); return buf; } +#define IIUT_DECL_TOSTRING(fmt_, type_) \ + inline ::std::string iu_to_string(type_ value) {\ + char buf[128]; \ + iu_snprintf(buf, sizeof(buf), fmt_, value); \ + return buf; \ + } + +IIUT_DECL_TOSTRING("%d", int) +IIUT_DECL_TOSTRING("%u", unsigned int) +IIUT_DECL_TOSTRING("%ld", long) +IIUT_DECL_TOSTRING("%lu", unsigned long) +IIUT_DECL_TOSTRING("%lld", long long) +IIUT_DECL_TOSTRING("%llu", unsigned long long) + +#undef IIUT_DECL_TOSTRING + inline ::std::string FormatSizeByte(UInt64 value) { const char* suffixes[] = { @@ -388,16 +406,16 @@ inline ::std::string FormatSizeByte(UInt64 value) view_value /= 1024; } - const UInt64 n = static_cast(::std::floor(view_value)); - const UInt64 f = static_cast(view_value * 10.0 - n * 10.0); + const UInt32 n = static_cast(::std::floor(view_value)); + const UInt32 f = static_cast(view_value * 10.0 - n * 10.0); const char* suffix = suffixes[index]; - if(view_value - n == 0) + if(view_value - n <= 0.0) { - return StringFormat("%llu%s", n, suffix); + return iu_to_string(n) + suffix; } else { - return StringFormat("%llu.%llu%s", n, f, suffix); + return iu_to_string(n) + "." + iu_to_string(f) + suffix; } } diff --git a/include/internal/iutest_time.hpp b/include/internal/iutest_time.hpp index 2694671533..48addf0db4 100644 --- a/include/internal/iutest_time.hpp +++ b/include/internal/iutest_time.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -52,6 +52,14 @@ namespace detail */ bool Localtime(time_t sec, struct tm* dst); +/** + * @internal + * @brief TimeInMillisec to string + * @param [in] msec = ミリ秒 + * @return ミリ秒数の文字列 +*/ +::std::string FormatTimeInMillisec(TimeInMillisec msec); + /** * @internal * @brief TimeInMillisec to string diff --git a/include/internal/iutest_type_traits.hpp b/include/internal/iutest_type_traits.hpp index 0d837d9bf8..43d7db2ab6 100644 --- a/include/internal/iutest_type_traits.hpp +++ b/include/internal/iutest_type_traits.hpp @@ -844,6 +844,9 @@ no_t& operator == (const T1& lhs, const T2& rhs); namespace has_equal_to_operator_impl { +IUTEST_PRAGMA_WARN_PUSH() +IUTEST_PRAGMA_WARN_FLOAT_EQUAL() + using namespace has_equal_to_operator_helper; // NOLINT /** @private */ template @@ -852,6 +855,8 @@ struct has_equal_to_operator typedef bool_constant< (sizeof(*(T*)0 == *(T*)0) != sizeof(has_equal_to_operator_helper::no_t) ) > type; // NOLINT }; +IUTEST_PRAGMA_MSC_WARN_POP() + } // end of namespace has_equal_to_operator_impl /** diff --git a/include/iutest_defs.hpp b/include/iutest_defs.hpp index aa4b2b53c0..838c3c28f9 100644 --- a/include/iutest_defs.hpp +++ b/include/iutest_defs.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2018, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -228,10 +228,13 @@ class floating_point { return false; } +IUTEST_PRAGMA_CLANG_WARN_PUSH() +IUTEST_PRAGMA_WARN_FLOAT_EQUAL() if( m_v.fv == rhs.m_v.fv ) { return true; } +IUTEST_PRAGMA_CLANG_WARN_POP() _Myt abs = Abs(rhs); if( abs.m_v.fv <= max_abs_error ) { diff --git a/include/iutest_prod.hpp b/include/iutest_prod.hpp index 1f8c06a659..a01b9612f3 100644 --- a/include/iutest_prod.hpp +++ b/include/iutest_prod.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2018, Takazumi Shirayanagi\n + * Copyright (C) 2012-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ diff --git a/include/listener/iutest_progress_printer.hpp b/include/listener/iutest_progress_printer.hpp index 686bee7d55..bdcf9da22b 100644 --- a/include/listener/iutest_progress_printer.hpp +++ b/include/listener/iutest_progress_printer.hpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n + * Copyright (C) 2011-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -77,11 +77,14 @@ inline void ProgressPrintListener::OnTestEnd(const TestInfo& test_info) ++m_ran_num; const int star_count = 51; const int n = (m_ran_num * star_count) / m_should_run_num; - char progress[star_count + 2] ={ 0 }; - for( int i=0; i < n; ++i ) progress[i] = '*'; + char progress[star_count + 2] = { 0 }; + for( int i=0; i < n; ++i ) + { + progress[i] = '*'; + } progress[n] = m_ran_num == m_should_run_num ? '\n' : '\r'; progress[n + 1] = '\0'; - detail::iuConsole::output(progress); + detail::iuConsole::output("%s", progress); } } // end of namespace iutest diff --git a/rocro.yml b/rocro.yml index 25ee3cce3f..3065c4b58e 100644 --- a/rocro.yml +++ b/rocro.yml @@ -46,6 +46,7 @@ inspecode: - "knownConditionTrueFalse:*/iutest_internal_defs.hpp" - "noExplicitConstructor:*/iutest_defs.hpp" - "noExplicitConstructor:*/iutest_any.hpp" + - "unusedPrivateFunction:*/iutest_console.hpp" - "unusedPrivateFunction:*/iutest_expression_assertion.hpp" - "unusedStructMember:*/iutest_constant.hpp" - "unusedStructMember:*/iutest_defs.hpp" diff --git a/samples/assertion.cpp b/samples/assertion.cpp index d0123290d6..7251b8f369 100644 --- a/samples/assertion.cpp +++ b/samples/assertion.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2014-2016, Takazumi Shirayanagi\n + * Copyright (C) 2014-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -54,11 +54,13 @@ IUTEST(AssertionTest, Base) { IUTEST_EXPECT_TRUE(true); IUTEST_EXPECT_TRUE(1); - IUTEST_EXPECT_TRUE(100==100); + IUTEST_EXPECT_TRUE(100 == 100); + IUTEST_EXPECT_TRUE(f()==42); IUTEST_EXPECT_FALSE(false); IUTEST_EXPECT_FALSE(0); - IUTEST_EXPECT_FALSE(100!=100); + IUTEST_EXPECT_FALSE(100 != 100); + IUTEST_EXPECT_FALSE(f()!=42); } // EQ { diff --git a/test/GNUmakefile b/test/GNUmakefile index 7b6ed1d48d..6337973603 100644 --- a/test/GNUmakefile +++ b/test/GNUmakefile @@ -34,7 +34,11 @@ include CommonMakefile.in # Optimize #OPTIMIZE=-O2 -CXXFLAGS += -g -Wall -Wextra $(OPTIMIZE) +STRICT_CXXFLAGS:= -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith +# Necessary for peep class operator +# STRICT_CXXFLAGS+= -Wconversion + +CXXFLAGS += -g -Wall -Wextra $(STRICT_CXXFLAGS) $(OPTIMIZE) ifdef _DEBUG CXXFLAGS += -ggdb diff --git a/test/assertion_tests.cpp b/test/assertion_tests.cpp index f6b4d7c102..4419653bb4 100644 --- a/test/assertion_tests.cpp +++ b/test/assertion_tests.cpp @@ -168,8 +168,8 @@ IUTEST(AssertionTest, GT) double d0=0.0, d1=1.0; IUTEST_EXPECT_GT(f1, f0); IUTEST_ASSERT_GT(x1, x0); - IUTEST_EXPECT_GT(d1, d0); IUTEST_INFORM_GT(0x1, 0.0f); + IUTEST_EXPECT_GT(d1, d0); } IUTEST(AssertionTest, GE) diff --git a/test/floatingpoint_tests.cpp b/test/floatingpoint_tests.cpp index 27da8e06e9..5df21df131 100644 --- a/test/floatingpoint_tests.cpp +++ b/test/floatingpoint_tests.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2017, Takazumi Shirayanagi\n + * Copyright (C) 2012-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -35,9 +35,9 @@ class FloatingpointTest : public ::iutest::Test static T ZERO; }; template -T FloatingpointTest::ONE = (T)1; +T FloatingpointTest::ONE = static_cast(1); template -T FloatingpointTest::ZERO = (T)0; +T FloatingpointTest::ZERO = static_cast(0); typedef ::iutest::Types FloatingpointTestTypes; IUTEST_TYPED_TEST_CASE(FloatingpointTest, FloatingpointTestTypes); @@ -48,15 +48,15 @@ IUTEST_TYPED_TEST(FloatingpointTest, PINF) TypeParam a=TestFixture::ONE; TypeParam b=TestFixture::ZERO; - IUTEST_EXPECT_EQ(FloatType(a/b), TestFixture::ftype::PINF()); + IUTEST_EXPECT_EQ(FloatType(a/b), FloatType::PINF()); } IUTEST_TYPED_TEST(FloatingpointTest, NINF) { typedef typename TestFixture::ftype FloatType; - TypeParam b=TestFixture::ZERO; - - IUTEST_EXPECT_EQ(FloatType(log(b)), TestFixture::ftype::NINF()); + const TypeParam b=TestFixture::ZERO; + const TypeParam lb=static_cast(log(b)); + IUTEST_EXPECT_EQ(FloatType(lb), FloatType::NINF()); } // MinGW-w64 sqrt bug @@ -65,9 +65,9 @@ IUTEST_TYPED_TEST(FloatingpointTest, NINF) IUTEST_TYPED_TEST(FloatingpointTest, NQNAN) { typedef typename TestFixture::ftype FloatType; - TypeParam a=TestFixture::ONE; - - IUTEST_EXPECT_EQ(FloatType(sqrt(-a)), TestFixture::ftype::NQNAN()); + const TypeParam a=TestFixture::ONE; + const TypeParam sq=static_cast(sqrt(-a)); + IUTEST_EXPECT_EQ(FloatType(sq), FloatType::NQNAN()); } #endif diff --git a/test/logger_tests.hpp b/test/logger_tests.hpp index 25a7a7ada8..3d8b69991f 100644 --- a/test/logger_tests.hpp +++ b/test/logger_tests.hpp @@ -25,22 +25,21 @@ class TestLogger : public ::iutest::detail::iuLogger { ::std::string m_log; public: - virtual void voutput(const char* fmt, va_list va) + virtual void voutput(const char* fmt, va_list va) IUTEST_CXX_OVERRIDE { IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN() + char buf[4096] = { 0 }; #ifdef va_copy va_list va2; va_copy(va2, va); - char buf[4096]; vsprintf(buf, fmt, va2); va_end(va2); m_log += buf; ::iutest::detail::iuConsole::nl_voutput(fmt, va); #else - char buf[4096]; vsprintf(buf, fmt, va); m_log += buf; - ::iutest::detail::iuConsole::nl_output(buf); + ::iutest::detail::iuConsole::nl_output("%s", buf); #endif IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END() } diff --git a/test/prod_tests1.cpp b/test/prod_tests1.cpp index cbedddd140..9d1dbd0718 100644 --- a/test/prod_tests1.cpp +++ b/test/prod_tests1.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2018, Takazumi Shirayanagi\n + * Copyright (C) 2012-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ diff --git a/test/spi_tests.cpp b/test/spi_tests.cpp index fad47d2745..d6851c8cad 100644 --- a/test/spi_tests.cpp +++ b/test/spi_tests.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2012-2016, Takazumi Shirayanagi\n + * Copyright (C) 2012-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -26,27 +26,28 @@ class SPITest : public ::iutest::Test public: #if IUTEST_HAS_SPI_LAMBDA_SUPPORT const char* null_str; - int a, b; + const int a, b; + const float fa; + const double da; int aa[5]; int ab[6]; char ac[5]; - ::std::string sa; - ::std::string sb; - ::std::string sa2; + const ::std::string sa; + const ::std::string sb; + const ::std::string sa2; SPITest() : null_str(NULL) , a(0), b(0) + , fa(0.0f) + , da(0.0) , sa("a") , sb("b") { - int aa_[5] = { 0, 1, 2, 3, 4 }; - int ab_[6] = { 0, 1, 2, 3, 4, 5 }; - char ac_[5] = { 0, 0, 2, 3, 5 }; + const char ac_[5] = { 0, 0, 2, 3, 5 }; for( int i=0; i < 5; ++i ) { - aa[i] = aa_[i]; - ab[i] = ab_[i]; + aa[i] = ab[i] = i; ac[i] = ac_[i]; } ab[5] = 5; @@ -60,12 +61,14 @@ class SPITest : public ::iutest::Test #if !IUTEST_HAS_SPI_LAMBDA_SUPPORT const char* null_str = NULL; -int a=0, b=0; -int aa[] = { 0, 1, 2, 3, 4 }; -int ab[] = { 0, 1, 2, 3, 4, 5 }; -char ac[] = { 0, 0, 2, 3, 5 }; -::std::string sa="a"; -::std::string sb="b"; +const int a=0, b=0; +const int aa[] = { 0, 1, 2, 3, 4 }; +const int ab[] = { 0, 1, 2, 3, 4, 5 }; +const char ac[] = { 0, 0, 2, 3, 5 }; +const ::std::string sa="a"; +const ::std::string sb="b"; +const float fa = static_cast(a); +const double da = static_cast(a); #endif void SPITest::FatalFailure_Sub(int& count) diff --git a/test/spi_tests_decl.cpp b/test/spi_tests_decl.cpp index 3defe866d7..88e95ab8de 100644 --- a/test/spi_tests_decl.cpp +++ b/test/spi_tests_decl.cpp @@ -6,7 +6,7 @@ * * @author t.shirayanagi * @par copyright - * Copyright (C) 2015-2016, Takazumi Shirayanagi\n + * Copyright (C) 2015-2019, Takazumi Shirayanagi\n * This software is released under the new BSD License, * see LICENSE */ @@ -35,8 +35,8 @@ #if !defined(IUTEST_USE_GTEST) FAILURE_MACRO( FLAVOR(_FLOAT_EQ)(0, 1), "(0x" ); FAILURE_MACRO( FLAVOR(_DOUBLE_EQ)(0, 1), "(0x" ); - FAILURE_MACRO( FLAVOR(_FLOAT_EQ)(0.0f/a, 0.0f/a), "(0x" ); - FAILURE_MACRO( FLAVOR(_DOUBLE_EQ)(0.0/a, 0.0f/a), "(0x" ); + FAILURE_MACRO( FLAVOR(_FLOAT_EQ)(0.0f/fa, 0.0f/fa), "(0x" ); + FAILURE_MACRO( FLAVOR(_DOUBLE_EQ)(0.0/da, 0.0f/da), "(0x" ); FAILURE_MACRO( FLAVOR(_PRED_FORMAT2)(::iutest::FloatLE , 2, 0), "(0x" ); FAILURE_MACRO( FLAVOR(_PRED_FORMAT2)(::iutest::DoubleLE, 2, 0), "(0x" ); #else diff --git a/test/typed_test_tests.cpp b/test/typed_test_tests.cpp index 8a16b8b07f..6e9a94741a 100644 --- a/test/typed_test_tests.cpp +++ b/test/typed_test_tests.cpp @@ -38,7 +38,7 @@ IUTEST_TYPED_TEST_CASE(TypedTest, TypedTestTypes); IUTEST_TYPED_TEST(TypedTest, Mul2) { TypeParam x = 1; - IUTEST_ASSERT_EQ(x+x, 2*x); + IUTEST_ASSERT_LT(x, 2*x); } IUTEST_TYPED_TEST(TypedTest, StaticMul2) @@ -54,7 +54,7 @@ IUTEST_TYPED_TEST_CASE(TypedTest2, float); IUTEST_TYPED_TEST(TypedTest2, Mul2) { TypeParam x = 1; - IUTEST_ASSERT_EQ(x+x, 2*x); + IUTEST_ASSERT_LT(x, 2*x); } IUTEST_TYPED_TEST(TypedTest2, StaticMul2) diff --git a/test/unit_string_tests.cpp b/test/unit_string_tests.cpp index 90012b9d32..8621a4cb94 100644 --- a/test/unit_string_tests.cpp +++ b/test/unit_string_tests.cpp @@ -195,3 +195,8 @@ IUTEST(UnitStringTest, FormatSizeTByte) IUTEST_EXPECT_STREQ("1TB", ::iutest::detail::FormatSizeByte(1024ull * 1024 * 1024 * 1024)); IUTEST_EXPECT_STREQ("1024TB", ::iutest::detail::FormatSizeByte(1024ull * 1024 * 1024 * 1024 * 1024)); } + +IUTEST(UnitStringTest, Utf8AsciiCode) +{ + IUTEST_EXPECT_STREQ("A", ::iutest::detail::WideStringToUTF8(L"A", -1)); +} From 1d3b3474d85fece7ded80ad825cb6769d985239b Mon Sep 17 00:00:00 2001 From: srz_zumix Date: Mon, 3 Jun 2019 10:10:44 +0900 Subject: [PATCH 3/3] update version --- docs/Doxyfile | 2 +- include/iutest_ver.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Doxyfile b/docs/Doxyfile index 2aea62daaa..574309db00 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = iutest # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.16.99.18 +PROJECT_NUMBER = 1.16.99.19 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/include/iutest_ver.hpp b/include/iutest_ver.hpp index 784ac183fa..05a010a949 100644 --- a/include/iutest_ver.hpp +++ b/include/iutest_ver.hpp @@ -17,11 +17,11 @@ //====================================================================== // define -#define IUTEST_VER 0x01169918u //!< iutest version 1.16.99.18 +#define IUTEST_VER 0x01169919u //!< iutest version 1.16.99.19 #define IUTEST_MAJORVER 0x01u //!< Major Version #define IUTEST_MINORVER 0x16u //!< Minor Version #define IUTEST_MICROVER 0x99u //!< Micro Version -#define IUTEST_REVISION 0x18u //!< Revision +#define IUTEST_REVISION 0x19u //!< Revision #define IUTEST_BUILD IUTEST_MICROVER //!< @deprecated