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

Unified Diff: net/test/gtest_util.h

Issue 2111093002: GMock matchers for net::Error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | 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 2769c34d588c8cc3fdb15adc563c5ca6a825be10..f8b4cf573c287648c6e8be25c4e8ba05b304718b 100644
--- a/net/test/gtest_util.h
+++ b/net/test/gtest_util.h
@@ -8,6 +8,7 @@
#define NET_TEST_GTEST_UTIL_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.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,6 +16,26 @@
namespace net {
namespace test {
+// A GMock matcher that checks whether the argument is the expected net::Error.
+// On failure, the expected and actual net::Error names will be printed.
+// Usage: EXPECT_THAT(foo(), IsError(net::ERR_INVALID_ARGUMENT));
+MATCHER_P(IsError,
+ expected,
+ std::string(negation ? "not " : "") + net::ErrorToString(expected)) {
+ if (arg <= 0)
+ *result_listener << net::ErrorToString(arg);
+ return arg == expected;
+}
+
+// Shorthand for IsError(net::OK).
+// Usage: EXPECT_THAT(foo(), IsOk());
+MATCHER(IsOk,
+ std::string(negation ? "not " : "") + net::ErrorToString(net::OK)) {
+ if (arg <= 0)
+ *result_listener << net::ErrorToString(arg);
+ return arg == net::OK;
+}
+
// Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL
// macros. Do not use this directly.
#define GTEST_DFATAL_(statement, matcher, fail) \
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698