diff options
author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2013-08-08 18:41:51 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2013-08-08 18:41:51 +0000 |
commit | 1cc1d4bcecdac906250f863bef2636b278eb679d (patch) | |
tree | a51411ad22ce343439b323c7cf4e8718f341deef /test/gmock-generated-matchers_test.cc | |
parent | 5579c1a8b1591d4932495b8cb3cc61f3edca2555 (diff) | |
download | googletest-1cc1d4bcecdac906250f863bef2636b278eb679d.tar.gz googletest-1cc1d4bcecdac906250f863bef2636b278eb679d.tar.bz2 googletest-1cc1d4bcecdac906250f863bef2636b278eb679d.zip |
Makes some container matchers accept initializer lists in C++11 mode and work with stream-like containers that don't have size() or empty(); exposes StringMatchResultListener for defining composite matchers.
Diffstat (limited to 'test/gmock-generated-matchers_test.cc')
-rw-r--r-- | test/gmock-generated-matchers_test.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc index e43781b6..dba74ecb 100644 --- a/test/gmock-generated-matchers_test.cc +++ b/test/gmock-generated-matchers_test.cc @@ -64,6 +64,7 @@ using testing::ElementsAreArray; using testing::Eq; using testing::Ge; using testing::Gt; +using testing::Le; using testing::Lt; using testing::MakeMatcher; using testing::Matcher; @@ -632,6 +633,44 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithVector) { EXPECT_THAT(test_vector, Not(ElementsAreArray(expected))); } +#if GTEST_LANG_CXX11 + +TEST(ElementsAreArrayTest, TakesInitializerList) { + const int a[5] = { 1, 2, 3, 4, 5 }; + EXPECT_THAT(a, ElementsAreArray({ 1, 2, 3, 4, 5 })); + EXPECT_THAT(a, Not(ElementsAreArray({ 1, 2, 3, 5, 4 }))); + EXPECT_THAT(a, Not(ElementsAreArray({ 1, 2, 3, 4, 6 }))); +} + +TEST(ElementsAreArrayTest, TakesInitializerListOfCStrings) { + const string a[5] = { "a", "b", "c", "d", "e" }; + EXPECT_THAT(a, ElementsAreArray({ "a", "b", "c", "d", "e" })); + EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "e", "d" }))); + EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "d", "ef" }))); +} + +TEST(ElementsAreArrayTest, TakesInitializerListOfSameTypedMatchers) { + const int a[5] = { 1, 2, 3, 4, 5 }; + EXPECT_THAT(a, ElementsAreArray( + { Eq(1), Eq(2), Eq(3), Eq(4), Eq(5) })); + EXPECT_THAT(a, Not(ElementsAreArray( + { Eq(1), Eq(2), Eq(3), Eq(4), Eq(6) }))); +} + +TEST(ElementsAreArrayTest, + TakesInitializerListOfDifferentTypedMatchers) { + const int a[5] = { 1, 2, 3, 4, 5 }; + // The compiler cannot infer the type of the initializer list if its + // elements have different types. We must explicitly specify the + // unified element type in this case. + EXPECT_THAT(a, ElementsAreArray<Matcher<int> >( + { Eq(1), Ne(-2), Ge(3), Le(4), Eq(5) })); + EXPECT_THAT(a, Not(ElementsAreArray<Matcher<int> >( + { Eq(1), Ne(-2), Ge(3), Le(4), Eq(6) }))); +} + +#endif // GTEST_LANG_CXX11 + TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) { const int a[] = { 1, 2, 3 }; const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) }; |