Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: net/test/gtest_util.h

Issue 2615383002: Implement StringPieceHasSubstrMatcher. (Closed)
Patch Set: Rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http2/hpack/decoder/hpack_whole_entry_buffer_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/gtest_util.h
diff --git a/net/test/gtest_util.h b/net/test/gtest_util.h
index 22d82b0bfa91f062d8586ce2e429a6731b195c30..dec0bb9b39606585d61f5b785c36c09d1a37f149 100644
--- a/net/test/gtest_util.h
+++ b/net/test/gtest_util.h
@@ -7,9 +7,14 @@
#ifndef NET_TEST_GTEST_UTIL_H_
#define NET_TEST_GTEST_UTIL_H_
+#include <string>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
#include "base/test/mock_log.h"
#include "net/base/net_errors.h"
#include "net/test/scoped_disable_exit_on_dfatal.h"
+#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -36,6 +41,34 @@ MATCHER(IsOk,
return arg == net::OK;
}
+// A gMock matcher for base::StringPiece arguments.
+// gMock's built-in HasSubstrMatcher does not work,
+// because base::StringPiece cannot be implicitly converted to std::string.
+class StringPieceHasSubstrMatcher {
+ public:
+ explicit StringPieceHasSubstrMatcher(const std::string& substring)
+ : substring_(substring) {}
+
+ bool MatchAndExplain(base::StringPiece s,
+ ::testing::MatchResultListener* listener) const {
+ return s.as_string().find(substring_) != std::string::npos;
+ }
+
+ // Describe what this matcher matches.
+ void DescribeTo(std::ostream* os) const {
+ *os << "has substring " << substring_;
+ }
+
+ void DescribeNegationTo(std::ostream* os) const {
+ *os << "has no substring " << substring_;
+ }
+
+ private:
+ const std::string substring_;
+
+ DISALLOW_ASSIGN(StringPieceHasSubstrMatcher);
+};
+
// Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL
// macros. Do not use this directly.
#define GTEST_DFATAL_(statement, severity, matcher, fail) \
« no previous file with comments | « net/http2/hpack/decoder/hpack_whole_entry_buffer_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698