Commit a0580103 authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

Deleted testing/gmock_mutant.h.

Code using testing::CreateFunctor and testing::CallbackToFunctor
is usually more easily read if they used C++ lamdas instead. This
also avoids the situation where some closures needed to use BindOnce
where others BindRepeating. Finally this eliminates a GN dependency
issue identified in issue 806952.

Bug: 1007833, 806952
Change-Id: I43d103b038465501019b68a3350d1a528d5686cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1908708Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarChris Mumford <cmumford@google.com>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/master@{#714122}
parent 5db3f422
......@@ -459,7 +459,6 @@ _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join((
'^sandbox/win/',
'^services/',
'^storage/browser/',
'^testing/gmock_mutant.h',
'^testing/libfuzzer/',
'^third_party/blink/',
'^third_party/crashpad/crashpad/test/gtest_main.cc',
......
......@@ -191,7 +191,6 @@ remoting/protocol/video_stream.h
sandbox/linux/system_headers/capability.h
skia/ext/convolver_mips_dspr2.h
skia/ext/skia_commit_hash.h
testing/gmock_mutant.h
third_party/cacheinvalidation/src/google/cacheinvalidation/impl/build_constants.h
third_party/hunspell/src/hunspell/hunvisapi.h
third_party/khronos/EGL/egl.h
......
......@@ -2,16 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("gmock_mutant") {
sources = [
"gmock_mutant.h", # gMock helpers
]
deps = [
"//base",
]
}
# Used by linux-gcc-rel to ensure gcc doesn't choke on clang-only flags.
executable("empty_main") {
sources = [
......
......@@ -6,8 +6,6 @@
# it stabilizes, Chromium code MUST use this target instead of reaching directly
# into //third_party/googletest.
import("//build_overrides/build.gni")
source_set("gmock") {
testonly = true
sources = [
......@@ -20,17 +18,6 @@ source_set("gmock") {
"//third_party/googletest:gmock",
]
# TODO(crbug.com/806952): Depending on gmock_mutant only if build_with_chromium,
# because gmock_mutant depends on //base which uses C++14. Since gmock is a
# third_party library used by other projects it should not include C++14 only code.
if (build_with_chromium) {
# Allow Chromium targets depending on gmock to #include testing/gmock_mutant.h
# without triggering a `gn check` error.
public_deps = [
"//testing:gmock_mutant",
]
}
public_configs = [
"//third_party/googletest:gmock_config",
"//third_party/googletest:gtest_config",
......
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TESTING_GMOCK_MUTANT_H_
#define TESTING_GMOCK_MUTANT_H_
// The intention of this file is to make possible using GMock actions in
// all of its syntactic beauty.
//
//
// Sample usage with gMock:
//
// struct Mock : public ObjectDelegate {
// MOCK_METHOD2(string, OnRequest(int n, const string& request));
// MOCK_METHOD1(void, OnQuit(int exit_code));
// MOCK_METHOD2(void, LogMessage(int level, const string& message));
//
// string HandleFlowers(const string& reply, int n, const string& request) {
// string result = SStringPrintf("In request of %d %s ", n, request);
// for (int i = 0; i < n; ++i) result.append(reply)
// return result;
// }
//
// void DoLogMessage(int level, const string& message) {
// }
//
// void QuitMessageLoop(int seconds) {
// base::MessageLoop* loop = base::MessageLoop::current();
// loop->PostDelayedTask(FROM_HERE,
// base::MessageLoop::QuitWhenIdleClosure(),
// 1000 * seconds);
// }
// };
//
// Mock mock;
// // Will invoke mock.HandleFlowers("orchids", n, request)
// // "orchids" is a pre-bound argument, and <n> and <request> are call-time
// // arguments - they are not known until the OnRequest mock is invoked.
// EXPECT_CALL(mock, OnRequest(Ge(5), base::StartsWith("flower"))
// .Times(1)
// .WillOnce(Invoke(CreateFunctor(
// &Mock::HandleFlowers, base::Unretained(&mock), string("orchids"))));
//
//
// // No pre-bound arguments, two call-time arguments passed
// // directly to DoLogMessage
// EXPECT_CALL(mock, OnLogMessage(_, _))
// .Times(AnyNumber())
// .WillAlways(Invoke(CreateFunctor(
// &Mock::DoLogMessage, base::Unretained(&mock))));
//
//
// // In this case we have a single pre-bound argument - 3. We ignore
// // all of the arguments of OnQuit.
// EXCEPT_CALL(mock, OnQuit(_))
// .Times(1)
// .WillOnce(InvokeWithoutArgs(CreateFunctor(
// &Mock::QuitMessageLoop, base::Unretained(&mock), 3)));
//
// MessageLoop loop;
// loop.Run();
//
//
// // Here is another example of how we can set an action that invokes
// // method of an object that is not yet created.
// struct Mock : public ObjectDelegate {
// MOCK_METHOD1(void, DemiurgeCreated(Demiurge*));
// MOCK_METHOD2(void, OnRequest(int count, const string&));
//
// void StoreDemiurge(Demiurge* w) {
// demiurge_ = w;
// }
//
// Demiurge* demiurge;
// }
//
// EXPECT_CALL(mock, DemiurgeCreated(_)).Times(1)
// .WillOnce(Invoke(CreateFunctor(
// &Mock::StoreDemiurge, base::Unretained(&mock))));
//
// EXPECT_CALL(mock, OnRequest(_, StrEq("Moby Dick")))
// .Times(AnyNumber())
// .WillAlways(WithArgs<0>(Invoke(CreateFunctor(
// &Demiurge::DecreaseMonsters, base::Unretained(&mock->demiurge_)))));
//
#include "base/bind.h"
namespace testing {
template <typename Signature>
class CallbackToFunctorHelper;
template <typename R, typename... Args>
class CallbackToFunctorHelper<R(Args...)> {
public:
explicit CallbackToFunctorHelper(const base::Callback<R(Args...)>& cb)
: cb_(cb) {}
template <typename... RunArgs>
R operator()(RunArgs&&... args) {
return cb_.Run(std::forward<RunArgs>(args)...);
}
private:
base::Callback<R(Args...)> cb_;
};
template <typename Signature>
CallbackToFunctorHelper<Signature>
CallbackToFunctor(const base::Callback<Signature>& cb) {
return CallbackToFunctorHelper<Signature>(cb);
}
template <typename Functor>
CallbackToFunctorHelper<typename Functor::RunType> CreateFunctor(
Functor functor) {
return CallbackToFunctor(functor);
}
template <typename Functor, typename... BoundArgs>
CallbackToFunctorHelper<base::MakeUnboundRunType<Functor, BoundArgs...>>
CreateFunctor(Functor functor, const BoundArgs&... args) {
return CallbackToFunctor(base::Bind(functor, args...));
}
} // namespace testing
#endif // TESTING_GMOCK_MUTANT_H_
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