mirror of
https://github.com/google/googletest.git
synced 2025-11-08 14:23:46 -05:00
Googletest export
Introduce a new matcher for unescaping Base-64 strings to gmock. PiperOrigin-RevId: 388471904
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -447,6 +447,8 @@ struct Function<R(Args...)> {
|
||||
template <typename R, typename... Args>
|
||||
constexpr size_t Function<R(Args...)>::ArgumentCount;
|
||||
|
||||
bool Base64Unescape(const std::string& encoded, std::string* decoded);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user