diff options
| author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2018-03-01 11:18:17 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-01 11:18:17 -0500 | 
| commit | f8fbe1c82175b493acd010a6891119dbe5712b5d (patch) | |
| tree | fa8e9f14e2b4efb66787742ac7bdd7ac4f262700 /googlemock/test | |
| parent | 837c24637040566a223d6330de3ae6182caa73ee (diff) | |
| parent | 447d58b4ee8ea96b4757a5bb5f0b3be75af6c2a1 (diff) | |
| download | googletest-f8fbe1c82175b493acd010a6891119dbe5712b5d.tar.gz googletest-f8fbe1c82175b493acd010a6891119dbe5712b5d.tar.bz2 googletest-f8fbe1c82175b493acd010a6891119dbe5712b5d.zip  | |
Merge branch 'master' into unsigned-wchar
Diffstat (limited to 'googlemock/test')
| -rw-r--r-- | googlemock/test/gmock-matchers_test.cc | 64 | ||||
| -rw-r--r-- | googlemock/test/gmock_link_test.h | 24 | 
2 files changed, 86 insertions, 2 deletions
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 761c0c22..829935ef 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5655,5 +5655,69 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) {    EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs));  } +class SampleVariantIntString { + public: +  SampleVariantIntString(int i) : i_(i), has_int_(true) {} +  SampleVariantIntString(const std::string& s) : s_(s), has_int_(false) {} + +  template <typename T> +  friend bool holds_alternative(const SampleVariantIntString& value) { +    return value.has_int_ == internal::IsSame<T, int>::value; +  } + +  template <typename T> +  friend const T& get(const SampleVariantIntString& value) { +    return value.get_impl(static_cast<T*>(NULL)); +  } + + private: +  const int& get_impl(int*) const { return i_; } +  const std::string& get_impl(std::string*) const { return s_; } + +  int i_; +  std::string s_; +  bool has_int_; +}; + +TEST(VariantTest, DescribesSelf) { +  const Matcher<SampleVariantIntString> m = VariantWith<int>(Eq(1)); +  EXPECT_THAT(Describe(m), ContainsRegex("is a variant<> with value of type " +                                         "'.*' and the value is equal to 1")); +} + +TEST(VariantTest, ExplainsSelf) { +  const Matcher<SampleVariantIntString> m = VariantWith<int>(Eq(1)); +  EXPECT_THAT(Explain(m, SampleVariantIntString(1)), +              ContainsRegex("whose value 1")); +  EXPECT_THAT(Explain(m, SampleVariantIntString("A")), +              HasSubstr("whose value is not of type '")); +  EXPECT_THAT(Explain(m, SampleVariantIntString(2)), +              "whose value 2 doesn't match"); +} + +TEST(VariantTest, FullMatch) { +  Matcher<SampleVariantIntString> m = VariantWith<int>(Eq(1)); +  EXPECT_TRUE(m.Matches(SampleVariantIntString(1))); + +  m = VariantWith<std::string>(Eq("1")); +  EXPECT_TRUE(m.Matches(SampleVariantIntString("1"))); +} + +TEST(VariantTest, TypeDoesNotMatch) { +  Matcher<SampleVariantIntString> m = VariantWith<int>(Eq(1)); +  EXPECT_FALSE(m.Matches(SampleVariantIntString("1"))); + +  m = VariantWith<std::string>(Eq("1")); +  EXPECT_FALSE(m.Matches(SampleVariantIntString(1))); +} + +TEST(VariantTest, InnerDoesNotMatch) { +  Matcher<SampleVariantIntString> m = VariantWith<int>(Eq(1)); +  EXPECT_FALSE(m.Matches(SampleVariantIntString(2))); + +  m = VariantWith<std::string>(Eq("1")); +  EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); +} +  }  // namespace gmock_matchers_test  }  // namespace testing diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 1f55f5bd..5f855d19 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -120,13 +120,15 @@  # include <errno.h>  #endif -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h"  #include <iostream>  #include <vector> +#include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" +  using testing::_;  using testing::A; +using testing::Action;  using testing::AllOf;  using testing::AnyOf;  using testing::Assign; @@ -148,6 +150,8 @@ using testing::Invoke;  using testing::InvokeArgument;  using testing::InvokeWithoutArgs;  using testing::IsNull; +using testing::IsSubsetOf; +using testing::IsSupersetOf;  using testing::Le;  using testing::Lt;  using testing::Matcher; @@ -592,6 +596,22 @@ TEST(LinkTest, TestMatcherElementsAreArray) {    ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());  } +// Tests the linkage of the IsSubsetOf matcher. +TEST(LinkTest, TestMatcherIsSubsetOf) { +  Mock mock; +  char arr[] = {'a', 'b'}; + +  ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return()); +} + +// Tests the linkage of the IsSupersetOf matcher. +TEST(LinkTest, TestMatcherIsSupersetOf) { +  Mock mock; +  char arr[] = {'a', 'b'}; + +  ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return()); +} +  // Tests the linkage of the ContainerEq matcher.  TEST(LinkTest, TestMatcherContainerEq) {    Mock mock;  | 
