Merge branch 'master' into master
This commit is contained in:
commit
7e6de2541e
|
@ -287,7 +287,7 @@ class MatcherBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff this matcher matches x.
|
// Returns true iff this matcher matches x.
|
||||||
bool Matches(T x) const {
|
bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const {
|
||||||
DummyMatchResultListener dummy;
|
DummyMatchResultListener dummy;
|
||||||
return MatchAndExplain(x, &dummy);
|
return MatchAndExplain(x, &dummy);
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,8 @@ class MatcherBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explains why x matches, or doesn't match, the matcher.
|
// Explains why x matches, or doesn't match, the matcher.
|
||||||
void ExplainMatchResultTo(T x, ::std::ostream* os) const {
|
void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||||
|
::std::ostream* os) const {
|
||||||
StreamMatchResultListener listener(os);
|
StreamMatchResultListener listener(os);
|
||||||
MatchAndExplain(x, &listener);
|
MatchAndExplain(x, &listener);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +318,8 @@ class MatcherBase {
|
||||||
MatcherBase() {}
|
MatcherBase() {}
|
||||||
|
|
||||||
// Constructs a matcher from its implementation.
|
// Constructs a matcher from its implementation.
|
||||||
explicit MatcherBase(const MatcherInterface<T>* impl)
|
explicit MatcherBase(
|
||||||
|
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
|
||||||
: impl_(impl) {}
|
: impl_(impl) {}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
@ -342,7 +344,9 @@ class MatcherBase {
|
||||||
//
|
//
|
||||||
// If performance becomes a problem, we should see if using
|
// If performance becomes a problem, we should see if using
|
||||||
// shared_ptr helps.
|
// shared_ptr helps.
|
||||||
::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
|
::testing::internal::linked_ptr<
|
||||||
|
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> >
|
||||||
|
impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -407,6 +411,8 @@ class GTEST_API_ Matcher<std::string>
|
||||||
public:
|
public:
|
||||||
Matcher() {}
|
Matcher() {}
|
||||||
|
|
||||||
|
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||||
|
: internal::MatcherBase<std::string>(impl) {}
|
||||||
explicit Matcher(const MatcherInterface<std::string>* impl)
|
explicit Matcher(const MatcherInterface<std::string>* impl)
|
||||||
: internal::MatcherBase<std::string>(impl) {}
|
: internal::MatcherBase<std::string>(impl) {}
|
||||||
|
|
||||||
|
@ -449,28 +455,95 @@ class GTEST_API_ Matcher<const ::string&>
|
||||||
Matcher(const char* s); // NOLINT
|
Matcher(const char* s); // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class GTEST_API_ Matcher<StringPiece>
|
class GTEST_API_ Matcher< ::string>
|
||||||
: public internal::MatcherBase<StringPiece> {
|
: public internal::MatcherBase< ::string> {
|
||||||
public:
|
public:
|
||||||
Matcher() {}
|
Matcher() {}
|
||||||
|
|
||||||
explicit Matcher(const MatcherInterface<StringPiece>* impl)
|
explicit Matcher(const MatcherInterface<const ::string&>* impl)
|
||||||
: internal::MatcherBase<StringPiece>(impl) {}
|
: internal::MatcherBase< ::string>(impl) {}
|
||||||
|
explicit Matcher(const MatcherInterface< ::string>* impl)
|
||||||
|
: internal::MatcherBase< ::string>(impl) {}
|
||||||
|
|
||||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
// str is a string object.
|
// str is a std::string object.
|
||||||
Matcher(const internal::string& s); // NOLINT
|
Matcher(const std::string& s); // NOLINT
|
||||||
|
|
||||||
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
|
// str is a ::string object.
|
||||||
|
Matcher(const ::string& s); // NOLINT
|
||||||
|
|
||||||
|
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||||
|
Matcher(const char* s); // NOLINT
|
||||||
|
};
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
// The following two specializations allow the user to write str
|
||||||
|
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
|
||||||
|
// matcher is expected.
|
||||||
|
template <>
|
||||||
|
class GTEST_API_ Matcher<const absl::string_view&>
|
||||||
|
: public internal::MatcherBase<const absl::string_view&> {
|
||||||
|
public:
|
||||||
|
Matcher() {}
|
||||||
|
|
||||||
|
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||||
|
: internal::MatcherBase<const absl::string_view&>(impl) {}
|
||||||
|
|
||||||
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
|
// str is a std::string object.
|
||||||
|
Matcher(const std::string& s); // NOLINT
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
|
// str is a ::string object.
|
||||||
|
Matcher(const ::string& s); // NOLINT
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||||
Matcher(const char* s); // NOLINT
|
Matcher(const char* s); // NOLINT
|
||||||
|
|
||||||
// Allows the user to pass StringPieces directly.
|
// Allows the user to pass absl::string_views directly.
|
||||||
Matcher(StringPiece s); // NOLINT
|
Matcher(absl::string_view s); // NOLINT
|
||||||
};
|
};
|
||||||
#endif // GTEST_HAS_STRING_PIECE_
|
|
||||||
|
template <>
|
||||||
|
class GTEST_API_ Matcher<absl::string_view>
|
||||||
|
: public internal::MatcherBase<absl::string_view> {
|
||||||
|
public:
|
||||||
|
Matcher() {}
|
||||||
|
|
||||||
|
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||||
|
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||||
|
explicit Matcher(const MatcherInterface<absl::string_view>* impl)
|
||||||
|
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||||
|
|
||||||
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
|
// str is a std::string object.
|
||||||
|
Matcher(const std::string& s); // NOLINT
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||||
|
// str is a ::string object.
|
||||||
|
Matcher(const ::string& s); // NOLINT
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||||
|
Matcher(const char* s); // NOLINT
|
||||||
|
|
||||||
|
// Allows the user to pass absl::string_views directly.
|
||||||
|
Matcher(absl::string_view s); // NOLINT
|
||||||
|
};
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
|
// Prints a matcher in a human-readable format.
|
||||||
|
template <typename T>
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
|
||||||
|
matcher.DescribeTo(&os);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
// The PolymorphicMatcher class template makes it easy to implement a
|
// The PolymorphicMatcher class template makes it easy to implement a
|
||||||
// polymorphic matcher (i.e. a matcher that can match values of more
|
// polymorphic matcher (i.e. a matcher that can match values of more
|
||||||
|
@ -499,7 +572,7 @@ class PolymorphicMatcher {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
operator Matcher<T>() const {
|
operator Matcher<T>() const {
|
||||||
return Matcher<T>(new MonomorphicImpl<T>(impl_));
|
return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -845,7 +918,7 @@ class TuplePrefix {
|
||||||
typename tuple_element<N - 1, MatcherTuple>::type matcher =
|
typename tuple_element<N - 1, MatcherTuple>::type matcher =
|
||||||
get<N - 1>(matchers);
|
get<N - 1>(matchers);
|
||||||
typedef typename tuple_element<N - 1, ValueTuple>::type Value;
|
typedef typename tuple_element<N - 1, ValueTuple>::type Value;
|
||||||
Value value = get<N - 1>(values);
|
GTEST_REFERENCE_TO_CONST_(Value) value = get<N - 1>(values);
|
||||||
StringMatchResultListener listener;
|
StringMatchResultListener listener;
|
||||||
if (!matcher.MatchAndExplain(value, &listener)) {
|
if (!matcher.MatchAndExplain(value, &listener)) {
|
||||||
// TODO(wan): include in the message the name of the parameter
|
// TODO(wan): include in the message the name of the parameter
|
||||||
|
@ -950,10 +1023,12 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
|
||||||
|
|
||||||
// Implements A<T>().
|
// Implements A<T>().
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class AnyMatcherImpl : public MatcherInterface<T> {
|
class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||||
public:
|
public:
|
||||||
virtual bool MatchAndExplain(
|
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */,
|
||||||
T /* x */, MatchResultListener* /* listener */) const { return true; }
|
MatchResultListener* /* listener */) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
|
virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
|
||||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||||
// This is mostly for completeness' safe, as it's not very useful
|
// This is mostly for completeness' safe, as it's not very useful
|
||||||
|
@ -1223,6 +1298,19 @@ class StrEqualityMatcher {
|
||||||
bool case_sensitive)
|
bool case_sensitive)
|
||||||
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
|
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
bool MatchAndExplain(const absl::string_view& s,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
|
if (s.data() == NULL) {
|
||||||
|
return !expect_eq_;
|
||||||
|
}
|
||||||
|
// This should fail to compile if absl::string_view is used with wide
|
||||||
|
// strings.
|
||||||
|
const StringType& str = string(s);
|
||||||
|
return MatchAndExplain(str, listener);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Accepts pointer types, particularly:
|
// Accepts pointer types, particularly:
|
||||||
// const char*
|
// const char*
|
||||||
// char*
|
// char*
|
||||||
|
@ -1239,7 +1327,7 @@ class StrEqualityMatcher {
|
||||||
// Matches anything that can convert to StringType.
|
// Matches anything that can convert to StringType.
|
||||||
//
|
//
|
||||||
// This is a template, not just a plain function with const StringType&,
|
// This is a template, not just a plain function with const StringType&,
|
||||||
// because StringPiece has some interfering non-explicit constructors.
|
// because absl::string_view has some interfering non-explicit constructors.
|
||||||
template <typename MatcheeStringType>
|
template <typename MatcheeStringType>
|
||||||
bool MatchAndExplain(const MatcheeStringType& s,
|
bool MatchAndExplain(const MatcheeStringType& s,
|
||||||
MatchResultListener* /* listener */) const {
|
MatchResultListener* /* listener */) const {
|
||||||
|
@ -1283,6 +1371,19 @@ class HasSubstrMatcher {
|
||||||
explicit HasSubstrMatcher(const StringType& substring)
|
explicit HasSubstrMatcher(const StringType& substring)
|
||||||
: substring_(substring) {}
|
: substring_(substring) {}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
bool MatchAndExplain(const absl::string_view& s,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
|
if (s.data() == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// This should fail to compile if absl::string_view is used with wide
|
||||||
|
// strings.
|
||||||
|
const StringType& str = string(s);
|
||||||
|
return MatchAndExplain(str, listener);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Accepts pointer types, particularly:
|
// Accepts pointer types, particularly:
|
||||||
// const char*
|
// const char*
|
||||||
// char*
|
// char*
|
||||||
|
@ -1296,7 +1397,7 @@ class HasSubstrMatcher {
|
||||||
// Matches anything that can convert to StringType.
|
// Matches anything that can convert to StringType.
|
||||||
//
|
//
|
||||||
// This is a template, not just a plain function with const StringType&,
|
// This is a template, not just a plain function with const StringType&,
|
||||||
// because StringPiece has some interfering non-explicit constructors.
|
// because absl::string_view has some interfering non-explicit constructors.
|
||||||
template <typename MatcheeStringType>
|
template <typename MatcheeStringType>
|
||||||
bool MatchAndExplain(const MatcheeStringType& s,
|
bool MatchAndExplain(const MatcheeStringType& s,
|
||||||
MatchResultListener* /* listener */) const {
|
MatchResultListener* /* listener */) const {
|
||||||
|
@ -1330,6 +1431,19 @@ class StartsWithMatcher {
|
||||||
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
|
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
bool MatchAndExplain(const absl::string_view& s,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
|
if (s.data() == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// This should fail to compile if absl::string_view is used with wide
|
||||||
|
// strings.
|
||||||
|
const StringType& str = string(s);
|
||||||
|
return MatchAndExplain(str, listener);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Accepts pointer types, particularly:
|
// Accepts pointer types, particularly:
|
||||||
// const char*
|
// const char*
|
||||||
// char*
|
// char*
|
||||||
|
@ -1343,7 +1457,7 @@ class StartsWithMatcher {
|
||||||
// Matches anything that can convert to StringType.
|
// Matches anything that can convert to StringType.
|
||||||
//
|
//
|
||||||
// This is a template, not just a plain function with const StringType&,
|
// This is a template, not just a plain function with const StringType&,
|
||||||
// because StringPiece has some interfering non-explicit constructors.
|
// because absl::string_view has some interfering non-explicit constructors.
|
||||||
template <typename MatcheeStringType>
|
template <typename MatcheeStringType>
|
||||||
bool MatchAndExplain(const MatcheeStringType& s,
|
bool MatchAndExplain(const MatcheeStringType& s,
|
||||||
MatchResultListener* /* listener */) const {
|
MatchResultListener* /* listener */) const {
|
||||||
|
@ -1376,6 +1490,19 @@ class EndsWithMatcher {
|
||||||
public:
|
public:
|
||||||
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
|
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
bool MatchAndExplain(const absl::string_view& s,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
|
if (s.data() == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// This should fail to compile if absl::string_view is used with wide
|
||||||
|
// strings.
|
||||||
|
const StringType& str = string(s);
|
||||||
|
return MatchAndExplain(str, listener);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Accepts pointer types, particularly:
|
// Accepts pointer types, particularly:
|
||||||
// const char*
|
// const char*
|
||||||
// char*
|
// char*
|
||||||
|
@ -1389,7 +1516,7 @@ class EndsWithMatcher {
|
||||||
// Matches anything that can convert to StringType.
|
// Matches anything that can convert to StringType.
|
||||||
//
|
//
|
||||||
// This is a template, not just a plain function with const StringType&,
|
// This is a template, not just a plain function with const StringType&,
|
||||||
// because StringPiece has some interfering non-explicit constructors.
|
// because absl::string_view has some interfering non-explicit constructors.
|
||||||
template <typename MatcheeStringType>
|
template <typename MatcheeStringType>
|
||||||
bool MatchAndExplain(const MatcheeStringType& s,
|
bool MatchAndExplain(const MatcheeStringType& s,
|
||||||
MatchResultListener* /* listener */) const {
|
MatchResultListener* /* listener */) const {
|
||||||
|
@ -1422,6 +1549,13 @@ class MatchesRegexMatcher {
|
||||||
MatchesRegexMatcher(const RE* regex, bool full_match)
|
MatchesRegexMatcher(const RE* regex, bool full_match)
|
||||||
: regex_(regex), full_match_(full_match) {}
|
: regex_(regex), full_match_(full_match) {}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
bool MatchAndExplain(const absl::string_view& s,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
|
return s.data() && MatchAndExplain(string(s), listener);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Accepts pointer types, particularly:
|
// Accepts pointer types, particularly:
|
||||||
// const char*
|
// const char*
|
||||||
// char*
|
// char*
|
||||||
|
@ -1535,12 +1669,13 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
|
||||||
// will prevent different instantiations of NotMatcher from sharing
|
// will prevent different instantiations of NotMatcher from sharing
|
||||||
// the same NotMatcherImpl<T> class.
|
// the same NotMatcherImpl<T> class.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class NotMatcherImpl : public MatcherInterface<T> {
|
class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||||
public:
|
public:
|
||||||
explicit NotMatcherImpl(const Matcher<T>& matcher)
|
explicit NotMatcherImpl(const Matcher<T>& matcher)
|
||||||
: matcher_(matcher) {}
|
: matcher_(matcher) {}
|
||||||
|
|
||||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
return !matcher_.MatchAndExplain(x, listener);
|
return !matcher_.MatchAndExplain(x, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1583,7 +1718,8 @@ class NotMatcher {
|
||||||
// that will prevent different instantiations of BothOfMatcher from
|
// that will prevent different instantiations of BothOfMatcher from
|
||||||
// sharing the same BothOfMatcherImpl<T> class.
|
// sharing the same BothOfMatcherImpl<T> class.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class BothOfMatcherImpl : public MatcherInterface<T> {
|
class BothOfMatcherImpl
|
||||||
|
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||||
public:
|
public:
|
||||||
BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
||||||
: matcher1_(matcher1), matcher2_(matcher2) {}
|
: matcher1_(matcher1), matcher2_(matcher2) {}
|
||||||
|
@ -1604,7 +1740,8 @@ class BothOfMatcherImpl : public MatcherInterface<T> {
|
||||||
*os << ")";
|
*os << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
// If either matcher1_ or matcher2_ doesn't match x, we only need
|
// If either matcher1_ or matcher2_ doesn't match x, we only need
|
||||||
// to explain why one of them fails.
|
// to explain why one of them fails.
|
||||||
StringMatchResultListener listener1;
|
StringMatchResultListener listener1;
|
||||||
|
@ -1755,7 +1892,8 @@ class BothOfMatcher {
|
||||||
// that will prevent different instantiations of AnyOfMatcher from
|
// that will prevent different instantiations of AnyOfMatcher from
|
||||||
// sharing the same EitherOfMatcherImpl<T> class.
|
// sharing the same EitherOfMatcherImpl<T> class.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class EitherOfMatcherImpl : public MatcherInterface<T> {
|
class EitherOfMatcherImpl
|
||||||
|
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||||
public:
|
public:
|
||||||
EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
||||||
: matcher1_(matcher1), matcher2_(matcher2) {}
|
: matcher1_(matcher1), matcher2_(matcher2) {}
|
||||||
|
@ -1776,7 +1914,8 @@ class EitherOfMatcherImpl : public MatcherInterface<T> {
|
||||||
*os << ")";
|
*os << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||||
|
MatchResultListener* listener) const {
|
||||||
// If either matcher1_ or matcher2_ matches x, we just need to
|
// If either matcher1_ or matcher2_ matches x, we just need to
|
||||||
// explain why *one* of them matches.
|
// explain why *one* of them matches.
|
||||||
StringMatchResultListener listener1;
|
StringMatchResultListener listener1;
|
||||||
|
@ -2224,7 +2363,8 @@ class PointeeMatcher {
|
||||||
// enough for implementing the DescribeTo() method of Pointee().
|
// enough for implementing the DescribeTo() method of Pointee().
|
||||||
template <typename Pointer>
|
template <typename Pointer>
|
||||||
operator Matcher<Pointer>() const {
|
operator Matcher<Pointer>() const {
|
||||||
return MakeMatcher(new Impl<Pointer>(matcher_));
|
return Matcher<Pointer>(
|
||||||
|
new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -105,6 +105,53 @@ Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||||
Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||||
#endif // GTEST_HAS_GLOBAL_STRING
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||||
|
// equal to s.
|
||||||
|
Matcher<const absl::string_view&>::Matcher(const std::string& s) {
|
||||||
|
*this = Eq(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||||
|
// equal to s.
|
||||||
|
Matcher<const absl::string_view&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||||
|
// equal to s.
|
||||||
|
Matcher<const absl::string_view&>::Matcher(const char* s) {
|
||||||
|
*this = Eq(std::string(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||||
|
// equal to s.
|
||||||
|
Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
|
||||||
|
*this = Eq(std::string(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||||
|
// s.
|
||||||
|
Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||||
|
// s.
|
||||||
|
Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||||
|
// s.
|
||||||
|
Matcher<absl::string_view>::Matcher(const char* s) {
|
||||||
|
*this = Eq(std::string(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||||
|
// s.
|
||||||
|
Matcher<absl::string_view>::Matcher(absl::string_view s) {
|
||||||
|
*this = Eq(std::string(s));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -113,12 +160,11 @@ namespace internal {
|
||||||
// 'negation' is false; otherwise returns the description of the
|
// 'negation' is false; otherwise returns the description of the
|
||||||
// negation of the matcher. 'param_values' contains a list of strings
|
// negation of the matcher. 'param_values' contains a list of strings
|
||||||
// that are the print-out of the matcher's parameters.
|
// that are the print-out of the matcher's parameters.
|
||||||
GTEST_API_ string FormatMatcherDescription(bool negation,
|
GTEST_API_ std::string FormatMatcherDescription(bool negation,
|
||||||
const char* matcher_name,
|
const char* matcher_name,
|
||||||
const Strings& param_values) {
|
const Strings& param_values) {
|
||||||
string result = ConvertIdentifierNameToWords(matcher_name);
|
std::string result = ConvertIdentifierNameToWords(matcher_name);
|
||||||
if (param_values.size() >= 1)
|
if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
|
||||||
result += " " + JoinAsTuple(param_values);
|
|
||||||
return negation ? "not (" + result + ")" : result;
|
return negation ? "not (" + result + ")" : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -58,13 +59,17 @@
|
||||||
# include <forward_list> // NOLINT
|
# include <forward_list> // NOLINT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Disable MSVC2015 warning for std::pair: "decorated name length exceeded, name was truncated".
|
// Disable MSVC2015 warning for std::pair:
|
||||||
|
// "decorated name length exceeded, name was truncated".
|
||||||
#if defined(_MSC_VER) && (_MSC_VER == 1900)
|
#if defined(_MSC_VER) && (_MSC_VER == 1900)
|
||||||
# pragma warning(disable:4503)
|
# pragma warning(disable:4503)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace testing {
|
#if GTEST_LANG_CXX11
|
||||||
|
# include <type_traits>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace testing {
|
||||||
namespace gmock_matchers_test {
|
namespace gmock_matchers_test {
|
||||||
|
|
||||||
using std::greater;
|
using std::greater;
|
||||||
|
@ -200,17 +205,13 @@ std::string OfType(const std::string& type_name) {
|
||||||
// Returns the description of the given matcher.
|
// Returns the description of the given matcher.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string Describe(const Matcher<T>& m) {
|
std::string Describe(const Matcher<T>& m) {
|
||||||
stringstream ss;
|
return DescribeMatcher<T>(m);
|
||||||
m.DescribeTo(&ss);
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the description of the negation of the given matcher.
|
// Returns the description of the negation of the given matcher.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string DescribeNegation(const Matcher<T>& m) {
|
std::string DescribeNegation(const Matcher<T>& m) {
|
||||||
stringstream ss;
|
return DescribeMatcher<T>(m, true);
|
||||||
m.DescribeNegationTo(&ss);
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the reason why x matches, or doesn't match, m.
|
// Returns the reason why x matches, or doesn't match, m.
|
||||||
|
@ -221,6 +222,12 @@ std::string Explain(const MatcherType& m, const Value& x) {
|
||||||
return listener.str();
|
return listener.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MonotonicMatcherTest, IsPrintable) {
|
||||||
|
stringstream ss;
|
||||||
|
ss << GreaterThan(5);
|
||||||
|
EXPECT_EQ("is > 5", ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MatchResultListenerTest, StreamingWorks) {
|
TEST(MatchResultListenerTest, StreamingWorks) {
|
||||||
StringMatchResultListener listener;
|
StringMatchResultListener listener;
|
||||||
listener << "hi" << 5;
|
listener << "hi" << 5;
|
||||||
|
@ -332,6 +339,22 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) {
|
||||||
EXPECT_FALSE(m1.Matches(&n));
|
EXPECT_FALSE(m1.Matches(&n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that matchers can be constructed from a variable that is not properly
|
||||||
|
// defined. This should be illegal, but many users rely on this accidentally.
|
||||||
|
struct Undefined {
|
||||||
|
virtual ~Undefined() = 0;
|
||||||
|
static const int kInt = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(MatcherTest, CanBeConstructedFromUndefinedVariable) {
|
||||||
|
Matcher<int> m1 = Undefined::kInt;
|
||||||
|
EXPECT_TRUE(m1.Matches(1));
|
||||||
|
EXPECT_FALSE(m1.Matches(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that a matcher parameterized with an abstract class compiles.
|
||||||
|
TEST(MatcherTest, CanAcceptAbstractClass) { Matcher<const Undefined&> m = _; }
|
||||||
|
|
||||||
// Tests that matchers are copyable.
|
// Tests that matchers are copyable.
|
||||||
TEST(MatcherTest, IsCopyable) {
|
TEST(MatcherTest, IsCopyable) {
|
||||||
// Tests the copy constructor.
|
// Tests the copy constructor.
|
||||||
|
@ -365,66 +388,132 @@ TEST(MatcherTest, MatchAndExplain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a C-string literal can be implicitly converted to a
|
// Tests that a C-string literal can be implicitly converted to a
|
||||||
// Matcher<string> or Matcher<const string&>.
|
// Matcher<std::string> or Matcher<const std::string&>.
|
||||||
TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
|
TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
|
||||||
Matcher<string> m1 = "hi";
|
Matcher<std::string> m1 = "hi";
|
||||||
EXPECT_TRUE(m1.Matches("hi"));
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
EXPECT_FALSE(m1.Matches("hello"));
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
Matcher<const string&> m2 = "hi";
|
Matcher<const std::string&> m2 = "hi";
|
||||||
EXPECT_TRUE(m2.Matches("hi"));
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
EXPECT_FALSE(m2.Matches("hello"));
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a string object can be implicitly converted to a
|
// Tests that a string object can be implicitly converted to a
|
||||||
// Matcher<string> or Matcher<const string&>.
|
// Matcher<std::string> or Matcher<const std::string&>.
|
||||||
TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
|
TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
|
||||||
Matcher<string> m1 = string("hi");
|
Matcher<std::string> m1 = std::string("hi");
|
||||||
EXPECT_TRUE(m1.Matches("hi"));
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
EXPECT_FALSE(m1.Matches("hello"));
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
Matcher<const string&> m2 = string("hi");
|
Matcher<const std::string&> m2 = std::string("hi");
|
||||||
EXPECT_TRUE(m2.Matches("hi"));
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
EXPECT_FALSE(m2.Matches("hello"));
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_STRING_PIECE_
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
// Tests that a ::string object can be implicitly converted to a
|
||||||
|
// Matcher<std::string> or Matcher<const std::string&>.
|
||||||
|
TEST(StringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
|
||||||
|
Matcher<std::string> m1 = ::string("hi");
|
||||||
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
|
Matcher<const std::string&> m2 = ::string("hi");
|
||||||
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
// Tests that a C-string literal can be implicitly converted to a
|
// Tests that a C-string literal can be implicitly converted to a
|
||||||
// Matcher<StringPiece> or Matcher<const StringPiece&>.
|
// Matcher<::string> or Matcher<const ::string&>.
|
||||||
TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
|
TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
|
||||||
Matcher<StringPiece> m1 = "cats";
|
Matcher< ::string> m1 = "hi";
|
||||||
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
|
Matcher<const ::string&> m2 = "hi";
|
||||||
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests that a std::string object can be implicitly converted to a
|
||||||
|
// Matcher<::string> or Matcher<const ::string&>.
|
||||||
|
TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromString) {
|
||||||
|
Matcher< ::string> m1 = std::string("hi");
|
||||||
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
|
Matcher<const ::string&> m2 = std::string("hi");
|
||||||
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests that a ::string object can be implicitly converted to a
|
||||||
|
// Matcher<::string> or Matcher<const ::string&>.
|
||||||
|
TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
|
||||||
|
Matcher< ::string> m1 = ::string("hi");
|
||||||
|
EXPECT_TRUE(m1.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m1.Matches("hello"));
|
||||||
|
|
||||||
|
Matcher<const ::string&> m2 = ::string("hi");
|
||||||
|
EXPECT_TRUE(m2.Matches("hi"));
|
||||||
|
EXPECT_FALSE(m2.Matches("hello"));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
// Tests that a C-string literal can be implicitly converted to a
|
||||||
|
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
|
||||||
|
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
|
||||||
|
Matcher<absl::string_view> m1 = "cats";
|
||||||
EXPECT_TRUE(m1.Matches("cats"));
|
EXPECT_TRUE(m1.Matches("cats"));
|
||||||
EXPECT_FALSE(m1.Matches("dogs"));
|
EXPECT_FALSE(m1.Matches("dogs"));
|
||||||
|
|
||||||
Matcher<const StringPiece&> m2 = "cats";
|
Matcher<const absl::string_view&> m2 = "cats";
|
||||||
EXPECT_TRUE(m2.Matches("cats"));
|
EXPECT_TRUE(m2.Matches("cats"));
|
||||||
EXPECT_FALSE(m2.Matches("dogs"));
|
EXPECT_FALSE(m2.Matches("dogs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a string object can be implicitly converted to a
|
// Tests that a std::string object can be implicitly converted to a
|
||||||
// Matcher<StringPiece> or Matcher<const StringPiece&>.
|
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
|
||||||
TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromString) {
|
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) {
|
||||||
Matcher<StringPiece> m1 = string("cats");
|
Matcher<absl::string_view> m1 = std::string("cats");
|
||||||
EXPECT_TRUE(m1.Matches("cats"));
|
EXPECT_TRUE(m1.Matches("cats"));
|
||||||
EXPECT_FALSE(m1.Matches("dogs"));
|
EXPECT_FALSE(m1.Matches("dogs"));
|
||||||
|
|
||||||
Matcher<const StringPiece&> m2 = string("cats");
|
Matcher<const absl::string_view&> m2 = std::string("cats");
|
||||||
EXPECT_TRUE(m2.Matches("cats"));
|
EXPECT_TRUE(m2.Matches("cats"));
|
||||||
EXPECT_FALSE(m2.Matches("dogs"));
|
EXPECT_FALSE(m2.Matches("dogs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a StringPiece object can be implicitly converted to a
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
// Matcher<StringPiece> or Matcher<const StringPiece&>.
|
// Tests that a ::string object can be implicitly converted to a
|
||||||
TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromStringPiece) {
|
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
|
||||||
Matcher<StringPiece> m1 = StringPiece("cats");
|
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromGlobalString) {
|
||||||
|
Matcher<absl::string_view> m1 = ::string("cats");
|
||||||
EXPECT_TRUE(m1.Matches("cats"));
|
EXPECT_TRUE(m1.Matches("cats"));
|
||||||
EXPECT_FALSE(m1.Matches("dogs"));
|
EXPECT_FALSE(m1.Matches("dogs"));
|
||||||
|
|
||||||
Matcher<const StringPiece&> m2 = StringPiece("cats");
|
Matcher<const absl::string_view&> m2 = ::string("cats");
|
||||||
EXPECT_TRUE(m2.Matches("cats"));
|
EXPECT_TRUE(m2.Matches("cats"));
|
||||||
EXPECT_FALSE(m2.Matches("dogs"));
|
EXPECT_FALSE(m2.Matches("dogs"));
|
||||||
}
|
}
|
||||||
#endif // GTEST_HAS_STRING_PIECE_
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
// Tests that a absl::string_view object can be implicitly converted to a
|
||||||
|
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
|
||||||
|
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) {
|
||||||
|
Matcher<absl::string_view> m1 = absl::string_view("cats");
|
||||||
|
EXPECT_TRUE(m1.Matches("cats"));
|
||||||
|
EXPECT_FALSE(m1.Matches("dogs"));
|
||||||
|
|
||||||
|
Matcher<const absl::string_view&> m2 = absl::string_view("cats");
|
||||||
|
EXPECT_TRUE(m2.Matches("cats"));
|
||||||
|
EXPECT_FALSE(m2.Matches("dogs"));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Tests that MakeMatcher() constructs a Matcher<T> from a
|
// Tests that MakeMatcher() constructs a Matcher<T> from a
|
||||||
// MatcherInterface* without requiring the user to explicitly
|
// MatcherInterface* without requiring the user to explicitly
|
||||||
|
@ -613,7 +702,7 @@ TEST(MatcherCastTest, FromSameType) {
|
||||||
struct ConvertibleFromAny {
|
struct ConvertibleFromAny {
|
||||||
ConvertibleFromAny(int a_value) : value(a_value) {}
|
ConvertibleFromAny(int a_value) : value(a_value) {}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) {
|
explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) {
|
||||||
ADD_FAILURE() << "Conversion constructor called";
|
ADD_FAILURE() << "Conversion constructor called";
|
||||||
}
|
}
|
||||||
int value;
|
int value;
|
||||||
|
@ -1177,6 +1266,13 @@ TEST(StrEqTest, MatchesEqualString) {
|
||||||
Matcher<const std::string&> m2 = StrEq("Hello");
|
Matcher<const std::string&> m2 = StrEq("Hello");
|
||||||
EXPECT_TRUE(m2.Matches("Hello"));
|
EXPECT_TRUE(m2.Matches("Hello"));
|
||||||
EXPECT_FALSE(m2.Matches("Hi"));
|
EXPECT_FALSE(m2.Matches("Hi"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view&> m3 = StrEq("Hello");
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("Hello")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("hello")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view()));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StrEqTest, CanDescribeSelf) {
|
TEST(StrEqTest, CanDescribeSelf) {
|
||||||
|
@ -1202,6 +1298,13 @@ TEST(StrNeTest, MatchesUnequalString) {
|
||||||
Matcher<std::string> m2 = StrNe(std::string("Hello"));
|
Matcher<std::string> m2 = StrNe(std::string("Hello"));
|
||||||
EXPECT_TRUE(m2.Matches("hello"));
|
EXPECT_TRUE(m2.Matches("hello"));
|
||||||
EXPECT_FALSE(m2.Matches("Hello"));
|
EXPECT_FALSE(m2.Matches("Hello"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view> m3 = StrNe("Hello");
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("")));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view()));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("Hello")));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StrNeTest, CanDescribeSelf) {
|
TEST(StrNeTest, CanDescribeSelf) {
|
||||||
|
@ -1210,15 +1313,23 @@ TEST(StrNeTest, CanDescribeSelf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
|
TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
|
||||||
Matcher<const char*> m = StrCaseEq(string("Hello"));
|
Matcher<const char*> m = StrCaseEq(std::string("Hello"));
|
||||||
EXPECT_TRUE(m.Matches("Hello"));
|
EXPECT_TRUE(m.Matches("Hello"));
|
||||||
EXPECT_TRUE(m.Matches("hello"));
|
EXPECT_TRUE(m.Matches("hello"));
|
||||||
EXPECT_FALSE(m.Matches("Hi"));
|
EXPECT_FALSE(m.Matches("Hi"));
|
||||||
EXPECT_FALSE(m.Matches(NULL));
|
EXPECT_FALSE(m.Matches(NULL));
|
||||||
|
|
||||||
Matcher<const string&> m2 = StrCaseEq("Hello");
|
Matcher<const std::string&> m2 = StrCaseEq("Hello");
|
||||||
EXPECT_TRUE(m2.Matches("hello"));
|
EXPECT_TRUE(m2.Matches("hello"));
|
||||||
EXPECT_FALSE(m2.Matches("Hi"));
|
EXPECT_FALSE(m2.Matches("Hi"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view&> m3 = StrCaseEq(std::string("Hello"));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("Hello")));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("hello")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("Hi")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view()));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
|
TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
|
||||||
|
@ -1261,6 +1372,14 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
|
||||||
Matcher<std::string> m2 = StrCaseNe(std::string("Hello"));
|
Matcher<std::string> m2 = StrCaseNe(std::string("Hello"));
|
||||||
EXPECT_TRUE(m2.Matches(""));
|
EXPECT_TRUE(m2.Matches(""));
|
||||||
EXPECT_FALSE(m2.Matches("Hello"));
|
EXPECT_FALSE(m2.Matches("Hello"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view> m3 = StrCaseNe("Hello");
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("Hi")));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view()));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("Hello")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("hello")));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StrCaseNeTest, CanDescribeSelf) {
|
TEST(StrCaseNeTest, CanDescribeSelf) {
|
||||||
|
@ -1292,6 +1411,25 @@ TEST(HasSubstrTest, WorksForCStrings) {
|
||||||
EXPECT_FALSE(m2.Matches(NULL));
|
EXPECT_FALSE(m2.Matches(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
// Tests that HasSubstr() works for matching absl::string_view-typed values.
|
||||||
|
TEST(HasSubstrTest, WorksForStringViewClasses) {
|
||||||
|
const Matcher<absl::string_view> m1 = HasSubstr("foo");
|
||||||
|
EXPECT_TRUE(m1.Matches(absl::string_view("I love food.")));
|
||||||
|
EXPECT_FALSE(m1.Matches(absl::string_view("tofo")));
|
||||||
|
EXPECT_FALSE(m1.Matches(absl::string_view()));
|
||||||
|
|
||||||
|
const Matcher<const absl::string_view&> m2 = HasSubstr("foo");
|
||||||
|
EXPECT_TRUE(m2.Matches(absl::string_view("I love food.")));
|
||||||
|
EXPECT_FALSE(m2.Matches(absl::string_view("tofo")));
|
||||||
|
EXPECT_FALSE(m2.Matches(absl::string_view()));
|
||||||
|
|
||||||
|
const Matcher<const absl::string_view&> m3 = HasSubstr("");
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("foo")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view()));
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
// Tests that HasSubstr(s) describes itself properly.
|
// Tests that HasSubstr(s) describes itself properly.
|
||||||
TEST(HasSubstrTest, CanDescribeSelf) {
|
TEST(HasSubstrTest, CanDescribeSelf) {
|
||||||
Matcher<std::string> m = HasSubstr("foo\n\"");
|
Matcher<std::string> m = HasSubstr("foo\n\"");
|
||||||
|
@ -1320,6 +1458,35 @@ TEST(KeyTest, MatchesCorrectly) {
|
||||||
EXPECT_THAT(p, Not(Key(Lt(25))));
|
EXPECT_THAT(p, Not(Key(Lt(25))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_LANG_CXX11
|
||||||
|
template <size_t I>
|
||||||
|
struct Tag {};
|
||||||
|
|
||||||
|
struct PairWithGet {
|
||||||
|
int member_1;
|
||||||
|
string member_2;
|
||||||
|
using first_type = int;
|
||||||
|
using second_type = string;
|
||||||
|
|
||||||
|
const int& GetImpl(Tag<0>) const { return member_1; }
|
||||||
|
const string& GetImpl(Tag<1>) const { return member_2; }
|
||||||
|
};
|
||||||
|
template <size_t I>
|
||||||
|
auto get(const PairWithGet& value) -> decltype(value.GetImpl(Tag<I>())) {
|
||||||
|
return value.GetImpl(Tag<I>());
|
||||||
|
}
|
||||||
|
TEST(PairTest, MatchesPairWithGetCorrectly) {
|
||||||
|
PairWithGet p{25, "foo"};
|
||||||
|
EXPECT_THAT(p, Key(25));
|
||||||
|
EXPECT_THAT(p, Not(Key(42)));
|
||||||
|
EXPECT_THAT(p, Key(Ge(20)));
|
||||||
|
EXPECT_THAT(p, Not(Key(Lt(25))));
|
||||||
|
|
||||||
|
std::vector<PairWithGet> v = {{11, "Foo"}, {29, "gMockIsBestMock"}};
|
||||||
|
EXPECT_THAT(v, Contains(Key(29)));
|
||||||
|
}
|
||||||
|
#endif // GTEST_LANG_CXX11
|
||||||
|
|
||||||
TEST(KeyTest, SafelyCastsInnerMatcher) {
|
TEST(KeyTest, SafelyCastsInnerMatcher) {
|
||||||
Matcher<int> is_positive = Gt(0);
|
Matcher<int> is_positive = Gt(0);
|
||||||
Matcher<int> is_negative = Lt(0);
|
Matcher<int> is_negative = Lt(0);
|
||||||
|
@ -1423,7 +1590,7 @@ TEST(PairTest, MatchesCorrectly) {
|
||||||
EXPECT_THAT(p, Pair(25, "foo"));
|
EXPECT_THAT(p, Pair(25, "foo"));
|
||||||
EXPECT_THAT(p, Pair(Ge(20), HasSubstr("o")));
|
EXPECT_THAT(p, Pair(Ge(20), HasSubstr("o")));
|
||||||
|
|
||||||
// 'first' does not match, but 'second' matches.
|
// 'first' doesnt' match, but 'second' matches.
|
||||||
EXPECT_THAT(p, Not(Pair(42, "foo")));
|
EXPECT_THAT(p, Not(Pair(42, "foo")));
|
||||||
EXPECT_THAT(p, Not(Pair(Lt(25), "foo")));
|
EXPECT_THAT(p, Not(Pair(Lt(25), "foo")));
|
||||||
|
|
||||||
|
@ -1457,6 +1624,18 @@ TEST(PairTest, InsideContainsUsingMap) {
|
||||||
EXPECT_THAT(container, Not(Contains(Pair(3, _))));
|
EXPECT_THAT(container, Not(Contains(Pair(3, _))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GTEST_LANG_CXX11
|
||||||
|
TEST(PairTest, UseGetInsteadOfMembers) {
|
||||||
|
PairWithGet pair{7, "ABC"};
|
||||||
|
EXPECT_THAT(pair, Pair(7, "ABC"));
|
||||||
|
EXPECT_THAT(pair, Pair(Ge(7), HasSubstr("AB")));
|
||||||
|
EXPECT_THAT(pair, Not(Pair(Lt(7), "ABC")));
|
||||||
|
|
||||||
|
std::vector<PairWithGet> v = {{11, "Foo"}, {29, "gMockIsBestMock"}};
|
||||||
|
EXPECT_THAT(v, ElementsAre(Pair(11, string("Foo")), Pair(Ge(10), Not(""))));
|
||||||
|
}
|
||||||
|
#endif // GTEST_LANG_CXX11
|
||||||
|
|
||||||
// Tests StartsWith(s).
|
// Tests StartsWith(s).
|
||||||
|
|
||||||
TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
|
TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
|
||||||
|
@ -1486,12 +1665,30 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
|
||||||
EXPECT_TRUE(m1.Matches(""));
|
EXPECT_TRUE(m1.Matches(""));
|
||||||
EXPECT_FALSE(m1.Matches(NULL));
|
EXPECT_FALSE(m1.Matches(NULL));
|
||||||
|
|
||||||
const Matcher<const string&> m2 = EndsWith(string("Hi"));
|
const Matcher<const std::string&> m2 = EndsWith(std::string("Hi"));
|
||||||
EXPECT_TRUE(m2.Matches("Hi"));
|
EXPECT_TRUE(m2.Matches("Hi"));
|
||||||
EXPECT_TRUE(m2.Matches("Wow Hi Hi"));
|
EXPECT_TRUE(m2.Matches("Wow Hi Hi"));
|
||||||
EXPECT_TRUE(m2.Matches("Super Hi"));
|
EXPECT_TRUE(m2.Matches("Super Hi"));
|
||||||
EXPECT_FALSE(m2.Matches("i"));
|
EXPECT_FALSE(m2.Matches("i"));
|
||||||
EXPECT_FALSE(m2.Matches("Hi "));
|
EXPECT_FALSE(m2.Matches("Hi "));
|
||||||
|
|
||||||
|
#if GTEST_HAS_GLOBAL_STRING
|
||||||
|
const Matcher<const ::string&> m3 = EndsWith(::string("Hi"));
|
||||||
|
EXPECT_TRUE(m3.Matches("Hi"));
|
||||||
|
EXPECT_TRUE(m3.Matches("Wow Hi Hi"));
|
||||||
|
EXPECT_TRUE(m3.Matches("Super Hi"));
|
||||||
|
EXPECT_FALSE(m3.Matches("i"));
|
||||||
|
EXPECT_FALSE(m3.Matches("Hi "));
|
||||||
|
#endif // GTEST_HAS_GLOBAL_STRING
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
const Matcher<const absl::string_view&> m4 = EndsWith("");
|
||||||
|
EXPECT_TRUE(m4.Matches("Hi"));
|
||||||
|
EXPECT_TRUE(m4.Matches(""));
|
||||||
|
// Default-constructed absl::string_view should not match anything, in order
|
||||||
|
// to distinguish it from an empty string.
|
||||||
|
EXPECT_FALSE(m4.Matches(absl::string_view()));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(EndsWithTest, CanDescribeSelf) {
|
TEST(EndsWithTest, CanDescribeSelf) {
|
||||||
|
@ -1511,6 +1708,18 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
|
||||||
EXPECT_TRUE(m2.Matches("azbz"));
|
EXPECT_TRUE(m2.Matches("azbz"));
|
||||||
EXPECT_FALSE(m2.Matches("az1"));
|
EXPECT_FALSE(m2.Matches("az1"));
|
||||||
EXPECT_FALSE(m2.Matches("1az"));
|
EXPECT_FALSE(m2.Matches("1az"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
const Matcher<const absl::string_view&> m3 = MatchesRegex("a.*z");
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("az")));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("abcz")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("1az")));
|
||||||
|
// Default-constructed absl::string_view should not match anything, in order
|
||||||
|
// to distinguish it from an empty string.
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view()));
|
||||||
|
const Matcher<const absl::string_view&> m4 = MatchesRegex("");
|
||||||
|
EXPECT_FALSE(m4.Matches(absl::string_view()));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MatchesRegexTest, CanDescribeSelf) {
|
TEST(MatchesRegexTest, CanDescribeSelf) {
|
||||||
|
@ -1519,6 +1728,11 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
|
||||||
|
|
||||||
Matcher<const char*> m2 = MatchesRegex(new RE("a.*"));
|
Matcher<const char*> m2 = MatchesRegex(new RE("a.*"));
|
||||||
EXPECT_EQ("matches regular expression \"a.*\"", Describe(m2));
|
EXPECT_EQ("matches regular expression \"a.*\"", Describe(m2));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view> m3 = MatchesRegex(new RE("0.*"));
|
||||||
|
EXPECT_EQ("matches regular expression \"0.*\"", Describe(m3));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests ContainsRegex().
|
// Tests ContainsRegex().
|
||||||
|
@ -1533,6 +1747,18 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
|
||||||
EXPECT_TRUE(m2.Matches("azbz"));
|
EXPECT_TRUE(m2.Matches("azbz"));
|
||||||
EXPECT_TRUE(m2.Matches("az1"));
|
EXPECT_TRUE(m2.Matches("az1"));
|
||||||
EXPECT_FALSE(m2.Matches("1a"));
|
EXPECT_FALSE(m2.Matches("1a"));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
const Matcher<const absl::string_view&> m3 = ContainsRegex(new RE("a.*z"));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("azbz")));
|
||||||
|
EXPECT_TRUE(m3.Matches(absl::string_view("az1")));
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view("1a")));
|
||||||
|
// Default-constructed absl::string_view should not match anything, in order
|
||||||
|
// to distinguish it from an empty string.
|
||||||
|
EXPECT_FALSE(m3.Matches(absl::string_view()));
|
||||||
|
const Matcher<const absl::string_view&> m4 = ContainsRegex("");
|
||||||
|
EXPECT_FALSE(m4.Matches(absl::string_view()));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ContainsRegexTest, CanDescribeSelf) {
|
TEST(ContainsRegexTest, CanDescribeSelf) {
|
||||||
|
@ -1541,6 +1767,11 @@ TEST(ContainsRegexTest, CanDescribeSelf) {
|
||||||
|
|
||||||
Matcher<const char*> m2 = ContainsRegex(new RE("a.*"));
|
Matcher<const char*> m2 = ContainsRegex(new RE("a.*"));
|
||||||
EXPECT_EQ("contains regular expression \"a.*\"", Describe(m2));
|
EXPECT_EQ("contains regular expression \"a.*\"", Describe(m2));
|
||||||
|
|
||||||
|
#if GTEST_HAS_ABSL
|
||||||
|
Matcher<const absl::string_view> m3 = ContainsRegex(new RE("0.*"));
|
||||||
|
EXPECT_EQ("contains regular expression \"0.*\"", Describe(m3));
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests for wide strings.
|
// Tests for wide strings.
|
||||||
|
|
|
@ -157,7 +157,7 @@ namespace edit_distance {
|
||||||
// Returns the optimal edits to go from 'left' to 'right'.
|
// Returns the optimal edits to go from 'left' to 'right'.
|
||||||
// All edits cost the same, with replace having lower priority than
|
// All edits cost the same, with replace having lower priority than
|
||||||
// add/remove.
|
// add/remove.
|
||||||
// Simple implementation of the Wagner–Fischer algorithm.
|
// Simple implementation of the Wagner-Fischer algorithm.
|
||||||
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
||||||
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
||||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||||
|
|
|
@ -228,10 +228,9 @@
|
||||||
//
|
//
|
||||||
// Regular expressions:
|
// Regular expressions:
|
||||||
// RE - a simple regular expression class using the POSIX
|
// RE - a simple regular expression class using the POSIX
|
||||||
// Extended Regular Expression syntax on UNIX-like
|
// Extended Regular Expression syntax on UNIX-like platforms
|
||||||
// platforms, or a reduced regular exception syntax on
|
// or a reduced regular exception syntax on other
|
||||||
// other platforms, including Windows.
|
// platforms, including Windows.
|
||||||
//
|
|
||||||
// Logging:
|
// Logging:
|
||||||
// GTEST_LOG_() - logs messages at the specified severity level.
|
// GTEST_LOG_() - logs messages at the specified severity level.
|
||||||
// LogToStderr() - directs all log messages to stderr.
|
// LogToStderr() - directs all log messages to stderr.
|
||||||
|
@ -652,7 +651,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||||
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
|
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
|
||||||
# define GTEST_HAS_TR1_TUPLE 0
|
# define GTEST_HAS_TR1_TUPLE 0
|
||||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
|
# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
|
||||||
// Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.`
|
// Prevent `warning C4996: 'std::tr1': warning STL4002:
|
||||||
|
// The non-Standard std::tr1 namespace and TR1-only machinery
|
||||||
|
// are deprecated and will be REMOVED.`
|
||||||
|
# define GTEST_HAS_TR1_TUPLE 0
|
||||||
|
# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
|
||||||
|
// libc++ doesn't support TR1.
|
||||||
# define GTEST_HAS_TR1_TUPLE 0
|
# define GTEST_HAS_TR1_TUPLE 0
|
||||||
# else
|
# else
|
||||||
// The user didn't tell us not to do it, so we assume it's OK.
|
// The user didn't tell us not to do it, so we assume it's OK.
|
||||||
|
@ -663,6 +667,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||||
// Determines whether Google Test's own tr1 tuple implementation
|
// Determines whether Google Test's own tr1 tuple implementation
|
||||||
// should be used.
|
// should be used.
|
||||||
#ifndef GTEST_USE_OWN_TR1_TUPLE
|
#ifndef GTEST_USE_OWN_TR1_TUPLE
|
||||||
|
// We use our own tuple implementation on Symbian.
|
||||||
|
# if GTEST_OS_SYMBIAN
|
||||||
|
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||||
|
# else
|
||||||
// The user didn't tell us, so we need to figure it out.
|
// The user didn't tell us, so we need to figure it out.
|
||||||
|
|
||||||
// We use our own TR1 tuple if we aren't sure the user has an
|
// We use our own TR1 tuple if we aren't sure the user has an
|
||||||
|
@ -693,12 +701,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||||
# else
|
# else
|
||||||
# define GTEST_USE_OWN_TR1_TUPLE 1
|
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||||
# endif
|
# endif
|
||||||
|
# endif // GTEST_OS_SYMBIAN
|
||||||
#endif // GTEST_USE_OWN_TR1_TUPLE
|
#endif // GTEST_USE_OWN_TR1_TUPLE
|
||||||
|
|
||||||
// To avoid conditional compilation everywhere, we make it
|
// To avoid conditional compilation we make it gtest-port.h's responsibility
|
||||||
// gtest-port.h's responsibility to #include the header implementing
|
// to #include the header implementing tuple.
|
||||||
// tuple.
|
|
||||||
#if GTEST_HAS_STD_TUPLE_
|
#if GTEST_HAS_STD_TUPLE_
|
||||||
# include <tuple> // IWYU pragma: export
|
# include <tuple> // IWYU pragma: export
|
||||||
# define GTEST_TUPLE_NAMESPACE_ ::std
|
# define GTEST_TUPLE_NAMESPACE_ ::std
|
||||||
|
@ -713,22 +720,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||||
|
|
||||||
# if GTEST_USE_OWN_TR1_TUPLE
|
# if GTEST_USE_OWN_TR1_TUPLE
|
||||||
# include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
|
# include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
|
||||||
# elif GTEST_ENV_HAS_STD_TUPLE_
|
|
||||||
# include <tuple>
|
|
||||||
// C++11 puts its tuple into the ::std namespace rather than
|
|
||||||
// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there.
|
|
||||||
// This causes undefined behavior, but supported compilers react in
|
|
||||||
// the way we intend.
|
|
||||||
namespace std {
|
|
||||||
namespace tr1 {
|
|
||||||
using ::std::get;
|
|
||||||
using ::std::make_tuple;
|
|
||||||
using ::std::tuple;
|
|
||||||
using ::std::tuple_element;
|
|
||||||
using ::std::tuple_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# elif GTEST_OS_SYMBIAN
|
# elif GTEST_OS_SYMBIAN
|
||||||
|
|
||||||
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
|
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
|
||||||
|
@ -763,10 +754,12 @@ using ::std::tuple_size;
|
||||||
# include <tr1/tuple> // NOLINT
|
# include <tr1/tuple> // NOLINT
|
||||||
# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
|
# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
|
||||||
|
|
||||||
# else
|
// VS 2010 now has tr1 support.
|
||||||
// If the compiler is not GCC 4.0+, we assume the user is using a
|
# elif _MSC_VER >= 1600
|
||||||
// spec-conforming TR1 implementation.
|
|
||||||
# include <tuple> // IWYU pragma: export // NOLINT
|
# include <tuple> // IWYU pragma: export // NOLINT
|
||||||
|
|
||||||
|
# else // GTEST_USE_OWN_TR1_TUPLE
|
||||||
|
# include <tr1/tuple> // IWYU pragma: export // NOLINT
|
||||||
# endif // GTEST_USE_OWN_TR1_TUPLE
|
# endif // GTEST_USE_OWN_TR1_TUPLE
|
||||||
|
|
||||||
#endif // GTEST_HAS_TR1_TUPLE
|
#endif // GTEST_HAS_TR1_TUPLE
|
||||||
|
@ -2093,8 +2086,13 @@ class MutexBase {
|
||||||
extern ::testing::internal::MutexBase mutex
|
extern ::testing::internal::MutexBase mutex
|
||||||
|
|
||||||
// Defines and statically (i.e. at link time) initializes a static mutex.
|
// Defines and statically (i.e. at link time) initializes a static mutex.
|
||||||
|
// The initialization list here does not explicitly initialize each field,
|
||||||
|
// instead relying on default initialization for the unspecified fields. In
|
||||||
|
// particular, the owner_ field (a pthread_t) is not explicitly initialized.
|
||||||
|
// This allows initialization to work whether pthread_t is a scalar or struct.
|
||||||
|
// The flag -Wmissing-field-initializers must not be specified for this to work.
|
||||||
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
||||||
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() }
|
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
|
||||||
|
|
||||||
// The Mutex class can only be used for mutexes created at runtime. It
|
// The Mutex class can only be used for mutexes created at runtime. It
|
||||||
// shares its API with MutexBase otherwise.
|
// shares its API with MutexBase otherwise.
|
||||||
|
|
|
@ -4621,6 +4621,11 @@ void UnitTest::AddTestPartResult(
|
||||||
// when a failure happens and both the --gtest_break_on_failure and
|
// when a failure happens and both the --gtest_break_on_failure and
|
||||||
// the --gtest_catch_exceptions flags are specified.
|
// the --gtest_catch_exceptions flags are specified.
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
|
#elif (!defined(__native_client__)) && \
|
||||||
|
((defined(__clang__) || defined(__GNUC__)) && \
|
||||||
|
(defined(__x86_64__) || defined(__i386__)))
|
||||||
|
// with clang/gcc we can achieve the same effect on x86 by invoking int3
|
||||||
|
asm("int3");
|
||||||
#else
|
#else
|
||||||
// Dereference NULL through a volatile pointer to prevent the compiler
|
// Dereference NULL through a volatile pointer to prevent the compiler
|
||||||
// from removing. We use this rather than abort() or __builtin_trap() for
|
// from removing. We use this rather than abort() or __builtin_trap() for
|
||||||
|
|
|
@ -7572,7 +7572,7 @@ TEST(IsHashTable, Basic) {
|
||||||
EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
|
EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_LANG_CXX11
|
||||||
#if GTEST_HAS_HASH_SET_
|
#if GTEST_HAS_HASH_SET_
|
||||||
EXPECT_TRUE(testing::internal::IsHashTable<hash_set<int>>::value);
|
EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set<int>>::value);
|
||||||
#endif // GTEST_HAS_HASH_SET_
|
#endif // GTEST_HAS_HASH_SET_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user