Commit 32886411 authored by robpercival's avatar robpercival Committed by Commit bot

GMock matchers for net::Error

Provides more informative test failure messages.

Review-Url: https://codereview.chromium.org/2111093002
Cr-Commit-Position: refs/heads/master@{#403426}
parent c09af045
......@@ -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) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment