Googletest export
Merge CONTRIBUTORS, delete LICENSEs in googletest/ and googlemock/ PiperOrigin-RevId: 352558822
This commit is contained in:
parent
d128fc8252
commit
14098f2015
@ -5,34 +5,59 @@
|
||||
|
||||
Ajay Joshi <jaj@google.com>
|
||||
Balázs Dán <balazs.dan@gmail.com>
|
||||
Benoit Sigoure <tsuna@google.com>
|
||||
Bharat Mediratta <bharat@menalto.com>
|
||||
Bogdan Piloca <boo@google.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Chris Prince <cprince@google.com>
|
||||
Chris Taylor <taylorc@google.com>
|
||||
Dan Egnor <egnor@google.com>
|
||||
Dave MacLachlan <dmaclach@gmail.com>
|
||||
David Anderson <danderson@google.com>
|
||||
Dean Sturtevant
|
||||
Eric Roman <eroman@chromium.org>
|
||||
Gene Volovich <gv@cite.com>
|
||||
Hady Zalek <hady.zalek@gmail.com>
|
||||
Hal Burch <gmock@hburch.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jim Keller <jimkeller@google.com>
|
||||
Joe Walnes <joe@truemesh.com>
|
||||
Jon Wray <jwray@google.com>
|
||||
Jói Sigurðsson <joi@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kenton Varda <kenton@google.com>
|
||||
Kostya Serebryany <kcc@google.com>
|
||||
Krystian Kuzniarek <krystian.kuzniarek@gmail.com>
|
||||
Lev Makhlis
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Mario Tanev <radix@google.com>
|
||||
Mark Paskin
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Matthew Simmons <simmonmt@acm.org>
|
||||
Mika Raento <mikie@iki.fi>
|
||||
Mike Bland <mbland@google.com>
|
||||
Miklós Fazekas <mfazekas@szemafor.com>
|
||||
Neal Norwitz <nnorwitz@gmail.com>
|
||||
Nermin Ozkiranartli <nermin@google.com>
|
||||
Owen Carlsen <ocarlsen@google.com>
|
||||
Paneendra Ba <paneendra@google.com>
|
||||
Pasi Valminen <pasi.valminen@gmail.com>
|
||||
Patrick Hanna <phanna@google.com>
|
||||
Patrick Riley <pfr@google.com>
|
||||
Paul Menage <menage@google.com>
|
||||
Peter Kaminski <piotrk@google.com>
|
||||
Piotr Kaminski <piotrk@google.com>
|
||||
Preston Jackson <preston.a.jackson@gmail.com>
|
||||
Rainer Klaffenboeck <rainer.klaffenboeck@dynatrace.com>
|
||||
Russ Cox <rsc@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sean Mcafee <eefacm@gmail.com>
|
||||
Sigurður Ásgeirsson <siggi@google.com>
|
||||
Sverre Sundsdal <sundsdal@gmail.com>
|
||||
Takeshi Yoshino <tyoshino@google.com>
|
||||
Tracy Bialik <tracy@pentad.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Wolfgang Klier <wklier@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
@ -1,8 +1,8 @@
|
||||
# Advanced googletest Topics
|
||||
|
||||
<!-- GOOGLETEST_CM0016 DO NOT DELETE -->
|
||||
go/gunitadvanced
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
## Introduction
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
# Googletest FAQ
|
||||
|
||||
<!-- GOOGLETEST_CM0014 DO NOT DELETE -->
|
||||
go/gunitfaq
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
## Why should test suite names and test names not contain underscore?
|
||||
|
||||
@ -350,7 +350,7 @@ You may still want to use `SetUp()/TearDown()` in the following cases:
|
||||
* In the body of a constructor (or destructor), it's not possible to use the
|
||||
`ASSERT_xx` macros. Therefore, if the set-up operation could cause a fatal
|
||||
test failure that should prevent the test from running, it's necessary to
|
||||
use `abort` <!-- GOOGLETEST_CM0015 DO NOT DELETE --> and abort the whole test executable,
|
||||
use `abort` (in google3, use `CHECK`) and abort the whole test executable,
|
||||
or to use `SetUp()` instead of a constructor.
|
||||
* If the tear-down operation could throw an exception, you must use
|
||||
`TearDown()` as opposed to the destructor, as throwing in a destructor leads
|
||||
|
@ -1,10 +1,10 @@
|
||||
# gMock Cheat Sheet
|
||||
|
||||
<!-- GOOGLETEST_CM0019 DO NOT DELETE -->
|
||||
go/gmockcheat
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
<!-- GOOGLETEST_CM0033 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_BUILD_rule.md"-->
|
||||
|
||||
## Defining a Mock Class
|
||||
|
||||
@ -229,7 +229,7 @@ and the default action will be taken each time.
|
||||
|
||||
## Matchers {#MatcherList}
|
||||
|
||||
<!-- GOOGLETEST_CM0020 DO NOT DELETE -->
|
||||
go/matchers
|
||||
|
||||
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
|
||||
`EXPECT_CALL()`, or use it to validate a value directly using two macros:
|
||||
@ -424,9 +424,9 @@ messages, you can use:
|
||||
| `WhenDynamicCastTo<T>(m)` | when `argument` is passed through `dynamic_cast<T>()`, it matches matcher `m`. |
|
||||
<!-- mdformat on -->
|
||||
|
||||
<!-- GOOGLETEST_CM0026 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_proto_matchers.md"-->
|
||||
|
||||
<!-- GOOGLETEST_CM0027 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_absl_status_matcher.md"-->
|
||||
|
||||
### Multi-argument Matchers {#MultiArgMatchers}
|
||||
|
||||
@ -467,7 +467,7 @@ You can make a matcher from one or more other matchers:
|
||||
| `Not(m)` | `argument` doesn't match matcher `m`. |
|
||||
<!-- mdformat on -->
|
||||
|
||||
<!-- GOOGLETEST_CM0028 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_useful_matchers_outsidegmock.md"-->
|
||||
|
||||
### Adapters for Matchers
|
||||
|
||||
@ -612,7 +612,7 @@ value, and `foo` by reference.
|
||||
**Note:** due to technical reasons, `DoDefault()` cannot be used inside a
|
||||
composite action - trying to do so will result in a run-time error.
|
||||
|
||||
<!-- GOOGLETEST_CM0032 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_stubby_actions.md"-->
|
||||
|
||||
### Composite Actions
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# gMock Cookbook
|
||||
|
||||
<!-- GOOGLETEST_CM0012 DO NOT DELETE -->
|
||||
go/gmockcook
|
||||
|
||||
You can find recipes for using gMock here. If you haven't yet, please read
|
||||
[the dummy guide](gmock_for_dummies.md) first to make sure you understand the
|
||||
@ -11,7 +11,7 @@ recommended to write `using ::testing::Foo;` once in your file before using the
|
||||
name `Foo` defined by gMock. We omit such `using` statements in this section for
|
||||
brevity, but you should do it in your own code.
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
## Creating Mock Classes
|
||||
|
||||
@ -184,7 +184,7 @@ class MockStack : public StackInterface<Elem> {
|
||||
### Mocking Non-virtual Methods {#MockingNonVirtualMethods}
|
||||
|
||||
gMock can mock non-virtual functions to be used in Hi-perf dependency
|
||||
injection.<!-- GOOGLETEST_CM0017 DO NOT DELETE -->
|
||||
injection.[See this](http://go/tott/33)
|
||||
|
||||
In this case, instead of sharing a common base class with the real class, your
|
||||
mock class will be *unrelated* to the real class, but contain methods with the
|
||||
@ -830,7 +830,7 @@ A frequently used matcher is `_`, which matches anything:
|
||||
```cpp
|
||||
EXPECT_CALL(foo, DoThat(_, NotNull()));
|
||||
```
|
||||
<!-- GOOGLETEST_CM0022 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_matching_proto_buffers_cookbook_recipe.md"-->
|
||||
|
||||
### Combining Matchers {#CombiningMatchers}
|
||||
|
||||
@ -1161,7 +1161,7 @@ Note that the predicate function / functor doesn't have to return `bool`. It
|
||||
works as long as the return value can be used as the condition in in statement
|
||||
`if (condition) ...`.
|
||||
|
||||
<!-- GOOGLETEST_CM0023 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_callbacks_as_matchers.md"-->
|
||||
|
||||
### Matching Arguments that Are Not Copyable
|
||||
|
||||
@ -1478,7 +1478,7 @@ mock object and gMock.
|
||||
|
||||
### Knowing When to Expect {#UseOnCall}
|
||||
|
||||
<!-- GOOGLETEST_CM0018 DO NOT DELETE -->
|
||||
(go/use-on-call)
|
||||
|
||||
**`ON_CALL`** is likely the *single most under-utilized construct* in gMock.
|
||||
|
||||
@ -2171,7 +2171,7 @@ own precedence order distinct from the `ON_CALL` precedence order.
|
||||
If the built-in actions don't suit you, you can use an existing callable
|
||||
(function, `std::function`, method, functor, lambda) as an action.
|
||||
|
||||
<!-- GOOGLETEST_CM0024 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_callback_snippet.md"-->
|
||||
|
||||
```cpp
|
||||
using ::testing::_; using ::testing::Invoke;
|
||||
@ -3266,7 +3266,7 @@ If you are interested in the mock call trace but not the stack traces, you can
|
||||
combine `--gmock_verbose=info` with `--gtest_stack_trace_depth=0` on the test
|
||||
command line.
|
||||
|
||||
<!-- GOOGLETEST_CM0025 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_testing_code_stubby_server.md"-->
|
||||
|
||||
### Running Tests in Emacs
|
||||
|
||||
@ -4313,4 +4313,4 @@ Although `std::function` supports unlimited number of arguments, `MockFunction`
|
||||
implementation is limited to ten. If you ever hit that limit... well, your
|
||||
callback has bigger problems than being mockable. :-)
|
||||
|
||||
<!-- GOOGLETEST_CM0034 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_content.md"-->
|
||||
|
@ -1,8 +1,8 @@
|
||||
## Legacy gMock FAQ {#GMockFaq}
|
||||
|
||||
<!-- GOOGLETEST_CM0021 DO NOT DELETE -->
|
||||
go/gmockfaq
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
### When I call a method on my mock object, the method for the real object is invoked instead. What's the problem?
|
||||
|
||||
@ -83,7 +83,7 @@ void Bar(int* p); // Neither p nor *p is const.
|
||||
void Bar(const int* p); // p is not const, but *p is.
|
||||
```
|
||||
|
||||
<!-- GOOGLETEST_CM0030 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_mock_multithreaded.md"-->
|
||||
|
||||
### I can't figure out why gMock thinks my expectations are not satisfied. What should I do?
|
||||
|
||||
@ -128,7 +128,7 @@ using ::testing::_;
|
||||
.Times(0);
|
||||
```
|
||||
|
||||
<!-- GOOGLETEST_CM0031 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_mock_a_stubby_server.md"-->
|
||||
|
||||
### I have a failed test where gMock tells me TWICE that a particular expectation is not satisfied. Isn't this redundant?
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
# gMock for Dummies {#GMockForDummies}
|
||||
|
||||
<!-- GOOGLETEST_CM0013 DO NOT DELETE -->
|
||||
go/gmockfordummies
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
## What Is gMock?
|
||||
|
||||
@ -208,7 +208,7 @@ choosing the adaptor interface can make your code easier to write and more
|
||||
readable (a net win in the long run), as you can choose `FooAdaptor` to fit your
|
||||
specific domain much better than `Foo` does.
|
||||
|
||||
<!-- GOOGLETEST_CM0029 DO NOT DELETE -->
|
||||
<!--#include file="includes/g3_wrap_external_api_snippet.md"-->
|
||||
|
||||
## Using Mocks in Tests
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
## Using GoogleTest from various build systems
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
GoogleTest comes with pkg-config files that can be used to determine all
|
||||
necessary flags for compiling and linking to GoogleTest (and GoogleMock).
|
||||
|
@ -1,8 +1,8 @@
|
||||
# Googletest Primer
|
||||
|
||||
<!-- GOOGLETEST_CM0036 DO NOT DELETE -->
|
||||
go/gunitprimer
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
## Introduction: Why googletest?
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<b>P</b>ump is <b>U</b>seful for <b>M</b>eta <b>P</b>rogramming.
|
||||
|
||||
<!-- GOOGLETEST_CM0035 DO NOT DELETE -->
|
||||
[TOC]
|
||||
|
||||
# The Problem
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Mocking Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Benoit Sigoure <tsuna@google.com>
|
||||
Bogdan Piloca <boo@google.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Dave MacLachlan <dmaclach@gmail.com>
|
||||
David Anderson <danderson@google.com>
|
||||
Dean Sturtevant
|
||||
Gene Volovich <gv@cite.com>
|
||||
Hal Burch <gmock@hburch.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jim Keller <jimkeller@google.com>
|
||||
Joe Walnes <joe@truemesh.com>
|
||||
Jon Wray <jwray@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kostya Serebryany <kcc@google.com>
|
||||
Lev Makhlis
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Mario Tanev <radix@google.com>
|
||||
Mark Paskin
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Matthew Simmons <simmonmt@acm.org>
|
||||
Mike Bland <mbland@google.com>
|
||||
Neal Norwitz <nnorwitz@gmail.com>
|
||||
Nermin Ozkiranartli <nermin@google.com>
|
||||
Owen Carlsen <ocarlsen@google.com>
|
||||
Paneendra Ba <paneendra@google.com>
|
||||
Paul Menage <menage@google.com>
|
||||
Piotr Kaminski <piotrk@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sverre Sundsdal <sundsdal@gmail.com>
|
||||
Takeshi Yoshino <tyoshino@google.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Wolfgang Klier <wklier@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
@ -1,28 +0,0 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -40,8 +40,8 @@ $$}} This meta comment fixes auto-indentation in editors.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#ifndef THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
@ -387,4 +387,4 @@ InvokeArgument(Params&&... params) {
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#endif // THIRD_PARTY_GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
@ -1,10 +1,149 @@
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gmock-generated-actions.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "gmock/gmock-actions.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Implements the Invoke(callback) action.
|
||||
template <typename CallbackType, typename Signature>
|
||||
class InvokeCallbackAction;
|
||||
|
||||
template <typename CallbackType, typename R, typename... Args>
|
||||
class InvokeCallbackAction<CallbackType, R(Args...)> {
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackAction(CallbackType* callback) : callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
R operator()(Args... args) const {
|
||||
return callback_->Run(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// Implements the InvokeWithoutArgs(callback) action.
|
||||
template <typename CallbackType>
|
||||
class InvokeCallbackWithoutArgsAction {
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
|
||||
: callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto operator()(const Args&...) -> decltype(this->callback_->Run()) {
|
||||
return callback_->Run();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypeIdentity {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
inline TypeIdentity<void()> CallbackSignatureImpl(Closure*);
|
||||
template <typename R>
|
||||
TypeIdentity<R()> CallbackSignatureImpl(ResultCallback<R>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback1<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback1<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback2<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback2<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback3<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback3<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback4<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback4<R, Args...>*);
|
||||
|
||||
template <typename... Args>
|
||||
TypeIdentity<void(Args...)> CallbackSignatureImpl(Callback5<Args...>*);
|
||||
template <typename R, typename... Args>
|
||||
TypeIdentity<R(Args...)> CallbackSignatureImpl(ResultCallback5<R, Args...>*);
|
||||
|
||||
template <typename T>
|
||||
using CallbackSignature = typename decltype(
|
||||
internal::CallbackSignatureImpl(std::declval<T*>()))::type;
|
||||
|
||||
// Specialization for protocol buffers.
|
||||
// We support setting a proto2::Message, which doesn't have an assignment
|
||||
// operator.
|
||||
template <size_t N, typename A>
|
||||
struct SetArgumentPointeeAction<
|
||||
N, A,
|
||||
typename std::enable_if<std::is_base_of<proto2::Message, A>::value>::type> {
|
||||
A value;
|
||||
|
||||
template <typename... Args>
|
||||
void operator()(const Args&... args) const {
|
||||
::std::get<N>(std::tie(args...))->CopyFrom(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Add Invoke overloads for google3 Callback types.
|
||||
|
||||
template <typename C, typename... Args,
|
||||
typename = internal::CallbackSignature<C>>
|
||||
auto InvokeArgument(C* cb, Args... args) -> decltype(cb->Run(args...)) {
|
||||
return cb->Run(args...);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Add Invoke overloads for google3 Callback types.
|
||||
|
||||
// Creates an action that invokes the given callback with the mock
|
||||
// function's arguments. The action takes ownership of the callback
|
||||
// and verifies that it's permanent.
|
||||
//
|
||||
// google3 doesn't support callbacks with more than 5
|
||||
// arguments yet, so we only support invoking callbacks with up to
|
||||
// 5 arguments.
|
||||
|
||||
template <typename Callback>
|
||||
internal::InvokeCallbackAction<Callback, internal::CallbackSignature<Callback>>
|
||||
Invoke(Callback* callback) {
|
||||
return internal::InvokeCallbackAction<Callback,
|
||||
internal::CallbackSignature<Callback>>(
|
||||
callback);
|
||||
}
|
||||
|
||||
// Creates an action that invokes the given callback with no argument.
|
||||
// The action takes ownership of the callback and verifies that it's
|
||||
// permanent.
|
||||
template <typename Callback, typename = internal::CallbackSignature<Callback>>
|
||||
internal::InvokeCallbackWithoutArgsAction<Callback> InvokeWithoutArgs(
|
||||
Callback* callback) {
|
||||
return internal::InvokeCallbackWithoutArgsAction<Callback>(callback);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
@ -1,12 +0,0 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to callback-actions.h.
|
||||
$$
|
||||
$var max_callback_arity = 5
|
||||
$$}} This meta comment fixes auto-indentation in editors.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
@ -33,4 +33,39 @@
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
#include "base/callback.h"
|
||||
|
||||
// Realistically this file should be included from gmock-matchers.h
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Specialization for permanent callbacks.
|
||||
template <typename ArgType, typename ResType>
|
||||
struct CallableTraits<ResultCallback1<ResType, ArgType>*> {
|
||||
typedef ResType ResultType;
|
||||
using StorageType = std::shared_ptr<ResultCallback1<ResType, ArgType>>;
|
||||
typedef ResultCallback1<ResType, ArgType> Callback;
|
||||
|
||||
static void CheckIsValid(const StorageType& callback) {
|
||||
GTEST_CHECK_(callback != nullptr)
|
||||
<< "NULL callback is passed into ResultOf().";
|
||||
callback->CheckIsRepeatable();
|
||||
}
|
||||
template <typename T>
|
||||
static ResType Invoke(const StorageType& callback, T arg) {
|
||||
return callback->Run(arg);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
|
@ -36,4 +36,29 @@
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
// Defines this iff Google Mock can use google3 callbacks. This is
|
||||
// internal as a user shouldn't rely on Google Mock to tell him
|
||||
// whether he can use google3 callbacks.
|
||||
# include "base/callback.h"
|
||||
# define GMOCK_HAS_GOOGLE3_CALLBACK_ 1
|
||||
|
||||
// Macros for declaring flags.
|
||||
# define GMOCK_DECLARE_bool_(name) DECLARE_bool(gmock_##name)
|
||||
# define GMOCK_DECLARE_int32_(name) DECLARE_int32(gmock_##name)
|
||||
# define GMOCK_DECLARE_string_(name) DECLARE_string(gmock_##name)
|
||||
|
||||
// Macros for defining flags.
|
||||
# define GMOCK_DEFINE_bool_(name, default_val, doc) \
|
||||
DEFINE_bool(gmock_##name, default_val, doc)
|
||||
# define GMOCK_DEFINE_int32_(name, default_val, doc) \
|
||||
DEFINE_int32(gmock_##name, default_val, doc)
|
||||
# define GMOCK_DEFINE_string_(name, default_val, doc) \
|
||||
DEFINE_string(gmock_##name, default_val, doc)
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
|
170
googlemock/test/gmock-generated-actions_nc.cc
Normal file
170
googlemock/test/gmock-generated-actions_nc.cc
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file contains negative compilation tests for script-generated
|
||||
// Google Mock actions.
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
using testing::Action;
|
||||
using testing::Invoke;
|
||||
using testing::WithArgs;
|
||||
|
||||
int Nullary() { return 0; }
|
||||
int Binary(int a, int b) { return a + b; }
|
||||
|
||||
#if defined(TEST_NULLARY_WITH_ARGS)
|
||||
|
||||
// Tests that WithArgs(action) doesn't compile.
|
||||
void Test() {
|
||||
Action<int(int)> a = WithArgs(Invoke(Nullary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_TOO_FEW_ARGS_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass too few arguments to the inner action in
|
||||
// WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, int, int)> a = WithArgs<1>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_TOO_MANY_ARGS_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass too many arguments to the inner action in
|
||||
// WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, int, int)> a = WithArgs<1, 2, 0>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_INCOMPATIBLE_ARG_TYPES_FOR_WITH_ARGS)
|
||||
|
||||
// Tests that you cannot pass arguments of incompatible types to the
|
||||
// inner action in WithArgs().
|
||||
void Test() {
|
||||
Action<int(int, const char*, int)> a = WithArgs<1, 2>(Invoke(Binary));
|
||||
}
|
||||
|
||||
#elif defined(TEST_WRONG_ARG_TYPE_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function whose argument
|
||||
// types are incompatible.
|
||||
ACTION(WrongArgType) { return 10/arg0; }
|
||||
|
||||
void Test() {
|
||||
Action<int(const char*)> a = WrongArgType();
|
||||
}
|
||||
|
||||
#elif defined(TEST_WRONG_RETURN_TYPE_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function whose return
|
||||
// types is incompatible.
|
||||
ACTION(WrongReturnType) { return 10; }
|
||||
|
||||
void Test() {
|
||||
Action<const char*()> a = WrongReturnType();
|
||||
}
|
||||
|
||||
#elif defined(TEST_EXCESSIVE_ARG_IN_ACTION_MACRO)
|
||||
|
||||
// Tests using an ACTION definition in a mock function that doesn't
|
||||
// provide enough arguments.
|
||||
ACTION(UseExcessiveArg) { return arg0 + arg1; }
|
||||
|
||||
void Test() {
|
||||
Action<int(int)> a = UseExcessiveArg();
|
||||
}
|
||||
|
||||
#elif defined(TEST_ACTION_MACRO_IN_CLASS)
|
||||
|
||||
// Tests using ACTION in a class scope.
|
||||
class Foo {
|
||||
public:
|
||||
// This won't compile as C++ doesn't allow defining a method of a
|
||||
// nested class out-of-line in the enclosing class.
|
||||
ACTION(Bar) { return arg0; }
|
||||
};
|
||||
|
||||
#elif defined(TEST_ACTION_MACRO_IN_FUNCTION)
|
||||
|
||||
// Tests using ACTION in a function body.
|
||||
void Test() {
|
||||
// This won't compile as C++ doesn't allow member templates in local
|
||||
// classes. We may want to revisit this when C++0x is widely
|
||||
// implemented.
|
||||
ACTION(Bar) { return arg0; }
|
||||
}
|
||||
|
||||
#elif defined(TEST_SET_ARG_REFEREE_MUST_BE_USED_WITH_REFERENCE)
|
||||
|
||||
// Verifies that using SetArgReferee<k>(...) where the k-th argument
|
||||
// of the mock function is not a reference generates a compiler error.
|
||||
void Test() {
|
||||
Action<void(bool, int)> a = testing::SetArgReferee<1>(5);
|
||||
}
|
||||
|
||||
#elif defined(TEST_DELETE_ARG_MUST_BE_USED_WITH_POINTER)
|
||||
|
||||
// Verifies that using DeleteArg<k>(...) where the k-th argument of the mock
|
||||
// function is not a pointer generates a compiler error.
|
||||
void Test() {
|
||||
Action<void(int)> a = testing::DeleteArg<0>(); // NOLINT
|
||||
}
|
||||
|
||||
#elif defined(TEST_CANNOT_OVERLOAD_ACTION_TEMPLATE_ON_TEMPLATE_PARAM_NUMBER)
|
||||
|
||||
// Tests that ACTION_TEMPLATE cannot be overloaded on the number of
|
||||
// template parameters alone.
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_1_TEMPLATE_PARAMS(typename, T),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_2_TEMPLATE_PARAMS(typename, T1, typename, T2),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
#elif defined(TEST_CANNOT_OVERLOAD_ACTION_AND_ACTION_TEMPLATE_W_SAME_VALUE_PS)
|
||||
|
||||
// Tests that ACTION_TEMPLATE and ACTION_P cannot be overloaded when
|
||||
// they have the same number of value parameters.
|
||||
|
||||
ACTION_P(OverloadedAction, p) {}
|
||||
|
||||
ACTION_TEMPLATE(OverloadedAction,
|
||||
HAS_1_TEMPLATE_PARAMS(typename, T),
|
||||
AND_1_VALUE_PARAMS(p)) {}
|
||||
|
||||
#else
|
||||
|
||||
// Sanity check - this should compile.
|
||||
|
||||
#endif
|
137
googlemock/test/gmock_generated_actions_nc_test.py
Executable file
137
googlemock/test/gmock_generated_actions_nc_test.py
Executable file
@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2008, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# Google Mock - a framework for writing C++ mock classes.
|
||||
#
|
||||
# This file drives the negative compilation tests for script-generated
|
||||
# Google Mock actions.
|
||||
|
||||
"""Driver for the NC tests for script-generated Google Mock actions."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
IS_LINUX = os.name == "posix" and os.uname()[0] == "Linux"
|
||||
if not IS_LINUX:
|
||||
sys.stderr.write(
|
||||
"WARNING: Negative compilation tests are not supported on this platform")
|
||||
sys.exit(0)
|
||||
|
||||
# Suppresses the 'Import not at the top of the file' lint complaint.
|
||||
# pylint: disable-msg=C6204
|
||||
from google3.testing.pybase import fake_target_util
|
||||
from google3.testing.pybase import googletest
|
||||
# pylint: enable-msg=C6204
|
||||
|
||||
|
||||
class GMockGeneratedActionTest(googletest.TestCase):
|
||||
"""Negative compilation tests for generated Google Mock actions."""
|
||||
|
||||
# The class body is intentionally empty. The actual test*() methods
|
||||
# will be defined at run time by a call to
|
||||
# DefineNegativeCompilationTests() later.
|
||||
pass
|
||||
|
||||
# Defines a list of test specs, where each element is a tuple
|
||||
# (test name, list of regexes for matching the compiler errors).
|
||||
TEST_SPECS = [
|
||||
("NULLARY_WITH_ARGS", [
|
||||
r"no matching function for call to 'WithArgs",
|
||||
]),
|
||||
("TOO_FEW_ARGS_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("TOO_MANY_ARGS_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("INCOMPATIBLE_ARG_TYPES_FOR_WITH_ARGS", [
|
||||
r"no known conversion",
|
||||
]),
|
||||
("WRONG_ARG_TYPE_IN_ACTION_MACRO", [
|
||||
r"invalid operands",
|
||||
]),
|
||||
(
|
||||
"WRONG_RETURN_TYPE_IN_ACTION_MACRO",
|
||||
[
|
||||
r"invalid conversion", # GCC
|
||||
r"cannot initialize return object", # Clang
|
||||
]),
|
||||
(
|
||||
"EXCESSIVE_ARG_IN_ACTION_MACRO",
|
||||
[
|
||||
r"no match for 'operator\+'", # GCC
|
||||
r"invalid operands to binary expression", # Clang
|
||||
]),
|
||||
(
|
||||
"ACTION_MACRO_IN_CLASS",
|
||||
[
|
||||
r"cannot define member function.*Bar.*within.*Foo", # GCC
|
||||
r"ACTION\(Bar\)", # Clang
|
||||
]),
|
||||
(
|
||||
"ACTION_MACRO_IN_FUNCTION",
|
||||
[
|
||||
r"invalid declaration of member template in local class", # GCC
|
||||
r"templates cannot be declared inside of a local class", # Clang
|
||||
]),
|
||||
("SET_ARG_REFEREE_MUST_BE_USED_WITH_REFERENCE",
|
||||
[r"Argument must be a reference type"]),
|
||||
(
|
||||
"DELETE_ARG_MUST_BE_USED_WITH_POINTER",
|
||||
[
|
||||
r"argument given to 'delete', expected pointer", # GCC
|
||||
r"cannot delete expression of type", # Clang
|
||||
]),
|
||||
(
|
||||
"CANNOT_OVERLOAD_ACTION_TEMPLATE_ON_TEMPLATE_PARAM_NUMBER",
|
||||
[
|
||||
r"wrong number of template arguments", # GCC
|
||||
r"too many template parameters", # Clang
|
||||
]),
|
||||
(
|
||||
"CANNOT_OVERLOAD_ACTION_AND_ACTION_TEMPLATE_W_SAME_VALUE_PS",
|
||||
[
|
||||
r"wrong number of template arguments", # GCC
|
||||
r"too many template parameters", # Clang
|
||||
]),
|
||||
("SANITY", None),
|
||||
]
|
||||
|
||||
# Define a test method in GMockGeneratedActionTest for each element in
|
||||
# TEST_SPECS.
|
||||
fake_target_util.DefineNegativeCompilationTests(
|
||||
GMockGeneratedActionTest,
|
||||
"google3/third_party/googletest/googlemock/test/gmock-generated-actions_nc", # fake target
|
||||
"gmock-generated-actions_nc.o", # object file
|
||||
TEST_SPECS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
googletest.main()
|
@ -1,28 +0,0 @@
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -33,5 +33,170 @@
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
#include "gtest/internal/gtest-port-arch.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
// NOTE:
|
||||
// GUNIT_NO_GOOGLE3 - Only used when compiled on Linux. Define it
|
||||
// to remove dependency on google3 - some features
|
||||
// are unavailable in this mode.
|
||||
|
||||
#define GTEST_FOR_GOOGLE_ 1 // Defined to 1 iff compiled inside Google.
|
||||
|
||||
// We define these even in non-google3 mode.
|
||||
|
||||
#define GTEST_FLAG(name) FLAGS_gunit_##name
|
||||
|
||||
#define GTEST_DEV_EMAIL_ "opensource-gtest@@google.com"
|
||||
#define GTEST_FLAG_PREFIX_ "gunit_"
|
||||
#define GTEST_FLAG_PREFIX_DASH_ "gunit-"
|
||||
#define GTEST_FLAG_PREFIX_UPPER_ "GUNIT_"
|
||||
#define GTEST_NAME_ "Google Test"
|
||||
#define GTEST_PROJECT_URL_ "http://go/gunit/"
|
||||
#define GTEST_DEFAULT_DEATH_TEST_STYLE "threadsafe"
|
||||
|
||||
// OS_MACOSX is defined by Blaze, when cross-compiling (on Linux) to
|
||||
// Mac OS X.
|
||||
// See also testing/base/public/BUILD for notes about GTEST_INTERNAL_PG3_MODE.
|
||||
#if !defined(GUNIT_NO_GOOGLE3) && (GTEST_OS_CYGWIN || GTEST_OS_LINUX || \
|
||||
defined(OS_MACOSX))
|
||||
# define GTEST_GOOGLE3_MODE_ 1
|
||||
#endif
|
||||
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
#define GTEST_HAS_ABSL 1
|
||||
|
||||
#define GTEST_INIT_GOOGLE_TEST_NAME_ "InitGoogle"
|
||||
|
||||
// Tell Google Test that hash_map/hash_set are available.
|
||||
// Only used for testing.
|
||||
#define GTEST_HAS_HASH_MAP_ 1
|
||||
#define GTEST_HAS_HASH_SET_ 1
|
||||
|
||||
// base/commandlineoptions.h has its own --flagfile flag.
|
||||
# define GTEST_USE_OWN_FLAGFILE_FLAG_ 0
|
||||
|
||||
// base/commandlineflags.h provides its own GetArgvs()
|
||||
# define GTEST_CUSTOM_GET_ARGVS_() ::GetArgvs()
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/logging_extensions.h"
|
||||
#include "base/synchronization.h"
|
||||
#include "thread/thread.h"
|
||||
|
||||
// Provide the PCRE regex library.
|
||||
#include "util/regexp/re2/re2.h"
|
||||
# define GTEST_USES_PCRE 1
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
// This is almost 'using RE = ::RE2', except that it disambiguates
|
||||
// RE::RE(std::string). It cannot be merged into the RE implementation below,
|
||||
// since this version will support embedded NUL characters.
|
||||
class RE {
|
||||
public:
|
||||
RE(absl::string_view regex) : regex_(new RE2(regex)) {} // NOLINT
|
||||
RE(const char* regex) : RE(absl::string_view(regex)) {} // NOLINT
|
||||
RE(const std::string& regex) : RE(absl::string_view(regex)) {} // NOLINT
|
||||
RE(const RE& other) : RE(other.pattern()) {}
|
||||
|
||||
// Returns the string representation of the regex.
|
||||
const std::string& pattern() const { return regex_->pattern(); }
|
||||
|
||||
static bool FullMatch(absl::string_view str, const RE& re) {
|
||||
return RE2::FullMatch(str, *re.regex_);
|
||||
}
|
||||
static bool PartialMatch(absl::string_view str, const RE& re) {
|
||||
return RE2::PartialMatch(str, *re.regex_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<RE2> regex_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
// For flags.
|
||||
# include "base/commandlineflags.h"
|
||||
|
||||
#define GTEST_FLAG_SAVER_ absl::FlagSaver
|
||||
|
||||
// Macros for declaring flags.
|
||||
# define GTEST_DECLARE_bool_(name) DECLARE_bool(gunit_##name)
|
||||
# define GTEST_DECLARE_int32_(name) DECLARE_int32(gunit_##name)
|
||||
# define GTEST_DECLARE_string_(name) DECLARE_string(gunit_##name)
|
||||
|
||||
// Macros for defining flags.
|
||||
# define GTEST_DEFINE_bool_(name, default_val, doc) \
|
||||
DEFINE_bool(gunit_##name, default_val, doc)
|
||||
# define GTEST_DEFINE_int32_(name, default_val, doc) \
|
||||
DEFINE_int32(gunit_##name, default_val, doc)
|
||||
# define GTEST_DEFINE_string_(name, default_val, doc) \
|
||||
DEFINE_string(gunit_##name, default_val, doc)
|
||||
|
||||
# define GTEST_GET_BOOL_FROM_ENV_(flag, default_val) \
|
||||
::BoolFromEnv(FlagToEnvVar(flag).c_str(), default_val)
|
||||
# define GTEST_GET_INT32_FROM_ENV_(flag, default_val) \
|
||||
::Int32FromEnv(FlagToEnvVar(flag).c_str(), default_val)
|
||||
# define GTEST_GET_STRING_FROM_ENV_(flag, default_val) \
|
||||
::StringFromEnv(FlagToEnvVar(flag).c_str(), default_val)
|
||||
|
||||
// For logging.
|
||||
# include "third_party/absl/base/log_severity.h"
|
||||
# include "base/logging.h"
|
||||
# define GTEST_LOG_(severity) LOG(severity)
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
using ::LogToStderr;
|
||||
inline void FlushInfoLog() { FlushLogFiles(base_logging::INFO); }
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
# define GTEST_CHECK_(condition) CHECK(condition)
|
||||
|
||||
// For CheckedDowncastToActualType
|
||||
# include "base/casts.h"
|
||||
# define GTEST_HAS_DOWNCAST_ 1
|
||||
|
||||
# define GTEST_HAS_NOTIFICATION_ 1
|
||||
#include "absl/synchronization/notification.h"
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
using ::absl::Notification;
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
# define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 1
|
||||
# include "base/mutex.h"
|
||||
# include "thread/threadlocal.h"
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
using absl::Mutex;
|
||||
using absl::MutexLock;
|
||||
using ::ThreadLocal;
|
||||
|
||||
// Forward-declares a static mutex.
|
||||
# define GTEST_DECLARE_STATIC_MUTEX_(mutex) extern absl::Mutex mutex
|
||||
|
||||
// Defines and statically initializes a static mutex.
|
||||
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
||||
absl::Mutex mutex(absl::kConstInit)
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
// For thread annotations.
|
||||
# include "third_party/absl/base/thread_annotations.h"
|
||||
# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) \
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(locks)
|
||||
# define GTEST_LOCK_EXCLUDED_(locks) ABSL_LOCKS_EXCLUDED(locks)
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
// Pre-r11 Android NDK releases for x86 and x86_64 do not have abi libraries.
|
||||
# if GTEST_OS_LINUX_ANDROID && (defined(__i386__) || defined(__x86_64__))
|
||||
# define GTEST_HAS_CXXABI_H_ 0
|
||||
# endif
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
|
@ -38,5 +38,83 @@
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
// absl:google3-begin(Custom Implementation)
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/cord.h"
|
||||
#include "util/task/codes.pb.h"
|
||||
#include "util/task/codes.proto.h"
|
||||
#include "util/task/status.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Specializations for types related to util::Status. We define these
|
||||
// printers here to avoid widening the //util/task API.
|
||||
|
||||
template <>
|
||||
class UniversalPrinter< ::util::ErrorSpace> {
|
||||
public:
|
||||
static void Print(const ::util::ErrorSpace& space, ::std::ostream* os) {
|
||||
*os << space.SpaceName();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class UniversalPrinter< ::util::error::Code> {
|
||||
public:
|
||||
static void Print(::util::error::Code code, ::std::ostream* os) {
|
||||
if (::util::error::Code_IsValid(code)) {
|
||||
*os << ::util::error::Code_Name(code);
|
||||
} else {
|
||||
*os << static_cast<int>(code);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class UniversalPrinter<absl::StatusOr<T> > {
|
||||
public:
|
||||
static void Print(const absl::StatusOr<T>& status_or, ::std::ostream* os) {
|
||||
*os << status_or.status();
|
||||
if (status_or.ok()) {
|
||||
*os << ": ";
|
||||
UniversalPrint(status_or.value(), os);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class FormatForComparisonAsStringImpl {
|
||||
public:
|
||||
static ::std::string Format(const char* value) {
|
||||
return ::testing::PrintToString(value);
|
||||
}
|
||||
};
|
||||
|
||||
// If a C string is compared with a absl::string_view or Cord, we know it's
|
||||
// meant to point to a NUL-terminated string, and thus can print it as a string.
|
||||
|
||||
template <>
|
||||
class FormatForComparison<char*, absl::string_view>
|
||||
: public FormatForComparisonAsStringImpl {};
|
||||
template <>
|
||||
class FormatForComparison<const char*, absl::string_view>
|
||||
: public FormatForComparisonAsStringImpl {};
|
||||
|
||||
template <>
|
||||
class FormatForComparison<char*, absl::Cord>
|
||||
: public FormatForComparisonAsStringImpl {};
|
||||
template <>
|
||||
class FormatForComparison<const char*, absl::Cord>
|
||||
: public FormatForComparisonAsStringImpl {};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
// absl:google3-end
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
|
@ -34,4 +34,105 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "third_party/googletest/googletest/src/gtest-internal-inl.h"
|
||||
|
||||
#if GTEST_GOOGLE3_MODE_
|
||||
|
||||
#define GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 1
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// In google3 we use ::InitGoogle instead.
|
||||
#define GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_ \
|
||||
::testing::internal::InitGoogleTestForGoogle3
|
||||
void InitGoogleTestForGoogle3(int* argc, char** argv);
|
||||
void InitGoogleTestForGoogle3(int* argc, wchar_t** argv);
|
||||
|
||||
#define GTEST_OS_STACK_TRACE_GETTER_ \
|
||||
::testing::internal::Google3OsStackTraceGetter
|
||||
|
||||
// Google3 implementation of the stack trace getter.
|
||||
class Google3OsStackTraceGetter : public OsStackTraceGetterInterface {
|
||||
public:
|
||||
Google3OsStackTraceGetter() : caller_frame_(nullptr) {}
|
||||
|
||||
std::string CurrentStackTrace(int max_depth, int skip_count) override
|
||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
void UponLeavingGTest() override GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
private:
|
||||
Mutex mutex_; // protects all internal state
|
||||
|
||||
// We save the stack frame below the frame that calls user code.
|
||||
// We do this because the address of the frame immediately below
|
||||
// the user code changes between the call to UponLeavingGTest()
|
||||
// and any calls to CurrentStackTrace() from within the user code.
|
||||
void* caller_frame_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Google3OsStackTraceGetter);
|
||||
};
|
||||
|
||||
#define GTEST_CUSTOM_TEST_EVENT_LISTENER_ \
|
||||
::testing::internal::GoogleProcessStateListener
|
||||
|
||||
// Report process state changes to Google3 base, after the unit test
|
||||
// has been initialized, and before it is torn down, as well as at
|
||||
// the start and end of each test case and test.
|
||||
class GoogleProcessStateListener : public EmptyTestEventListener {
|
||||
public:
|
||||
GoogleProcessStateListener() {}
|
||||
~GoogleProcessStateListener() override;
|
||||
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override;
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override;
|
||||
void OnTestSuiteStart(const TestSuite& test_case) override;
|
||||
void OnTestSuiteEnd(const TestSuite& test_case) override;
|
||||
void OnTestStart(const TestInfo& test_info) override;
|
||||
void OnTestEnd(const TestInfo& test_info) override;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GoogleProcessStateListener);
|
||||
}; // class GoogleProcessStateListener
|
||||
|
||||
|
||||
// For KilledBySignal.
|
||||
bool KilledBySignalOverride(int signum, int exit_status, bool* result);
|
||||
|
||||
#define GTEST_KILLED_BY_SIGNAL_OVERRIDE_ \
|
||||
::testing::internal::KilledBySignalOverride
|
||||
|
||||
// Override --debugger_command (if any) with an empty one:
|
||||
// we don't want the child to have a debugger automagically attaching
|
||||
// to it when it (expectedly) dies.
|
||||
// Also, enable --logtostderr.
|
||||
::std::vector<std::string> GetGoogle3DeathTestCommandLineArgs();
|
||||
|
||||
#define GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_() \
|
||||
::testing::internal::GetGoogle3DeathTestCommandLineArgs()
|
||||
|
||||
|
||||
// For b/11021341, disable (slow) AddressToLineNumberDecorator.
|
||||
void Google3DeathTestChildSetup();
|
||||
|
||||
#define GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_() \
|
||||
::testing::internal::Google3DeathTestChildSetup()
|
||||
|
||||
// returns temp directory for test in Google3 manner
|
||||
std::string GetGoogle3TestTempDir();
|
||||
|
||||
// In google3 we use ::testing:GetTestTmpdir() instead.
|
||||
#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ \
|
||||
::testing::internal::GetGoogle3TestTempDir
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace testing
|
||||
#endif // GTEST_GOOGLE3_MODE_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
|
Loading…
Reference in New Issue
Block a user