diff --git a/CHANGES b/CHANGES index 7f44e78718..87f1ec3f72 100644 --- a/CHANGES +++ b/CHANGES @@ -8,10 +8,11 @@ Changes for 1.11.0: * Matcher に StrEq,StrNe,StrCaseEq,StrCaseNe,HasSubstr を追加 * Matcher に FloatEq,DoubleEq,NanSensitiveFloatEq,NanSensitiveDoubleEq を追加 * コンテナMatcher に Each,ElementsAre,ElementsAreArray を追加 -* コンテナMatcher の条件に Matcher を使えるように修正 +* メンバーMatcher に Pair を追加 ** 修正 * IUTEST_*_FLOAT_EQ,DOUBLE_EQ で NAN の比較が真を返す不具合を修正 +* コンテナMatcher の条件に Matcher を使えるように修正 * バグ修正 -------------------------------------------------- diff --git a/doc/Doxyfile b/doc/Doxyfile index 3ec9c6d1a5..0261ce08e1 100644 --- a/doc/Doxyfile +++ b/doc/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.10.99.11 +PROJECT_NUMBER = 1.10.99.12 # 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_matcher.hpp b/include/iutest_matcher.hpp index bf8f512cc3..ca5f734d3a 100644 --- a/include/iutest_matcher.hpp +++ b/include/iutest_matcher.hpp @@ -607,13 +607,13 @@ template class ElementsAreArrayMatcher : public IMatcher { public: - ElementsAreArrayMatcher(const T& expected) : m_expected(expected) {} + ElementsAreArrayMatcher(const T& expected, int count=-1) : m_expected(expected), m_count(count){} public: template AssertionResult operator ()(const U& actual) const { - if( Check(actual, m_expected) ) return AssertionSuccess(); + if( Check(actual, m_expected, m_count) ) return AssertionSuccess(); return AssertionFailure() << WitchIs(); } @@ -626,37 +626,38 @@ class ElementsAreArrayMatcher : public IMatcher } private: template - static bool Check(const Container& actual, const TT& expected) + static bool Check(const Container& actual, const TT& expected, int count) { - return Check(actual.begin(), actual.end(), expected); + return Check(actual.begin(), actual.end(), expected, count); } #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING) template - static bool Check(const U(&actual)[SIZE], const TT& expected) + static bool Check(const U(&actual)[SIZE], const TT& expected, int count) { - return Check(actual, actual + SIZE, expected); + return Check(actual, actual + SIZE, expected, count); } #endif template - static bool Check(Ite begin, Ite end, const Container& expected) + static bool Check(Ite begin, Ite end, const Container& expected, int count) { - return Check(begin, end, expected.begin(), expected.end()); + return Check(begin, end, expected.begin(), expected.end(), count); } #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING) template - static bool Check(Ite begin, Ite end, const U(&expected)[SIZE]) + static bool Check(Ite begin, Ite end, const U(&expected)[SIZE], int count) { - return Check(begin, end, expected, expected + SIZE); + return Check(begin, end, expected, expected + SIZE, count); } #endif template - static bool Check(Ite1 actual_begin, Ite1 actual_end, Ite2 expected_begin, Ite2 expected_end) + static bool Check(Ite1 actual_begin, Ite1 actual_end, Ite2 expected_begin, Ite2 expected_end, int count) { Ite1 a=actual_begin; Ite2 e=expected_begin; - for( ; e != expected_end; ++e, ++a ) + const int n = count >= 0 ? count : ::std::distance(expected_begin, expected_end); + for( int i=0; i < n && e != expected_end; ++e, ++a, ++i ) { if( a == actual_end ) return false; if( *a != *e ) return false; @@ -668,6 +669,7 @@ class ElementsAreArrayMatcher : public IMatcher IUTEST_PP_DISALLOW_ASSIGN(ElementsAreArrayMatcher); const T& m_expected; + int m_count; }; #if IUTEST_HAS_MATCHER_ELEMENTSARE @@ -826,6 +828,59 @@ IIUT_DECL_ELEMENTSARE_MATCHER(10); #endif + +/** + * @brief Pair matcher +*/ +template +class PairMatcher : public IMatcher +{ +public: + PairMatcher(const T1& m1, const T2& m2) : m_m1(m1), m_m2(m2) {} + +public: + template + AssertionResult operator ()(const U& actual) const + { + if( !CheckElem(actual.first, m_m1) ) + { + return AssertionFailure() << WitchIs(); + } + if( !CheckElem(actual.second, m_m2) ) + { + return AssertionFailure() << WitchIs(); + } + return AssertionSuccess(); + } + +public: + ::std::string WitchIs(void) const IUTEST_CXX_OVERRIDE + { + iu_global_format_stringstream strm; + strm << "Pair: (" << m_m1 << ", " << m_m2 << ")"; + return strm.str(); + } +private: + template + static bool CheckElem(const T& actual, const U& matcher + , typename detail::enable_if_t< is_matcher >::type*& = detail::enabler::value) + { + return static_cast(matcher(actual)); + } + template + static bool CheckElem(const T& actual, const U& matcher + , typename detail::disable_if_t< is_matcher >::type*& = detail::enabler::value) + { + return CheckElem(actual, EqMatcher(matcher)); + } + +private: + IUTEST_PP_DISALLOW_ASSIGN(PairMatcher); + + const T1& m_m1; + const T2& m_m2; +}; + #if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF /** @@ -1225,6 +1280,12 @@ detail::EachMatcher Each(const T& expected) { return detail::EachMatcher(e template detail::ElementsAreArrayMatcher ElementsAreArray(const T& a) { return detail::ElementsAreArrayMatcher(a); } +/** + * @brief Make ElementsAreArray matcher +*/ +template +detail::ElementsAreArrayMatcher ElementsAreArray(const T& a, int count) { return detail::ElementsAreArrayMatcher(a, count); } + #if IUTEST_HAS_MATCHER_ELEMENTSARE #if IUTEST_HAS_VARIADIC_TEMPLATES @@ -1263,6 +1324,13 @@ IIUT_DECL_ELEMENTSARE(10) #endif +/** + * @brief Make Pair matcher +*/ +template +detail::PairMatcher Pair(const T1& m1, const T2& m2) { return detail::PairMatcher(m1, m2); } + + #if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF #if IUTEST_HAS_VARIADIC_TEMPLATES diff --git a/include/iutest_ver.hpp b/include/iutest_ver.hpp index 83321f6f32..b0140caa61 100644 --- a/include/iutest_ver.hpp +++ b/include/iutest_ver.hpp @@ -17,11 +17,11 @@ //====================================================================== // define -#define IUTEST_VER 0x01109911u //!< iutest version 1.10.99.11 +#define IUTEST_VER 0x01109912u //!< iutest version 1.10.99.12 #define IUTEST_MAJORVER 0x01u //!< Major Version #define IUTEST_MINORVER 0x10u //!< Minor Version #define IUTEST_BUILD 0x99u //!< Build -#define IUTEST_REVISION 0x11u //!< Revision +#define IUTEST_REVISION 0x12u //!< Revision /** * @mainpage @@ -122,6 +122,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Matcher に FloatEq,DoubleEq,NanSensitiveFloatEq,NanSensitiveDoubleEq を追加
  • コンテナMatcher に Each,ElementsAre,ElementsAreArray を追加
  • コンテナMatcher の条件に Matcher を使えるように修正
  • +
  • メンバーMatcher に Pair を追加
  • IUTEST_*_FLOAT_EQ,DOUBLE_EQ で NAN の比較が真を返す不具合を修正
  • diff --git a/shippable.yml b/shippable.yml index 30275481f5..c34873ca7c 100644 --- a/shippable.yml +++ b/shippable.yml @@ -11,5 +11,24 @@ before_script: script: - cd tools/wandbox - - python ./iuwandbox.py ../../test/iutest_syntax_tests.cpp +# - python ./iuwandbox.py ../../test/iutest_syntax_tests.cpp -c ${WANDBOX_COMPILER} + - python ./iuwandbox.py sample.cpp -c ${WANDBOX_COMPILER} +env: + - WANDBOX_COMPILER=gcc-head + - WANDBOX_COMPILER=gcc-4.9.1 + - WANDBOX_COMPILER=gcc-4.9.0 + - WANDBOX_COMPILER=gcc-4.8.2 +# - WANDBOX_COMPILER=gcc-4.8.1 # travis + - WANDBOX_COMPILER=gcc-4.7.3 +# - WANDBOX_COMPILER=gcc-4.6.4 # drone + - WANDBOX_COMPILER=gcc-4.5.4 + - WANDBOX_COMPILER=gcc-4.4.7 + - WANDBOX_COMPILER=gcc-4.3.6 + - WANDBOX_COMPILER=clang-head +# - WANDBOX_COMPILER=clang-3.4 # travis + - WANDBOX_COMPILER=clang-3.3 + - WANDBOX_COMPILER=clang-3.2 + - WANDBOX_COMPILER=clang-3.1 + - WANDBOX_COMPILER=clang-3.0 + \ No newline at end of file diff --git a/test/iutest_matcher_tests.cpp b/test/iutest_matcher_tests.cpp index 384c774b5a..8634dbebf6 100644 --- a/test/iutest_matcher_tests.cpp +++ b/test/iutest_matcher_tests.cpp @@ -16,6 +16,7 @@ //====================================================================== // include #include "../include/gtest/iutest_spi_switch.hpp" +#include #if IUTEST_HAS_MATCHERS @@ -30,6 +31,7 @@ ::std::vector< ::std::vector > vv; int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int b[3] = { 1, 2, 3 }; int c[3] = { 1, 1, 1 }; +::std::map m; void* p1 = NULL; void* p2 = &p1; float f0 = 0.0f; @@ -189,12 +191,18 @@ IUTEST(Matcher, Each) IUTEST_EXPECT_THAT(vv, ::iutest::Each(::iutest::Each(::iutest::Le(10)))); } +IUTEST(Matcher, Pair) +{ + IUTEST_EXPECT_THAT( m, ::iutest::Each(::iutest::Pair(::iutest::Le(10), 100))); +} + IUTEST(Matcher, ElementsAreArray) { IUTEST_EXPECT_THAT( a, ::iutest::ElementsAreArray(va)); IUTEST_EXPECT_THAT(va, ::iutest::ElementsAreArray(a)); IUTEST_EXPECT_THAT(va, ::iutest::ElementsAreArray(va)); IUTEST_EXPECT_THAT( c, ::iutest::ElementsAreArray(c)); + IUTEST_EXPECT_THAT( c, ::iutest::ElementsAreArray(b, 1)); } IUTEST(MatcherFailure, Eq) @@ -328,6 +336,11 @@ IUTEST(MatcherFailure, Each) IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT(vv, ::iutest::Each(::iutest::Each(::iutest::Gt(5)))), "Each: Each: Gt: 5" ); } +IUTEST(MatcherFailure, Pair) +{ + IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT( m, ::iutest::Each(::iutest::Pair(::iutest::Gt(5), 100))), "Each: Pair: (Gt: 5, 100)" ); +} + IUTEST(MatcherFailure, ElementsAreArray) { IUTEST_EXPECT_FATAL_FAILURE( IUTEST_ASSERT_THAT(b, ::iutest::ElementsAreArray(c)), "ElementsAreArray: " ); @@ -422,6 +435,7 @@ int main(int argc, char* argv[]) #if IUTEST_HAS_MATCHERS for( int i=0; i < 10; ++i ) va.push_back(i); for( int i=0; i < 10; ++i ) vv.push_back(va); + for( int i=0; i < 10; ++i ) m.insert( ::std::pair(i, 100) ); #endif IUTEST_INIT(&argc, argv);