diff options
author | Abseil Team <absl-team@google.com> | 2021-08-03 16:19:54 (GMT) |
---|---|---|
committer | Andy Soffer <asoffer@google.com> | 2021-08-04 17:54:39 (GMT) |
commit | 652ec31f9f53ab34af1257e5e2783d77e872ed45 (patch) | |
tree | 5e2b03cd82d06d80cfe1637642e133bac3abecbf /googlemock/include/gmock/gmock-matchers.h | |
parent | c22ce88775eaa364d085de7741a3625f3f0d5055 (diff) | |
download | googletest-652ec31f9f53ab34af1257e5e2783d77e872ed45.zip googletest-652ec31f9f53ab34af1257e5e2783d77e872ed45.tar.gz googletest-652ec31f9f53ab34af1257e5e2783d77e872ed45.tar.bz2 |
Googletest export
Introduce a new matcher for unescaping Base-64 strings to gmock.
PiperOrigin-RevId: 388471904
Diffstat (limited to 'googlemock/include/gmock/gmock-matchers.h')
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 8c5ccb7..244dd2d 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1122,6 +1122,45 @@ class EndsWithMatcher { const StringType suffix_; }; +// Implements the polymorphic WhenBase64Unescaped(matcher) matcher, which can be +// used as a Matcher<T> as long as T can be converted to a string. +class WhenBase64UnescapedMatcher { + public: + using is_gtest_matcher = void; + + explicit WhenBase64UnescapedMatcher( + const Matcher<const std::string&>& internal_matcher) + : internal_matcher_(internal_matcher) {} + + // Matches anything that can convert to std::string. + template <typename MatcheeStringType> + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* listener) const { + const std::string s2(s); // NOLINT (needed for working with string_view). + std::string unescaped; + if (!internal::Base64Unescape(s2, &unescaped)) { + if (listener != nullptr) { + *listener << "is not a valid base64 escaped string"; + } + return false; + } + return MatchPrintAndExplain(unescaped, internal_matcher_, listener); + } + + void DescribeTo(::std::ostream* os) const { + *os << "matches after Base64Unescape "; + internal_matcher_.DescribeTo(os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "does not match after Base64Unescape "; + internal_matcher_.DescribeTo(os); + } + + private: + const Matcher<const std::string&> internal_matcher_; +}; + // Implements a matcher that compares the two fields of a 2-tuple // using one of the ==, <=, <, etc, operators. The two fields being // compared don't have to have the same type. @@ -4986,6 +5025,14 @@ inline internal::AddressMatcher<InnerMatcher> Address( const InnerMatcher& inner_matcher) { return internal::AddressMatcher<InnerMatcher>(inner_matcher); } + +// Matches a base64 escaped string, when the unescaped string matches the +// internal matcher. +template <typename MatcherType> +internal::WhenBase64UnescapedMatcher WhenBase64Unescaped( + const MatcherType& internal_matcher) { + return internal::WhenBase64UnescapedMatcher(internal_matcher); +} } // namespace no_adl // Returns a predicate that is satisfied by anything that matches the |