Merge branch 'master' of https://github.com/google/googletest
This commit is contained in:
commit
25905b9f9a
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,6 +12,7 @@ bazel-testlogs
|
||||
*.pyc
|
||||
|
||||
# Visual Studio files
|
||||
.vs
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.VC.opendb
|
||||
@ -41,6 +42,8 @@ googletest/fused-src/
|
||||
|
||||
# macOS files
|
||||
.DS_Store
|
||||
googletest/.DS_Store
|
||||
googletest/xcode/.DS_Store
|
||||
|
||||
# Ignore cmake generated directories and files.
|
||||
CMakeFiles
|
||||
|
@ -10,6 +10,13 @@ language: cpp
|
||||
# It is more tedious, but grants us far more flexibility.
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
dist: trusty
|
||||
sudo: required
|
||||
group: deprecated-2017Q3
|
||||
before_install: chmod -R +x ./ci/*platformio.sh
|
||||
install: ./ci/install-platformio.sh
|
||||
script: ./ci/build-platformio.sh
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
sudo : true
|
||||
|
74
BUILD.bazel
74
BUILD.bazel
@ -38,12 +38,7 @@ licenses(["notice"])
|
||||
|
||||
config_setting(
|
||||
name = "windows",
|
||||
values = {"cpu": "x64_windows"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "windows_msvc",
|
||||
values = {"cpu": "x64_windows_msvc"},
|
||||
constraint_values = ["@bazel_tools//platforms:windows"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
@ -51,6 +46,13 @@ config_setting(
|
||||
values = {"define": "absl=1"},
|
||||
)
|
||||
|
||||
# Library that defines the FRIEND_TEST macro.
|
||||
cc_library(
|
||||
name = "gtest_prod",
|
||||
hdrs = ["googletest/include/gtest/gtest_prod.h"],
|
||||
includes = ["googletest/include"],
|
||||
)
|
||||
|
||||
# Google Test including Google Mock
|
||||
cc_library(
|
||||
name = "gtest",
|
||||
@ -73,21 +75,14 @@ cc_library(
|
||||
"googletest/include/gtest/*.h",
|
||||
"googlemock/include/gmock/*.h",
|
||||
]),
|
||||
copts = select(
|
||||
{
|
||||
":windows": [],
|
||||
":windows_msvc": [],
|
||||
"//conditions:default": ["-pthread"],
|
||||
},
|
||||
),
|
||||
defines = select(
|
||||
{
|
||||
":has_absl": [
|
||||
"GTEST_HAS_ABSL=1",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
},
|
||||
),
|
||||
copts = select({
|
||||
":windows": [],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
defines = select({
|
||||
":has_absl": ["GTEST_HAS_ABSL=1"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"googlemock",
|
||||
"googlemock/include",
|
||||
@ -96,31 +91,24 @@ cc_library(
|
||||
],
|
||||
linkopts = select({
|
||||
":windows": [],
|
||||
":windows_msvc": [],
|
||||
"//conditions:default": [
|
||||
"-pthread",
|
||||
],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
deps = select({
|
||||
":has_absl": [
|
||||
"@com_google_absl//absl/debugging:failure_signal_handler",
|
||||
"@com_google_absl//absl/debugging:stacktrace",
|
||||
"@com_google_absl//absl/debugging:symbolize",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = select(
|
||||
{
|
||||
":has_absl": [
|
||||
"@com_google_absl//absl/debugging:failure_signal_handler",
|
||||
"@com_google_absl//absl/debugging:stacktrace",
|
||||
"@com_google_absl//absl/debugging:symbolize",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "gtest_main",
|
||||
srcs = [
|
||||
"googlemock/src/gmock_main.cc",
|
||||
],
|
||||
srcs = ["googlemock/src/gmock_main.cc"],
|
||||
deps = [":gtest"],
|
||||
)
|
||||
|
||||
@ -174,7 +162,5 @@ cc_test(
|
||||
name = "sample10_unittest",
|
||||
size = "small",
|
||||
srcs = ["googletest/samples/sample10_unittest.cc"],
|
||||
deps = [
|
||||
":gtest",
|
||||
],
|
||||
deps = [":gtest"],
|
||||
)
|
||||
|
@ -1,5 +1,12 @@
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
add_definitions(-std=c++11)
|
||||
|
||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||
add_definitions(-std=c++11)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
if (POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
# Google Test #
|
||||
|
||||
[](https://travis-ci.org/google/googletest)
|
||||
[](https://travis-ci.org/google/googletest)
|
||||
[](https://ci.appveyor.com/project/GoogleTestAppVeyor/googletest/branch/master)
|
||||
|
||||
**Future Plans**:
|
||||
@ -16,10 +16,8 @@ This repository is a merger of the formerly separate GoogleTest and
|
||||
GoogleMock projects. These were so closely related that it makes sense to
|
||||
maintain and release them together.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on [OFTC](https://webchat.oftc.net/) (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
Please subscribe to the mailing list at googletestframework@googlegroups.com for questions, discussions, and development.
|
||||
There is also an IRC channel on [OFTC](https://webchat.oftc.net/) (irc.oftc.net) #gtest available.
|
||||
|
||||
Getting started information for **Google Test** is available in the
|
||||
[Google Test Primer](googletest/docs/primer.md) documentation.
|
||||
|
@ -1,5 +1,7 @@
|
||||
workspace(name = "com_google_googletest")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
# Abseil
|
||||
http_archive(
|
||||
name = "com_google_absl",
|
||||
|
2
ci/build-platformio.sh
Normal file
2
ci/build-platformio.sh
Normal file
@ -0,0 +1,2 @@
|
||||
# run PlatformIO builds
|
||||
platformio run
|
@ -34,7 +34,8 @@
|
||||
#
|
||||
|
||||
# TODO() - we can check if this is being sourced using $BASH_VERSION and $BASH_SOURCE[0] != ${0}.
|
||||
#
|
||||
|
||||
if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
|
||||
if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
|
||||
if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.9" CC="clang-3.9"; fi
|
||||
fi
|
||||
|
5
ci/install-platformio.sh
Normal file
5
ci/install-platformio.sh
Normal file
@ -0,0 +1,5 @@
|
||||
# install PlatformIO
|
||||
sudo pip install -U platformio
|
||||
|
||||
# update PlatformIO
|
||||
platformio update
|
@ -75,18 +75,6 @@ set(gmock_build_include_dirs
|
||||
"${gtest_SOURCE_DIR}")
|
||||
include_directories(${gmock_build_include_dirs})
|
||||
|
||||
# Summary of tuple support for Microsoft Visual Studio:
|
||||
# Compiler version(MS) version(cmake) Support
|
||||
# ---------- ----------- -------------- -----------------------------
|
||||
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
|
||||
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
|
||||
# VS 2013 12 1800 std::tr1::tuple
|
||||
# VS 2015 14 1900 std::tuple
|
||||
# VS 2017 15 >= 1910 std::tuple
|
||||
if (MSVC AND MSVC_VERSION EQUAL 1700)
|
||||
add_definitions(/D _VARIADIC_MAX=10)
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Defines the gmock & gmock_main libraries. User tests should link
|
||||
@ -165,6 +153,7 @@ $env:Path = \"$project_bin;$env:Path\"
|
||||
cxx_test(gmock-actions_test gmock_main)
|
||||
cxx_test(gmock-cardinalities_test gmock_main)
|
||||
cxx_test(gmock_ex_test gmock_main)
|
||||
cxx_test(gmock-function-mocker_test gmock_main)
|
||||
cxx_test(gmock-generated-actions_test gmock_main)
|
||||
cxx_test(gmock-generated-function-mockers_test gmock_main)
|
||||
cxx_test(gmock-generated-internal-utils_test gmock_main)
|
||||
@ -199,25 +188,12 @@ $env:Path = \"$project_bin;$env:Path\"
|
||||
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
if (MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
|
||||
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
|
||||
# conflict with our own definitions. Therefore using our own tuple does not
|
||||
# work on those compilers.
|
||||
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
|
||||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
|
||||
|
||||
cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
|
||||
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
|
||||
endif()
|
||||
else()
|
||||
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
|
||||
target_link_libraries(gmock_main_no_exception PUBLIC gmock)
|
||||
|
||||
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
|
||||
target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
|
||||
|
||||
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
|
||||
target_link_libraries(gmock_main_use_own_tuple PUBLIC gmock)
|
||||
endif()
|
||||
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
|
||||
gmock_main_no_exception test/gmock-more-actions_test.cc)
|
||||
|
@ -28,13 +28,14 @@ lib_libgmock_la_SOURCES = src/gmock-all.cc
|
||||
pkginclude_HEADERS = \
|
||||
include/gmock/gmock-actions.h \
|
||||
include/gmock/gmock-cardinalities.h \
|
||||
include/gmock/gmock-function-mocker.h \
|
||||
include/gmock/gmock-generated-actions.h \
|
||||
include/gmock/gmock-generated-function-mockers.h \
|
||||
include/gmock/gmock-generated-matchers.h \
|
||||
include/gmock/gmock-generated-nice-strict.h \
|
||||
include/gmock/gmock-matchers.h \
|
||||
include/gmock/gmock-more-actions.h \
|
||||
include/gmock/gmock-more-matchers.h \
|
||||
include/gmock/gmock-nice-strict.h \
|
||||
include/gmock/gmock-spec-builders.h \
|
||||
include/gmock/gmock.h
|
||||
|
||||
@ -43,6 +44,7 @@ pkginclude_internal_HEADERS = \
|
||||
include/gmock/internal/gmock-generated-internal-utils.h \
|
||||
include/gmock/internal/gmock-internal-utils.h \
|
||||
include/gmock/internal/gmock-port.h \
|
||||
include/gmock/internal/gmock-pp.h \
|
||||
include/gmock/internal/custom/gmock-generated-actions.h \
|
||||
include/gmock/internal/custom/gmock-matchers.h \
|
||||
include/gmock/internal/custom/gmock-port.h
|
||||
@ -107,6 +109,7 @@ EXTRA_DIST += \
|
||||
test/gmock-cardinalities_test.cc \
|
||||
test/gmock_ex_test.cc \
|
||||
test/gmock-generated-actions_test.cc \
|
||||
test/gmock-function-mocker_test.cc \
|
||||
test/gmock-generated-function-mockers_test.cc \
|
||||
test/gmock-generated-internal-utils_test.cc \
|
||||
test/gmock-generated-matchers_test.cc \
|
||||
@ -138,7 +141,6 @@ EXTRA_DIST += \
|
||||
include/gmock/gmock-generated-actions.h.pump \
|
||||
include/gmock/gmock-generated-function-mockers.h.pump \
|
||||
include/gmock/gmock-generated-matchers.h.pump \
|
||||
include/gmock/gmock-generated-nice-strict.h.pump \
|
||||
include/gmock/internal/gmock-generated-internal-utils.h.pump \
|
||||
include/gmock/internal/custom/gmock-generated-actions.h.pump
|
||||
|
||||
|
@ -35,7 +35,7 @@ We hope you find it useful!
|
||||
* Does automatic verification of expectations (no record-and-replay needed).
|
||||
* Allows arbitrary (partial) ordering constraints on
|
||||
function calls to be expressed,.
|
||||
* Lets an user extend it by defining new matchers and actions.
|
||||
* Lets a user extend it by defining new matchers and actions.
|
||||
* Does not use exceptions.
|
||||
* Is easy to learn and use.
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
prefix=${pcfiledir}/../..
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: gmock
|
||||
Description: GoogleMock (without main() function)
|
||||
|
@ -1,5 +1,6 @@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
prefix=${pcfiledir}/../..
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: gmock_main
|
||||
Description: GoogleMock (with main() function)
|
||||
|
@ -181,6 +181,7 @@ divided into several categories:
|
||||
|`Ne(value)` |`argument != value`|
|
||||
|`IsNull()` |`argument` is a `NULL` pointer (raw or smart).|
|
||||
|`NotNull()` |`argument` is a non-null pointer (raw or smart).|
|
||||
|`Optional(m)` |`argument` is `optional<>` that contains a value matching `m`.|
|
||||
|`VariantWith<T>(m)` |`argument` is `variant<>` that holds the alternative of type T with a value matching `m`.|
|
||||
|`Ref(variable)` |`argument` is a reference to `variable`.|
|
||||
|`TypedEq<type>(value)`|`argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded.|
|
||||
|
@ -42,15 +42,19 @@
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h.
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#endif // GTEST_LANG_CXX11
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -65,9 +69,6 @@ namespace testing {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename F1, typename F2>
|
||||
class ActionAdaptor;
|
||||
|
||||
// BuiltInDefaultValueGetter<T, true>::Get() returns a
|
||||
// default-constructed T value. BuiltInDefaultValueGetter<T,
|
||||
// false>::Get() crashes with an error.
|
||||
@ -98,7 +99,6 @@ struct BuiltInDefaultValueGetter<T, false> {
|
||||
template <typename T>
|
||||
class BuiltInDefaultValue {
|
||||
public:
|
||||
#if GTEST_LANG_CXX11
|
||||
// This function returns true iff type T has a built-in default value.
|
||||
static bool Exists() {
|
||||
return ::std::is_default_constructible<T>::value;
|
||||
@ -108,18 +108,6 @@ class BuiltInDefaultValue {
|
||||
return BuiltInDefaultValueGetter<
|
||||
T, ::std::is_default_constructible<T>::value>::Get();
|
||||
}
|
||||
|
||||
#else // GTEST_LANG_CXX11
|
||||
// This function returns true iff type T has a built-in default value.
|
||||
static bool Exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static T Get() {
|
||||
return BuiltInDefaultValueGetter<T, false>::Get();
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
};
|
||||
|
||||
// This partial specialization says that we use the same built-in
|
||||
@ -250,7 +238,7 @@ class DefaultValue {
|
||||
class FixedValueProducer : public ValueProducer {
|
||||
public:
|
||||
explicit FixedValueProducer(T value) : value_(value) {}
|
||||
virtual T Produce() { return value_; }
|
||||
T Produce() override { return value_; }
|
||||
|
||||
private:
|
||||
const T value_;
|
||||
@ -261,7 +249,7 @@ class DefaultValue {
|
||||
public:
|
||||
explicit FactoryValueProducer(FactoryFunction factory)
|
||||
: factory_(factory) {}
|
||||
virtual T Produce() { return factory_(); }
|
||||
T Produce() override { return factory_(); }
|
||||
|
||||
private:
|
||||
const FactoryFunction factory_;
|
||||
@ -345,14 +333,25 @@ class ActionInterface {
|
||||
// An Action<F> is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that represents an action to be taken when a mock function
|
||||
// of type F is called. The implementation of Action<T> is just a
|
||||
// linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
|
||||
// Don't inherit from Action!
|
||||
//
|
||||
// std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
|
||||
// You can view an object implementing ActionInterface<F> as a
|
||||
// concrete action (including its current state), and an Action<F>
|
||||
// object as a handle to it.
|
||||
template <typename F>
|
||||
class Action {
|
||||
// Adapter class to allow constructing Action from a legacy ActionInterface.
|
||||
// New code should create Actions from functors instead.
|
||||
struct ActionAdapter {
|
||||
// Adapter must be copyable to satisfy std::function requirements.
|
||||
::std::shared_ptr<ActionInterface<F>> impl_;
|
||||
|
||||
template <typename... Args>
|
||||
typename internal::Function<F>::Result operator()(Args&&... args) {
|
||||
return impl_->Perform(
|
||||
::std::forward_as_tuple(::std::forward<Args>(args)...));
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
typedef typename internal::Function<F>::Result Result;
|
||||
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
|
||||
@ -361,7 +360,6 @@ class Action {
|
||||
// STL containers.
|
||||
Action() {}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Construct an Action from a specified callable.
|
||||
// This cannot take std::function directly, because then Action would not be
|
||||
// directly constructible from lambda (it would require two conversions).
|
||||
@ -369,26 +367,19 @@ class Action {
|
||||
typename = typename ::std::enable_if<
|
||||
::std::is_constructible<::std::function<F>, G>::value>::type>
|
||||
Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
|
||||
#endif
|
||||
|
||||
// Constructs an Action from its implementation.
|
||||
explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
|
||||
explicit Action(ActionInterface<F>* impl)
|
||||
: fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
|
||||
|
||||
// This constructor allows us to turn an Action<Func> object into an
|
||||
// Action<F>, as long as F's arguments can be implicitly converted
|
||||
// to Func's and Func's return type can be implicitly converted to
|
||||
// F's.
|
||||
// to Func's and Func's return type can be implicitly converted to F's.
|
||||
template <typename Func>
|
||||
explicit Action(const Action<Func>& action);
|
||||
explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
|
||||
|
||||
// Returns true iff this is the DoDefault() action.
|
||||
bool IsDoDefault() const {
|
||||
#if GTEST_LANG_CXX11
|
||||
return impl_ == nullptr && fun_ == nullptr;
|
||||
#else
|
||||
return impl_ == NULL;
|
||||
#endif
|
||||
}
|
||||
bool IsDoDefault() const { return fun_ == nullptr; }
|
||||
|
||||
// Performs the action. Note that this method is const even though
|
||||
// the corresponding method in ActionInterface is not. The reason
|
||||
@ -400,31 +391,15 @@ class Action {
|
||||
if (IsDoDefault()) {
|
||||
internal::IllegalDoDefault(__FILE__, __LINE__);
|
||||
}
|
||||
#if GTEST_LANG_CXX11
|
||||
if (fun_ != nullptr) {
|
||||
return internal::Apply(fun_, ::std::move(args));
|
||||
}
|
||||
#endif
|
||||
return impl_->Perform(args);
|
||||
return internal::Apply(fun_, ::std::move(args));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename F1, typename F2>
|
||||
friend class internal::ActionAdaptor;
|
||||
|
||||
template <typename G>
|
||||
friend class Action;
|
||||
|
||||
// In C++11, Action can be implemented either as a generic functor (through
|
||||
// std::function), or legacy ActionInterface. In C++98, only ActionInterface
|
||||
// is available. The invariants are as follows:
|
||||
// * in C++98, impl_ is null iff this is the default action
|
||||
// * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff
|
||||
// this is the default action
|
||||
#if GTEST_LANG_CXX11
|
||||
// fun_ is an empty function iff this is the DoDefault() action.
|
||||
::std::function<F> fun_;
|
||||
#endif
|
||||
internal::linked_ptr<ActionInterface<F> > impl_;
|
||||
};
|
||||
|
||||
// The PolymorphicAction class template makes it easy to implement a
|
||||
@ -439,7 +414,7 @@ class Action {
|
||||
// template <typename Result, typename ArgumentTuple>
|
||||
// Result Perform(const ArgumentTuple& args) const {
|
||||
// // Processes the arguments and returns a result, using
|
||||
// // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple.
|
||||
// // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
|
||||
// }
|
||||
// ...
|
||||
// };
|
||||
@ -467,7 +442,7 @@ class PolymorphicAction {
|
||||
|
||||
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple& args) {
|
||||
Result Perform(const ArgumentTuple& args) override {
|
||||
return impl_.template Perform<Result>(args);
|
||||
}
|
||||
|
||||
@ -503,31 +478,11 @@ inline PolymorphicAction<Impl> MakePolymorphicAction(const Impl& impl) {
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Allows an Action<F2> object to pose as an Action<F1>, as long as F2
|
||||
// and F1 are compatible.
|
||||
template <typename F1, typename F2>
|
||||
class ActionAdaptor : public ActionInterface<F1> {
|
||||
public:
|
||||
typedef typename internal::Function<F1>::Result Result;
|
||||
typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple& args) {
|
||||
return impl_->Perform(args);
|
||||
}
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<ActionInterface<F2> > impl_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
|
||||
};
|
||||
|
||||
// Helper struct to specialize ReturnAction to execute a move instead of a copy
|
||||
// on return. Useful for move-only types, but could be used on any type.
|
||||
template <typename T>
|
||||
struct ByMoveWrapper {
|
||||
explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
|
||||
explicit ByMoveWrapper(T value) : payload(std::move(value)) {}
|
||||
T payload;
|
||||
};
|
||||
|
||||
@ -564,12 +519,12 @@ class ReturnAction {
|
||||
// Constructs a ReturnAction object from the value to be returned.
|
||||
// 'value' is passed by value instead of by const reference in order
|
||||
// to allow Return("string literal") to compile.
|
||||
explicit ReturnAction(R value) : value_(new R(internal::move(value))) {}
|
||||
explicit ReturnAction(R value) : value_(new R(std::move(value))) {}
|
||||
|
||||
// This template type conversion operator allows Return(x) to be
|
||||
// used in ANY function that returns x's type.
|
||||
template <typename F>
|
||||
operator Action<F>() const {
|
||||
operator Action<F>() const { // NOLINT
|
||||
// Assert statement belongs here because this is the best place to verify
|
||||
// conditions on F. It produces the clearest error messages
|
||||
// in most compilers.
|
||||
@ -582,6 +537,8 @@ class ReturnAction {
|
||||
GTEST_COMPILE_ASSERT_(
|
||||
!is_reference<Result>::value,
|
||||
use_ReturnRef_instead_of_Return_to_return_a_reference);
|
||||
static_assert(!std::is_void<Result>::value,
|
||||
"Can't use Return() on an action expected to return `void`.");
|
||||
return Action<F>(new Impl<R, F>(value_));
|
||||
}
|
||||
|
||||
@ -600,11 +557,11 @@ class ReturnAction {
|
||||
// Result to call. ImplicitCast_ forces the compiler to convert R to
|
||||
// Result without considering explicit constructors, thus resolving the
|
||||
// ambiguity. value_ is then initialized using its copy constructor.
|
||||
explicit Impl(const linked_ptr<R>& value)
|
||||
explicit Impl(const std::shared_ptr<R>& value)
|
||||
: value_before_cast_(*value),
|
||||
value_(ImplicitCast_<Result>(value_before_cast_)) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple&) { return value_; }
|
||||
Result Perform(const ArgumentTuple&) override { return value_; }
|
||||
|
||||
private:
|
||||
GTEST_COMPILE_ASSERT_(!is_reference<Result>::value,
|
||||
@ -625,24 +582,24 @@ class ReturnAction {
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
explicit Impl(const linked_ptr<R>& wrapper)
|
||||
explicit Impl(const std::shared_ptr<R>& wrapper)
|
||||
: performed_(false), wrapper_(wrapper) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple&) {
|
||||
Result Perform(const ArgumentTuple&) override {
|
||||
GTEST_CHECK_(!performed_)
|
||||
<< "A ByMove() action should only be performed once.";
|
||||
performed_ = true;
|
||||
return internal::move(wrapper_->payload);
|
||||
return std::move(wrapper_->payload);
|
||||
}
|
||||
|
||||
private:
|
||||
bool performed_;
|
||||
const linked_ptr<R> wrapper_;
|
||||
const std::shared_ptr<R> wrapper_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(Impl);
|
||||
};
|
||||
|
||||
const linked_ptr<R> value_;
|
||||
const std::shared_ptr<R> value_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ReturnAction);
|
||||
};
|
||||
@ -655,13 +612,7 @@ class ReturnNullAction {
|
||||
// pointer type on compile time.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
static Result Perform(const ArgumentTuple&) {
|
||||
#if GTEST_LANG_CXX11
|
||||
return nullptr;
|
||||
#else
|
||||
GTEST_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
|
||||
ReturnNull_can_be_used_to_return_a_pointer_only);
|
||||
return NULL;
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
};
|
||||
|
||||
@ -707,9 +658,7 @@ class ReturnRefAction {
|
||||
|
||||
explicit Impl(T& ref) : ref_(ref) {} // NOLINT
|
||||
|
||||
virtual Result Perform(const ArgumentTuple&) {
|
||||
return ref_;
|
||||
}
|
||||
Result Perform(const ArgumentTuple&) override { return ref_; }
|
||||
|
||||
private:
|
||||
T& ref_;
|
||||
@ -756,9 +705,7 @@ class ReturnRefOfCopyAction {
|
||||
|
||||
explicit Impl(const T& value) : value_(value) {} // NOLINT
|
||||
|
||||
virtual Result Perform(const ArgumentTuple&) {
|
||||
return value_;
|
||||
}
|
||||
Result Perform(const ArgumentTuple&) override { return value_; }
|
||||
|
||||
private:
|
||||
T value_;
|
||||
@ -838,7 +785,7 @@ class SetArgumentPointeeAction {
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
void Perform(const ArgumentTuple& args) const {
|
||||
CompileAssertTypesEqual<void, Result>();
|
||||
*::testing::get<N>(args) = value_;
|
||||
*::std::get<N>(args) = value_;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -861,11 +808,11 @@ class SetArgumentPointeeAction<N, Proto, true> {
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
void Perform(const ArgumentTuple& args) const {
|
||||
CompileAssertTypesEqual<void, Result>();
|
||||
::testing::get<N>(args)->CopyFrom(*proto_);
|
||||
::std::get<N>(args)->CopyFrom(*proto_);
|
||||
}
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<Proto> proto_;
|
||||
const std::shared_ptr<Proto> proto_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
|
||||
};
|
||||
@ -930,7 +877,7 @@ class InvokeCallbackWithoutArgsAction {
|
||||
Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<CallbackType> callback_;
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
|
||||
};
|
||||
@ -968,7 +915,7 @@ class IgnoreResultAction {
|
||||
|
||||
explicit Impl(const A& action) : action_(action) {}
|
||||
|
||||
virtual void Perform(const ArgumentTuple& args) {
|
||||
void Perform(const ArgumentTuple& args) override {
|
||||
// Performs the action and ignores its result.
|
||||
action_.Perform(args);
|
||||
}
|
||||
@ -1016,49 +963,51 @@ void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
|
||||
UniversalPrinter<T&>::Print(value, os);
|
||||
}
|
||||
|
||||
// Does two actions sequentially. Used for implementing the DoAll(a1,
|
||||
// a2, ...) action.
|
||||
template <typename Action1, typename Action2>
|
||||
class DoBothAction {
|
||||
public:
|
||||
DoBothAction(Action1 action1, Action2 action2)
|
||||
: action1_(action1), action2_(action2) {}
|
||||
template <typename InnerAction, size_t... I>
|
||||
struct WithArgsAction {
|
||||
InnerAction action;
|
||||
|
||||
// This template type conversion operator allows DoAll(a1, ..., a_n)
|
||||
// to be used in ANY function of compatible type.
|
||||
template <typename F>
|
||||
operator Action<F>() const {
|
||||
return Action<F>(new Impl<F>(action1_, action2_));
|
||||
// The inner action could be anything convertible to Action<X>.
|
||||
// We use the conversion operator to detect the signature of the inner Action.
|
||||
template <typename R, typename... Args>
|
||||
operator Action<R(Args...)>() const { // NOLINT
|
||||
Action<R(typename std::tuple_element<I, std::tuple<Args...>>::type...)>
|
||||
converted(action);
|
||||
|
||||
return [converted](Args... args) -> R {
|
||||
return converted.Perform(std::forward_as_tuple(
|
||||
std::get<I>(std::forward_as_tuple(std::forward<Args>(args)...))...));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Actions>
|
||||
struct DoAllAction {
|
||||
private:
|
||||
template <typename... Args, size_t... I>
|
||||
std::vector<Action<void(Args...)>> Convert(IndexSequence<I...>) const {
|
||||
return {std::get<I>(actions)...};
|
||||
}
|
||||
|
||||
private:
|
||||
// Implements the DoAll(...) action for a particular function type F.
|
||||
template <typename F>
|
||||
class Impl : public ActionInterface<F> {
|
||||
public:
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
typedef typename Function<F>::MakeResultVoid VoidResult;
|
||||
public:
|
||||
std::tuple<Actions...> actions;
|
||||
|
||||
Impl(const Action<VoidResult>& action1, const Action<F>& action2)
|
||||
: action1_(action1), action2_(action2) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple& args) {
|
||||
action1_.Perform(args);
|
||||
return action2_.Perform(args);
|
||||
}
|
||||
|
||||
private:
|
||||
const Action<VoidResult> action1_;
|
||||
const Action<F> action2_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(Impl);
|
||||
};
|
||||
|
||||
Action1 action1_;
|
||||
Action2 action2_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(DoBothAction);
|
||||
template <typename R, typename... Args>
|
||||
operator Action<R(Args...)>() const { // NOLINT
|
||||
struct Op {
|
||||
std::vector<Action<void(Args...)>> converted;
|
||||
Action<R(Args...)> last;
|
||||
R operator()(Args... args) const {
|
||||
auto tuple_args = std::forward_as_tuple(std::forward<Args>(args)...);
|
||||
for (auto& a : converted) {
|
||||
a.Perform(tuple_args);
|
||||
}
|
||||
return last.Perform(tuple_args);
|
||||
}
|
||||
};
|
||||
return Op{Convert<Args...>(MakeIndexSequence<sizeof...(Actions) - 1>()),
|
||||
std::get<sizeof...(Actions) - 1>(actions)};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
@ -1095,20 +1044,43 @@ class DoBothAction {
|
||||
// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
|
||||
typedef internal::IgnoredValue Unused;
|
||||
|
||||
// This constructor allows us to turn an Action<From> object into an
|
||||
// Action<To>, as long as To's arguments can be implicitly converted
|
||||
// to From's and From's return type cann be implicitly converted to
|
||||
// To's.
|
||||
template <typename To>
|
||||
template <typename From>
|
||||
Action<To>::Action(const Action<From>& from)
|
||||
:
|
||||
#if GTEST_LANG_CXX11
|
||||
fun_(from.fun_),
|
||||
#endif
|
||||
impl_(from.impl_ == nullptr
|
||||
? nullptr
|
||||
: new internal::ActionAdaptor<To, From>(from)) {
|
||||
// Creates an action that does actions a1, a2, ..., sequentially in
|
||||
// each invocation.
|
||||
template <typename... Action>
|
||||
internal::DoAllAction<typename std::decay<Action>::type...> DoAll(
|
||||
Action&&... action) {
|
||||
return {std::forward_as_tuple(std::forward<Action>(action)...)};
|
||||
}
|
||||
|
||||
// WithArg<k>(an_action) creates an action that passes the k-th
|
||||
// (0-based) argument of the mock function to an_action and performs
|
||||
// it. It adapts an action accepting one argument to one that accepts
|
||||
// multiple arguments. For convenience, we also provide
|
||||
// WithArgs<k>(an_action) (defined below) as a synonym.
|
||||
template <size_t k, typename InnerAction>
|
||||
internal::WithArgsAction<typename std::decay<InnerAction>::type, k>
|
||||
WithArg(InnerAction&& action) {
|
||||
return {std::forward<InnerAction>(action)};
|
||||
}
|
||||
|
||||
// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
|
||||
// the selected arguments of the mock function to an_action and
|
||||
// performs it. It serves as an adaptor between actions with
|
||||
// different argument lists.
|
||||
template <size_t k, size_t... ks, typename InnerAction>
|
||||
internal::WithArgsAction<typename std::decay<InnerAction>::type, k, ks...>
|
||||
WithArgs(InnerAction&& action) {
|
||||
return {std::forward<InnerAction>(action)};
|
||||
}
|
||||
|
||||
// WithoutArgs(inner_action) can be used in a mock function with a
|
||||
// non-empty argument list to perform inner_action, which takes no
|
||||
// argument. In other words, it adapts an action accepting no
|
||||
// argument to one that accepts (and ignores) arguments.
|
||||
template <typename InnerAction>
|
||||
internal::WithArgsAction<typename std::decay<InnerAction>::type>
|
||||
WithoutArgs(InnerAction&& action) {
|
||||
return {std::forward<InnerAction>(action)};
|
||||
}
|
||||
|
||||
// Creates an action that returns 'value'. 'value' is passed by value
|
||||
@ -1116,7 +1088,7 @@ Action<To>::Action(const Action<From>& from)
|
||||
// will trigger a compiler error about using array as initializer.
|
||||
template <typename R>
|
||||
internal::ReturnAction<R> Return(R value) {
|
||||
return internal::ReturnAction<R>(internal::move(value));
|
||||
return internal::ReturnAction<R>(std::move(value));
|
||||
}
|
||||
|
||||
// Creates an action that returns NULL.
|
||||
@ -1149,7 +1121,7 @@ inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
|
||||
// invariant.
|
||||
template <typename R>
|
||||
internal::ByMoveWrapper<R> ByMove(R x) {
|
||||
return internal::ByMoveWrapper<R>(internal::move(x));
|
||||
return internal::ByMoveWrapper<R>(std::move(x));
|
||||
}
|
||||
|
||||
// Creates an action that does the default action for the give mock function.
|
||||
@ -1259,4 +1231,9 @@ inline internal::ReferenceWrapper<T> ByRef(T& l_value) { // NOLINT
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
|
||||
|
@ -40,6 +40,7 @@
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
|
||||
|
||||
#include <limits.h>
|
||||
#include <memory>
|
||||
#include <ostream> // NOLINT
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
@ -81,9 +82,8 @@ class CardinalityInterface {
|
||||
|
||||
// A Cardinality is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that specifies how many times a mock function is expected to
|
||||
// be called. The implementation of Cardinality is just a linked_ptr
|
||||
// to const CardinalityInterface, so copying is fairly cheap.
|
||||
// Don't inherit from Cardinality!
|
||||
// be called. The implementation of Cardinality is just a std::shared_ptr
|
||||
// to const CardinalityInterface. Don't inherit from Cardinality!
|
||||
class GTEST_API_ Cardinality {
|
||||
public:
|
||||
// Constructs a null cardinality. Needed for storing Cardinality
|
||||
@ -123,7 +123,7 @@ class GTEST_API_ Cardinality {
|
||||
::std::ostream* os);
|
||||
|
||||
private:
|
||||
internal::linked_ptr<const CardinalityInterface> impl_;
|
||||
std::shared_ptr<const CardinalityInterface> impl_;
|
||||
};
|
||||
|
||||
// Creates a cardinality that allows at least n calls.
|
||||
|
218
googlemock/include/gmock/gmock-function-mocker.h
Normal file
218
googlemock/include/gmock/gmock-function-mocker.h
Normal file
@ -0,0 +1,218 @@
|
||||
#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
|
||||
#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
|
||||
|
||||
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
|
||||
#include "gmock/internal/gmock-pp.h"
|
||||
|
||||
#define MOCK_METHOD(...) \
|
||||
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \
|
||||
GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ())
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
|
||||
GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec); \
|
||||
GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
|
||||
GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
|
||||
GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
|
||||
GMOCK_INTERNAL_HAS_NOEXCEPT(_Spec), GMOCK_INTERNAL_GET_CALLTYPE(_Spec), \
|
||||
(GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)))
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_WRONG_ARITY(...) \
|
||||
static_assert( \
|
||||
false, \
|
||||
"MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \
|
||||
"_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \
|
||||
"enclosed in parentheses. If _Ret is a type with unprotected commas, " \
|
||||
"it must also be enclosed in parentheses.")
|
||||
|
||||
#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \
|
||||
static_assert( \
|
||||
GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \
|
||||
GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.")
|
||||
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \
|
||||
static_assert( \
|
||||
std::is_function<__VA_ARGS__>::value, \
|
||||
"Signature must be a function type, maybe return type contains " \
|
||||
"unprotected comma."); \
|
||||
static_assert( \
|
||||
::testing::tuple_size<typename ::testing::internal::Function< \
|
||||
__VA_ARGS__>::ArgumentTuple>::value == _N, \
|
||||
"This method does not take " GMOCK_PP_STRINGIZE( \
|
||||
_N) " arguments. Parenthesize all types with unproctected commas.")
|
||||
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec)
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \
|
||||
_Override, _Final, _Noexcept, \
|
||||
_CallType, _Signature) \
|
||||
typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \
|
||||
_Signature)>::Result \
|
||||
GMOCK_INTERNAL_EXPAND(_CallType) \
|
||||
_MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \
|
||||
GMOCK_PP_IF(_Constness, const, ) GMOCK_PP_IF(_Noexcept, noexcept, ) \
|
||||
GMOCK_PP_IF(_Override, override, ) \
|
||||
GMOCK_PP_IF(_Final, final, ) { \
|
||||
GMOCK_MOCKER_(_N, _Constness, _MethodName) \
|
||||
.SetOwnerAndName(this, #_MethodName); \
|
||||
return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
|
||||
.Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \
|
||||
} \
|
||||
::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
|
||||
GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \
|
||||
GMOCK_PP_IF(_Constness, const, ) { \
|
||||
GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \
|
||||
return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
|
||||
.With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \
|
||||
} \
|
||||
::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
|
||||
const ::testing::internal::WithoutMatchers&, \
|
||||
GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \
|
||||
GMOCK_PP_REMOVE_PARENS(_Signature)>*) \
|
||||
const GMOCK_PP_IF(_Noexcept, noexcept, ) { \
|
||||
return GMOCK_PP_CAT(::testing::internal::AdjustConstness_, \
|
||||
GMOCK_PP_IF(_Constness, const, ))(this) \
|
||||
->gmock_##_MethodName(GMOCK_PP_REPEAT( \
|
||||
GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \
|
||||
} \
|
||||
mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \
|
||||
GMOCK_MOCKER_(_N, _Constness, _MethodName)
|
||||
|
||||
#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__
|
||||
|
||||
// Five Valid modifiers.
|
||||
#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple))
|
||||
|
||||
#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \
|
||||
GMOCK_PP_HAS_COMMA( \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple))
|
||||
|
||||
#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple))
|
||||
|
||||
#define GMOCK_INTERNAL_HAS_NOEXCEPT(_Tuple) \
|
||||
GMOCK_PP_HAS_COMMA( \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_NOEXCEPT, ~, _Tuple))
|
||||
|
||||
#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple)
|
||||
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
|
||||
static_assert( \
|
||||
(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
|
||||
GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \
|
||||
GMOCK_PP_STRINGIZE( \
|
||||
_elem) " cannot be recognized as a valid specification modifier.");
|
||||
|
||||
// Modifiers implementation.
|
||||
#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem)
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_CONST_I_const ,
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem)
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override ,
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem)
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_FINAL_I_final ,
|
||||
|
||||
// TODO(iserna): Maybe noexcept should accept an argument here as well.
|
||||
#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem)
|
||||
|
||||
#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept ,
|
||||
|
||||
#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \
|
||||
GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \
|
||||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \
|
||||
(_elem)
|
||||
|
||||
// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and
|
||||
// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows
|
||||
// maybe they can be simplified somehow.
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \
|
||||
GMOCK_INTERNAL_IS_CALLTYPE_I( \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg)
|
||||
|
||||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \
|
||||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
|
||||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \
|
||||
GMOCK_PP_CAT(GMOCK_PP_IDENTITY, _arg)
|
||||
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
|
||||
|
||||
#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
|
||||
GMOCK_PP_IDENTITY) \
|
||||
(_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
|
||||
|
||||
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \
|
||||
GMOCK_PP_IDENTITY) \
|
||||
(_elem)
|
||||
|
||||
#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
|
||||
GMOCK_PP_REMOVE_PARENS(_Signature)) \
|
||||
gmock_a##_i
|
||||
|
||||
#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
::std::forward<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
|
||||
GMOCK_PP_REMOVE_PARENS(_Signature))>( \
|
||||
gmock_a##_i)
|
||||
|
||||
#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
GMOCK_INTERNAL_MATCHER_O(typename, GMOCK_PP_INC(_i), \
|
||||
GMOCK_PP_REMOVE_PARENS(_Signature)) \
|
||||
gmock_a##_i
|
||||
|
||||
#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
gmock_a##_i
|
||||
|
||||
#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \
|
||||
GMOCK_PP_COMMA_IF(_i) \
|
||||
::testing::A<GMOCK_INTERNAL_ARG_O(typename, GMOCK_PP_INC(_i), \
|
||||
GMOCK_PP_REMOVE_PARENS(_Signature))>()
|
||||
|
||||
#define GMOCK_INTERNAL_ARG_O(_tn, _i, ...) GMOCK_ARG_(_tn, _i, __VA_ARGS__)
|
||||
|
||||
#define GMOCK_INTERNAL_MATCHER_O(_tn, _i, ...) \
|
||||
GMOCK_MATCHER_(_tn, _i, __VA_ARGS__)
|
||||
|
||||
#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_
|
File diff suppressed because it is too large
Load Diff
@ -43,6 +43,9 @@ $$}} This meta comment fixes auto-indentation in editors.
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
@ -63,19 +66,19 @@ $range j 1..i
|
||||
$var types = [[$for j [[, typename A$j]]]]
|
||||
$var as = [[$for j, [[A$j]]]]
|
||||
$var args = [[$if i==0 [[]] $else [[ args]]]]
|
||||
$var gets = [[$for j, [[get<$(j - 1)>(args)]]]]
|
||||
$var gets = [[$for j, [[std::get<$(j - 1)>(args)]]]]
|
||||
template <typename R$types>
|
||||
class InvokeHelper<R, ::testing::tuple<$as> > {
|
||||
class InvokeHelper<R, ::std::tuple<$as> > {
|
||||
public:
|
||||
template <typename Function>
|
||||
static R Invoke(Function function, const ::testing::tuple<$as>&$args) {
|
||||
static R Invoke(Function function, const ::std::tuple<$as>&$args) {
|
||||
return function($gets);
|
||||
}
|
||||
|
||||
template <class Class, typename MethodPtr>
|
||||
static R InvokeMethod(Class* obj_ptr,
|
||||
MethodPtr method_ptr,
|
||||
const ::testing::tuple<$as>&$args) {
|
||||
const ::std::tuple<$as>&$args) {
|
||||
return (obj_ptr->*method_ptr)($gets);
|
||||
}
|
||||
|
||||
@ -83,7 +86,7 @@ class InvokeHelper<R, ::testing::tuple<$as> > {
|
||||
$if i <= max_callback_arity [[
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<$as>&$args) {
|
||||
const ::std::tuple<$as>&$args) {
|
||||
return callback->Run($gets);
|
||||
}
|
||||
]] $else [[
|
||||
@ -116,98 +119,7 @@ class InvokeCallbackAction {
|
||||
callback_.get(), args);
|
||||
}
|
||||
private:
|
||||
const linked_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// An INTERNAL macro for extracting the type of a tuple field. It's
|
||||
// subject to change without notice - DO NOT USE IN USER CODE!
|
||||
#define GMOCK_FIELD_(Tuple, N) \
|
||||
typename ::testing::tuple_element<N, Tuple>::type
|
||||
|
||||
$range i 1..n
|
||||
|
||||
// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
|
||||
// type of an n-ary function whose i-th (1-based) argument type is the
|
||||
// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
|
||||
// type, and whose return type is Result. For example,
|
||||
// SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type
|
||||
// is int(bool, long).
|
||||
//
|
||||
// SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
|
||||
// returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
|
||||
// For example,
|
||||
// SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select(
|
||||
// ::testing::make_tuple(true, 'a', 2.5))
|
||||
// returns tuple (2.5, true).
|
||||
//
|
||||
// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
|
||||
// in the range [0, $n]. Duplicates are allowed and they don't have
|
||||
// to be in an ascending or descending order.
|
||||
|
||||
template <typename Result, typename ArgumentTuple, $for i, [[int k$i]]>
|
||||
class SelectArgs {
|
||||
public:
|
||||
typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]);
|
||||
typedef typename Function<type>::ArgumentTuple SelectedArgs;
|
||||
static SelectedArgs Select(const ArgumentTuple& args) {
|
||||
return SelectedArgs($for i, [[get<k$i>(args)]]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$for i [[
|
||||
$range j 1..n
|
||||
$range j1 1..i-1
|
||||
template <typename Result, typename ArgumentTuple$for j1[[, int k$j1]]>
|
||||
class SelectArgs<Result, ArgumentTuple,
|
||||
$for j, [[$if j <= i-1 [[k$j]] $else [[-1]]]]> {
|
||||
public:
|
||||
typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]);
|
||||
typedef typename Function<type>::ArgumentTuple SelectedArgs;
|
||||
static SelectedArgs Select(const ArgumentTuple& [[]]
|
||||
$if i == 1 [[/* args */]] $else [[args]]) {
|
||||
return SelectedArgs($for j1, [[get<k$j1>(args)]]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
#undef GMOCK_FIELD_
|
||||
|
||||
$var ks = [[$for i, [[k$i]]]]
|
||||
|
||||
// Implements the WithArgs action.
|
||||
template <typename InnerAction, $for i, [[int k$i = -1]]>
|
||||
class WithArgsAction {
|
||||
public:
|
||||
explicit WithArgsAction(const InnerAction& action) : action_(action) {}
|
||||
|
||||
template <typename F>
|
||||
operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
|
||||
|
||||
private:
|
||||
template <typename F>
|
||||
class Impl : public ActionInterface<F> {
|
||||
public:
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
explicit Impl(const InnerAction& action) : action_(action) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple& args) {
|
||||
return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef typename SelectArgs<Result, ArgumentTuple,
|
||||
$ks>::type InnerFunctionType;
|
||||
|
||||
Action<InnerFunctionType> action_;
|
||||
};
|
||||
|
||||
const InnerAction action_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(WithArgsAction);
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// A macro from the ACTION* family (defined later in this file)
|
||||
@ -240,12 +152,12 @@ $range j 0..i-1
|
||||
]]]]
|
||||
$range j 0..i-1
|
||||
$var As = [[$for j, [[A$j]]]]
|
||||
$var as = [[$for j, [[get<$j>(args)]]]]
|
||||
$var as = [[$for j, [[std::get<$j>(args)]]]]
|
||||
$range k 1..n-i
|
||||
$var eas = [[$for k, [[ExcessiveArg()]]]]
|
||||
$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
|
||||
$template
|
||||
static Result Perform(Impl* impl, const ::testing::tuple<$As>& args) {
|
||||
static Result Perform(Impl* impl, const ::std::tuple<$As>& args) {
|
||||
return impl->template gmock_PerformImpl<$As>(args, $arg_list);
|
||||
}
|
||||
|
||||
@ -253,53 +165,6 @@ $template
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Various overloads for Invoke().
|
||||
|
||||
// WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
|
||||
// the selected arguments of the mock function to an_action and
|
||||
// performs it. It serves as an adaptor between actions with
|
||||
// different argument lists. C++ doesn't support default arguments for
|
||||
// function templates, so we have to overload it.
|
||||
|
||||
$range i 1..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
template <$for j [[int k$j, ]]typename InnerAction>
|
||||
inline internal::WithArgsAction<InnerAction$for j [[, k$j]]>
|
||||
WithArgs(const InnerAction& action) {
|
||||
return internal::WithArgsAction<InnerAction$for j [[, k$j]]>(action);
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
// Creates an action that does actions a1, a2, ..., sequentially in
|
||||
// each invocation.
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 2..i
|
||||
$var types = [[$for j, [[typename Action$j]]]]
|
||||
$var Aas = [[$for j [[, Action$j a$j]]]]
|
||||
|
||||
template <typename Action1, $types>
|
||||
$range k 1..i-1
|
||||
|
||||
inline $for k [[internal::DoBothAction<Action$k, ]]Action$i$for k [[>]]
|
||||
|
||||
DoAll(Action1 a1$Aas) {
|
||||
$if i==2 [[
|
||||
|
||||
return internal::DoBothAction<Action1, Action2>(a1, a2);
|
||||
]] $else [[
|
||||
$range j2 2..i
|
||||
|
||||
return DoAll(a1, DoAll($for j2, [[a$j2]]));
|
||||
]]
|
||||
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// The ACTION* family of macros can be used in a namespace scope to
|
||||
@ -395,8 +260,8 @@ $range j2 2..i
|
||||
//
|
||||
// MORE INFORMATION:
|
||||
//
|
||||
// To learn more about using these macros, please search for 'ACTION'
|
||||
// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
|
||||
// To learn more about using these macros, please search for 'ACTION' on
|
||||
// https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
|
||||
|
||||
$range i 0..n
|
||||
$range k 0..n-1
|
||||
@ -432,7 +297,7 @@ $for k [[, \
|
||||
// ACTION_TEMPLATE(DuplicateArg,
|
||||
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
|
||||
// AND_1_VALUE_PARAMS(output)) {
|
||||
// *output = T(::testing::get<k>(args));
|
||||
// *output = T(::std::get<k>(args));
|
||||
// }
|
||||
// ...
|
||||
// int n;
|
||||
@ -525,7 +390,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
|
||||
$for i [[
|
||||
$range j 0..i-1
|
||||
#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
|
||||
($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::testing::internal::move(gmock_p$j))]]
|
||||
($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::std::move(gmock_p$j))]]
|
||||
|
||||
|
||||
]]
|
||||
@ -658,7 +523,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
|
||||
$range j 0..i-1
|
||||
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::forward<p$j##_type>(gmock_p$j))]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::forward<p$j##_type>(gmock_p$j))]]]]]]
|
||||
$var param_field_decls = [[$for j
|
||||
[[
|
||||
|
||||
@ -796,7 +661,7 @@ ACTION_TEMPLATE(InvokeArgument,
|
||||
using internal::invoke_argument::InvokeArgumentAdl;
|
||||
return InvokeArgumentAdl<return_type>(
|
||||
internal::invoke_argument::AdlTag(),
|
||||
::testing::get<k>(args)$for j [[, p$j]]);
|
||||
::std::get<k>(args)$for j [[, p$j]]);
|
||||
}
|
||||
|
||||
]]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,59 +42,16 @@ $var n = 10 $$ The maximum arity we support.
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
template <typename F>
|
||||
class FunctionMockerBase;
|
||||
|
||||
// Note: class FunctionMocker really belongs to the ::testing
|
||||
// namespace. However if we define it in ::testing, MSVC will
|
||||
// complain when classes in ::testing::internal declare it as a
|
||||
// friend class template. To workaround this compiler bug, we define
|
||||
// FunctionMocker in ::testing::internal and import it into ::testing.
|
||||
template <typename F>
|
||||
class FunctionMocker;
|
||||
|
||||
|
||||
$range i 0..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$var typename_As = [[$for j [[, typename A$j]]]]
|
||||
$var As = [[$for j, [[A$j]]]]
|
||||
$var as = [[$for j, [[internal::forward<A$j>(a$j)]]]]
|
||||
$var Aas = [[$for j, [[A$j a$j]]]]
|
||||
$var ms = [[$for j, [[m$j]]]]
|
||||
$var matchers = [[$for j, [[const Matcher<A$j>& m$j]]]]
|
||||
template <typename R$typename_As>
|
||||
class FunctionMocker<R($As)> : public
|
||||
internal::FunctionMockerBase<R($As)> {
|
||||
public:
|
||||
typedef R F($As);
|
||||
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
MockSpec<F> With($matchers) {
|
||||
return MockSpec<F>(this, ::testing::make_tuple($ms));
|
||||
}
|
||||
|
||||
R Invoke($Aas) {
|
||||
// Even though gcc and MSVC don't enforce it, 'this->' is required
|
||||
// by the C++ standard [14.6.4] here, as the base class type is
|
||||
// dependent on the template argument (and thus shouldn't be
|
||||
// looked into when resolving InvokeWith).
|
||||
return this->InvokeWith(ArgumentTuple($as));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
// Removes the given pointer; this is a helper for the expectation setter method
|
||||
// for parameterless matchers.
|
||||
//
|
||||
@ -184,7 +141,7 @@ $for i [[
|
||||
$range j 1..i
|
||||
$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
|
||||
$var as = [[$for j, \
|
||||
[[::testing::internal::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
|
||||
[[::std::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
|
||||
$var matcher_arg_as = [[$for j, \
|
||||
[[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
|
||||
$var matcher_as = [[$for j, [[gmock_a$j]]]]
|
||||
@ -194,7 +151,7 @@ $var anything_matchers = [[$for j, \
|
||||
#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
|
||||
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
|
||||
$arg_as) constness { \
|
||||
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
|
||||
GTEST_COMPILE_ASSERT_((::std::tuple_size< \
|
||||
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \
|
||||
this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \
|
||||
GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
|
||||
@ -267,82 +224,6 @@ $for i [[
|
||||
|
||||
]]
|
||||
|
||||
// A MockFunction<F> class has one mock method whose type is F. It is
|
||||
// useful when you just want your test code to emit some messages and
|
||||
// have Google Mock verify the right messages are sent (and perhaps at
|
||||
// the right times). For example, if you are exercising code:
|
||||
//
|
||||
// Foo(1);
|
||||
// Foo(2);
|
||||
// Foo(3);
|
||||
//
|
||||
// and want to verify that Foo(1) and Foo(3) both invoke
|
||||
// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
|
||||
//
|
||||
// TEST(FooTest, InvokesBarCorrectly) {
|
||||
// MyMock mock;
|
||||
// MockFunction<void(string check_point_name)> check;
|
||||
// {
|
||||
// InSequence s;
|
||||
//
|
||||
// EXPECT_CALL(mock, Bar("a"));
|
||||
// EXPECT_CALL(check, Call("1"));
|
||||
// EXPECT_CALL(check, Call("2"));
|
||||
// EXPECT_CALL(mock, Bar("a"));
|
||||
// }
|
||||
// Foo(1);
|
||||
// check.Call("1");
|
||||
// Foo(2);
|
||||
// check.Call("2");
|
||||
// Foo(3);
|
||||
// }
|
||||
//
|
||||
// The expectation spec says that the first Bar("a") must happen
|
||||
// before check point "1", the second Bar("a") must happen after check
|
||||
// point "2", and nothing should happen between the two check
|
||||
// points. The explicit check points make it easy to tell which
|
||||
// Bar("a") is called by which call to Foo().
|
||||
//
|
||||
// MockFunction<F> can also be used to exercise code that accepts
|
||||
// std::function<F> callbacks. To do so, use AsStdFunction() method
|
||||
// to create std::function proxy forwarding to original object's Call.
|
||||
// Example:
|
||||
//
|
||||
// TEST(FooTest, RunsCallbackWithBarArgument) {
|
||||
// MockFunction<int(string)> callback;
|
||||
// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
|
||||
// Foo(callback.AsStdFunction());
|
||||
// }
|
||||
template <typename F>
|
||||
class MockFunction;
|
||||
|
||||
|
||||
$for i [[
|
||||
$range j 0..i-1
|
||||
$var ArgTypes = [[$for j, [[A$j]]]]
|
||||
$var ArgValues = [[$for j, [[::std::forward<A$j>(a$j)]]]]
|
||||
$var ArgDecls = [[$for j, [[A$j a$j]]]]
|
||||
template <typename R$for j [[, typename A$j]]>
|
||||
class MockFunction<R($ArgTypes)> {
|
||||
public:
|
||||
MockFunction() {}
|
||||
|
||||
MOCK_METHOD$i[[]]_T(Call, R($ArgTypes));
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
::std::function<R($ArgTypes)> AsStdFunction() {
|
||||
return [this]($ArgDecls) -> R {
|
||||
return this->Call($ArgValues);
|
||||
};
|
||||
}
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
|
||||
|
@ -43,515 +43,10 @@
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// The type of the i-th (0-based) field of Tuple.
|
||||
#define GMOCK_FIELD_TYPE_(Tuple, i) \
|
||||
typename ::testing::tuple_element<i, Tuple>::type
|
||||
|
||||
// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
|
||||
// tuple of type Tuple. It has two members:
|
||||
//
|
||||
// type: a tuple type whose i-th field is the ki-th field of Tuple.
|
||||
// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
|
||||
//
|
||||
// For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
|
||||
//
|
||||
// type is tuple<int, bool>, and
|
||||
// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
|
||||
|
||||
template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
|
||||
int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
|
||||
int k9 = -1>
|
||||
class TupleFields;
|
||||
|
||||
// This generic version is used when there are 10 selectors.
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
|
||||
int k7, int k8, int k9>
|
||||
class TupleFields {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k9)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
|
||||
get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
|
||||
}
|
||||
};
|
||||
|
||||
// The following specialization is used for 0 ~ 9 selectors.
|
||||
|
||||
template <class Tuple>
|
||||
class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<> type;
|
||||
static type GetSelectedFields(const Tuple& /* t */) {
|
||||
return type();
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0>
|
||||
class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1>
|
||||
class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2>
|
||||
class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k5)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
|
||||
get<k5>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
|
||||
get<k5>(t), get<k6>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
|
||||
int k7>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k7)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
|
||||
get<k5>(t), get<k6>(t), get<k7>(t));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
|
||||
int k7, int k8>
|
||||
class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
|
||||
public:
|
||||
typedef ::testing::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
|
||||
GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
|
||||
get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
|
||||
}
|
||||
};
|
||||
|
||||
#undef GMOCK_FIELD_TYPE_
|
||||
|
||||
// Implements the Args() matcher.
|
||||
template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
|
||||
int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
|
||||
int k9 = -1>
|
||||
class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
|
||||
public:
|
||||
// ArgsTuple may have top-level const or reference modifiers.
|
||||
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
|
||||
typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
|
||||
k6, k7, k8, k9>::type SelectedArgs;
|
||||
typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
|
||||
|
||||
template <typename InnerMatcher>
|
||||
explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
|
||||
: inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
|
||||
|
||||
virtual bool MatchAndExplain(ArgsTuple args,
|
||||
MatchResultListener* listener) const {
|
||||
const SelectedArgs& selected_args = GetSelectedArgs(args);
|
||||
if (!listener->IsInterested())
|
||||
return inner_matcher_.Matches(selected_args);
|
||||
|
||||
PrintIndices(listener->stream());
|
||||
*listener << "are " << PrintToString(selected_args);
|
||||
|
||||
StringMatchResultListener inner_listener;
|
||||
const bool match = inner_matcher_.MatchAndExplain(selected_args,
|
||||
&inner_listener);
|
||||
PrintIfNotEmpty(inner_listener.str(), listener->stream());
|
||||
return match;
|
||||
}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
*os << "are a tuple ";
|
||||
PrintIndices(os);
|
||||
inner_matcher_.DescribeTo(os);
|
||||
}
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "are a tuple ";
|
||||
PrintIndices(os);
|
||||
inner_matcher_.DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
private:
|
||||
static SelectedArgs GetSelectedArgs(ArgsTuple args) {
|
||||
return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
|
||||
k9>::GetSelectedFields(args);
|
||||
}
|
||||
|
||||
// Prints the indices of the selected fields.
|
||||
static void PrintIndices(::std::ostream* os) {
|
||||
*os << "whose fields (";
|
||||
const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (indices[i] < 0)
|
||||
break;
|
||||
|
||||
if (i >= 1)
|
||||
*os << ", ";
|
||||
|
||||
*os << "#" << indices[i];
|
||||
}
|
||||
*os << ") ";
|
||||
}
|
||||
|
||||
const MonomorphicInnerMatcher inner_matcher_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
|
||||
};
|
||||
|
||||
template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
|
||||
int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
|
||||
int k8 = -1, int k9 = -1>
|
||||
class ArgsMatcher {
|
||||
public:
|
||||
explicit ArgsMatcher(const InnerMatcher& inner_matcher)
|
||||
: inner_matcher_(inner_matcher) {}
|
||||
|
||||
template <typename ArgsTuple>
|
||||
operator Matcher<ArgsTuple>() const {
|
||||
return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
|
||||
k6, k7, k8, k9>(inner_matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
const InnerMatcher inner_matcher_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
|
||||
};
|
||||
|
||||
// A set of metafunctions for computing the result type of AnyOf.
|
||||
// AnyOf(m1, ..., mN) returns
|
||||
// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
|
||||
|
||||
// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
|
||||
// to simplify the implementation.
|
||||
template <typename M1>
|
||||
struct AnyOfResult1 {
|
||||
typedef M1 type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2>
|
||||
struct AnyOfResult2 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult1<M1>::type,
|
||||
typename AnyOfResult1<M2>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3>
|
||||
struct AnyOfResult3 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult1<M1>::type,
|
||||
typename AnyOfResult2<M2, M3>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4>
|
||||
struct AnyOfResult4 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult2<M1, M2>::type,
|
||||
typename AnyOfResult2<M3, M4>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5>
|
||||
struct AnyOfResult5 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult2<M1, M2>::type,
|
||||
typename AnyOfResult3<M3, M4, M5>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6>
|
||||
struct AnyOfResult6 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult3<M1, M2, M3>::type,
|
||||
typename AnyOfResult3<M4, M5, M6>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7>
|
||||
struct AnyOfResult7 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult3<M1, M2, M3>::type,
|
||||
typename AnyOfResult4<M4, M5, M6, M7>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8>
|
||||
struct AnyOfResult8 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult4<M1, M2, M3, M4>::type,
|
||||
typename AnyOfResult4<M5, M6, M7, M8>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9>
|
||||
struct AnyOfResult9 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult4<M1, M2, M3, M4>::type,
|
||||
typename AnyOfResult5<M5, M6, M7, M8, M9>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9, typename M10>
|
||||
struct AnyOfResult10 {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
|
||||
typename AnyOfResult5<M6, M7, M8, M9, M10>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
|
||||
// fields of it matches a_matcher. C++ doesn't support default
|
||||
// arguments for function templates, so we have to overload it.
|
||||
template <typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
|
||||
typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
|
||||
k7>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
|
||||
typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
|
||||
k8>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
|
||||
int k9, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
|
||||
k9>(matcher);
|
||||
}
|
||||
|
||||
template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
|
||||
int k9, int k10, typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
|
||||
k10>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
|
||||
k9, k10>(matcher);
|
||||
}
|
||||
|
||||
|
||||
// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
|
||||
// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
|
||||
|
||||
template <typename M1, typename M2>
|
||||
inline typename internal::AnyOfResult2<M1, M2>::type
|
||||
AnyOf(M1 m1, M2 m2) {
|
||||
return typename internal::AnyOfResult2<M1, M2>::type(
|
||||
m1,
|
||||
m2);
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3>
|
||||
inline typename internal::AnyOfResult3<M1, M2, M3>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3) {
|
||||
return typename internal::AnyOfResult3<M1, M2, M3>::type(
|
||||
m1,
|
||||
::testing::AnyOf(m2, m3));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4>
|
||||
inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
|
||||
return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
|
||||
::testing::AnyOf(m1, m2),
|
||||
::testing::AnyOf(m3, m4));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5>
|
||||
inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
|
||||
return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
|
||||
::testing::AnyOf(m1, m2),
|
||||
::testing::AnyOf(m3, m4, m5));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6>
|
||||
inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
|
||||
return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
|
||||
::testing::AnyOf(m1, m2, m3),
|
||||
::testing::AnyOf(m4, m5, m6));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7>
|
||||
inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
|
||||
return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
|
||||
::testing::AnyOf(m1, m2, m3),
|
||||
::testing::AnyOf(m4, m5, m6, m7));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8>
|
||||
inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
|
||||
return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4),
|
||||
::testing::AnyOf(m5, m6, m7, m8));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9>
|
||||
inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
|
||||
return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
|
||||
M9>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4),
|
||||
::testing::AnyOf(m5, m6, m7, m8, m9));
|
||||
}
|
||||
|
||||
template <typename M1, typename M2, typename M3, typename M4, typename M5,
|
||||
typename M6, typename M7, typename M8, typename M9, typename M10>
|
||||
inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
|
||||
M10>::type
|
||||
AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
|
||||
M10>::type(
|
||||
::testing::AnyOf(m1, m2, m3, m4, m5),
|
||||
::testing::AnyOf(m6, m7, m8, m9, m10));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
|
||||
// The MATCHER* family of macros can be used in a namespace scope to
|
||||
// define custom matchers easily.
|
||||
//
|
||||
@ -795,7 +290,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<>()));\
|
||||
::std::tuple<>()));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
@ -825,7 +320,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
explicit gmock_Impl(p0##_type gmock_p0)\
|
||||
: p0(::testing::internal::move(gmock_p0)) {}\
|
||||
: p0(::std::move(gmock_p0)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -845,7 +340,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type>(p0)));\
|
||||
::std::tuple<p0##_type>(p0)));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
@ -853,8 +348,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::Matcher<arg_type>(\
|
||||
new gmock_Impl<arg_type>(p0));\
|
||||
}\
|
||||
explicit name##MatcherP(p0##_type gmock_p0) : \
|
||||
p0(::testing::internal::move(gmock_p0)) {\
|
||||
explicit name##MatcherP(p0##_type gmock_p0) : p0(::std::move(gmock_p0)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
private:\
|
||||
@ -879,8 +373,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -901,7 +394,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type>(p0, p1)));\
|
||||
::std::tuple<p0##_type, p1##_type>(p0, p1)));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
@ -910,8 +403,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
new gmock_Impl<arg_type>(p0, p1));\
|
||||
}\
|
||||
name##MatcherP2(p0##_type gmock_p0, \
|
||||
p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)) {\
|
||||
p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -939,9 +432,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -963,8 +455,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
|
||||
p2)));\
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, p2)));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
@ -973,9 +464,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
new gmock_Impl<arg_type>(p0, p1, p2));\
|
||||
}\
|
||||
name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)) {\
|
||||
p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1006,10 +496,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1032,8 +520,8 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, \
|
||||
p3##_type>(p0, p1, p2, p3)));\
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
|
||||
p1, p2, p3)));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
@ -1042,11 +530,9 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
new gmock_Impl<arg_type>(p0, p1, p2, p3));\
|
||||
}\
|
||||
name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)) {\
|
||||
p2##_type gmock_p2, p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1082,11 +568,9 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1110,7 +594,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type>(p0, p1, p2, p3, p4)));\
|
||||
}\
|
||||
};\
|
||||
@ -1121,11 +605,9 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
}\
|
||||
name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, \
|
||||
p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)) {\
|
||||
p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1162,12 +644,9 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1192,7 +671,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
|
||||
}\
|
||||
};\
|
||||
@ -1203,12 +682,10 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
}\
|
||||
name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)) {\
|
||||
p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1248,13 +725,10 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1280,7 +754,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
|
||||
p6)));\
|
||||
}\
|
||||
@ -1292,14 +766,10 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
}\
|
||||
name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)) {\
|
||||
p5##_type gmock_p5, p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1343,14 +813,10 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1377,7 +843,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
|
||||
p3, p4, p5, p6, p7)));\
|
||||
}\
|
||||
@ -1390,14 +856,11 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, \
|
||||
p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)) {\
|
||||
p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1444,15 +907,11 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
|
||||
p8(::std::move(gmock_p8)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1480,7 +939,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type, p6##_type, p7##_type, \
|
||||
p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
|
||||
}\
|
||||
@ -1493,15 +952,11 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)) {\
|
||||
p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
@ -1552,16 +1007,11 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9)\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)), \
|
||||
p9(::testing::internal::move(gmock_p9)) {}\
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
|
||||
p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
@ -1590,7 +1040,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
::std::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
|
||||
p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
|
||||
}\
|
||||
@ -1603,17 +1053,12 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
||||
name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)), \
|
||||
p9(::testing::internal::move(gmock_p9)) {\
|
||||
p8##_type gmock_p8, p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
|
||||
p9(::std::move(gmock_p9)) {\
|
||||
}\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
|
@ -45,221 +45,10 @@ $$ }} This line fixes auto-indentation of the following code in Emacs.
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
$range i 0..n-1
|
||||
|
||||
// The type of the i-th (0-based) field of Tuple.
|
||||
#define GMOCK_FIELD_TYPE_(Tuple, i) \
|
||||
typename ::testing::tuple_element<i, Tuple>::type
|
||||
|
||||
// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
|
||||
// tuple of type Tuple. It has two members:
|
||||
//
|
||||
// type: a tuple type whose i-th field is the ki-th field of Tuple.
|
||||
// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
|
||||
//
|
||||
// For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
|
||||
//
|
||||
// type is tuple<int, bool>, and
|
||||
// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
|
||||
|
||||
template <class Tuple$for i [[, int k$i = -1]]>
|
||||
class TupleFields;
|
||||
|
||||
// This generic version is used when there are $n selectors.
|
||||
template <class Tuple$for i [[, int k$i]]>
|
||||
class TupleFields {
|
||||
public:
|
||||
typedef ::testing::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type;
|
||||
static type GetSelectedFields(const Tuple& t) {
|
||||
return type($for i, [[get<k$i>(t)]]);
|
||||
}
|
||||
};
|
||||
|
||||
// The following specialization is used for 0 ~ $(n-1) selectors.
|
||||
|
||||
$for i [[
|
||||
$$ }}}
|
||||
$range j 0..i-1
|
||||
$range k 0..n-1
|
||||
|
||||
template <class Tuple$for j [[, int k$j]]>
|
||||
class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> {
|
||||
public:
|
||||
typedef ::testing::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type;
|
||||
static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) {
|
||||
return type($for j, [[get<k$j>(t)]]);
|
||||
}
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
#undef GMOCK_FIELD_TYPE_
|
||||
|
||||
// Implements the Args() matcher.
|
||||
|
||||
$var ks = [[$for i, [[k$i]]]]
|
||||
template <class ArgsTuple$for i [[, int k$i = -1]]>
|
||||
class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
|
||||
public:
|
||||
// ArgsTuple may have top-level const or reference modifiers.
|
||||
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
|
||||
typedef typename internal::TupleFields<RawArgsTuple, $ks>::type SelectedArgs;
|
||||
typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
|
||||
|
||||
template <typename InnerMatcher>
|
||||
explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
|
||||
: inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
|
||||
|
||||
virtual bool MatchAndExplain(ArgsTuple args,
|
||||
MatchResultListener* listener) const {
|
||||
const SelectedArgs& selected_args = GetSelectedArgs(args);
|
||||
if (!listener->IsInterested())
|
||||
return inner_matcher_.Matches(selected_args);
|
||||
|
||||
PrintIndices(listener->stream());
|
||||
*listener << "are " << PrintToString(selected_args);
|
||||
|
||||
StringMatchResultListener inner_listener;
|
||||
const bool match = inner_matcher_.MatchAndExplain(selected_args,
|
||||
&inner_listener);
|
||||
PrintIfNotEmpty(inner_listener.str(), listener->stream());
|
||||
return match;
|
||||
}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
*os << "are a tuple ";
|
||||
PrintIndices(os);
|
||||
inner_matcher_.DescribeTo(os);
|
||||
}
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "are a tuple ";
|
||||
PrintIndices(os);
|
||||
inner_matcher_.DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
private:
|
||||
static SelectedArgs GetSelectedArgs(ArgsTuple args) {
|
||||
return TupleFields<RawArgsTuple, $ks>::GetSelectedFields(args);
|
||||
}
|
||||
|
||||
// Prints the indices of the selected fields.
|
||||
static void PrintIndices(::std::ostream* os) {
|
||||
*os << "whose fields (";
|
||||
const int indices[$n] = { $ks };
|
||||
for (int i = 0; i < $n; i++) {
|
||||
if (indices[i] < 0)
|
||||
break;
|
||||
|
||||
if (i >= 1)
|
||||
*os << ", ";
|
||||
|
||||
*os << "#" << indices[i];
|
||||
}
|
||||
*os << ") ";
|
||||
}
|
||||
|
||||
const MonomorphicInnerMatcher inner_matcher_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
|
||||
};
|
||||
|
||||
template <class InnerMatcher$for i [[, int k$i = -1]]>
|
||||
class ArgsMatcher {
|
||||
public:
|
||||
explicit ArgsMatcher(const InnerMatcher& inner_matcher)
|
||||
: inner_matcher_(inner_matcher) {}
|
||||
|
||||
template <typename ArgsTuple>
|
||||
operator Matcher<ArgsTuple>() const {
|
||||
return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, $ks>(inner_matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
const InnerMatcher inner_matcher_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
|
||||
};
|
||||
|
||||
// A set of metafunctions for computing the result type of AnyOf.
|
||||
// AnyOf(m1, ..., mN) returns
|
||||
// AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
|
||||
|
||||
// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
|
||||
// to simplify the implementation.
|
||||
template <typename M1>
|
||||
struct AnyOfResult1 {
|
||||
typedef M1 type;
|
||||
};
|
||||
|
||||
$range i 1..n
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 2..i
|
||||
$var m = i/2
|
||||
$range k 1..m
|
||||
$range t m+1..i
|
||||
|
||||
template <typename M1$for j [[, typename M$j]]>
|
||||
struct AnyOfResult$i {
|
||||
typedef EitherOfMatcher<
|
||||
typename AnyOfResult$m<$for k, [[M$k]]>::type,
|
||||
typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type
|
||||
> type;
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
|
||||
// fields of it matches a_matcher. C++ doesn't support default
|
||||
// arguments for function templates, so we have to overload it.
|
||||
|
||||
$range i 0..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
template <$for j [[int k$j, ]]typename InnerMatcher>
|
||||
inline internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>
|
||||
Args(const InnerMatcher& matcher) {
|
||||
return internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>(matcher);
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
|
||||
// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
|
||||
// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$var m = i/2
|
||||
$range k 1..m
|
||||
$range t m+1..i
|
||||
|
||||
template <$for j, [[typename M$j]]>
|
||||
inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type
|
||||
AnyOf($for j, [[M$j m$j]]) {
|
||||
return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type(
|
||||
$if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]],
|
||||
$if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]);
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
} // namespace testing
|
||||
$$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not
|
||||
$$ // show up in the generated code.
|
||||
|
||||
|
||||
// The MATCHER* family of macros can be used in a namespace scope to
|
||||
// define custom matchers easily.
|
||||
//
|
||||
@ -491,8 +280,8 @@ $var template = [[$if i==0 [[]] $else [[
|
||||
]]]]
|
||||
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
|
||||
$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]]
|
||||
$var params = [[$for j, [[p$j]]]]
|
||||
$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
|
||||
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
|
||||
@ -534,7 +323,7 @@ $var param_field_decls2 = [[$for j
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
|
||||
::std::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
|
||||
}\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
|
@ -1,459 +0,0 @@
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gmock-generated-nice-strict.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// 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.
|
||||
|
||||
|
||||
// Implements class templates NiceMock, NaggyMock, and StrictMock.
|
||||
//
|
||||
// Given a mock class MockFoo that is created using Google Mock,
|
||||
// NiceMock<MockFoo> is a subclass of MockFoo that allows
|
||||
// uninteresting calls (i.e. calls to mock methods that have no
|
||||
// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
|
||||
// that prints a warning when an uninteresting call occurs, and
|
||||
// StrictMock<MockFoo> is a subclass of MockFoo that treats all
|
||||
// uninteresting calls as errors.
|
||||
//
|
||||
// Currently a mock is naggy by default, so MockFoo and
|
||||
// NaggyMock<MockFoo> behave like the same. However, we will soon
|
||||
// switch the default behavior of mocks to be nice, as that in general
|
||||
// leads to more maintainable tests. When that happens, MockFoo will
|
||||
// stop behaving like NaggyMock<MockFoo> and start behaving like
|
||||
// NiceMock<MockFoo>.
|
||||
//
|
||||
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
|
||||
// their respective base class. Therefore you can write
|
||||
// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
|
||||
// has a constructor that accepts (int, const char*), for example.
|
||||
//
|
||||
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
|
||||
// and StrictMock<MockFoo> only works for mock methods defined using
|
||||
// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
|
||||
// If a mock method is defined in a base class of MockFoo, the "nice"
|
||||
// or "strict" modifier may not affect it, depending on the compiler.
|
||||
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
|
||||
// supported.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
template <class MockClass>
|
||||
class NiceMock : public MockClass {
|
||||
public:
|
||||
NiceMock() : MockClass() {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NiceMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NiceMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class NaggyMock : public MockClass {
|
||||
public:
|
||||
NaggyMock() : MockClass() {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NaggyMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NaggyMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class StrictMock : public MockClass {
|
||||
public:
|
||||
StrictMock() : MockClass() {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit StrictMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
template <typename A1, typename A2>
|
||||
StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3,
|
||||
const A4& a4) : MockClass(a1, a2, a3, a4) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
|
||||
a6, a7) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
|
||||
a2, a3, a4, a5, a6, a7, a8) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8,
|
||||
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
|
||||
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
|
||||
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~StrictMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
|
||||
};
|
||||
|
||||
// The following specializations catch some (relatively more common)
|
||||
// user errors of nesting nice and strict mocks. They do NOT catch
|
||||
// all possible errors.
|
||||
|
||||
// These specializations are declared but not defined, as NiceMock,
|
||||
// NaggyMock, and StrictMock cannot be nested.
|
||||
|
||||
template <typename MockClass>
|
||||
class NiceMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NiceMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NiceMock<StrictMock<MockClass> >;
|
||||
|
||||
template <typename MockClass>
|
||||
class NaggyMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NaggyMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class NaggyMock<StrictMock<MockClass> >;
|
||||
|
||||
template <typename MockClass>
|
||||
class StrictMock<NiceMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class StrictMock<NaggyMock<MockClass> >;
|
||||
template <typename MockClass>
|
||||
class StrictMock<StrictMock<MockClass> >;
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
File diff suppressed because it is too large
Load Diff
@ -127,27 +127,6 @@ PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
|
||||
internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
|
||||
}
|
||||
|
||||
// WithoutArgs(inner_action) can be used in a mock function with a
|
||||
// non-empty argument list to perform inner_action, which takes no
|
||||
// argument. In other words, it adapts an action accepting no
|
||||
// argument to one that accepts (and ignores) arguments.
|
||||
template <typename InnerAction>
|
||||
inline internal::WithArgsAction<InnerAction>
|
||||
WithoutArgs(const InnerAction& action) {
|
||||
return internal::WithArgsAction<InnerAction>(action);
|
||||
}
|
||||
|
||||
// WithArg<k>(an_action) creates an action that passes the k-th
|
||||
// (0-based) argument of the mock function to an_action and performs
|
||||
// it. It adapts an action accepting one argument to one that accepts
|
||||
// multiple arguments. For convenience, we also provide
|
||||
// WithArgs<k>(an_action) (defined below) as a synonym.
|
||||
template <int k, typename InnerAction>
|
||||
inline internal::WithArgsAction<InnerAction, k>
|
||||
WithArg(const InnerAction& action) {
|
||||
return internal::WithArgsAction<InnerAction, k>(action);
|
||||
}
|
||||
|
||||
// The ACTION*() macros trigger warning C4100 (unreferenced formal
|
||||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
@ -162,7 +141,7 @@ WithArg(const InnerAction& action) {
|
||||
ACTION_TEMPLATE(ReturnArg,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_0_VALUE_PARAMS()) {
|
||||
return ::testing::get<k>(args);
|
||||
return ::std::get<k>(args);
|
||||
}
|
||||
|
||||
// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
|
||||
@ -170,7 +149,7 @@ ACTION_TEMPLATE(ReturnArg,
|
||||
ACTION_TEMPLATE(SaveArg,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_1_VALUE_PARAMS(pointer)) {
|
||||
*pointer = ::testing::get<k>(args);
|
||||
*pointer = ::std::get<k>(args);
|
||||
}
|
||||
|
||||
// Action SaveArgPointee<k>(pointer) saves the value pointed to
|
||||
@ -178,7 +157,7 @@ ACTION_TEMPLATE(SaveArg,
|
||||
ACTION_TEMPLATE(SaveArgPointee,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_1_VALUE_PARAMS(pointer)) {
|
||||
*pointer = *::testing::get<k>(args);
|
||||
*pointer = *::std::get<k>(args);
|
||||
}
|
||||
|
||||
// Action SetArgReferee<k>(value) assigns 'value' to the variable
|
||||
@ -186,13 +165,13 @@ ACTION_TEMPLATE(SaveArgPointee,
|
||||
ACTION_TEMPLATE(SetArgReferee,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_1_VALUE_PARAMS(value)) {
|
||||
typedef typename ::testing::tuple_element<k, args_type>::type argk_type;
|
||||
typedef typename ::std::tuple_element<k, args_type>::type argk_type;
|
||||
// Ensures that argument #k is a reference. If you get a compiler
|
||||
// error on the next line, you are using SetArgReferee<k>(value) in
|
||||
// a mock function whose k-th (0-based) argument is not a reference.
|
||||
GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
|
||||
SetArgReferee_must_be_used_with_a_reference_argument);
|
||||
::testing::get<k>(args) = value;
|
||||
::std::get<k>(args) = value;
|
||||
}
|
||||
|
||||
// Action SetArrayArgument<k>(first, last) copies the elements in
|
||||
@ -205,9 +184,9 @@ ACTION_TEMPLATE(SetArrayArgument,
|
||||
AND_2_VALUE_PARAMS(first, last)) {
|
||||
// Visual Studio deprecates ::std::copy, so we use our own copy in that case.
|
||||
#ifdef _MSC_VER
|
||||
internal::CopyElements(first, last, ::testing::get<k>(args));
|
||||
internal::CopyElements(first, last, ::std::get<k>(args));
|
||||
#else
|
||||
::std::copy(first, last, ::testing::get<k>(args));
|
||||
::std::copy(first, last, ::std::get<k>(args));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -216,7 +195,7 @@ ACTION_TEMPLATE(SetArrayArgument,
|
||||
ACTION_TEMPLATE(DeleteArg,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_0_VALUE_PARAMS()) {
|
||||
delete ::testing::get<k>(args);
|
||||
delete ::std::get<k>(args);
|
||||
}
|
||||
|
||||
// This action returns the value pointed to by 'pointer'.
|
||||
|
@ -1,8 +1,3 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to gmock-generated-nice-strict.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
@ -65,34 +60,22 @@ $var n = 10 $$ The maximum arity we support.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
$range kind 0..2
|
||||
$for kind [[
|
||||
|
||||
$var clazz=[[$if kind==0 [[NiceMock]]
|
||||
$elif kind==1 [[NaggyMock]]
|
||||
$else [[StrictMock]]]]
|
||||
|
||||
$var method=[[$if kind==0 [[AllowUninterestingCalls]]
|
||||
$elif kind==1 [[WarnUninterestingCalls]]
|
||||
$else [[FailUninterestingCalls]]]]
|
||||
|
||||
template <class MockClass>
|
||||
class $clazz : public MockClass {
|
||||
class NiceMock : public MockClass {
|
||||
public:
|
||||
$clazz() : MockClass() {
|
||||
::testing::Mock::$method(
|
||||
NiceMock() : MockClass() {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
@ -101,50 +84,103 @@ class $clazz : public MockClass {
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::$method(
|
||||
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
$clazz(A1&& arg1, A2&& arg2, An&&... args)
|
||||
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit $clazz(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::$method(
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
$range i 2..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
template <$for j, [[typename A$j]]>
|
||||
$clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
|
||||
]]
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~$clazz() {
|
||||
~NiceMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz);
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
|
||||
};
|
||||
|
||||
]]
|
||||
template <class MockClass>
|
||||
class NaggyMock : public MockClass {
|
||||
public:
|
||||
NaggyMock() : MockClass() {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
~NaggyMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
class StrictMock : public MockClass {
|
||||
public:
|
||||
StrictMock() : MockClass() {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
~StrictMock() { // NOLINT
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
|
||||
};
|
||||
|
||||
// The following specializations catch some (relatively more common)
|
||||
// user errors of nesting nice and strict mocks. They do NOT catch
|
||||
@ -176,4 +212,4 @@ class StrictMock<StrictMock<MockClass> >;
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
@ -62,9 +62,11 @@
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/gmock-cardinalities.h"
|
||||
@ -104,9 +106,6 @@ template <typename F> class TypedExpectation;
|
||||
// Helper class for testing the Expectation class template.
|
||||
class ExpectationTester;
|
||||
|
||||
// Base class for function mockers.
|
||||
template <typename F> class FunctionMockerBase;
|
||||
|
||||
// Protects the mock object registry (in class Mock), all function
|
||||
// mockers, and all expectations.
|
||||
//
|
||||
@ -123,9 +122,9 @@ GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
|
||||
// Untyped base class for ActionResultHolder<R>.
|
||||
class UntypedActionResultHolderBase;
|
||||
|
||||
// Abstract base class of FunctionMockerBase. This is the
|
||||
// Abstract base class of FunctionMocker. This is the
|
||||
// type-agnostic part of the function mocker interface. Its pure
|
||||
// virtual methods are implemented by FunctionMockerBase.
|
||||
// virtual methods are implemented by FunctionMocker.
|
||||
class GTEST_API_ UntypedFunctionMockerBase {
|
||||
public:
|
||||
UntypedFunctionMockerBase();
|
||||
@ -218,8 +217,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
||||
protected:
|
||||
typedef std::vector<const void*> UntypedOnCallSpecs;
|
||||
|
||||
typedef std::vector<internal::linked_ptr<ExpectationBase> >
|
||||
UntypedExpectations;
|
||||
using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>;
|
||||
|
||||
// Returns an Expectation object that references and co-owns exp,
|
||||
// which must be an expectation on this mock function.
|
||||
@ -398,13 +396,23 @@ class GTEST_API_ Mock {
|
||||
static bool VerifyAndClear(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||
|
||||
// Returns whether the mock was created as a naggy mock (default)
|
||||
static bool IsNaggy(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||
// Returns whether the mock was created as a nice mock
|
||||
static bool IsNice(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||
// Returns whether the mock was created as a strict mock
|
||||
static bool IsStrict(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||
|
||||
private:
|
||||
friend class internal::UntypedFunctionMockerBase;
|
||||
|
||||
// Needed for a function mocker to register itself (so that we know
|
||||
// how to clear a mock object).
|
||||
template <typename F>
|
||||
friend class internal::FunctionMockerBase;
|
||||
friend class internal::FunctionMocker;
|
||||
|
||||
template <typename M>
|
||||
friend class NiceMock;
|
||||
@ -467,7 +475,7 @@ class GTEST_API_ Mock {
|
||||
// Unregisters a mock method; removes the owning mock object from
|
||||
// the registry when the last mock method associated with it has
|
||||
// been unregistered. This is called only in the destructor of
|
||||
// FunctionMockerBase.
|
||||
// FunctionMocker.
|
||||
static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
|
||||
}; // class Mock
|
||||
@ -487,12 +495,7 @@ class GTEST_API_ Mock {
|
||||
// - Constness is shallow: a const Expectation object itself cannot
|
||||
// be modified, but the mutable methods of the ExpectationBase
|
||||
// object it references can be called via expectation_base().
|
||||
// - The constructors and destructor are defined out-of-line because
|
||||
// the Symbian WINSCW compiler wants to otherwise instantiate them
|
||||
// when it sees this class definition, at which point it doesn't have
|
||||
// ExpectationBase available yet, leading to incorrect destruction
|
||||
// in the linked_ptr (or compilation errors if using a checking
|
||||
// linked_ptr).
|
||||
|
||||
class GTEST_API_ Expectation {
|
||||
public:
|
||||
// Constructs a null object that doesn't reference any expectation.
|
||||
@ -528,7 +531,7 @@ class GTEST_API_ Expectation {
|
||||
friend class ::testing::internal::UntypedFunctionMockerBase;
|
||||
|
||||
template <typename F>
|
||||
friend class ::testing::internal::FunctionMockerBase;
|
||||
friend class ::testing::internal::FunctionMocker;
|
||||
|
||||
template <typename F>
|
||||
friend class ::testing::internal::TypedExpectation;
|
||||
@ -544,16 +547,15 @@ class GTEST_API_ Expectation {
|
||||
typedef ::std::set<Expectation, Less> Set;
|
||||
|
||||
Expectation(
|
||||
const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
|
||||
const std::shared_ptr<internal::ExpectationBase>& expectation_base);
|
||||
|
||||
// Returns the expectation this object references.
|
||||
const internal::linked_ptr<internal::ExpectationBase>&
|
||||
expectation_base() const {
|
||||
const std::shared_ptr<internal::ExpectationBase>& expectation_base() const {
|
||||
return expectation_base_;
|
||||
}
|
||||
|
||||
// A linked_ptr that co-owns the expectation this handle references.
|
||||
internal::linked_ptr<internal::ExpectationBase> expectation_base_;
|
||||
// A shared_ptr that co-owns the expectation this handle references.
|
||||
std::shared_ptr<internal::ExpectationBase> expectation_base_;
|
||||
};
|
||||
|
||||
// A set of expectation handles. Useful in the .After() clause of
|
||||
@ -635,11 +637,8 @@ class GTEST_API_ Sequence {
|
||||
void AddExpectation(const Expectation& expectation) const;
|
||||
|
||||
private:
|
||||
// The last expectation in this sequence. We use a linked_ptr here
|
||||
// because Sequence objects are copyable and we want the copies to
|
||||
// be aliases. The linked_ptr allows the copies to co-own and share
|
||||
// the same Expectation object.
|
||||
internal::linked_ptr<Expectation> last_expectation_;
|
||||
// The last expectation in this sequence.
|
||||
std::shared_ptr<Expectation> last_expectation_;
|
||||
}; // class Sequence
|
||||
|
||||
// An object of this type causes all EXPECT_CALL() statements
|
||||
@ -862,7 +861,7 @@ class GTEST_API_ ExpectationBase {
|
||||
Cardinality cardinality_; // The cardinality of the expectation.
|
||||
// The immediate pre-requisites (i.e. expectations that must be
|
||||
// satisfied before this expectation can be matched) of this
|
||||
// expectation. We use linked_ptr in the set because we want an
|
||||
// expectation. We use std::shared_ptr in the set because we want an
|
||||
// Expectation object to be co-owned by its FunctionMocker and its
|
||||
// successors. This allows multiple mock objects to be deleted at
|
||||
// different times.
|
||||
@ -891,7 +890,7 @@ class TypedExpectation : public ExpectationBase {
|
||||
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
|
||||
typedef typename Function<F>::Result Result;
|
||||
|
||||
TypedExpectation(FunctionMockerBase<F>* owner, const char* a_file, int a_line,
|
||||
TypedExpectation(FunctionMocker<F>* owner, const char* a_file, int a_line,
|
||||
const std::string& a_source_text,
|
||||
const ArgumentMatcherTuple& m)
|
||||
: ExpectationBase(a_file, a_line, a_source_text),
|
||||
@ -904,7 +903,7 @@ class TypedExpectation : public ExpectationBase {
|
||||
extra_matcher_(A<const ArgumentTuple&>()),
|
||||
repeated_action_(DoDefault()) {}
|
||||
|
||||
virtual ~TypedExpectation() {
|
||||
~TypedExpectation() override {
|
||||
// Check the validity of the action count if it hasn't been done
|
||||
// yet (for example, if the expectation was never used).
|
||||
CheckActionCountIfNotDone();
|
||||
@ -1070,7 +1069,7 @@ class TypedExpectation : public ExpectationBase {
|
||||
|
||||
// If this mock method has an extra matcher (i.e. .With(matcher)),
|
||||
// describes it to the ostream.
|
||||
virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
|
||||
void MaybeDescribeExtraMatcherTo(::std::ostream* os) override {
|
||||
if (extra_matcher_specified_) {
|
||||
*os << " Expected args: ";
|
||||
extra_matcher_.DescribeTo(os);
|
||||
@ -1080,13 +1079,11 @@ class TypedExpectation : public ExpectationBase {
|
||||
|
||||
private:
|
||||
template <typename Function>
|
||||
friend class FunctionMockerBase;
|
||||
friend class FunctionMocker;
|
||||
|
||||
// Returns an Expectation object that references and co-owns this
|
||||
// expectation.
|
||||
virtual Expectation GetHandle() {
|
||||
return owner_->GetHandleOf(this);
|
||||
}
|
||||
Expectation GetHandle() override { return owner_->GetHandleOf(this); }
|
||||
|
||||
// The following methods will be called only after the EXPECT_CALL()
|
||||
// statement finishes and when the current thread holds
|
||||
@ -1159,10 +1156,9 @@ class TypedExpectation : public ExpectationBase {
|
||||
}
|
||||
|
||||
// Returns the action that should be taken for the current invocation.
|
||||
const Action<F>& GetCurrentAction(
|
||||
const FunctionMockerBase<F>* mocker,
|
||||
const ArgumentTuple& args) const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
const Action<F>& GetCurrentAction(const FunctionMocker<F>* mocker,
|
||||
const ArgumentTuple& args) const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
const int count = call_count();
|
||||
Assert(count >= 1, __FILE__, __LINE__,
|
||||
@ -1184,9 +1180,10 @@ class TypedExpectation : public ExpectationBase {
|
||||
Log(kWarning, ss.str(), 1);
|
||||
}
|
||||
|
||||
return count <= action_count ?
|
||||
*static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
|
||||
repeated_action();
|
||||
return count <= action_count
|
||||
? *static_cast<const Action<F>*>(
|
||||
untyped_actions_[static_cast<size_t>(count - 1)])
|
||||
: repeated_action();
|
||||
}
|
||||
|
||||
// Given the arguments of a mock function call, if the call will
|
||||
@ -1196,12 +1193,11 @@ class TypedExpectation : public ExpectationBase {
|
||||
// Mock does it to 'why'. This method is not const as it calls
|
||||
// IncrementCallCount(). A return value of NULL means the default
|
||||
// action.
|
||||
const Action<F>* GetActionForArguments(
|
||||
const FunctionMockerBase<F>* mocker,
|
||||
const ArgumentTuple& args,
|
||||
::std::ostream* what,
|
||||
::std::ostream* why)
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
const Action<F>* GetActionForArguments(const FunctionMocker<F>* mocker,
|
||||
const ArgumentTuple& args,
|
||||
::std::ostream* what,
|
||||
::std::ostream* why)
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
if (IsSaturated()) {
|
||||
// We have an excessive call.
|
||||
@ -1230,7 +1226,7 @@ class TypedExpectation : public ExpectationBase {
|
||||
|
||||
// All the fields below won't change once the EXPECT_CALL()
|
||||
// statement finishes.
|
||||
FunctionMockerBase<F>* const owner_;
|
||||
FunctionMocker<F>* const owner_;
|
||||
ArgumentMatcherTuple matchers_;
|
||||
Matcher<const ArgumentTuple&> extra_matcher_;
|
||||
Action<F> repeated_action_;
|
||||
@ -1262,7 +1258,7 @@ class MockSpec {
|
||||
|
||||
// Constructs a MockSpec object, given the function mocker object
|
||||
// that the spec is associated with.
|
||||
MockSpec(internal::FunctionMockerBase<F>* function_mocker,
|
||||
MockSpec(internal::FunctionMocker<F>* function_mocker,
|
||||
const ArgumentMatcherTuple& matchers)
|
||||
: function_mocker_(function_mocker), matchers_(matchers) {}
|
||||
|
||||
@ -1298,7 +1294,7 @@ class MockSpec {
|
||||
friend class internal::FunctionMocker;
|
||||
|
||||
// The function mocker that owns this spec.
|
||||
internal::FunctionMockerBase<F>* const function_mocker_;
|
||||
internal::FunctionMocker<F>* const function_mocker_;
|
||||
// The argument matchers specified in the spec.
|
||||
ArgumentMatcherTuple matchers_;
|
||||
|
||||
@ -1319,13 +1315,13 @@ class ReferenceOrValueWrapper {
|
||||
public:
|
||||
// Constructs a wrapper from the given value/reference.
|
||||
explicit ReferenceOrValueWrapper(T value)
|
||||
: value_(::testing::internal::move(value)) {
|
||||
: value_(std::move(value)) {
|
||||
}
|
||||
|
||||
// Unwraps and returns the underlying value/reference, exactly as
|
||||
// originally passed. The behavior of calling this more than once on
|
||||
// the same object is unspecified.
|
||||
T Unwrap() { return ::testing::internal::move(value_); }
|
||||
T Unwrap() { return std::move(value_); }
|
||||
|
||||
// Provides nondestructive access to the underlying value/reference.
|
||||
// Always returns a const reference (more precisely,
|
||||
@ -1389,7 +1385,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
|
||||
}
|
||||
|
||||
// Prints the held value as an action's result to os.
|
||||
virtual void PrintAsActionResult(::std::ostream* os) const {
|
||||
void PrintAsActionResult(::std::ostream* os) const override {
|
||||
*os << "\n Returns: ";
|
||||
// T may be a reference type, so we don't use UniversalPrint().
|
||||
UniversalPrinter<T>::Print(result_.Peek(), os);
|
||||
@ -1399,28 +1395,27 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
|
||||
// result in a new-ed ActionResultHolder.
|
||||
template <typename F>
|
||||
static ActionResultHolder* PerformDefaultAction(
|
||||
const FunctionMockerBase<F>* func_mocker,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const FunctionMocker<F>* func_mocker,
|
||||
typename Function<F>::ArgumentTuple&& args,
|
||||
const std::string& call_description) {
|
||||
return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
|
||||
internal::move(args), call_description)));
|
||||
std::move(args), call_description)));
|
||||
}
|
||||
|
||||
// Performs the given action and returns the result in a new-ed
|
||||
// ActionResultHolder.
|
||||
template <typename F>
|
||||
static ActionResultHolder* PerformAction(
|
||||
const Action<F>& action,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
|
||||
const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
|
||||
return new ActionResultHolder(
|
||||
Wrapper(action.Perform(internal::move(args))));
|
||||
Wrapper(action.Perform(std::move(args))));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef ReferenceOrValueWrapper<T> Wrapper;
|
||||
|
||||
explicit ActionResultHolder(Wrapper result)
|
||||
: result_(::testing::internal::move(result)) {
|
||||
: result_(std::move(result)) {
|
||||
}
|
||||
|
||||
Wrapper result_;
|
||||
@ -1434,16 +1429,16 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
|
||||
public:
|
||||
void Unwrap() { }
|
||||
|
||||
virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
|
||||
void PrintAsActionResult(::std::ostream* /* os */) const override {}
|
||||
|
||||
// Performs the given mock function's default action and returns ownership
|
||||
// of an empty ActionResultHolder*.
|
||||
template <typename F>
|
||||
static ActionResultHolder* PerformDefaultAction(
|
||||
const FunctionMockerBase<F>* func_mocker,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const FunctionMocker<F>* func_mocker,
|
||||
typename Function<F>::ArgumentTuple&& args,
|
||||
const std::string& call_description) {
|
||||
func_mocker->PerformDefaultAction(internal::move(args), call_description);
|
||||
func_mocker->PerformDefaultAction(std::move(args), call_description);
|
||||
return new ActionResultHolder;
|
||||
}
|
||||
|
||||
@ -1451,9 +1446,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
|
||||
// ActionResultHolder*.
|
||||
template <typename F>
|
||||
static ActionResultHolder* PerformAction(
|
||||
const Action<F>& action,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
|
||||
action.Perform(internal::move(args));
|
||||
const Action<F>& action, typename Function<F>::ArgumentTuple&& args) {
|
||||
action.Perform(std::move(args));
|
||||
return new ActionResultHolder;
|
||||
}
|
||||
|
||||
@ -1462,23 +1456,39 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
|
||||
};
|
||||
|
||||
// The base of the function mocker class for the given function type.
|
||||
// We put the methods in this class instead of its child to avoid code
|
||||
// bloat.
|
||||
template <typename F>
|
||||
class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
public:
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
|
||||
class FunctionMocker;
|
||||
|
||||
FunctionMockerBase() {}
|
||||
template <typename R, typename... Args>
|
||||
class FunctionMocker<R(Args...)> : public UntypedFunctionMockerBase {
|
||||
using F = R(Args...);
|
||||
|
||||
public:
|
||||
using Result = R;
|
||||
using ArgumentTuple = std::tuple<Args...>;
|
||||
using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
|
||||
|
||||
FunctionMocker() {}
|
||||
|
||||
// There is no generally useful and implementable semantics of
|
||||
// copying a mock object, so copying a mock is usually a user error.
|
||||
// Thus we disallow copying function mockers. If the user really
|
||||
// wants to copy a mock object, they should implement their own copy
|
||||
// operation, for example:
|
||||
//
|
||||
// class MockFoo : public Foo {
|
||||
// public:
|
||||
// // Defines a copy constructor explicitly.
|
||||
// MockFoo(const MockFoo& src) {}
|
||||
// ...
|
||||
// };
|
||||
FunctionMocker(const FunctionMocker&) = delete;
|
||||
FunctionMocker& operator=(const FunctionMocker&) = delete;
|
||||
|
||||
// The destructor verifies that all expectations on this mock
|
||||
// function have been satisfied. If not, it will report Google Test
|
||||
// non-fatal failures for the violations.
|
||||
virtual ~FunctionMockerBase()
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
MutexLock l(&g_gmock_mutex);
|
||||
VerifyAndClearExpectationsLocked();
|
||||
Mock::UnregisterLocked(this);
|
||||
@ -1508,13 +1518,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
// mutable state of this object, and thus can be called concurrently
|
||||
// without locking.
|
||||
// L = *
|
||||
Result PerformDefaultAction(
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const std::string& call_description) const {
|
||||
Result PerformDefaultAction(ArgumentTuple&& args,
|
||||
const std::string& call_description) const {
|
||||
const OnCallSpec<F>* const spec =
|
||||
this->FindOnCallSpec(args);
|
||||
if (spec != nullptr) {
|
||||
return spec->GetAction().Perform(internal::move(args));
|
||||
return spec->GetAction().Perform(std::move(args));
|
||||
}
|
||||
const std::string message =
|
||||
call_description +
|
||||
@ -1535,11 +1544,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
// the error message to describe the call in the case the default
|
||||
// action fails. The caller is responsible for deleting the result.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
|
||||
UntypedActionResultHolderBase* UntypedPerformDefaultAction(
|
||||
void* untyped_args, // must point to an ArgumentTuple
|
||||
const std::string& call_description) const {
|
||||
const std::string& call_description) const override {
|
||||
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformDefaultAction(this, internal::move(*args),
|
||||
return ResultHolder::PerformDefaultAction(this, std::move(*args),
|
||||
call_description);
|
||||
}
|
||||
|
||||
@ -1547,18 +1556,18 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
// the action's result. The caller is responsible for deleting the
|
||||
// result.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformAction(
|
||||
const void* untyped_action, void* untyped_args) const {
|
||||
UntypedActionResultHolderBase* UntypedPerformAction(
|
||||
const void* untyped_action, void* untyped_args) const override {
|
||||
// Make a copy of the action before performing it, in case the
|
||||
// action deletes the mock object (and thus deletes itself).
|
||||
const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
|
||||
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformAction(action, internal::move(*args));
|
||||
return ResultHolder::PerformAction(action, std::move(*args));
|
||||
}
|
||||
|
||||
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
|
||||
// clears the ON_CALL()s set on this mock function.
|
||||
virtual void ClearDefaultActionsLocked()
|
||||
void ClearDefaultActionsLocked() override
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
|
||||
@ -1584,26 +1593,26 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
g_gmock_mutex.Lock();
|
||||
}
|
||||
|
||||
// Returns the result of invoking this mock function with the given
|
||||
// arguments. This function can be safely called from multiple
|
||||
// threads concurrently.
|
||||
Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
ArgumentTuple tuple(std::forward<Args>(args)...);
|
||||
std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>(
|
||||
this->UntypedInvokeWith(static_cast<void*>(&tuple))));
|
||||
return holder->Unwrap();
|
||||
}
|
||||
|
||||
MockSpec<F> With(Matcher<Args>... m) {
|
||||
return MockSpec<F>(this, ::std::make_tuple(std::move(m)...));
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename Function>
|
||||
friend class MockSpec;
|
||||
|
||||
typedef ActionResultHolder<Result> ResultHolder;
|
||||
|
||||
// Returns the result of invoking this mock function with the given
|
||||
// arguments. This function can be safely called from multiple
|
||||
// threads concurrently.
|
||||
Result InvokeWith(
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
// const_cast is required since in C++98 we still pass ArgumentTuple around
|
||||
// by const& instead of rvalue reference.
|
||||
void* untyped_args = const_cast<void*>(static_cast<const void*>(&args));
|
||||
scoped_ptr<ResultHolder> holder(
|
||||
DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args)));
|
||||
return holder->Unwrap();
|
||||
}
|
||||
|
||||
// Adds and returns a default action spec for this mock function.
|
||||
OnCallSpec<F>& AddNewOnCallSpec(
|
||||
const char* file, int line,
|
||||
@ -1623,7 +1632,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
||||
TypedExpectation<F>* const expectation =
|
||||
new TypedExpectation<F>(this, file, line, source_text, m);
|
||||
const linked_ptr<ExpectationBase> untyped_expectation(expectation);
|
||||
const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
|
||||
// See the definition of untyped_expectations_ for why access to
|
||||
// it is unprotected here.
|
||||
untyped_expectations_.push_back(untyped_expectation);
|
||||
@ -1662,10 +1671,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
// Writes a message that the call is uninteresting (i.e. neither
|
||||
// explicitly expected nor explicitly unexpected) to the given
|
||||
// ostream.
|
||||
virtual void UntypedDescribeUninterestingCall(
|
||||
const void* untyped_args,
|
||||
::std::ostream* os) const
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
void UntypedDescribeUninterestingCall(const void* untyped_args,
|
||||
::std::ostream* os) const override
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
const ArgumentTuple& args =
|
||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||
*os << "Uninteresting mock function call - ";
|
||||
@ -1690,11 +1698,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
// section. The reason is that we have no control on what the
|
||||
// action does (it can invoke an arbitrary user function or even a
|
||||
// mock function) and excessive locking could cause a dead lock.
|
||||
virtual const ExpectationBase* UntypedFindMatchingExpectation(
|
||||
const void* untyped_args,
|
||||
const void** untyped_action, bool* is_excessive,
|
||||
::std::ostream* what, ::std::ostream* why)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
const ExpectationBase* UntypedFindMatchingExpectation(
|
||||
const void* untyped_args, const void** untyped_action, bool* is_excessive,
|
||||
::std::ostream* what, ::std::ostream* why) override
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
const ArgumentTuple& args =
|
||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||
MutexLock l(&g_gmock_mutex);
|
||||
@ -1716,8 +1723,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
}
|
||||
|
||||
// Prints the given function arguments to the ostream.
|
||||
virtual void UntypedPrintArgs(const void* untyped_args,
|
||||
::std::ostream* os) const {
|
||||
void UntypedPrintArgs(const void* untyped_args,
|
||||
::std::ostream* os) const override {
|
||||
const ArgumentTuple& args =
|
||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||
UniversalPrint(args, os);
|
||||
@ -1762,12 +1769,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
::std::ostream* why) const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
const int count = static_cast<int>(untyped_expectations_.size());
|
||||
const size_t count = untyped_expectations_.size();
|
||||
*why << "Google Mock tried the following " << count << " "
|
||||
<< (count == 1 ? "expectation, but it didn't match" :
|
||||
"expectations, but none matched")
|
||||
<< ":\n";
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
TypedExpectation<F>* const expectation =
|
||||
static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
|
||||
*why << "\n";
|
||||
@ -1780,36 +1787,98 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
expectation->DescribeCallCountTo(why);
|
||||
}
|
||||
}
|
||||
|
||||
// There is no generally useful and implementable semantics of
|
||||
// copying a mock object, so copying a mock is usually a user error.
|
||||
// Thus we disallow copying function mockers. If the user really
|
||||
// wants to copy a mock object, they should implement their own copy
|
||||
// operation, for example:
|
||||
//
|
||||
// class MockFoo : public Foo {
|
||||
// public:
|
||||
// // Defines a copy constructor explicitly.
|
||||
// MockFoo(const MockFoo& src) {}
|
||||
// ...
|
||||
// };
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
|
||||
}; // class FunctionMockerBase
|
||||
}; // class FunctionMocker
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355
|
||||
|
||||
// Implements methods of FunctionMockerBase.
|
||||
|
||||
// Verifies that all expectations on this mock function have been
|
||||
// satisfied. Reports one or more Google Test non-fatal failures and
|
||||
// returns false if not.
|
||||
|
||||
// Reports an uninteresting call (whose description is in msg) in the
|
||||
// manner specified by 'reaction'.
|
||||
void ReportUninterestingCall(CallReaction reaction, const std::string& msg);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// A MockFunction<F> class has one mock method whose type is F. It is
|
||||
// useful when you just want your test code to emit some messages and
|
||||
// have Google Mock verify the right messages are sent (and perhaps at
|
||||
// the right times). For example, if you are exercising code:
|
||||
//
|
||||
// Foo(1);
|
||||
// Foo(2);
|
||||
// Foo(3);
|
||||
//
|
||||
// and want to verify that Foo(1) and Foo(3) both invoke
|
||||
// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write:
|
||||
//
|
||||
// TEST(FooTest, InvokesBarCorrectly) {
|
||||
// MyMock mock;
|
||||
// MockFunction<void(string check_point_name)> check;
|
||||
// {
|
||||
// InSequence s;
|
||||
//
|
||||
// EXPECT_CALL(mock, Bar("a"));
|
||||
// EXPECT_CALL(check, Call("1"));
|
||||
// EXPECT_CALL(check, Call("2"));
|
||||
// EXPECT_CALL(mock, Bar("a"));
|
||||
// }
|
||||
// Foo(1);
|
||||
// check.Call("1");
|
||||
// Foo(2);
|
||||
// check.Call("2");
|
||||
// Foo(3);
|
||||
// }
|
||||
//
|
||||
// The expectation spec says that the first Bar("a") must happen
|
||||
// before check point "1", the second Bar("a") must happen after check
|
||||
// point "2", and nothing should happen between the two check
|
||||
// points. The explicit check points make it easy to tell which
|
||||
// Bar("a") is called by which call to Foo().
|
||||
//
|
||||
// MockFunction<F> can also be used to exercise code that accepts
|
||||
// std::function<F> callbacks. To do so, use AsStdFunction() method
|
||||
// to create std::function proxy forwarding to original object's Call.
|
||||
// Example:
|
||||
//
|
||||
// TEST(FooTest, RunsCallbackWithBarArgument) {
|
||||
// MockFunction<int(string)> callback;
|
||||
// EXPECT_CALL(callback, Call("bar")).WillOnce(Return(1));
|
||||
// Foo(callback.AsStdFunction());
|
||||
// }
|
||||
template <typename F>
|
||||
class MockFunction;
|
||||
|
||||
template <typename R, typename... Args>
|
||||
class MockFunction<R(Args...)> {
|
||||
public:
|
||||
MockFunction() {}
|
||||
MockFunction(const MockFunction&) = delete;
|
||||
MockFunction& operator=(const MockFunction&) = delete;
|
||||
|
||||
std::function<R(Args...)> AsStdFunction() {
|
||||
return [this](Args... args) -> R {
|
||||
return this->Call(std::forward<Args>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
// Implementation detail: the expansion of the MOCK_METHOD macro.
|
||||
R Call(Args... args) {
|
||||
mock_.SetOwnerAndName(this, "Call");
|
||||
return mock_.Invoke(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
internal::MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) {
|
||||
mock_.RegisterOwner(this);
|
||||
return mock_.With(std::move(m)...);
|
||||
}
|
||||
|
||||
internal::MockSpec<R(Args...)> gmock_Call(const internal::WithoutMatchers&,
|
||||
R (*)(Args...)) {
|
||||
return this->gmock_Call(::testing::A<Args>()...);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable internal::FunctionMocker<R(Args...)> mock_;
|
||||
};
|
||||
|
||||
// The style guide prohibits "using" statements in a namespace scope
|
||||
// inside a header file. However, the MockSpec class template is
|
||||
// meant to be defined in the ::testing namespace. The following line
|
||||
@ -1905,8 +1974,9 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
// second argument is an internal type derived from the method signature. The
|
||||
// failure to disambiguate two overloads of this method in the ON_CALL statement
|
||||
// is how we block callers from setting expectations on overloaded methods.
|
||||
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
|
||||
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \
|
||||
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
|
||||
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
|
||||
nullptr) \
|
||||
.Setter(__FILE__, __LINE__, #mock_expr, #call)
|
||||
|
||||
#define ON_CALL(obj, call) \
|
||||
|
@ -58,13 +58,14 @@
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/gmock-cardinalities.h"
|
||||
#include "gmock/gmock-function-mocker.h"
|
||||
#include "gmock/gmock-generated-actions.h"
|
||||
#include "gmock/gmock-generated-function-mockers.h"
|
||||
#include "gmock/gmock-generated-matchers.h"
|
||||
#include "gmock/gmock-generated-nice-strict.h"
|
||||
#include "gmock/gmock-matchers.h"
|
||||
#include "gmock/gmock-more-actions.h"
|
||||
#include "gmock/gmock-more-matchers.h"
|
||||
#include "gmock/gmock-nice-strict.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
namespace testing {
|
||||
|
@ -70,79 +70,71 @@ template <typename Tuple>
|
||||
struct MatcherTuple;
|
||||
|
||||
template <>
|
||||
struct MatcherTuple< ::testing::tuple<> > {
|
||||
typedef ::testing::tuple< > type;
|
||||
struct MatcherTuple< ::std::tuple<> > {
|
||||
typedef ::std::tuple< > type;
|
||||
};
|
||||
|
||||
template <typename A1>
|
||||
struct MatcherTuple< ::testing::tuple<A1> > {
|
||||
typedef ::testing::tuple<Matcher<A1> > type;
|
||||
struct MatcherTuple< ::std::tuple<A1> > {
|
||||
typedef ::std::tuple<Matcher<A1> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2> > type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>,
|
||||
Matcher<A4> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>,
|
||||
Matcher<A9> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9> > type;
|
||||
};
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5,
|
||||
typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
struct MatcherTuple< ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
|
||||
A10> > {
|
||||
typedef ::testing::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>,
|
||||
Matcher<A9>, Matcher<A10> >
|
||||
type;
|
||||
struct MatcherTuple< ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> > {
|
||||
typedef ::std::tuple<Matcher<A1>, Matcher<A2>, Matcher<A3>, Matcher<A4>,
|
||||
Matcher<A5>, Matcher<A6>, Matcher<A7>, Matcher<A8>, Matcher<A9>,
|
||||
Matcher<A10> > type;
|
||||
};
|
||||
|
||||
// Template struct Function<F>, where F must be a function type, contains
|
||||
@ -164,7 +156,7 @@ struct Function;
|
||||
template <typename R>
|
||||
struct Function<R()> {
|
||||
typedef R Result;
|
||||
typedef ::testing::tuple<> ArgumentTuple;
|
||||
typedef ::std::tuple<> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid();
|
||||
typedef IgnoredValue MakeResultIgnoredValue();
|
||||
@ -174,7 +166,7 @@ template <typename R, typename A1>
|
||||
struct Function<R(A1)>
|
||||
: Function<R()> {
|
||||
typedef A1 Argument1;
|
||||
typedef ::testing::tuple<A1> ArgumentTuple;
|
||||
typedef ::std::tuple<A1> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1);
|
||||
@ -184,7 +176,7 @@ template <typename R, typename A1, typename A2>
|
||||
struct Function<R(A1, A2)>
|
||||
: Function<R(A1)> {
|
||||
typedef A2 Argument2;
|
||||
typedef ::testing::tuple<A1, A2> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2);
|
||||
@ -194,7 +186,7 @@ template <typename R, typename A1, typename A2, typename A3>
|
||||
struct Function<R(A1, A2, A3)>
|
||||
: Function<R(A1, A2)> {
|
||||
typedef A3 Argument3;
|
||||
typedef ::testing::tuple<A1, A2, A3> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3);
|
||||
@ -204,7 +196,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4>
|
||||
struct Function<R(A1, A2, A3, A4)>
|
||||
: Function<R(A1, A2, A3)> {
|
||||
typedef A4 Argument4;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4);
|
||||
@ -215,7 +207,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5)>
|
||||
: Function<R(A1, A2, A3, A4)> {
|
||||
typedef A5 Argument5;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5);
|
||||
@ -226,7 +218,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5, A6)>
|
||||
: Function<R(A1, A2, A3, A4, A5)> {
|
||||
typedef A6 Argument6;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5, A6> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6);
|
||||
@ -237,7 +229,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5, A6, A7)>
|
||||
: Function<R(A1, A2, A3, A4, A5, A6)> {
|
||||
typedef A7 Argument7;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7);
|
||||
@ -248,7 +240,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>
|
||||
: Function<R(A1, A2, A3, A4, A5, A6, A7)> {
|
||||
typedef A8 Argument8;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8);
|
||||
@ -259,7 +251,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
|
||||
: Function<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
|
||||
typedef A9 Argument9;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
|
||||
@ -272,8 +264,7 @@ template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
struct Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
|
||||
: Function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
|
||||
typedef A10 Argument10;
|
||||
typedef ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
|
||||
A10> ArgumentTuple;
|
||||
typedef ::std::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
|
||||
typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8,
|
||||
|
@ -78,8 +78,8 @@ $var typename_As = [[$for j, [[typename A$j]]]]
|
||||
$var As = [[$for j, [[A$j]]]]
|
||||
$var matcher_As = [[$for j, [[Matcher<A$j>]]]]
|
||||
template <$typename_As>
|
||||
struct MatcherTuple< ::testing::tuple<$As> > {
|
||||
typedef ::testing::tuple<$matcher_As > type;
|
||||
struct MatcherTuple< ::std::tuple<$As> > {
|
||||
typedef ::std::tuple<$matcher_As > type;
|
||||
};
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ struct Function;
|
||||
template <typename R>
|
||||
struct Function<R()> {
|
||||
typedef R Result;
|
||||
typedef ::testing::tuple<> ArgumentTuple;
|
||||
typedef ::std::tuple<> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid();
|
||||
typedef IgnoredValue MakeResultIgnoredValue();
|
||||
@ -122,7 +122,7 @@ template <typename R$typename_As>
|
||||
struct Function<R($As)>
|
||||
: Function<R($prev_As)> {
|
||||
typedef A$i Argument$i;
|
||||
typedef ::testing::tuple<$As> ArgumentTuple;
|
||||
typedef ::std::tuple<$As> ArgumentTuple;
|
||||
typedef typename MatcherTuple<ArgumentTuple>::type ArgumentMatcherTuple;
|
||||
typedef void MakeResultVoid($As);
|
||||
typedef IgnoredValue MakeResultIgnoredValue($As);
|
||||
|
@ -92,15 +92,6 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
||||
template <typename Element>
|
||||
inline Element* GetRawPointer(Element* p) { return p; }
|
||||
|
||||
// This comparator allows linked_ptr to be stored in sets.
|
||||
template <typename T>
|
||||
struct LinkedPtrLessThan {
|
||||
bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
|
||||
const ::testing::internal::linked_ptr<T>& rhs) const {
|
||||
return lhs.get() < rhs.get();
|
||||
}
|
||||
};
|
||||
|
||||
// Symbian compilation can be done with wchar_t being either a native
|
||||
// type or a typedef. Using Google Mock with OpenC without wchar_t
|
||||
// should require the definition of _STLP_NO_WCHAR_T.
|
||||
@ -493,7 +484,7 @@ class StlContainerView<Element[N]> {
|
||||
// This specialization is used when RawContainer is a native array
|
||||
// represented as a (pointer, size) tuple.
|
||||
template <typename ElementPointer, typename Size>
|
||||
class StlContainerView< ::testing::tuple<ElementPointer, Size> > {
|
||||
class StlContainerView< ::std::tuple<ElementPointer, Size> > {
|
||||
public:
|
||||
typedef GTEST_REMOVE_CONST_(
|
||||
typename internal::PointeeOf<ElementPointer>::type) RawElement;
|
||||
@ -501,11 +492,12 @@ class StlContainerView< ::testing::tuple<ElementPointer, Size> > {
|
||||
typedef const type const_reference;
|
||||
|
||||
static const_reference ConstReference(
|
||||
const ::testing::tuple<ElementPointer, Size>& array) {
|
||||
return type(get<0>(array), get<1>(array), RelationToSourceReference());
|
||||
const ::std::tuple<ElementPointer, Size>& array) {
|
||||
return type(std::get<0>(array), std::get<1>(array),
|
||||
RelationToSourceReference());
|
||||
}
|
||||
static type Copy(const ::testing::tuple<ElementPointer, Size>& array) {
|
||||
return type(get<0>(array), get<1>(array), RelationToSourceCopy());
|
||||
static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
|
||||
return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
|
||||
}
|
||||
};
|
||||
|
||||
@ -536,7 +528,6 @@ struct BooleanConstant {};
|
||||
// reduce code size.
|
||||
GTEST_API_ void IllegalDoDefault(const char* file, int line);
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Helper types for Apply() below.
|
||||
template <size_t... Is> struct int_pack { typedef int_pack type; };
|
||||
|
||||
@ -562,7 +553,6 @@ auto Apply(F&& f, Tuple&& args)
|
||||
return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
|
||||
make_int_pack<std::tuple_size<Tuple>::value>());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -52,14 +52,13 @@
|
||||
// here, as Google Mock depends on Google Test. Only add a utility
|
||||
// here if it's truly specific to Google Mock.
|
||||
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gmock/internal/custom/gmock-port.h"
|
||||
|
||||
// For MS Visual C++, check the compiler version. At least VS 2003 is
|
||||
// For MS Visual C++, check the compiler version. At least VS 2015 is
|
||||
// required to compile Google Mock.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1310
|
||||
# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
|
||||
#endif
|
||||
|
||||
// Macro for referencing flags. This is public as we want the user to
|
||||
|
317
googlemock/include/gmock/internal/gmock-pp.h
Normal file
317
googlemock/include/gmock/internal/gmock-pp.h
Normal file
@ -0,0 +1,317 @@
|
||||
#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
|
||||
#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
|
||||
|
||||
#undef GMOCK_PP_INTERNAL_USE_MSVC
|
||||
#if defined(__clang__)
|
||||
#define GMOCK_PP_INTERNAL_USE_MSVC 0
|
||||
#elif defined(_MSC_VER)
|
||||
// TODO(iserna): Also verify tradional versus comformant preprocessor.
|
||||
static_assert(
|
||||
_MSC_VER >= 1900,
|
||||
"MSVC version not supported. There is support for MSVC 14.0 and above.");
|
||||
#define GMOCK_PP_INTERNAL_USE_MSVC 1
|
||||
#else
|
||||
#define GMOCK_PP_INTERNAL_USE_MSVC 0
|
||||
#endif
|
||||
|
||||
// Expands and concatenates the arguments. Constructed macros reevaluate.
|
||||
#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2)
|
||||
|
||||
// Expands and stringifies the only argument.
|
||||
#define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__)
|
||||
|
||||
// Returns empty. Given a variadic number of arguments.
|
||||
#define GMOCK_PP_EMPTY(...)
|
||||
|
||||
// Returns a comma. Given a variadic number of arguments.
|
||||
#define GMOCK_PP_COMMA(...) ,
|
||||
|
||||
// Returns the only argument.
|
||||
#define GMOCK_PP_IDENTITY(_1) _1
|
||||
|
||||
// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a
|
||||
// CAT-like directive to force correct evaluation. Each macro has its own.
|
||||
#if GMOCK_PP_INTERNAL_USE_MSVC
|
||||
|
||||
// Evaluates to the number of arguments after expansion.
|
||||
//
|
||||
// #define PAIR x, y
|
||||
//
|
||||
// GMOCK_PP_NARG() => 1
|
||||
// GMOCK_PP_NARG(x) => 1
|
||||
// GMOCK_PP_NARG(x, y) => 2
|
||||
// GMOCK_PP_NARG(PAIR) => 2
|
||||
//
|
||||
// Requires: the number of arguments after expansion is at most 15.
|
||||
#define GMOCK_PP_NARG(...) \
|
||||
GMOCK_PP_INTERNAL_NARG_CAT( \
|
||||
GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \
|
||||
8, 7, 6, 5, 4, 3, 2, 1), )
|
||||
|
||||
// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise
|
||||
// returns 0. Requires no more than 15 unprotected commas.
|
||||
#define GMOCK_PP_HAS_COMMA(...) \
|
||||
GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \
|
||||
GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
|
||||
1, 1, 1, 1, 1, 0), )
|
||||
// Returns the first argument.
|
||||
#define GMOCK_PP_HEAD(...) \
|
||||
GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), )
|
||||
|
||||
// Returns the tail. A variadic list of all arguments minus the first. Requires
|
||||
// at least one argument.
|
||||
#define GMOCK_PP_TAIL(...) \
|
||||
GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), )
|
||||
|
||||
// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
|
||||
GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \
|
||||
GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), )
|
||||
|
||||
#else // GMOCK_PP_INTERNAL_USE_MSVC
|
||||
|
||||
#define GMOCK_PP_NARG(...) \
|
||||
GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \
|
||||
7, 6, 5, 4, 3, 2, 1)
|
||||
#define GMOCK_PP_HAS_COMMA(...) \
|
||||
GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
|
||||
1, 1, 1, 1, 0)
|
||||
#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__)
|
||||
#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__)
|
||||
#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
|
||||
GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)
|
||||
|
||||
#endif // GMOCK_PP_INTERNAL_USE_MSVC
|
||||
|
||||
// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise
|
||||
// evaluates to `0`.
|
||||
//
|
||||
// Requires: * the number of arguments after expansion is at most 15.
|
||||
// * If the argument is a macro, it must be able to be called with one
|
||||
// argument.
|
||||
//
|
||||
// Implementation details:
|
||||
//
|
||||
// There is one case when it generates a compile error: if the argument is macro
|
||||
// that cannot be called with one argument.
|
||||
//
|
||||
// #define M(a, b) // it doesn't matter what it expands to
|
||||
//
|
||||
// // Expected: expands to `0`.
|
||||
// // Actual: compile error.
|
||||
// GMOCK_PP_IS_EMPTY(M)
|
||||
//
|
||||
// There are 4 cases tested:
|
||||
//
|
||||
// * __VA_ARGS__ possible expansion has no unparen'd commas. Expected 0.
|
||||
// * __VA_ARGS__ possible expansion is not enclosed in parenthesis. Expected 0.
|
||||
// * __VA_ARGS__ possible expansion is not a macro that ()-evaluates to a comma.
|
||||
// Expected 0
|
||||
// * __VA_ARGS__ is empty, or has unparen'd commas, or is enclosed in
|
||||
// parenthesis, or is a macro that ()-evaluates to comma. Expected 1.
|
||||
//
|
||||
// We trigger detection on '0001', i.e. on empty.
|
||||
#define GMOCK_PP_IS_EMPTY(...) \
|
||||
GMOCK_PP_INTERNAL_IS_EMPTY(GMOCK_PP_HAS_COMMA(__VA_ARGS__), \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__), \
|
||||
GMOCK_PP_HAS_COMMA(__VA_ARGS__()), \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_COMMA __VA_ARGS__()))
|
||||
|
||||
// Evaluates to _Then if _Cond is 1 and _Else if _Cond is 0.
|
||||
#define GMOCK_PP_IF(_Cond, _Then, _Else) \
|
||||
GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IF_, _Cond)(_Then, _Else)
|
||||
|
||||
// Evaluates to the number of arguments after expansion. Identifies 'empty' as
|
||||
// 0.
|
||||
//
|
||||
// #define PAIR x, y
|
||||
//
|
||||
// GMOCK_PP_NARG0() => 0
|
||||
// GMOCK_PP_NARG0(x) => 1
|
||||
// GMOCK_PP_NARG0(x, y) => 2
|
||||
// GMOCK_PP_NARG0(PAIR) => 2
|
||||
//
|
||||
// Requires: * the number of arguments after expansion is at most 15.
|
||||
// * If the argument is a macro, it must be able to be called with one
|
||||
// argument.
|
||||
#define GMOCK_PP_NARG0(...) \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(__VA_ARGS__), 0, GMOCK_PP_NARG(__VA_ARGS__))
|
||||
|
||||
// Expands to 1 if the first argument starts with something in parentheses,
|
||||
// otherwise to 0.
|
||||
#define GMOCK_PP_IS_BEGIN_PARENS(...) \
|
||||
GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \
|
||||
GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
|
||||
GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
|
||||
|
||||
// Expands to 1 is there is only one argument and it is enclosed in parentheses.
|
||||
#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(__VA_ARGS__), \
|
||||
GMOCK_PP_IS_EMPTY(GMOCK_PP_EMPTY __VA_ARGS__), 0)
|
||||
|
||||
// Remove the parens, requires GMOCK_PP_IS_ENCLOSED_PARENS(args) => 1.
|
||||
#define GMOCK_PP_REMOVE_PARENS(...) GMOCK_PP_INTERNAL_REMOVE_PARENS __VA_ARGS__
|
||||
|
||||
// Expands to _Macro(0, _Data, e1) _Macro(1, _Data, e2) ... _Macro(K -1, _Data,
|
||||
// eK) as many of GMOCK_INTERNAL_NARG0 _Tuple.
|
||||
// Requires: * |_Macro| can be called with 3 arguments.
|
||||
// * |_Tuple| expansion has no more than 15 elements.
|
||||
#define GMOCK_PP_FOR_EACH(_Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, GMOCK_PP_NARG0 _Tuple) \
|
||||
(0, _Macro, _Data, _Tuple)
|
||||
|
||||
// Expands to _Macro(0, _Data, ) _Macro(1, _Data, ) ... _Macro(K - 1, _Data, )
|
||||
// Empty if _K = 0.
|
||||
// Requires: * |_Macro| can be called with 3 arguments.
|
||||
// * |_K| literal between 0 and 15
|
||||
#define GMOCK_PP_REPEAT(_Macro, _Data, _N) \
|
||||
GMOCK_PP_CAT(GMOCK_PP_INTERNAL_FOR_EACH_IMPL_, _N) \
|
||||
(0, _Macro, _Data, GMOCK_PP_INTENRAL_EMPTY_TUPLE)
|
||||
|
||||
// Increments the argument, requires the argument to be between 0 and 15.
|
||||
#define GMOCK_PP_INC(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_INC_, _i)
|
||||
|
||||
// Returns comma if _i != 0. Requires _i to be between 0 and 15.
|
||||
#define GMOCK_PP_COMMA_IF(_i) GMOCK_PP_CAT(GMOCK_PP_INTERNAL_COMMA_IF_, _i)
|
||||
|
||||
// Internal details follow. Do not use any of these symbols outside of this
|
||||
// file or we will break your code.
|
||||
#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , )
|
||||
#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__
|
||||
#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
|
||||
_10, _11, _12, _13, _14, _15, _16, \
|
||||
...) \
|
||||
_16
|
||||
#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5
|
||||
#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \
|
||||
_1, _2, _3, _4))
|
||||
#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 ,
|
||||
#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then
|
||||
#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else
|
||||
#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1
|
||||
#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__
|
||||
|
||||
#if GMOCK_PP_INTERNAL_USE_MSVC
|
||||
#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \
|
||||
GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \
|
||||
GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2
|
||||
#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \
|
||||
GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), )
|
||||
#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \
|
||||
GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2)
|
||||
#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2
|
||||
#else // GMOCK_PP_INTERNAL_USE_MSVC
|
||||
#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__)
|
||||
#endif // GMOCK_PP_INTERNAL_USE_MSVC
|
||||
|
||||
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _
|
||||
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1,
|
||||
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C \
|
||||
0,
|
||||
#define GMOCK_PP_INTERNAL_REMOVE_PARENS(...) __VA_ARGS__
|
||||
#define GMOCK_PP_INTERNAL_INC_0 1
|
||||
#define GMOCK_PP_INTERNAL_INC_1 2
|
||||
#define GMOCK_PP_INTERNAL_INC_2 3
|
||||
#define GMOCK_PP_INTERNAL_INC_3 4
|
||||
#define GMOCK_PP_INTERNAL_INC_4 5
|
||||
#define GMOCK_PP_INTERNAL_INC_5 6
|
||||
#define GMOCK_PP_INTERNAL_INC_6 7
|
||||
#define GMOCK_PP_INTERNAL_INC_7 8
|
||||
#define GMOCK_PP_INTERNAL_INC_8 9
|
||||
#define GMOCK_PP_INTERNAL_INC_9 10
|
||||
#define GMOCK_PP_INTERNAL_INC_10 11
|
||||
#define GMOCK_PP_INTERNAL_INC_11 12
|
||||
#define GMOCK_PP_INTERNAL_INC_12 13
|
||||
#define GMOCK_PP_INTERNAL_INC_13 14
|
||||
#define GMOCK_PP_INTERNAL_INC_14 15
|
||||
#define GMOCK_PP_INTERNAL_INC_15 16
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_0
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_1 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_2 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_3 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_4 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_5 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_6 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_7 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_8 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_9 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_10 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_11 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_12 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_13 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_14 ,
|
||||
#define GMOCK_PP_INTERNAL_COMMA_IF_15 ,
|
||||
#define GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, _element) \
|
||||
_Macro(_i, _Data, _element)
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_0(_i, _Macro, _Data, _Tuple)
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple)
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_1(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_2(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_3(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_4(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_5(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_6(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_7(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_8(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_9(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_10(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_11(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_12(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_13(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
#define GMOCK_PP_INTERNAL_FOR_EACH_IMPL_15(_i, _Macro, _Data, _Tuple) \
|
||||
GMOCK_PP_INTERNAL_CALL_MACRO(_Macro, _i, _Data, GMOCK_PP_HEAD _Tuple) \
|
||||
GMOCK_PP_INTERNAL_FOR_EACH_IMPL_14(GMOCK_PP_INC(_i), _Macro, _Data, \
|
||||
(GMOCK_PP_TAIL _Tuple))
|
||||
|
||||
#endif // THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PP_H_
|
@ -70,18 +70,18 @@ class BetweenCardinalityImpl : public CardinalityInterface {
|
||||
|
||||
// Conservative estimate on the lower/upper bound of the number of
|
||||
// calls allowed.
|
||||
virtual int ConservativeLowerBound() const { return min_; }
|
||||
virtual int ConservativeUpperBound() const { return max_; }
|
||||
int ConservativeLowerBound() const override { return min_; }
|
||||
int ConservativeUpperBound() const override { return max_; }
|
||||
|
||||
virtual bool IsSatisfiedByCallCount(int call_count) const {
|
||||
bool IsSatisfiedByCallCount(int call_count) const override {
|
||||
return min_ <= call_count && call_count <= max_;
|
||||
}
|
||||
|
||||
virtual bool IsSaturatedByCallCount(int call_count) const {
|
||||
bool IsSaturatedByCallCount(int call_count) const override {
|
||||
return call_count >= max_;
|
||||
}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const;
|
||||
void DescribeTo(::std::ostream* os) const override;
|
||||
|
||||
private:
|
||||
const int min_;
|
||||
|
@ -93,8 +93,8 @@ GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) {
|
||||
// use Google Mock with a testing framework other than Google Test.
|
||||
class GoogleTestFailureReporter : public FailureReporterInterface {
|
||||
public:
|
||||
virtual void ReportFailure(FailureType type, const char* file, int line,
|
||||
const std::string& message) {
|
||||
void ReportFailure(FailureType type, const char* file, int line,
|
||||
const std::string& message) override {
|
||||
AssertHelper(type == kFatal ?
|
||||
TestPartResult::kFatalFailure :
|
||||
TestPartResult::kNonFatalFailure,
|
||||
|
@ -42,116 +42,6 @@
|
||||
#include <string>
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const ::string& s) {
|
||||
*this = Eq(static_cast<std::string>(s));
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const ::string& s) {
|
||||
*this = Eq(static_cast<std::string>(s));
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const std::string& s) {
|
||||
*this = Eq(static_cast<::string>(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||
|
||||
// Constructs a matcher that matches a ::string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const std::string& s) {
|
||||
*this = Eq(static_cast<::string>(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a ::string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
|
||||
// Constructs a matcher that matches a string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const std::string& s) {
|
||||
*this = Eq(s);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Returns the description for a matcher defined using the MATCHER*()
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <iostream> // NOLINT
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -49,9 +50,9 @@
|
||||
#endif
|
||||
|
||||
// Silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14,15
|
||||
// to bool 'true' or 'false') for MSVC 15
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
@ -757,6 +758,19 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj)
|
||||
return expectations_met;
|
||||
}
|
||||
|
||||
bool Mock::IsNaggy(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kWarn;
|
||||
}
|
||||
bool Mock::IsNice(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kAllow;
|
||||
}
|
||||
bool Mock::IsStrict(void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kFail;
|
||||
}
|
||||
|
||||
// Registers a mock object and a mock method it owns.
|
||||
void Mock::Register(const void* mock_obj,
|
||||
internal::UntypedFunctionMockerBase* mocker)
|
||||
@ -835,7 +849,7 @@ void Mock::ClearDefaultActionsLocked(void* mock_obj)
|
||||
Expectation::Expectation() {}
|
||||
|
||||
Expectation::Expectation(
|
||||
const internal::linked_ptr<internal::ExpectationBase>& an_expectation_base)
|
||||
const std::shared_ptr<internal::ExpectationBase>& an_expectation_base)
|
||||
: expectation_base_(an_expectation_base) {}
|
||||
|
||||
Expectation::~Expectation() {}
|
||||
@ -853,7 +867,7 @@ void Sequence::AddExpectation(const Expectation& expectation) const {
|
||||
|
||||
// Creates the implicit sequence if there isn't one.
|
||||
InSequence::InSequence() {
|
||||
if (internal::g_gmock_implicit_sequence.get() == NULL) {
|
||||
if (internal::g_gmock_implicit_sequence.get() == nullptr) {
|
||||
internal::g_gmock_implicit_sequence.set(new Sequence);
|
||||
sequence_created_ = true;
|
||||
} else {
|
||||
@ -866,14 +880,14 @@ InSequence::InSequence() {
|
||||
InSequence::~InSequence() {
|
||||
if (sequence_created_) {
|
||||
delete internal::g_gmock_implicit_sequence.get();
|
||||
internal::g_gmock_implicit_sequence.set(NULL);
|
||||
internal::g_gmock_implicit_sequence.set(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
@ -32,6 +32,22 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#ifdef ARDUINO
|
||||
void setup() {
|
||||
// Since Arduino doesn't have a command line, fake out the argc/argv arguments
|
||||
int argc = 1;
|
||||
const auto arg0 = "PlatformIO";
|
||||
char* argv0 = const_cast<char*>(arg0);
|
||||
char** argv = &argv0;
|
||||
|
||||
// Since Google Mock depends on Google Test, InitGoogleMock() is
|
||||
// also responsible for initializing Google Test. Therefore there's
|
||||
// no need for calling testing::InitGoogleTest() separately.
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
}
|
||||
void loop() { RUN_ALL_TESTS(); }
|
||||
#else
|
||||
|
||||
// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
|
||||
// causes a link error when _tmain is defined in a static library and UNICODE
|
||||
// is enabled. For this reason instead of _tmain, main function is used on
|
||||
@ -52,3 +68,4 @@ GTEST_API_ int main(int argc, char** argv) {
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
#endif
|
||||
|
@ -34,28 +34,19 @@
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
""" gmock own tests """
|
||||
|
||||
# Tests for GMock itself
|
||||
cc_test(
|
||||
name = "gmock_all_test",
|
||||
size = "small",
|
||||
srcs = glob(
|
||||
include = [
|
||||
"gmock-*.cc",
|
||||
],
|
||||
),
|
||||
srcs = glob(include = ["gmock-*.cc"]),
|
||||
linkopts = select({
|
||||
"//:windows": [],
|
||||
"//:windows_msvc": [],
|
||||
"//conditions:default": [
|
||||
"-pthread",
|
||||
],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
# Py tests
|
||||
|
||||
# Python tests
|
||||
py_library(
|
||||
name = "gmock_test_utils",
|
||||
testonly = 1,
|
||||
@ -66,9 +57,7 @@ cc_binary(
|
||||
name = "gmock_leak_test_",
|
||||
testonly = 1,
|
||||
srcs = ["gmock_leak_test_.cc"],
|
||||
deps = [
|
||||
"//:gtest_main",
|
||||
],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
@ -89,17 +78,13 @@ cc_test(
|
||||
"gmock_link_test.cc",
|
||||
"gmock_link_test.h",
|
||||
],
|
||||
deps = [
|
||||
"//:gtest_main",
|
||||
],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "gmock_output_test_",
|
||||
srcs = ["gmock_output_test_.cc"],
|
||||
deps = [
|
||||
"//:gtest",
|
||||
],
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
@ -117,7 +102,5 @@ cc_test(
|
||||
name = "gmock_test",
|
||||
size = "small",
|
||||
srcs = ["gmock_test.cc"],
|
||||
deps = [
|
||||
"//:gtest_main",
|
||||
],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
@ -33,9 +33,9 @@
|
||||
// This file tests the built-in actions.
|
||||
|
||||
// Silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14,15
|
||||
// to bool 'true' or 'false') for MSVC 15
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
@ -74,14 +74,11 @@ using testing::ReturnRefOfCopy;
|
||||
using testing::SetArgPointee;
|
||||
using testing::SetArgumentPointee;
|
||||
using testing::Unused;
|
||||
using testing::WithArgs;
|
||||
using testing::_;
|
||||
using testing::get;
|
||||
using testing::internal::BuiltInDefaultValue;
|
||||
using testing::internal::Int64;
|
||||
using testing::internal::UInt64;
|
||||
using testing::make_tuple;
|
||||
using testing::tuple;
|
||||
using testing::tuple_element;
|
||||
|
||||
#if !GTEST_OS_WINDOWS_MOBILE
|
||||
using testing::SetErrnoAndReturn;
|
||||
@ -223,7 +220,6 @@ class MyNonDefaultConstructible {
|
||||
int value_;
|
||||
};
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
|
||||
EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
|
||||
@ -233,7 +229,6 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
|
||||
EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
|
||||
EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
|
||||
@ -303,7 +298,6 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
|
||||
}, "");
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() == nullptr);
|
||||
@ -314,7 +308,6 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
|
||||
std::unique_ptr<int> i = DefaultValue<std::unique_ptr<int>>::Get();
|
||||
EXPECT_EQ(42, *i);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
// Tests that DefaultValue<void>::Get() returns void.
|
||||
TEST(DefaultValueTest, GetWorksForVoid) {
|
||||
@ -382,8 +375,8 @@ typedef int MyGlobalFunction(bool, int);
|
||||
|
||||
class MyActionImpl : public ActionInterface<MyGlobalFunction> {
|
||||
public:
|
||||
virtual int Perform(const tuple<bool, int>& args) {
|
||||
return get<0>(args) ? get<1>(args) : 0;
|
||||
int Perform(const std::tuple<bool, int>& args) override {
|
||||
return std::get<0>(args) ? std::get<1>(args) : 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -399,8 +392,8 @@ TEST(ActionInterfaceTest, MakeAction) {
|
||||
// it a tuple whose size and type are compatible with F's argument
|
||||
// types. For example, if F is int(), then Perform() takes a
|
||||
// 0-tuple; if F is void(bool, int), then Perform() takes a
|
||||
// tuple<bool, int>, and so on.
|
||||
EXPECT_EQ(5, action.Perform(make_tuple(true, 5)));
|
||||
// std::tuple<bool, int>, and so on.
|
||||
EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5)));
|
||||
}
|
||||
|
||||
// Tests that Action<F> can be contructed from a pointer to
|
||||
@ -413,8 +406,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) {
|
||||
TEST(ActionTest, DelegatesWorkToActionInterface) {
|
||||
const Action<MyGlobalFunction> action(new MyActionImpl);
|
||||
|
||||
EXPECT_EQ(5, action.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, action.Perform(make_tuple(false, 1)));
|
||||
EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, action.Perform(std::make_tuple(false, 1)));
|
||||
}
|
||||
|
||||
// Tests that Action<F> can be copied.
|
||||
@ -423,22 +416,22 @@ TEST(ActionTest, IsCopyable) {
|
||||
Action<MyGlobalFunction> a2(a1); // Tests the copy constructor.
|
||||
|
||||
// a1 should continue to work after being copied from.
|
||||
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(make_tuple(false, 1)));
|
||||
EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1)));
|
||||
|
||||
// a2 should work like the action it was copied from.
|
||||
EXPECT_EQ(5, a2.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a2.Perform(make_tuple(false, 1)));
|
||||
EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1)));
|
||||
|
||||
a2 = a1; // Tests the assignment operator.
|
||||
|
||||
// a1 should continue to work after being copied from.
|
||||
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(make_tuple(false, 1)));
|
||||
EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1)));
|
||||
|
||||
// a2 should work like the action it was copied from.
|
||||
EXPECT_EQ(5, a2.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a2.Perform(make_tuple(false, 1)));
|
||||
EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1)));
|
||||
}
|
||||
|
||||
// Tests that an Action<From> object can be converted to a
|
||||
@ -446,8 +439,8 @@ TEST(ActionTest, IsCopyable) {
|
||||
|
||||
class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
|
||||
public:
|
||||
virtual bool Perform(const tuple<int>& arg) {
|
||||
return get<0>(arg) != 0;
|
||||
bool Perform(const std::tuple<int>& arg) override {
|
||||
return std::get<0>(arg) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
@ -460,8 +453,8 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
|
||||
TEST(ActionTest, CanBeConvertedToOtherActionType) {
|
||||
const Action<bool(int)> a1(new IsNotZero); // NOLINT
|
||||
const Action<int(char)> a2 = Action<int(char)>(a1); // NOLINT
|
||||
EXPECT_EQ(1, a2.Perform(make_tuple('a')));
|
||||
EXPECT_EQ(0, a2.Perform(make_tuple('\0')));
|
||||
EXPECT_EQ(1, a2.Perform(std::make_tuple('a')));
|
||||
EXPECT_EQ(0, a2.Perform(std::make_tuple('\0')));
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN
|
||||
|
||||
@ -475,7 +468,9 @@ class ReturnSecondArgumentAction {
|
||||
// polymorphic action whose Perform() method template is either
|
||||
// const or not. This lets us verify the non-const case.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
Result Perform(const ArgumentTuple& args) { return get<1>(args); }
|
||||
Result Perform(const ArgumentTuple& args) {
|
||||
return std::get<1>(args);
|
||||
}
|
||||
};
|
||||
|
||||
// Implements a polymorphic action that can be used in a nullary
|
||||
@ -490,7 +485,9 @@ class ReturnZeroFromNullaryFunctionAction {
|
||||
// polymorphic action whose Perform() method template is either
|
||||
// const or not. This lets us verify the const case.
|
||||
template <typename Result>
|
||||
Result Perform(const tuple<>&) const { return 0; }
|
||||
Result Perform(const std::tuple<>&) const {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// These functions verify that MakePolymorphicAction() returns a
|
||||
@ -509,42 +506,42 @@ ReturnZeroFromNullaryFunction() {
|
||||
// implementation class into a polymorphic action.
|
||||
TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) {
|
||||
Action<int(bool, int, double)> a1 = ReturnSecondArgument(); // NOLINT
|
||||
EXPECT_EQ(5, a1.Perform(make_tuple(false, 5, 2.0)));
|
||||
EXPECT_EQ(5, a1.Perform(std::make_tuple(false, 5, 2.0)));
|
||||
}
|
||||
|
||||
// Tests that MakePolymorphicAction() works when the implementation
|
||||
// class' Perform() method template has only one template parameter.
|
||||
TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) {
|
||||
Action<int()> a1 = ReturnZeroFromNullaryFunction();
|
||||
EXPECT_EQ(0, a1.Perform(make_tuple()));
|
||||
EXPECT_EQ(0, a1.Perform(std::make_tuple()));
|
||||
|
||||
Action<void*()> a2 = ReturnZeroFromNullaryFunction();
|
||||
EXPECT_TRUE(a2.Perform(make_tuple()) == nullptr);
|
||||
EXPECT_TRUE(a2.Perform(std::make_tuple()) == nullptr);
|
||||
}
|
||||
|
||||
// Tests that Return() works as an action for void-returning
|
||||
// functions.
|
||||
TEST(ReturnTest, WorksForVoid) {
|
||||
const Action<void(int)> ret = Return(); // NOLINT
|
||||
return ret.Perform(make_tuple(1));
|
||||
return ret.Perform(std::make_tuple(1));
|
||||
}
|
||||
|
||||
// Tests that Return(v) returns v.
|
||||
TEST(ReturnTest, ReturnsGivenValue) {
|
||||
Action<int()> ret = Return(1); // NOLINT
|
||||
EXPECT_EQ(1, ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(1, ret.Perform(std::make_tuple()));
|
||||
|
||||
ret = Return(-5);
|
||||
EXPECT_EQ(-5, ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(-5, ret.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that Return("string literal") works.
|
||||
TEST(ReturnTest, AcceptsStringLiteral) {
|
||||
Action<const char*()> a1 = Return("Hello");
|
||||
EXPECT_STREQ("Hello", a1.Perform(make_tuple()));
|
||||
EXPECT_STREQ("Hello", a1.Perform(std::make_tuple()));
|
||||
|
||||
Action<std::string()> a2 = Return("world");
|
||||
EXPECT_EQ("world", a2.Perform(make_tuple()));
|
||||
EXPECT_EQ("world", a2.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Test struct which wraps a vector of integers. Used in
|
||||
@ -563,7 +560,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) {
|
||||
// Return() called with 'v' as argument. The Action will return the same data
|
||||
// as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper.
|
||||
Action<IntegerVectorWrapper()> a = Return(v);
|
||||
const std::vector<int>& result = *(a.Perform(make_tuple()).v);
|
||||
const std::vector<int>& result = *(a.Perform(std::make_tuple()).v);
|
||||
EXPECT_THAT(result, ::testing::ElementsAre(0, 1, 2, 3, 4));
|
||||
}
|
||||
|
||||
@ -581,10 +578,10 @@ TEST(ReturnTest, IsCovariant) {
|
||||
Base base;
|
||||
Derived derived;
|
||||
Action<Base*()> ret = Return(&base);
|
||||
EXPECT_EQ(&base, ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(&base, ret.Perform(std::make_tuple()));
|
||||
|
||||
ret = Return(&derived);
|
||||
EXPECT_EQ(&derived, ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(&derived, ret.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that the type of the value passed into Return is converted into T
|
||||
@ -615,7 +612,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) {
|
||||
EXPECT_TRUE(converted) << "Return must convert its argument in its own "
|
||||
<< "conversion operator.";
|
||||
converted = false;
|
||||
action.Perform(tuple<>());
|
||||
action.Perform(std::tuple<>());
|
||||
EXPECT_FALSE(converted) << "Action must NOT convert its argument "
|
||||
<< "when performed.";
|
||||
}
|
||||
@ -636,30 +633,28 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
|
||||
// Tests that ReturnNull() returns NULL in a pointer-returning function.
|
||||
TEST(ReturnNullTest, WorksInPointerReturningFunction) {
|
||||
const Action<int*()> a1 = ReturnNull();
|
||||
EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr);
|
||||
EXPECT_TRUE(a1.Perform(std::make_tuple()) == nullptr);
|
||||
|
||||
const Action<const char*(bool)> a2 = ReturnNull(); // NOLINT
|
||||
EXPECT_TRUE(a2.Perform(make_tuple(true)) == nullptr);
|
||||
EXPECT_TRUE(a2.Perform(std::make_tuple(true)) == nullptr);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
|
||||
// functions.
|
||||
TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
|
||||
const Action<std::unique_ptr<const int>()> a1 = ReturnNull();
|
||||
EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr);
|
||||
EXPECT_TRUE(a1.Perform(std::make_tuple()) == nullptr);
|
||||
|
||||
const Action<std::shared_ptr<int>(std::string)> a2 = ReturnNull();
|
||||
EXPECT_TRUE(a2.Perform(make_tuple("foo")) == nullptr);
|
||||
EXPECT_TRUE(a2.Perform(std::make_tuple("foo")) == nullptr);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
// Tests that ReturnRef(v) works for reference types.
|
||||
TEST(ReturnRefTest, WorksForReference) {
|
||||
const int n = 0;
|
||||
const Action<const int&(bool)> ret = ReturnRef(n); // NOLINT
|
||||
|
||||
EXPECT_EQ(&n, &ret.Perform(make_tuple(true)));
|
||||
EXPECT_EQ(&n, &ret.Perform(std::make_tuple(true)));
|
||||
}
|
||||
|
||||
// Tests that ReturnRef(v) is covariant.
|
||||
@ -667,10 +662,10 @@ TEST(ReturnRefTest, IsCovariant) {
|
||||
Base base;
|
||||
Derived derived;
|
||||
Action<Base&()> a = ReturnRef(base);
|
||||
EXPECT_EQ(&base, &a.Perform(make_tuple()));
|
||||
EXPECT_EQ(&base, &a.Perform(std::make_tuple()));
|
||||
|
||||
a = ReturnRef(derived);
|
||||
EXPECT_EQ(&derived, &a.Perform(make_tuple()));
|
||||
EXPECT_EQ(&derived, &a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that ReturnRefOfCopy(v) works for reference types.
|
||||
@ -678,12 +673,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) {
|
||||
int n = 42;
|
||||
const Action<const int&()> ret = ReturnRefOfCopy(n);
|
||||
|
||||
EXPECT_NE(&n, &ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(42, ret.Perform(make_tuple()));
|
||||
EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(42, ret.Perform(std::make_tuple()));
|
||||
|
||||
n = 43;
|
||||
EXPECT_NE(&n, &ret.Perform(make_tuple()));
|
||||
EXPECT_EQ(42, ret.Perform(make_tuple()));
|
||||
EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(42, ret.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that ReturnRefOfCopy(v) is covariant.
|
||||
@ -691,10 +686,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
|
||||
Base base;
|
||||
Derived derived;
|
||||
Action<Base&()> a = ReturnRefOfCopy(base);
|
||||
EXPECT_NE(&base, &a.Perform(make_tuple()));
|
||||
EXPECT_NE(&base, &a.Perform(std::make_tuple()));
|
||||
|
||||
a = ReturnRefOfCopy(derived);
|
||||
EXPECT_NE(&derived, &a.Perform(make_tuple()));
|
||||
EXPECT_NE(&derived, &a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that DoDefault() does the default action for the mock method.
|
||||
@ -705,14 +700,12 @@ class MockClass {
|
||||
|
||||
MOCK_METHOD1(IntFunc, int(bool flag)); // NOLINT
|
||||
MOCK_METHOD0(Foo, MyNonDefaultConstructible());
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
MOCK_METHOD0(MakeUnique, std::unique_ptr<int>());
|
||||
MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>());
|
||||
MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
|
||||
MOCK_METHOD1(TakeUnique, int(std::unique_ptr<int>));
|
||||
MOCK_METHOD2(TakeUnique,
|
||||
int(const std::unique_ptr<int>&, std::unique_ptr<int>));
|
||||
#endif
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockClass);
|
||||
@ -800,14 +793,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
|
||||
|
||||
int n = 0;
|
||||
char ch = '\0';
|
||||
a.Perform(make_tuple(true, &n, &ch));
|
||||
a.Perform(std::make_tuple(true, &n, &ch));
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('\0', ch);
|
||||
|
||||
a = SetArgPointee<2>('a');
|
||||
n = 0;
|
||||
ch = '\0';
|
||||
a.Perform(make_tuple(true, &n, &ch));
|
||||
a.Perform(std::make_tuple(true, &n, &ch));
|
||||
EXPECT_EQ(0, n);
|
||||
EXPECT_EQ('a', ch);
|
||||
}
|
||||
@ -820,13 +813,13 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
|
||||
Action<MyFunction> a = SetArgPointee<0>("hi");
|
||||
std::string str;
|
||||
const char* ptr = nullptr;
|
||||
a.Perform(make_tuple(&str, &ptr));
|
||||
a.Perform(std::make_tuple(&str, &ptr));
|
||||
EXPECT_EQ("hi", str);
|
||||
EXPECT_TRUE(ptr == nullptr);
|
||||
|
||||
a = SetArgPointee<1>("world");
|
||||
str = "";
|
||||
a.Perform(make_tuple(&str, &ptr));
|
||||
a.Perform(std::make_tuple(&str, &ptr));
|
||||
EXPECT_EQ("", str);
|
||||
EXPECT_STREQ("world", ptr);
|
||||
}
|
||||
@ -835,7 +828,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
|
||||
typedef void MyFunction(const wchar_t**);
|
||||
Action<MyFunction> a = SetArgPointee<0>(L"world");
|
||||
const wchar_t* ptr = nullptr;
|
||||
a.Perform(make_tuple(&ptr));
|
||||
a.Perform(std::make_tuple(&ptr));
|
||||
EXPECT_STREQ(L"world", ptr);
|
||||
|
||||
# if GTEST_HAS_STD_WSTRING
|
||||
@ -843,7 +836,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
|
||||
typedef void MyStringFunction(std::wstring*);
|
||||
Action<MyStringFunction> a2 = SetArgPointee<0>(L"world");
|
||||
std::wstring str = L"";
|
||||
a2.Perform(make_tuple(&str));
|
||||
a2.Perform(std::make_tuple(&str));
|
||||
EXPECT_EQ(L"world", str);
|
||||
|
||||
# endif
|
||||
@ -857,7 +850,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
|
||||
Action<MyFunction> a = SetArgPointee<1>(hi);
|
||||
std::string str;
|
||||
const char* ptr = nullptr;
|
||||
a.Perform(make_tuple(true, &str, &ptr));
|
||||
a.Perform(std::make_tuple(true, &str, &ptr));
|
||||
EXPECT_EQ("hi", str);
|
||||
EXPECT_TRUE(ptr == nullptr);
|
||||
|
||||
@ -865,7 +858,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
|
||||
char* const world = world_array;
|
||||
a = SetArgPointee<2>(world);
|
||||
str = "";
|
||||
a.Perform(make_tuple(true, &str, &ptr));
|
||||
a.Perform(std::make_tuple(true, &str, &ptr));
|
||||
EXPECT_EQ("", str);
|
||||
EXPECT_EQ(world, ptr);
|
||||
}
|
||||
@ -875,7 +868,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
|
||||
const wchar_t* const hi = L"hi";
|
||||
Action<MyFunction> a = SetArgPointee<1>(hi);
|
||||
const wchar_t* ptr = nullptr;
|
||||
a.Perform(make_tuple(true, &ptr));
|
||||
a.Perform(std::make_tuple(true, &ptr));
|
||||
EXPECT_EQ(hi, ptr);
|
||||
|
||||
# if GTEST_HAS_STD_WSTRING
|
||||
@ -885,7 +878,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
|
||||
wchar_t* const world = world_array;
|
||||
Action<MyStringFunction> a2 = SetArgPointee<1>(world);
|
||||
std::wstring str;
|
||||
a2.Perform(make_tuple(true, &str));
|
||||
a2.Perform(std::make_tuple(true, &str));
|
||||
EXPECT_EQ(world_array, str);
|
||||
# endif
|
||||
}
|
||||
@ -898,14 +891,14 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
|
||||
|
||||
int n = 0;
|
||||
char ch = '\0';
|
||||
a.Perform(make_tuple(true, &n, &ch));
|
||||
a.Perform(std::make_tuple(true, &n, &ch));
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('\0', ch);
|
||||
|
||||
a = SetArgumentPointee<2>('a');
|
||||
n = 0;
|
||||
ch = '\0';
|
||||
a.Perform(make_tuple(true, &n, &ch));
|
||||
a.Perform(std::make_tuple(true, &n, &ch));
|
||||
EXPECT_EQ(0, n);
|
||||
EXPECT_EQ('a', ch);
|
||||
}
|
||||
@ -926,6 +919,21 @@ class VoidNullaryFunctor {
|
||||
void operator()() { g_done = true; }
|
||||
};
|
||||
|
||||
short Short(short n) { return n; } // NOLINT
|
||||
char Char(char ch) { return ch; }
|
||||
|
||||
const char* CharPtr(const char* s) { return s; }
|
||||
|
||||
bool Unary(int x) { return x < 0; }
|
||||
|
||||
const char* Binary(const char* input, short n) { return input + n; } // NOLINT
|
||||
|
||||
void VoidBinary(int, char) { g_done = true; }
|
||||
|
||||
int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT
|
||||
|
||||
int SumOf4(int a, int b, int c, int d) { return a + b + c + d; }
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
Foo() : value_(123) {}
|
||||
@ -940,16 +948,16 @@ class Foo {
|
||||
TEST(InvokeWithoutArgsTest, Function) {
|
||||
// As an action that takes one argument.
|
||||
Action<int(int)> a = InvokeWithoutArgs(Nullary); // NOLINT
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(2)));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(2)));
|
||||
|
||||
// As an action that takes two arguments.
|
||||
Action<int(int, double)> a2 = InvokeWithoutArgs(Nullary); // NOLINT
|
||||
EXPECT_EQ(1, a2.Perform(make_tuple(2, 3.5)));
|
||||
EXPECT_EQ(1, a2.Perform(std::make_tuple(2, 3.5)));
|
||||
|
||||
// As an action that returns void.
|
||||
Action<void(int)> a3 = InvokeWithoutArgs(VoidNullary); // NOLINT
|
||||
g_done = false;
|
||||
a3.Perform(make_tuple(1));
|
||||
a3.Perform(std::make_tuple(1));
|
||||
EXPECT_TRUE(g_done);
|
||||
}
|
||||
|
||||
@ -957,17 +965,17 @@ TEST(InvokeWithoutArgsTest, Function) {
|
||||
TEST(InvokeWithoutArgsTest, Functor) {
|
||||
// As an action that takes no argument.
|
||||
Action<int()> a = InvokeWithoutArgs(NullaryFunctor()); // NOLINT
|
||||
EXPECT_EQ(2, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(2, a.Perform(std::make_tuple()));
|
||||
|
||||
// As an action that takes three arguments.
|
||||
Action<int(int, double, char)> a2 = // NOLINT
|
||||
InvokeWithoutArgs(NullaryFunctor());
|
||||
EXPECT_EQ(2, a2.Perform(make_tuple(3, 3.5, 'a')));
|
||||
EXPECT_EQ(2, a2.Perform(std::make_tuple(3, 3.5, 'a')));
|
||||
|
||||
// As an action that returns void.
|
||||
Action<void()> a3 = InvokeWithoutArgs(VoidNullaryFunctor());
|
||||
g_done = false;
|
||||
a3.Perform(make_tuple());
|
||||
a3.Perform(std::make_tuple());
|
||||
EXPECT_TRUE(g_done);
|
||||
}
|
||||
|
||||
@ -976,13 +984,13 @@ TEST(InvokeWithoutArgsTest, Method) {
|
||||
Foo foo;
|
||||
Action<int(bool, char)> a = // NOLINT
|
||||
InvokeWithoutArgs(&foo, &Foo::Nullary);
|
||||
EXPECT_EQ(123, a.Perform(make_tuple(true, 'a')));
|
||||
EXPECT_EQ(123, a.Perform(std::make_tuple(true, 'a')));
|
||||
}
|
||||
|
||||
// Tests using IgnoreResult() on a polymorphic action.
|
||||
TEST(IgnoreResultTest, PolymorphicAction) {
|
||||
Action<void(int)> a = IgnoreResult(Return(5)); // NOLINT
|
||||
a.Perform(make_tuple(1));
|
||||
a.Perform(std::make_tuple(1));
|
||||
}
|
||||
|
||||
// Tests using IgnoreResult() on a monomorphic action.
|
||||
@ -995,7 +1003,7 @@ int ReturnOne() {
|
||||
TEST(IgnoreResultTest, MonomorphicAction) {
|
||||
g_done = false;
|
||||
Action<void()> a = IgnoreResult(Invoke(ReturnOne));
|
||||
a.Perform(make_tuple());
|
||||
a.Perform(std::make_tuple());
|
||||
EXPECT_TRUE(g_done);
|
||||
}
|
||||
|
||||
@ -1010,55 +1018,155 @@ TEST(IgnoreResultTest, ActionReturningClass) {
|
||||
g_done = false;
|
||||
Action<void(int)> a =
|
||||
IgnoreResult(Invoke(ReturnMyNonDefaultConstructible)); // NOLINT
|
||||
a.Perform(make_tuple(2));
|
||||
a.Perform(std::make_tuple(2));
|
||||
EXPECT_TRUE(g_done);
|
||||
}
|
||||
|
||||
TEST(AssignTest, Int) {
|
||||
int x = 0;
|
||||
Action<void(int)> a = Assign(&x, 5);
|
||||
a.Perform(make_tuple(0));
|
||||
a.Perform(std::make_tuple(0));
|
||||
EXPECT_EQ(5, x);
|
||||
}
|
||||
|
||||
TEST(AssignTest, String) {
|
||||
::std::string x;
|
||||
Action<void(void)> a = Assign(&x, "Hello, world");
|
||||
a.Perform(make_tuple());
|
||||
a.Perform(std::make_tuple());
|
||||
EXPECT_EQ("Hello, world", x);
|
||||
}
|
||||
|
||||
TEST(AssignTest, CompatibleTypes) {
|
||||
double x = 0;
|
||||
Action<void(int)> a = Assign(&x, 5);
|
||||
a.Perform(make_tuple(0));
|
||||
a.Perform(std::make_tuple(0));
|
||||
EXPECT_DOUBLE_EQ(5, x);
|
||||
}
|
||||
|
||||
|
||||
// Tests using WithArgs and with an action that takes 1 argument.
|
||||
TEST(WithArgsTest, OneArg) {
|
||||
Action<bool(double x, int n)> a = WithArgs<1>(Invoke(Unary)); // NOLINT
|
||||
EXPECT_TRUE(a.Perform(std::make_tuple(1.5, -1)));
|
||||
EXPECT_FALSE(a.Perform(std::make_tuple(1.5, 1)));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 2 arguments.
|
||||
TEST(WithArgsTest, TwoArgs) {
|
||||
Action<const char*(const char* s, double x, short n)> a = // NOLINT
|
||||
WithArgs<0, 2>(Invoke(Binary));
|
||||
const char s[] = "Hello";
|
||||
EXPECT_EQ(s + 2, a.Perform(std::make_tuple(CharPtr(s), 0.5, Short(2))));
|
||||
}
|
||||
|
||||
struct ConcatAll {
|
||||
std::string operator()() const { return {}; }
|
||||
template <typename... I>
|
||||
std::string operator()(const char* a, I... i) const {
|
||||
return a + ConcatAll()(i...);
|
||||
}
|
||||
};
|
||||
|
||||
// Tests using WithArgs with an action that takes 10 arguments.
|
||||
TEST(WithArgsTest, TenArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(Invoke(ConcatAll{}));
|
||||
EXPECT_EQ("0123210123",
|
||||
a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that is not Invoke().
|
||||
class SubtractAction : public ActionInterface<int(int, int)> {
|
||||
public:
|
||||
int Perform(const std::tuple<int, int>& args) override {
|
||||
return std::get<0>(args) - std::get<1>(args);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(WithArgsTest, NonInvokeAction) {
|
||||
Action<int(const std::string&, int, int)> a =
|
||||
WithArgs<2, 1>(MakeAction(new SubtractAction));
|
||||
std::tuple<std::string, int, int> dummy =
|
||||
std::make_tuple(std::string("hi"), 2, 10);
|
||||
EXPECT_EQ(8, a.Perform(dummy));
|
||||
}
|
||||
|
||||
// Tests using WithArgs to pass all original arguments in the original order.
|
||||
TEST(WithArgsTest, Identity) {
|
||||
Action<int(int x, char y, short z)> a = // NOLINT
|
||||
WithArgs<0, 1, 2>(Invoke(Ternary));
|
||||
EXPECT_EQ(123, a.Perform(std::make_tuple(100, Char(20), Short(3))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with repeated arguments.
|
||||
TEST(WithArgsTest, RepeatedArguments) {
|
||||
Action<int(bool, int m, int n)> a = // NOLINT
|
||||
WithArgs<1, 1, 1, 1>(Invoke(SumOf4));
|
||||
EXPECT_EQ(4, a.Perform(std::make_tuple(false, 1, 10)));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with reversed argument order.
|
||||
TEST(WithArgsTest, ReversedArgumentOrder) {
|
||||
Action<const char*(short n, const char* input)> a = // NOLINT
|
||||
WithArgs<1, 0>(Invoke(Binary));
|
||||
const char s[] = "Hello";
|
||||
EXPECT_EQ(s + 2, a.Perform(std::make_tuple(Short(2), CharPtr(s))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with compatible, but not identical, argument types.
|
||||
TEST(WithArgsTest, ArgsOfCompatibleTypes) {
|
||||
Action<long(short x, char y, double z, char c)> a = // NOLINT
|
||||
WithArgs<0, 1, 3>(Invoke(Ternary));
|
||||
EXPECT_EQ(123,
|
||||
a.Perform(std::make_tuple(Short(100), Char(20), 5.6, Char(3))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that returns void.
|
||||
TEST(WithArgsTest, VoidAction) {
|
||||
Action<void(double x, char c, int n)> a = WithArgs<2, 1>(Invoke(VoidBinary));
|
||||
g_done = false;
|
||||
a.Perform(std::make_tuple(1.5, 'a', 3));
|
||||
EXPECT_TRUE(g_done);
|
||||
}
|
||||
|
||||
TEST(WithArgsTest, ReturnReference) {
|
||||
Action<int&(int&, void*)> aa = WithArgs<0>([](int& a) -> int& { return a; });
|
||||
int i = 0;
|
||||
const int& res = aa.Perform(std::forward_as_tuple(i, nullptr));
|
||||
EXPECT_EQ(&i, &res);
|
||||
}
|
||||
|
||||
TEST(WithArgsTest, InnerActionWithConversion) {
|
||||
Action<Derived*()> inner = [] { return nullptr; };
|
||||
Action<Base*(double)> a = testing::WithoutArgs(inner);
|
||||
EXPECT_EQ(nullptr, a.Perform(std::make_tuple(1.1)));
|
||||
}
|
||||
|
||||
#if !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
class SetErrnoAndReturnTest : public testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() { errno = 0; }
|
||||
virtual void TearDown() { errno = 0; }
|
||||
void SetUp() override { errno = 0; }
|
||||
void TearDown() override { errno = 0; }
|
||||
};
|
||||
|
||||
TEST_F(SetErrnoAndReturnTest, Int) {
|
||||
Action<int(void)> a = SetErrnoAndReturn(ENOTTY, -5);
|
||||
EXPECT_EQ(-5, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(-5, a.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(ENOTTY, errno);
|
||||
}
|
||||
|
||||
TEST_F(SetErrnoAndReturnTest, Ptr) {
|
||||
int x;
|
||||
Action<int*(void)> a = SetErrnoAndReturn(ENOTTY, &x);
|
||||
EXPECT_EQ(&x, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(&x, a.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(ENOTTY, errno);
|
||||
}
|
||||
|
||||
TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
|
||||
Action<double()> a = SetErrnoAndReturn(EINVAL, 5);
|
||||
EXPECT_DOUBLE_EQ(5.0, a.Perform(make_tuple()));
|
||||
EXPECT_DOUBLE_EQ(5.0, a.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
@ -1149,7 +1257,6 @@ TEST(ByRefTest, PrintsCorrectly) {
|
||||
EXPECT_EQ(expected.str(), actual.str());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
std::unique_ptr<int> UniquePtrSource() {
|
||||
return std::unique_ptr<int>(new int(19));
|
||||
@ -1262,9 +1369,7 @@ TEST(MockMethodTest, CanTakeMoveOnlyValue) {
|
||||
EXPECT_EQ(42, *saved);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Tests for std::function based action.
|
||||
|
||||
int Add(int val, int& ref, int* ptr) { // NOLINT
|
||||
@ -1298,47 +1403,47 @@ TEST(FunctorActionTest, ActionFromFunction) {
|
||||
|
||||
TEST(FunctorActionTest, ActionFromLambda) {
|
||||
Action<int(bool, int)> a1 = [](bool b, int i) { return b ? i : 0; };
|
||||
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(make_tuple(false, 5)));
|
||||
EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 5)));
|
||||
|
||||
std::unique_ptr<int> saved;
|
||||
Action<void(std::unique_ptr<int>)> a2 = [&saved](std::unique_ptr<int> p) {
|
||||
saved = std::move(p);
|
||||
};
|
||||
a2.Perform(make_tuple(UniqueInt(5)));
|
||||
a2.Perform(std::make_tuple(UniqueInt(5)));
|
||||
EXPECT_EQ(5, *saved);
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, PolymorphicFunctor) {
|
||||
Action<int(int)> ai = Double();
|
||||
EXPECT_EQ(2, ai.Perform(make_tuple(1)));
|
||||
EXPECT_EQ(2, ai.Perform(std::make_tuple(1)));
|
||||
Action<double(double)> ad = Double(); // Double? Double double!
|
||||
EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5)));
|
||||
EXPECT_EQ(3.0, ad.Perform(std::make_tuple(1.5)));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, TypeConversion) {
|
||||
// Numeric promotions are allowed.
|
||||
const Action<bool(int)> a1 = [](int i) { return i > 1; };
|
||||
const Action<int(bool)> a2 = Action<int(bool)>(a1);
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(42)));
|
||||
EXPECT_EQ(0, a2.Perform(make_tuple(42)));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple(42)));
|
||||
EXPECT_EQ(0, a2.Perform(std::make_tuple(42)));
|
||||
|
||||
// Implicit constructors are allowed.
|
||||
const Action<bool(std::string)> s1 = [](std::string s) { return !s.empty(); };
|
||||
const Action<int(const char*)> s2 = Action<int(const char*)>(s1);
|
||||
EXPECT_EQ(0, s2.Perform(make_tuple("")));
|
||||
EXPECT_EQ(1, s2.Perform(make_tuple("hello")));
|
||||
EXPECT_EQ(0, s2.Perform(std::make_tuple("")));
|
||||
EXPECT_EQ(1, s2.Perform(std::make_tuple("hello")));
|
||||
|
||||
// Also between the lambda and the action itself.
|
||||
const Action<bool(std::string)> x = [](Unused) { return 42; };
|
||||
EXPECT_TRUE(x.Perform(make_tuple("hello")));
|
||||
EXPECT_TRUE(x.Perform(std::make_tuple("hello")));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, UnusedArguments) {
|
||||
// Verify that users can ignore uninteresting arguments.
|
||||
Action<int(int, double y, double z)> a =
|
||||
[](int i, Unused, Unused) { return 2 * i; };
|
||||
tuple<int, double, double> dummy = make_tuple(3, 7.3, 9.44);
|
||||
std::tuple<int, double, double> dummy = std::make_tuple(3, 7.3, 9.44);
|
||||
EXPECT_EQ(6, a.Perform(dummy));
|
||||
}
|
||||
|
||||
@ -1349,18 +1454,17 @@ TEST(FunctorActionTest, UnusedArguments) {
|
||||
// so maybe it's better to make users use lambdas instead.
|
||||
TEST(MoveOnlyArgumentsTest, ReturningActions) {
|
||||
Action<int(std::unique_ptr<int>)> a = Return(1);
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(nullptr)));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(nullptr)));
|
||||
|
||||
a = testing::WithoutArgs([]() { return 7; });
|
||||
EXPECT_EQ(7, a.Perform(make_tuple(nullptr)));
|
||||
EXPECT_EQ(7, a.Perform(std::make_tuple(nullptr)));
|
||||
|
||||
Action<void(std::unique_ptr<int>, int*)> a2 = testing::SetArgPointee<1>(3);
|
||||
int x = 0;
|
||||
a2.Perform(make_tuple(nullptr, &x));
|
||||
a2.Perform(std::make_tuple(nullptr, &x));
|
||||
EXPECT_EQ(x, 3);
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
} // Unnamed namespace
|
||||
|
||||
|
@ -396,17 +396,17 @@ TEST(ExactlyTest, HasCorrectBounds) {
|
||||
class EvenCardinality : public CardinalityInterface {
|
||||
public:
|
||||
// Returns true iff call_count calls will satisfy this cardinality.
|
||||
virtual bool IsSatisfiedByCallCount(int call_count) const {
|
||||
bool IsSatisfiedByCallCount(int call_count) const override {
|
||||
return (call_count % 2 == 0);
|
||||
}
|
||||
|
||||
// Returns true iff call_count calls will saturate this cardinality.
|
||||
virtual bool IsSaturatedByCallCount(int /* call_count */) const {
|
||||
bool IsSaturatedByCallCount(int /* call_count */) const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Describes self to an ostream.
|
||||
virtual void DescribeTo(::std::ostream* ss) const {
|
||||
void DescribeTo(::std::ostream* ss) const override {
|
||||
*ss << "called even number of times";
|
||||
}
|
||||
};
|
||||
|
16
googlemock/test/gmock-function-mocker_nc.cc
Normal file
16
googlemock/test/gmock-function-mocker_nc.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#if defined(TEST_MOCK_METHOD_INVALID_CONST_SPEC)
|
||||
|
||||
struct Base {
|
||||
MOCK_METHOD(int, F, (), (onst));
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// Sanity check - this should compile.
|
||||
|
||||
#endif
|
43
googlemock/test/gmock-function-mocker_nc_test.py
Normal file
43
googlemock/test/gmock-function-mocker_nc_test.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Negative compilation tests for Google Mock macro MOCK_METHOD."""
|
||||
|
||||
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 GMockMethodNCTest(googletest.TestCase):
|
||||
"""Negative compilation tests for MOCK_METHOD."""
|
||||
|
||||
# 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 = [
|
||||
("MOCK_METHOD_INVALID_CONST_SPEC",
|
||||
[r"onst cannot be recognized as a valid specification modifier"]),
|
||||
]
|
||||
|
||||
# Define a test method in GMockNCTest for each element in TEST_SPECS.
|
||||
fake_target_util.DefineNegativeCompilationTests(
|
||||
GMockMethodNCTest,
|
||||
"google3/third_party/googletest/googlemock/test/gmock-function-mocker_nc",
|
||||
"gmock-function-mocker_nc.o", TEST_SPECS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
googletest.main()
|
657
googlemock/test/gmock-function-mocker_test.cc
Normal file
657
googlemock/test/gmock-function-mocker_test.cc
Normal file
@ -0,0 +1,657 @@
|
||||
// Copyright 2007, 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 tests the function mocker classes.
|
||||
#include "gmock/gmock-generated-function-mockers.h"
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
|
||||
// we are getting compiler errors if we use basetyps.h, hence including
|
||||
// objbase.h for definition of STDMETHOD.
|
||||
# include <objbase.h>
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
|
||||
// mock for a function with const arguments, so we don't test such
|
||||
// cases for MSVC versions older than 2008.
|
||||
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_function_mocker_test {
|
||||
|
||||
using testing::_;
|
||||
using testing::A;
|
||||
using testing::An;
|
||||
using testing::AnyNumber;
|
||||
using testing::Const;
|
||||
using testing::DoDefault;
|
||||
using testing::Eq;
|
||||
using testing::Lt;
|
||||
using testing::MockFunction;
|
||||
using testing::Ref;
|
||||
using testing::Return;
|
||||
using testing::ReturnRef;
|
||||
using testing::TypedEq;
|
||||
|
||||
class FooInterface {
|
||||
public:
|
||||
virtual ~FooInterface() {}
|
||||
|
||||
virtual void VoidReturning(int x) = 0;
|
||||
|
||||
virtual int Nullary() = 0;
|
||||
virtual bool Unary(int x) = 0;
|
||||
virtual long Binary(short x, int y) = 0; // NOLINT
|
||||
virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
|
||||
float g, double h, unsigned i, char* j,
|
||||
const std::string& k) = 0;
|
||||
|
||||
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
|
||||
virtual std::string TakesConstReference(const int& n) = 0;
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
virtual bool TakesConst(const int x) = 0;
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
virtual int OverloadedOnArgumentNumber() = 0;
|
||||
virtual int OverloadedOnArgumentNumber(int n) = 0;
|
||||
|
||||
virtual int OverloadedOnArgumentType(int n) = 0;
|
||||
virtual char OverloadedOnArgumentType(char c) = 0;
|
||||
|
||||
virtual int OverloadedOnConstness() = 0;
|
||||
virtual char OverloadedOnConstness() const = 0;
|
||||
|
||||
virtual int TypeWithHole(int (*func)()) = 0;
|
||||
virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
STDMETHOD_(int, CTNullary)() = 0;
|
||||
STDMETHOD_(bool, CTUnary)(int x) = 0;
|
||||
STDMETHOD_(int, CTDecimal)
|
||||
(bool b, char c, short d, int e, long f, // NOLINT
|
||||
float g, double h, unsigned i, char* j, const std::string& k) = 0;
|
||||
STDMETHOD_(char, CTConst)(int x) const = 0;
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
};
|
||||
|
||||
// Const qualifiers on arguments were once (incorrectly) considered
|
||||
// significant in determining whether two virtual functions had the same
|
||||
// signature. This was fixed in Visual Studio 2008. However, the compiler
|
||||
// still emits a warning that alerts about this change in behavior.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4373)
|
||||
#endif
|
||||
class MockFoo : public FooInterface {
|
||||
public:
|
||||
MockFoo() {}
|
||||
|
||||
// Makes sure that a mock function parameter can be named.
|
||||
MOCK_METHOD(void, VoidReturning, (int n)); // NOLINT
|
||||
|
||||
MOCK_METHOD(int, Nullary, ()); // NOLINT
|
||||
|
||||
// Makes sure that a mock function parameter can be unnamed.
|
||||
MOCK_METHOD(bool, Unary, (int)); // NOLINT
|
||||
MOCK_METHOD(long, Binary, (short, int)); // NOLINT
|
||||
MOCK_METHOD(int, Decimal,
|
||||
(bool, char, short, int, long, float, // NOLINT
|
||||
double, unsigned, char*, const std::string& str),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, TakesNonConstReference, (int&)); // NOLINT
|
||||
MOCK_METHOD(std::string, TakesConstReference, (const int&));
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
MOCK_METHOD(bool, TakesConst, (const int)); // NOLINT
|
||||
#endif
|
||||
|
||||
// Tests that the function return type can contain unprotected comma.
|
||||
MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (), ());
|
||||
MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (int),
|
||||
(const)); // NOLINT
|
||||
|
||||
MOCK_METHOD(int, OverloadedOnArgumentNumber, ()); // NOLINT
|
||||
MOCK_METHOD(int, OverloadedOnArgumentNumber, (int)); // NOLINT
|
||||
|
||||
MOCK_METHOD(int, OverloadedOnArgumentType, (int)); // NOLINT
|
||||
MOCK_METHOD(char, OverloadedOnArgumentType, (char)); // NOLINT
|
||||
|
||||
MOCK_METHOD(int, OverloadedOnConstness, (), (override)); // NOLINT
|
||||
MOCK_METHOD(char, OverloadedOnConstness, (), (override, const)); // NOLINT
|
||||
|
||||
MOCK_METHOD(int, TypeWithHole, (int (*)()), ()); // NOLINT
|
||||
MOCK_METHOD(int, TypeWithComma, ((const std::map<int, std::string>&)));
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
|
||||
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
|
||||
MOCK_METHOD(int, CTDecimal,
|
||||
(bool b, char c, short d, int e, long f, float g, double h,
|
||||
unsigned i, char* j, const std::string& k),
|
||||
(Calltype(STDMETHODCALLTYPE)));
|
||||
MOCK_METHOD(char, CTConst, (int), (const, Calltype(STDMETHODCALLTYPE)));
|
||||
MOCK_METHOD((std::map<int, std::string>), CTReturnTypeWithComma, (),
|
||||
(Calltype(STDMETHODCALLTYPE)));
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
};
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
class MockMethodFunctionMockerTest : public testing::Test {
|
||||
protected:
|
||||
MockMethodFunctionMockerTest() : foo_(&mock_foo_) {}
|
||||
|
||||
FooInterface* const foo_;
|
||||
MockFoo mock_foo_;
|
||||
};
|
||||
|
||||
// Tests mocking a void-returning function.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksVoidFunction) {
|
||||
EXPECT_CALL(mock_foo_, VoidReturning(Lt(100)));
|
||||
foo_->VoidReturning(0);
|
||||
}
|
||||
|
||||
// Tests mocking a nullary function.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksNullaryFunction) {
|
||||
EXPECT_CALL(mock_foo_, Nullary())
|
||||
.WillOnce(DoDefault())
|
||||
.WillOnce(Return(1));
|
||||
|
||||
EXPECT_EQ(0, foo_->Nullary());
|
||||
EXPECT_EQ(1, foo_->Nullary());
|
||||
}
|
||||
|
||||
// Tests mocking a unary function.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksUnaryFunction) {
|
||||
EXPECT_CALL(mock_foo_, Unary(Eq(2)))
|
||||
.Times(2)
|
||||
.WillOnce(Return(true));
|
||||
|
||||
EXPECT_TRUE(foo_->Unary(2));
|
||||
EXPECT_FALSE(foo_->Unary(2));
|
||||
}
|
||||
|
||||
// Tests mocking a binary function.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksBinaryFunction) {
|
||||
EXPECT_CALL(mock_foo_, Binary(2, _))
|
||||
.WillOnce(Return(3));
|
||||
|
||||
EXPECT_EQ(3, foo_->Binary(2, 1));
|
||||
}
|
||||
|
||||
// Tests mocking a decimal function.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksDecimalFunction) {
|
||||
EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(),
|
||||
Lt(100), 5U, NULL, "hi"))
|
||||
.WillOnce(Return(5));
|
||||
|
||||
EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
|
||||
}
|
||||
|
||||
// Tests mocking a function that takes a non-const reference.
|
||||
TEST_F(MockMethodFunctionMockerTest,
|
||||
MocksFunctionWithNonConstReferenceArgument) {
|
||||
int a = 0;
|
||||
EXPECT_CALL(mock_foo_, TakesNonConstReference(Ref(a)))
|
||||
.WillOnce(Return(true));
|
||||
|
||||
EXPECT_TRUE(foo_->TakesNonConstReference(a));
|
||||
}
|
||||
|
||||
// Tests mocking a function that takes a const reference.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
|
||||
int a = 0;
|
||||
EXPECT_CALL(mock_foo_, TakesConstReference(Ref(a)))
|
||||
.WillOnce(Return("Hello"));
|
||||
|
||||
EXPECT_EQ("Hello", foo_->TakesConstReference(a));
|
||||
}
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
// Tests mocking a function that takes a const variable.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) {
|
||||
EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
|
||||
.WillOnce(DoDefault());
|
||||
|
||||
EXPECT_FALSE(foo_->TakesConst(5));
|
||||
}
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
// Tests mocking functions overloaded on the number of arguments.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
|
||||
EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
|
||||
.WillOnce(Return(1));
|
||||
EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber(_))
|
||||
.WillOnce(Return(2));
|
||||
|
||||
EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
|
||||
EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
|
||||
}
|
||||
|
||||
// Tests mocking functions overloaded on the types of argument.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) {
|
||||
EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(An<int>()))
|
||||
.WillOnce(Return(1));
|
||||
EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a')))
|
||||
.WillOnce(Return('b'));
|
||||
|
||||
EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
|
||||
EXPECT_EQ('b', foo_->OverloadedOnArgumentType('a'));
|
||||
}
|
||||
|
||||
// Tests mocking functions overloaded on the const-ness of this object.
|
||||
TEST_F(MockMethodFunctionMockerTest,
|
||||
MocksFunctionsOverloadedOnConstnessOfThis) {
|
||||
EXPECT_CALL(mock_foo_, OverloadedOnConstness());
|
||||
EXPECT_CALL(Const(mock_foo_), OverloadedOnConstness())
|
||||
.WillOnce(Return('a'));
|
||||
|
||||
EXPECT_EQ(0, foo_->OverloadedOnConstness());
|
||||
EXPECT_EQ('a', Const(*foo_).OverloadedOnConstness());
|
||||
}
|
||||
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithComma) {
|
||||
const std::map<int, std::string> a_map;
|
||||
EXPECT_CALL(mock_foo_, ReturnTypeWithComma())
|
||||
.WillOnce(Return(a_map));
|
||||
EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42))
|
||||
.WillOnce(Return(a_map));
|
||||
|
||||
EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
|
||||
EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
|
||||
}
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
// Tests mocking a nullary function with calltype.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksNullaryFunctionWithCallType) {
|
||||
EXPECT_CALL(mock_foo_, CTNullary())
|
||||
.WillOnce(Return(-1))
|
||||
.WillOnce(Return(0));
|
||||
|
||||
EXPECT_EQ(-1, foo_->CTNullary());
|
||||
EXPECT_EQ(0, foo_->CTNullary());
|
||||
}
|
||||
|
||||
// Tests mocking a unary function with calltype.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksUnaryFunctionWithCallType) {
|
||||
EXPECT_CALL(mock_foo_, CTUnary(Eq(2)))
|
||||
.Times(2)
|
||||
.WillOnce(Return(true))
|
||||
.WillOnce(Return(false));
|
||||
|
||||
EXPECT_TRUE(foo_->CTUnary(2));
|
||||
EXPECT_FALSE(foo_->CTUnary(2));
|
||||
}
|
||||
|
||||
// Tests mocking a decimal function with calltype.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksDecimalFunctionWithCallType) {
|
||||
EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(),
|
||||
Lt(100), 5U, NULL, "hi"))
|
||||
.WillOnce(Return(10));
|
||||
|
||||
EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi"));
|
||||
}
|
||||
|
||||
// Tests mocking functions overloaded on the const-ness of this object.
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
|
||||
EXPECT_CALL(Const(mock_foo_), CTConst(_))
|
||||
.WillOnce(Return('a'));
|
||||
|
||||
EXPECT_EQ('a', Const(*foo_).CTConst(0));
|
||||
}
|
||||
|
||||
TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
|
||||
const std::map<int, std::string> a_map;
|
||||
EXPECT_CALL(mock_foo_, CTReturnTypeWithComma())
|
||||
.WillOnce(Return(a_map));
|
||||
|
||||
EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
|
||||
}
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
class MockB {
|
||||
public:
|
||||
MockB() {}
|
||||
|
||||
MOCK_METHOD(void, DoB, ());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
|
||||
};
|
||||
|
||||
// Tests that functions with no EXPECT_CALL() rules can be called any
|
||||
// number of times.
|
||||
TEST(MockMethodExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
|
||||
{
|
||||
MockB b;
|
||||
}
|
||||
|
||||
{
|
||||
MockB b;
|
||||
b.DoB();
|
||||
}
|
||||
|
||||
{
|
||||
MockB b;
|
||||
b.DoB();
|
||||
b.DoB();
|
||||
}
|
||||
}
|
||||
|
||||
// Tests mocking template interfaces.
|
||||
|
||||
template <typename T>
|
||||
class StackInterface {
|
||||
public:
|
||||
virtual ~StackInterface() {}
|
||||
|
||||
// Template parameter appears in function parameter.
|
||||
virtual void Push(const T& value) = 0;
|
||||
virtual void Pop() = 0;
|
||||
virtual int GetSize() const = 0;
|
||||
// Template parameter appears in function return type.
|
||||
virtual const T& GetTop() const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MockStack : public StackInterface<T> {
|
||||
public:
|
||||
MockStack() {}
|
||||
|
||||
MOCK_METHOD(void, Push, (const T& elem), ());
|
||||
MOCK_METHOD(void, Pop, (), (final));
|
||||
MOCK_METHOD(int, GetSize, (), (const, override));
|
||||
MOCK_METHOD(const T&, GetTop, (), (const));
|
||||
|
||||
// Tests that the function return type can contain unprotected comma.
|
||||
MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (), ());
|
||||
MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (int), (const));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
|
||||
};
|
||||
|
||||
// Tests that template mock works.
|
||||
TEST(MockMethodTemplateMockTest, Works) {
|
||||
MockStack<int> mock;
|
||||
|
||||
EXPECT_CALL(mock, GetSize())
|
||||
.WillOnce(Return(0))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(mock, Push(_));
|
||||
int n = 5;
|
||||
EXPECT_CALL(mock, GetTop())
|
||||
.WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop())
|
||||
.Times(AnyNumber());
|
||||
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
mock.Push(5);
|
||||
EXPECT_EQ(1, mock.GetSize());
|
||||
EXPECT_EQ(5, mock.GetTop());
|
||||
mock.Pop();
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
}
|
||||
|
||||
TEST(MockMethodTemplateMockTest, MethodWithCommaInReturnTypeWorks) {
|
||||
MockStack<int> mock;
|
||||
|
||||
const std::map<int, int> a_map;
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma())
|
||||
.WillOnce(Return(a_map));
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma(1))
|
||||
.WillOnce(Return(a_map));
|
||||
|
||||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
|
||||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
|
||||
}
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
// Tests mocking template interfaces with calltype.
|
||||
|
||||
template <typename T>
|
||||
class StackInterfaceWithCallType {
|
||||
public:
|
||||
virtual ~StackInterfaceWithCallType() {}
|
||||
|
||||
// Template parameter appears in function parameter.
|
||||
STDMETHOD_(void, Push)(const T& value) = 0;
|
||||
STDMETHOD_(void, Pop)() = 0;
|
||||
STDMETHOD_(int, GetSize)() const = 0;
|
||||
// Template parameter appears in function return type.
|
||||
STDMETHOD_(const T&, GetTop)() const = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MockStackWithCallType : public StackInterfaceWithCallType<T> {
|
||||
public:
|
||||
MockStackWithCallType() {}
|
||||
|
||||
MOCK_METHOD(void, Push, (const T& elem),
|
||||
(Calltype(STDMETHODCALLTYPE), override));
|
||||
MOCK_METHOD(void, Pop, (), (Calltype(STDMETHODCALLTYPE), override));
|
||||
MOCK_METHOD(int, GetSize, (), (Calltype(STDMETHODCALLTYPE), override, const));
|
||||
MOCK_METHOD(const T&, GetTop, (),
|
||||
(Calltype(STDMETHODCALLTYPE), override, const));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
|
||||
};
|
||||
|
||||
// Tests that template mock with calltype works.
|
||||
TEST(MockMethodTemplateMockTestWithCallType, Works) {
|
||||
MockStackWithCallType<int> mock;
|
||||
|
||||
EXPECT_CALL(mock, GetSize())
|
||||
.WillOnce(Return(0))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(mock, Push(_));
|
||||
int n = 5;
|
||||
EXPECT_CALL(mock, GetTop())
|
||||
.WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop())
|
||||
.Times(AnyNumber());
|
||||
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
mock.Push(5);
|
||||
EXPECT_EQ(1, mock.GetSize());
|
||||
EXPECT_EQ(5, mock.GetTop());
|
||||
mock.Pop();
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
}
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#define MY_MOCK_METHODS1_ \
|
||||
MOCK_METHOD(void, Overloaded, ()); \
|
||||
MOCK_METHOD(int, Overloaded, (int), (const)); \
|
||||
MOCK_METHOD(bool, Overloaded, (bool f, int n))
|
||||
|
||||
class MockOverloadedOnArgNumber {
|
||||
public:
|
||||
MockOverloadedOnArgNumber() {}
|
||||
|
||||
MY_MOCK_METHODS1_;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
|
||||
};
|
||||
|
||||
TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
|
||||
MockOverloadedOnArgNumber mock;
|
||||
EXPECT_CALL(mock, Overloaded());
|
||||
EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
|
||||
EXPECT_CALL(mock, Overloaded(true, 1)).WillOnce(Return(true));
|
||||
|
||||
mock.Overloaded();
|
||||
EXPECT_EQ(2, mock.Overloaded(1));
|
||||
EXPECT_TRUE(mock.Overloaded(true, 1));
|
||||
}
|
||||
|
||||
#define MY_MOCK_METHODS2_ \
|
||||
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
|
||||
MOCK_METHOD1(Overloaded, int(int n));
|
||||
|
||||
class MockOverloadedOnConstness {
|
||||
public:
|
||||
MockOverloadedOnConstness() {}
|
||||
|
||||
MY_MOCK_METHODS2_;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness);
|
||||
};
|
||||
|
||||
TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
|
||||
MockOverloadedOnConstness mock;
|
||||
const MockOverloadedOnConstness* const_mock = &mock;
|
||||
EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
|
||||
EXPECT_CALL(*const_mock, Overloaded(1)).WillOnce(Return(3));
|
||||
|
||||
EXPECT_EQ(2, mock.Overloaded(1));
|
||||
EXPECT_EQ(3, const_mock->Overloaded(1));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForVoidNullary) {
|
||||
MockFunction<void()> foo;
|
||||
EXPECT_CALL(foo, Call());
|
||||
foo.Call();
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForNonVoidNullary) {
|
||||
MockFunction<int()> foo;
|
||||
EXPECT_CALL(foo, Call())
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
EXPECT_EQ(1, foo.Call());
|
||||
EXPECT_EQ(2, foo.Call());
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForVoidUnary) {
|
||||
MockFunction<void(int)> foo;
|
||||
EXPECT_CALL(foo, Call(1));
|
||||
foo.Call(1);
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForNonVoidBinary) {
|
||||
MockFunction<int(bool, int)> foo;
|
||||
EXPECT_CALL(foo, Call(false, 42))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
EXPECT_CALL(foo, Call(true, Ge(100)))
|
||||
.WillOnce(Return(3));
|
||||
EXPECT_EQ(1, foo.Call(false, 42));
|
||||
EXPECT_EQ(2, foo.Call(false, 42));
|
||||
EXPECT_EQ(3, foo.Call(true, 120));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
|
||||
MockFunction<int(bool a0, char a1, int a2, int a3, int a4,
|
||||
int a5, int a6, char a7, int a8, bool a9)> foo;
|
||||
EXPECT_CALL(foo, Call(_, 'a', _, _, _, _, _, _, _, _))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
EXPECT_EQ(1, foo.Call(false, 'a', 0, 0, 0, 0, 0, 'b', 0, true));
|
||||
EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunction) {
|
||||
MockFunction<int(int)> foo;
|
||||
auto call = [](const std::function<int(int)> &f, int i) {
|
||||
return f(i);
|
||||
};
|
||||
EXPECT_CALL(foo, Call(1)).WillOnce(Return(-1));
|
||||
EXPECT_CALL(foo, Call(2)).WillOnce(Return(-2));
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), 1));
|
||||
EXPECT_EQ(-2, call(foo.AsStdFunction(), 2));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunctionReturnsReference) {
|
||||
MockFunction<int&()> foo;
|
||||
int value = 1;
|
||||
EXPECT_CALL(foo, Call()).WillOnce(ReturnRef(value));
|
||||
int& ref = foo.AsStdFunction()();
|
||||
EXPECT_EQ(1, ref);
|
||||
value = 2;
|
||||
EXPECT_EQ(2, ref);
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) {
|
||||
MockFunction<int(int &)> foo;
|
||||
auto call = [](const std::function<int(int& )> &f, int &i) {
|
||||
return f(i);
|
||||
};
|
||||
int i = 42;
|
||||
EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1));
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
|
||||
}
|
||||
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD(void, func, ());
|
||||
};
|
||||
struct MockMethodSizes1 {
|
||||
MOCK_METHOD(void, func, (int));
|
||||
};
|
||||
struct MockMethodSizes2 {
|
||||
MOCK_METHOD(void, func, (int, int));
|
||||
};
|
||||
struct MockMethodSizes3 {
|
||||
MOCK_METHOD(void, func, (int, int, int));
|
||||
};
|
||||
struct MockMethodSizes4 {
|
||||
MOCK_METHOD(void, func, (int, int, int, int));
|
||||
};
|
||||
|
||||
TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) {
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4));
|
||||
}
|
||||
|
||||
} // namespace gmock_function_mocker_test
|
||||
} // namespace testing
|
@ -35,6 +35,7 @@
|
||||
#include "gmock/gmock-generated-actions.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "gmock/gmock.h"
|
||||
@ -45,10 +46,6 @@ namespace gmock_generated_actions_test {
|
||||
|
||||
using ::std::plus;
|
||||
using ::std::string;
|
||||
using testing::get;
|
||||
using testing::make_tuple;
|
||||
using testing::tuple;
|
||||
using testing::tuple_element;
|
||||
using testing::_;
|
||||
using testing::Action;
|
||||
using testing::ActionInterface;
|
||||
@ -60,7 +57,6 @@ using testing::ReturnNew;
|
||||
using testing::SetArgPointee;
|
||||
using testing::StaticAssertTypeEq;
|
||||
using testing::Unused;
|
||||
using testing::WithArgs;
|
||||
|
||||
// For suppressing compiler warnings on conversion possibly losing precision.
|
||||
inline short Short(short n) { return n; } // NOLINT
|
||||
@ -69,43 +65,19 @@ inline char Char(char ch) { return ch; }
|
||||
// Sample functions and functors for testing various actions.
|
||||
int Nullary() { return 1; }
|
||||
|
||||
class NullaryFunctor {
|
||||
public:
|
||||
int operator()() { return 2; }
|
||||
};
|
||||
|
||||
bool g_done = false;
|
||||
|
||||
bool Unary(int x) { return x < 0; }
|
||||
|
||||
const char* Plus1(const char* s) { return s + 1; }
|
||||
|
||||
bool ByConstRef(const std::string& s) { return s == "Hi"; }
|
||||
|
||||
const double g_double = 0;
|
||||
bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; }
|
||||
|
||||
std::string ByNonConstRef(std::string& s) { return s += "+"; } // NOLINT
|
||||
|
||||
struct UnaryFunctor {
|
||||
int operator()(bool x) { return x ? 1 : -1; }
|
||||
};
|
||||
|
||||
const char* Binary(const char* input, short n) { return input + n; } // NOLINT
|
||||
|
||||
void VoidBinary(int, char) { g_done = true; }
|
||||
|
||||
int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT
|
||||
|
||||
void VoidTernary(int, char, bool) { g_done = true; }
|
||||
|
||||
int SumOf4(int a, int b, int c, int d) { return a + b + c + d; }
|
||||
|
||||
std::string Concat4(const char* s1, const char* s2, const char* s3,
|
||||
const char* s4) {
|
||||
return std::string(s1) + s2 + s3 + s4;
|
||||
}
|
||||
|
||||
int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; }
|
||||
|
||||
struct SumOf5Functor {
|
||||
@ -168,41 +140,41 @@ inline const char* CharPtr(const char* s) { return s; }
|
||||
// Tests using InvokeArgument with a nullary function.
|
||||
TEST(InvokeArgumentTest, Function0) {
|
||||
Action<int(int, int(*)())> a = InvokeArgument<1>(); // NOLINT
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(2, &Nullary)));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(2, &Nullary)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a unary function.
|
||||
TEST(InvokeArgumentTest, Functor1) {
|
||||
Action<int(UnaryFunctor)> a = InvokeArgument<0>(true); // NOLINT
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(UnaryFunctor())));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryFunctor())));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 5-ary function.
|
||||
TEST(InvokeArgumentTest, Function5) {
|
||||
Action<int(int(*)(int, int, int, int, int))> a = // NOLINT
|
||||
InvokeArgument<0>(10000, 2000, 300, 40, 5);
|
||||
EXPECT_EQ(12345, a.Perform(make_tuple(&SumOf5)));
|
||||
EXPECT_EQ(12345, a.Perform(std::make_tuple(&SumOf5)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 5-ary functor.
|
||||
TEST(InvokeArgumentTest, Functor5) {
|
||||
Action<int(SumOf5Functor)> a = // NOLINT
|
||||
InvokeArgument<0>(10000, 2000, 300, 40, 5);
|
||||
EXPECT_EQ(12345, a.Perform(make_tuple(SumOf5Functor())));
|
||||
EXPECT_EQ(12345, a.Perform(std::make_tuple(SumOf5Functor())));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 6-ary function.
|
||||
TEST(InvokeArgumentTest, Function6) {
|
||||
Action<int(int(*)(int, int, int, int, int, int))> a = // NOLINT
|
||||
InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
|
||||
EXPECT_EQ(123456, a.Perform(make_tuple(&SumOf6)));
|
||||
EXPECT_EQ(123456, a.Perform(std::make_tuple(&SumOf6)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 6-ary functor.
|
||||
TEST(InvokeArgumentTest, Functor6) {
|
||||
Action<int(SumOf6Functor)> a = // NOLINT
|
||||
InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6);
|
||||
EXPECT_EQ(123456, a.Perform(make_tuple(SumOf6Functor())));
|
||||
EXPECT_EQ(123456, a.Perform(std::make_tuple(SumOf6Functor())));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 7-ary function.
|
||||
@ -211,7 +183,7 @@ TEST(InvokeArgumentTest, Function7) {
|
||||
const char*, const char*, const char*,
|
||||
const char*))>
|
||||
a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7");
|
||||
EXPECT_EQ("1234567", a.Perform(make_tuple(&Concat7)));
|
||||
EXPECT_EQ("1234567", a.Perform(std::make_tuple(&Concat7)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 8-ary function.
|
||||
@ -220,7 +192,7 @@ TEST(InvokeArgumentTest, Function8) {
|
||||
const char*, const char*, const char*,
|
||||
const char*, const char*))>
|
||||
a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8");
|
||||
EXPECT_EQ("12345678", a.Perform(make_tuple(&Concat8)));
|
||||
EXPECT_EQ("12345678", a.Perform(std::make_tuple(&Concat8)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 9-ary function.
|
||||
@ -229,7 +201,7 @@ TEST(InvokeArgumentTest, Function9) {
|
||||
const char*, const char*, const char*,
|
||||
const char*, const char*, const char*))>
|
||||
a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9");
|
||||
EXPECT_EQ("123456789", a.Perform(make_tuple(&Concat9)));
|
||||
EXPECT_EQ("123456789", a.Perform(std::make_tuple(&Concat9)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a 10-ary function.
|
||||
@ -238,14 +210,14 @@ TEST(InvokeArgumentTest, Function10) {
|
||||
const char*, const char*, const char*, const char*, const char*,
|
||||
const char*, const char*, const char*, const char*, const char*))>
|
||||
a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
|
||||
EXPECT_EQ("1234567890", a.Perform(make_tuple(&Concat10)));
|
||||
EXPECT_EQ("1234567890", a.Perform(std::make_tuple(&Concat10)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a function that takes a pointer argument.
|
||||
TEST(InvokeArgumentTest, ByPointerFunction) {
|
||||
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
|
||||
InvokeArgument<0>(static_cast<const char*>("Hi"), Short(1));
|
||||
EXPECT_STREQ("i", a.Perform(make_tuple(&Binary)));
|
||||
EXPECT_STREQ("i", a.Perform(std::make_tuple(&Binary)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a function that takes a const char*
|
||||
@ -253,7 +225,7 @@ TEST(InvokeArgumentTest, ByPointerFunction) {
|
||||
TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
|
||||
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
|
||||
InvokeArgument<0>("Hi", Short(1));
|
||||
EXPECT_STREQ("i", a.Perform(make_tuple(&Binary)));
|
||||
EXPECT_STREQ("i", a.Perform(std::make_tuple(&Binary)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with a function that takes a const reference.
|
||||
@ -263,7 +235,7 @@ TEST(InvokeArgumentTest, ByConstReferenceFunction) {
|
||||
// When action 'a' is constructed, it makes a copy of the temporary
|
||||
// string object passed to it, so it's OK to use 'a' later, when the
|
||||
// temporary object has already died.
|
||||
EXPECT_TRUE(a.Perform(make_tuple(&ByConstRef)));
|
||||
EXPECT_TRUE(a.Perform(std::make_tuple(&ByConstRef)));
|
||||
}
|
||||
|
||||
// Tests using InvokeArgument with ByRef() and a function that takes a
|
||||
@ -272,148 +244,11 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
|
||||
Action<bool(bool(*)(const double& x))> a = // NOLINT
|
||||
InvokeArgument<0>(ByRef(g_double));
|
||||
// The above line calls ByRef() on a const value.
|
||||
EXPECT_TRUE(a.Perform(make_tuple(&ReferencesGlobalDouble)));
|
||||
EXPECT_TRUE(a.Perform(std::make_tuple(&ReferencesGlobalDouble)));
|
||||
|
||||
double x = 0;
|
||||
a = InvokeArgument<0>(ByRef(x)); // This calls ByRef() on a non-const.
|
||||
EXPECT_FALSE(a.Perform(make_tuple(&ReferencesGlobalDouble)));
|
||||
}
|
||||
|
||||
// Tests using WithArgs and with an action that takes 1 argument.
|
||||
TEST(WithArgsTest, OneArg) {
|
||||
Action<bool(double x, int n)> a = WithArgs<1>(Invoke(Unary)); // NOLINT
|
||||
EXPECT_TRUE(a.Perform(make_tuple(1.5, -1)));
|
||||
EXPECT_FALSE(a.Perform(make_tuple(1.5, 1)));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 2 arguments.
|
||||
TEST(WithArgsTest, TwoArgs) {
|
||||
Action<const char*(const char* s, double x, short n)> a =
|
||||
WithArgs<0, 2>(Invoke(Binary));
|
||||
const char s[] = "Hello";
|
||||
EXPECT_EQ(s + 2, a.Perform(make_tuple(CharPtr(s), 0.5, Short(2))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 3 arguments.
|
||||
TEST(WithArgsTest, ThreeArgs) {
|
||||
Action<int(int, double, char, short)> a = // NOLINT
|
||||
WithArgs<0, 2, 3>(Invoke(Ternary));
|
||||
EXPECT_EQ(123, a.Perform(make_tuple(100, 6.5, Char(20), Short(3))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 4 arguments.
|
||||
TEST(WithArgsTest, FourArgs) {
|
||||
Action<std::string(const char*, const char*, double, const char*,
|
||||
const char*)>
|
||||
a = WithArgs<4, 3, 1, 0>(Invoke(Concat4));
|
||||
EXPECT_EQ("4310", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), 2.5,
|
||||
CharPtr("3"), CharPtr("4"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 5 arguments.
|
||||
TEST(WithArgsTest, FiveArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*,
|
||||
const char*)>
|
||||
a = WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5));
|
||||
EXPECT_EQ("43210",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"), CharPtr("4"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 6 arguments.
|
||||
TEST(WithArgsTest, SixArgs) {
|
||||
Action<std::string(const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 2, 1, 0>(Invoke(Concat6));
|
||||
EXPECT_EQ("012210",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 7 arguments.
|
||||
TEST(WithArgsTest, SevenArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 3, 2, 1, 0>(Invoke(Concat7));
|
||||
EXPECT_EQ("0123210",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 8 arguments.
|
||||
TEST(WithArgsTest, EightArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 3, 0, 1, 2, 3>(Invoke(Concat8));
|
||||
EXPECT_EQ("01230123",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 9 arguments.
|
||||
TEST(WithArgsTest, NineArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 3, 1, 2, 3, 2, 3>(Invoke(Concat9));
|
||||
EXPECT_EQ("012312323",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that takes 10 arguments.
|
||||
TEST(WithArgsTest, TenArgs) {
|
||||
Action<std::string(const char*, const char*, const char*, const char*)> a =
|
||||
WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(Invoke(Concat10));
|
||||
EXPECT_EQ("0123210123",
|
||||
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
|
||||
CharPtr("3"))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that is not Invoke().
|
||||
class SubstractAction : public ActionInterface<int(int, int)> { // NOLINT
|
||||
public:
|
||||
virtual int Perform(const tuple<int, int>& args) {
|
||||
return get<0>(args) - get<1>(args);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(WithArgsTest, NonInvokeAction) {
|
||||
Action<int(const std::string&, int, int)> a = // NOLINT
|
||||
WithArgs<2, 1>(MakeAction(new SubstractAction));
|
||||
tuple<std::string, int, int> dummy = make_tuple(std::string("hi"), 2, 10);
|
||||
EXPECT_EQ(8, a.Perform(dummy));
|
||||
}
|
||||
|
||||
// Tests using WithArgs to pass all original arguments in the original order.
|
||||
TEST(WithArgsTest, Identity) {
|
||||
Action<int(int x, char y, short z)> a = // NOLINT
|
||||
WithArgs<0, 1, 2>(Invoke(Ternary));
|
||||
EXPECT_EQ(123, a.Perform(make_tuple(100, Char(20), Short(3))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with repeated arguments.
|
||||
TEST(WithArgsTest, RepeatedArguments) {
|
||||
Action<int(bool, int m, int n)> a = // NOLINT
|
||||
WithArgs<1, 1, 1, 1>(Invoke(SumOf4));
|
||||
EXPECT_EQ(4, a.Perform(make_tuple(false, 1, 10)));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with reversed argument order.
|
||||
TEST(WithArgsTest, ReversedArgumentOrder) {
|
||||
Action<const char*(short n, const char* input)> a = // NOLINT
|
||||
WithArgs<1, 0>(Invoke(Binary));
|
||||
const char s[] = "Hello";
|
||||
EXPECT_EQ(s + 2, a.Perform(make_tuple(Short(2), CharPtr(s))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with compatible, but not identical, argument types.
|
||||
TEST(WithArgsTest, ArgsOfCompatibleTypes) {
|
||||
Action<long(short x, char y, double z, char c)> a = // NOLINT
|
||||
WithArgs<0, 1, 3>(Invoke(Ternary));
|
||||
EXPECT_EQ(123, a.Perform(make_tuple(Short(100), Char(20), 5.6, Char(3))));
|
||||
}
|
||||
|
||||
// Tests using WithArgs with an action that returns void.
|
||||
TEST(WithArgsTest, VoidAction) {
|
||||
Action<void(double x, char c, int n)> a = WithArgs<2, 1>(Invoke(VoidBinary));
|
||||
g_done = false;
|
||||
a.Perform(make_tuple(1.5, 'a', 3));
|
||||
EXPECT_TRUE(g_done);
|
||||
EXPECT_FALSE(a.Perform(std::make_tuple(&ReferencesGlobalDouble)));
|
||||
}
|
||||
|
||||
// Tests DoAll(a1, a2).
|
||||
@ -421,7 +256,7 @@ TEST(DoAllTest, TwoActions) {
|
||||
int n = 0;
|
||||
Action<int(int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT
|
||||
Return(2));
|
||||
EXPECT_EQ(2, a.Perform(make_tuple(&n)));
|
||||
EXPECT_EQ(2, a.Perform(std::make_tuple(&n)));
|
||||
EXPECT_EQ(1, n);
|
||||
}
|
||||
|
||||
@ -431,7 +266,7 @@ TEST(DoAllTest, ThreeActions) {
|
||||
Action<int(int*, int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT
|
||||
SetArgPointee<1>(2),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, a.Perform(make_tuple(&m, &n)));
|
||||
EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
}
|
||||
@ -445,7 +280,7 @@ TEST(DoAllTest, FourActions) {
|
||||
SetArgPointee<1>(2),
|
||||
SetArgPointee<2>('a'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, a.Perform(make_tuple(&m, &n, &ch)));
|
||||
EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n, &ch)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', ch);
|
||||
@ -461,7 +296,7 @@ TEST(DoAllTest, FiveActions) {
|
||||
SetArgPointee<2>('a'),
|
||||
SetArgPointee<3>('b'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b)));
|
||||
EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -479,7 +314,7 @@ TEST(DoAllTest, SixActions) {
|
||||
SetArgPointee<3>('b'),
|
||||
SetArgPointee<4>('c'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c)));
|
||||
EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -499,7 +334,7 @@ TEST(DoAllTest, SevenActions) {
|
||||
SetArgPointee<4>('c'),
|
||||
SetArgPointee<5>('d'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d)));
|
||||
EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -522,7 +357,7 @@ TEST(DoAllTest, EightActions) {
|
||||
SetArgPointee<5>('d'),
|
||||
SetArgPointee<6>('e'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e)));
|
||||
EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -547,7 +382,7 @@ TEST(DoAllTest, NineActions) {
|
||||
SetArgPointee<6>('e'),
|
||||
SetArgPointee<7>('f'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e, &f)));
|
||||
EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -575,7 +410,8 @@ TEST(DoAllTest, TenActions) {
|
||||
SetArgPointee<7>('f'),
|
||||
SetArgPointee<8>('g'),
|
||||
Return(3));
|
||||
EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g)));
|
||||
EXPECT_EQ(
|
||||
3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g)));
|
||||
EXPECT_EQ(1, m);
|
||||
EXPECT_EQ(2, n);
|
||||
EXPECT_EQ('a', a);
|
||||
@ -592,11 +428,12 @@ TEST(DoAllTest, TenActions) {
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
// is expanded and macro expansion cannot contain #pragma. Therefore
|
||||
// we suppress them here.
|
||||
// Also suppress C4503 decorated name length exceeded, name was truncated
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
# pragma warning(disable:4503)
|
||||
#endif
|
||||
|
||||
// Tests the ACTION*() macro family.
|
||||
|
||||
// Tests that ACTION() can define an action that doesn't reference the
|
||||
@ -605,10 +442,10 @@ ACTION(Return5) { return 5; }
|
||||
|
||||
TEST(ActionMacroTest, WorksWhenNotReferencingArguments) {
|
||||
Action<double()> a1 = Return5();
|
||||
EXPECT_DOUBLE_EQ(5, a1.Perform(make_tuple()));
|
||||
EXPECT_DOUBLE_EQ(5, a1.Perform(std::make_tuple()));
|
||||
|
||||
Action<int(double, bool)> a2 = Return5();
|
||||
EXPECT_EQ(5, a2.Perform(make_tuple(1, true)));
|
||||
EXPECT_EQ(5, a2.Perform(std::make_tuple(1, true)));
|
||||
}
|
||||
|
||||
// Tests that ACTION() can define an action that returns void.
|
||||
@ -617,7 +454,7 @@ ACTION(IncrementArg1) { (*arg1)++; }
|
||||
TEST(ActionMacroTest, WorksWhenReturningVoid) {
|
||||
Action<void(int, int*)> a1 = IncrementArg1();
|
||||
int n = 0;
|
||||
a1.Perform(make_tuple(5, &n));
|
||||
a1.Perform(std::make_tuple(5, &n));
|
||||
EXPECT_EQ(1, n);
|
||||
}
|
||||
|
||||
@ -632,22 +469,22 @@ ACTION(IncrementArg2) {
|
||||
TEST(ActionMacroTest, CanReferenceArgumentType) {
|
||||
Action<void(int, bool, int*)> a1 = IncrementArg2();
|
||||
int n = 0;
|
||||
a1.Perform(make_tuple(5, false, &n));
|
||||
a1.Perform(std::make_tuple(5, false, &n));
|
||||
EXPECT_EQ(1, n);
|
||||
}
|
||||
|
||||
// Tests that the body of ACTION() can reference the argument tuple
|
||||
// via args_type and args.
|
||||
ACTION(Sum2) {
|
||||
StaticAssertTypeEq<tuple<int, char, int*>, args_type>();
|
||||
StaticAssertTypeEq<std::tuple<int, char, int*>, args_type>();
|
||||
args_type args_copy = args;
|
||||
return get<0>(args_copy) + get<1>(args_copy);
|
||||
return std::get<0>(args_copy) + std::get<1>(args_copy);
|
||||
}
|
||||
|
||||
TEST(ActionMacroTest, CanReferenceArgumentTuple) {
|
||||
Action<int(int, char, int*)> a1 = Sum2();
|
||||
int dummy = 0;
|
||||
EXPECT_EQ(11, a1.Perform(make_tuple(5, Char(6), &dummy)));
|
||||
EXPECT_EQ(11, a1.Perform(std::make_tuple(5, Char(6), &dummy)));
|
||||
}
|
||||
|
||||
// Tests that the body of ACTION() can reference the mock function
|
||||
@ -662,8 +499,8 @@ ACTION(InvokeDummy) {
|
||||
|
||||
TEST(ActionMacroTest, CanReferenceMockFunctionType) {
|
||||
Action<int(bool)> a1 = InvokeDummy();
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(true)));
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(false)));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple(true)));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple(false)));
|
||||
}
|
||||
|
||||
// Tests that the body of ACTION() can reference the mock function's
|
||||
@ -676,8 +513,8 @@ ACTION(InvokeDummy2) {
|
||||
|
||||
TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) {
|
||||
Action<int(bool)> a1 = InvokeDummy2();
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(true)));
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(false)));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple(true)));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple(false)));
|
||||
}
|
||||
|
||||
// Tests that ACTION() works for arguments passed by const reference.
|
||||
@ -689,7 +526,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) {
|
||||
TEST(ActionMacroTest, WorksForConstReferenceArg) {
|
||||
Action<const bool*(int, const bool&)> a = ReturnAddrOfConstBoolReferenceArg();
|
||||
const bool b = false;
|
||||
EXPECT_EQ(&b, a.Perform(tuple<int, const bool&>(0, b)));
|
||||
EXPECT_EQ(&b, a.Perform(std::tuple<int, const bool&>(0, b)));
|
||||
}
|
||||
|
||||
// Tests that ACTION() works for arguments passed by non-const reference.
|
||||
@ -701,7 +538,7 @@ ACTION(ReturnAddrOfIntReferenceArg) {
|
||||
TEST(ActionMacroTest, WorksForNonConstReferenceArg) {
|
||||
Action<int*(int&, bool, int)> a = ReturnAddrOfIntReferenceArg();
|
||||
int n = 0;
|
||||
EXPECT_EQ(&n, a.Perform(tuple<int&, bool, int>(n, true, 1)));
|
||||
EXPECT_EQ(&n, a.Perform(std::tuple<int&, bool, int>(n, true, 1)));
|
||||
}
|
||||
|
||||
// Tests that ACTION() can be used in a namespace.
|
||||
@ -711,7 +548,7 @@ ACTION(Sum) { return arg0 + arg1; }
|
||||
|
||||
TEST(ActionMacroTest, WorksInNamespace) {
|
||||
Action<int(int, int)> a1 = action_test::Sum();
|
||||
EXPECT_EQ(3, a1.Perform(make_tuple(1, 2)));
|
||||
EXPECT_EQ(3, a1.Perform(std::make_tuple(1, 2)));
|
||||
}
|
||||
|
||||
// Tests that the same ACTION definition works for mock functions with
|
||||
@ -720,11 +557,11 @@ ACTION(PlusTwo) { return arg0 + 2; }
|
||||
|
||||
TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) {
|
||||
Action<int(int)> a1 = PlusTwo();
|
||||
EXPECT_EQ(4, a1.Perform(make_tuple(2)));
|
||||
EXPECT_EQ(4, a1.Perform(std::make_tuple(2)));
|
||||
|
||||
Action<double(float, void*)> a2 = PlusTwo();
|
||||
int dummy;
|
||||
EXPECT_DOUBLE_EQ(6, a2.Perform(make_tuple(4.0f, &dummy)));
|
||||
EXPECT_DOUBLE_EQ(6, a2.Perform(std::make_tuple(4.0f, &dummy)));
|
||||
}
|
||||
|
||||
// Tests that ACTION_P can define a parameterized action.
|
||||
@ -732,7 +569,7 @@ ACTION_P(Plus, n) { return arg0 + n; }
|
||||
|
||||
TEST(ActionPMacroTest, DefinesParameterizedAction) {
|
||||
Action<int(int m, bool t)> a1 = Plus(9);
|
||||
EXPECT_EQ(10, a1.Perform(make_tuple(1, true)));
|
||||
EXPECT_EQ(10, a1.Perform(std::make_tuple(1, true)));
|
||||
}
|
||||
|
||||
// Tests that the body of ACTION_P can reference the argument types
|
||||
@ -745,7 +582,7 @@ ACTION_P(TypedPlus, n) {
|
||||
|
||||
TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
|
||||
Action<int(char m, bool t)> a1 = TypedPlus(9);
|
||||
EXPECT_EQ(10, a1.Perform(make_tuple(Char(1), true)));
|
||||
EXPECT_EQ(10, a1.Perform(std::make_tuple(Char(1), true)));
|
||||
}
|
||||
|
||||
// Tests that a parameterized action can be used in any mock function
|
||||
@ -753,7 +590,7 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
|
||||
TEST(ActionPMacroTest, WorksInCompatibleMockFunction) {
|
||||
Action<std::string(const std::string& s)> a1 = Plus("tail");
|
||||
const std::string re = "re";
|
||||
tuple<const std::string> dummy = make_tuple(re);
|
||||
std::tuple<const std::string> dummy = std::make_tuple(re);
|
||||
EXPECT_EQ("retail", a1.Perform(dummy));
|
||||
}
|
||||
|
||||
@ -774,16 +611,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) {
|
||||
typedef Action<const char*(bool, const char*)> MyAction;
|
||||
|
||||
const MyAction a1 = OverloadedAction();
|
||||
EXPECT_STREQ("hello", a1.Perform(make_tuple(false, CharPtr("world"))));
|
||||
EXPECT_STREQ("world", a1.Perform(make_tuple(true, CharPtr("world"))));
|
||||
EXPECT_STREQ("hello", a1.Perform(std::make_tuple(false, CharPtr("world"))));
|
||||
EXPECT_STREQ("world", a1.Perform(std::make_tuple(true, CharPtr("world"))));
|
||||
|
||||
const MyAction a2 = OverloadedAction("hi");
|
||||
EXPECT_STREQ("hi", a2.Perform(make_tuple(false, CharPtr("world"))));
|
||||
EXPECT_STREQ("world", a2.Perform(make_tuple(true, CharPtr("world"))));
|
||||
EXPECT_STREQ("hi", a2.Perform(std::make_tuple(false, CharPtr("world"))));
|
||||
EXPECT_STREQ("world", a2.Perform(std::make_tuple(true, CharPtr("world"))));
|
||||
|
||||
const MyAction a3 = OverloadedAction("hi", "you");
|
||||
EXPECT_STREQ("hi", a3.Perform(make_tuple(true, CharPtr("world"))));
|
||||
EXPECT_STREQ("you", a3.Perform(make_tuple(false, CharPtr("world"))));
|
||||
EXPECT_STREQ("hi", a3.Perform(std::make_tuple(true, CharPtr("world"))));
|
||||
EXPECT_STREQ("you", a3.Perform(std::make_tuple(false, CharPtr("world"))));
|
||||
}
|
||||
|
||||
// Tests ACTION_Pn where n >= 3.
|
||||
@ -792,11 +629,11 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; }
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor3Parameters) {
|
||||
Action<double(int m, bool t)> a1 = Plus(100, 20, 3.4);
|
||||
EXPECT_DOUBLE_EQ(3123.4, a1.Perform(make_tuple(3000, true)));
|
||||
EXPECT_DOUBLE_EQ(3123.4, a1.Perform(std::make_tuple(3000, true)));
|
||||
|
||||
Action<std::string(const std::string& s)> a2 = Plus("tail", "-", ">");
|
||||
const std::string re = "re";
|
||||
tuple<const std::string> dummy = make_tuple(re);
|
||||
std::tuple<const std::string> dummy = std::make_tuple(re);
|
||||
EXPECT_EQ("retail->", a2.Perform(dummy));
|
||||
}
|
||||
|
||||
@ -804,14 +641,14 @@ ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; }
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor4Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4, a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P5(Plus, p0, p1, p2, p3, p4) { return arg0 + p0 + p1 + p2 + p3 + p4; }
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor5Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5, a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) {
|
||||
@ -820,7 +657,7 @@ ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) {
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor6Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6, a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) {
|
||||
@ -829,7 +666,7 @@ ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) {
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor7Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) {
|
||||
@ -838,7 +675,8 @@ ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) {
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor8Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8,
|
||||
a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) {
|
||||
@ -847,7 +685,8 @@ ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) {
|
||||
|
||||
TEST(ActionPnMacroTest, WorksFor9Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, a1.Perform(make_tuple(10)));
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9,
|
||||
a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
|
||||
@ -859,7 +698,7 @@ ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
|
||||
TEST(ActionPnMacroTest, WorksFor10Parameters) {
|
||||
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10,
|
||||
a1.Perform(make_tuple(10)));
|
||||
a1.Perform(std::make_tuple(10)));
|
||||
}
|
||||
|
||||
// Tests that the action body can promote the parameter types.
|
||||
@ -876,8 +715,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) {
|
||||
PadArgument(std::string("foo"), 'r');
|
||||
Action<std::string(const char*)> promo =
|
||||
PadArgument("foo", static_cast<int>('r'));
|
||||
EXPECT_EQ("foobar", no_promo.Perform(make_tuple(CharPtr("ba"))));
|
||||
EXPECT_EQ("foobar", promo.Perform(make_tuple(CharPtr("ba"))));
|
||||
EXPECT_EQ("foobar", no_promo.Perform(std::make_tuple(CharPtr("ba"))));
|
||||
EXPECT_EQ("foobar", promo.Perform(std::make_tuple(CharPtr("ba"))));
|
||||
}
|
||||
|
||||
// Tests that we can partially restrict parameter types using a
|
||||
@ -926,10 +765,10 @@ Concat(T1 a, int b, T2 c) {
|
||||
|
||||
TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) {
|
||||
Action<const std::string()> a1 = Concat("Hello", "1", 2);
|
||||
EXPECT_EQ("Hello12", a1.Perform(make_tuple()));
|
||||
EXPECT_EQ("Hello12", a1.Perform(std::make_tuple()));
|
||||
|
||||
a1 = Concat(1, 2, 3);
|
||||
EXPECT_EQ("123", a1.Perform(make_tuple()));
|
||||
EXPECT_EQ("123", a1.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Verifies the type of an ACTION*.
|
||||
@ -987,7 +826,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
||||
|
||||
TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) {
|
||||
int x = 1, y = 2, z = 3;
|
||||
const tuple<> empty = make_tuple();
|
||||
const std::tuple<> empty = std::make_tuple();
|
||||
|
||||
Action<int()> a = Plus1<int&>(x);
|
||||
EXPECT_EQ(1, a.Perform(empty));
|
||||
@ -1014,7 +853,7 @@ class NullaryConstructorClass {
|
||||
// Tests using ReturnNew() with a nullary constructor.
|
||||
TEST(ReturnNewTest, NoArgs) {
|
||||
Action<NullaryConstructorClass*()> a = ReturnNew<NullaryConstructorClass>();
|
||||
NullaryConstructorClass* c = a.Perform(make_tuple());
|
||||
NullaryConstructorClass* c = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(123, c->value_);
|
||||
delete c;
|
||||
}
|
||||
@ -1028,7 +867,7 @@ class UnaryConstructorClass {
|
||||
// Tests using ReturnNew() with a unary constructor.
|
||||
TEST(ReturnNewTest, Unary) {
|
||||
Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000);
|
||||
UnaryConstructorClass* c = a.Perform(make_tuple());
|
||||
UnaryConstructorClass* c = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(4000, c->value_);
|
||||
delete c;
|
||||
}
|
||||
@ -1036,7 +875,7 @@ TEST(ReturnNewTest, Unary) {
|
||||
TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
|
||||
Action<UnaryConstructorClass*(bool, int)> a =
|
||||
ReturnNew<UnaryConstructorClass>(4000);
|
||||
UnaryConstructorClass* c = a.Perform(make_tuple(false, 5));
|
||||
UnaryConstructorClass* c = a.Perform(std::make_tuple(false, 5));
|
||||
EXPECT_EQ(4000, c->value_);
|
||||
delete c;
|
||||
}
|
||||
@ -1044,7 +883,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
|
||||
TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) {
|
||||
Action<const UnaryConstructorClass*()> a =
|
||||
ReturnNew<UnaryConstructorClass>(4000);
|
||||
const UnaryConstructorClass* c = a.Perform(make_tuple());
|
||||
const UnaryConstructorClass* c = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(4000, c->value_);
|
||||
delete c;
|
||||
}
|
||||
@ -1064,7 +903,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
|
||||
ReturnNew<TenArgConstructorClass>(1000000000, 200000000, 30000000,
|
||||
4000000, 500000, 60000,
|
||||
7000, 800, 90, 0);
|
||||
TenArgConstructorClass* c = a.Perform(make_tuple());
|
||||
TenArgConstructorClass* c = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(1234567890, c->value_);
|
||||
delete c;
|
||||
}
|
||||
@ -1078,7 +917,7 @@ ACTION_TEMPLATE(CreateNew,
|
||||
|
||||
TEST(ActionTemplateTest, WorksWithoutValueParam) {
|
||||
const Action<int*()> a = CreateNew<int>();
|
||||
int* p = a.Perform(make_tuple());
|
||||
int* p = a.Perform(std::make_tuple());
|
||||
delete p;
|
||||
}
|
||||
|
||||
@ -1091,7 +930,7 @@ ACTION_TEMPLATE(CreateNew,
|
||||
|
||||
TEST(ActionTemplateTest, WorksWithValueParams) {
|
||||
const Action<int*()> a = CreateNew<int>(42);
|
||||
int* p = a.Perform(make_tuple());
|
||||
int* p = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(42, *p);
|
||||
delete p;
|
||||
}
|
||||
@ -1100,7 +939,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) {
|
||||
ACTION_TEMPLATE(MyDeleteArg,
|
||||
HAS_1_TEMPLATE_PARAMS(int, k),
|
||||
AND_0_VALUE_PARAMS()) {
|
||||
delete get<k>(args);
|
||||
delete std::get<k>(args);
|
||||
}
|
||||
|
||||
// Resets a bool variable in the destructor.
|
||||
@ -1117,7 +956,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
|
||||
int n = 0;
|
||||
bool b = true;
|
||||
BoolResetter* resetter = new BoolResetter(&b);
|
||||
a.Perform(make_tuple(&n, resetter));
|
||||
a.Perform(std::make_tuple(&n, resetter));
|
||||
EXPECT_FALSE(b); // Verifies that resetter is deleted.
|
||||
}
|
||||
|
||||
@ -1130,9 +969,9 @@ ACTION_TEMPLATE(ReturnSmartPointer,
|
||||
}
|
||||
|
||||
TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) {
|
||||
using ::testing::internal::linked_ptr;
|
||||
const Action<linked_ptr<int>()> a = ReturnSmartPointer<linked_ptr>(42);
|
||||
linked_ptr<int> p = a.Perform(make_tuple());
|
||||
const Action<std::shared_ptr<int>()> a =
|
||||
ReturnSmartPointer<std::shared_ptr>(42);
|
||||
std::shared_ptr<int> p = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(42, *p);
|
||||
}
|
||||
|
||||
@ -1162,12 +1001,11 @@ ACTION_TEMPLATE(ReturnGiant,
|
||||
}
|
||||
|
||||
TEST(ActionTemplateTest, WorksFor10TemplateParameters) {
|
||||
using ::testing::internal::linked_ptr;
|
||||
typedef GiantTemplate<linked_ptr<int>, bool, double, 5,
|
||||
true, 6, char, unsigned, int> Giant;
|
||||
const Action<Giant()> a = ReturnGiant<
|
||||
int, bool, double, 5, true, 6, char, unsigned, int, linked_ptr>(42);
|
||||
Giant giant = a.Perform(make_tuple());
|
||||
using Giant = GiantTemplate<std::shared_ptr<int>, bool, double, 5, true, 6,
|
||||
char, unsigned, int>;
|
||||
const Action<Giant()> a = ReturnGiant<int, bool, double, 5, true, 6, char,
|
||||
unsigned, int, std::shared_ptr>(42);
|
||||
Giant giant = a.Perform(std::make_tuple());
|
||||
EXPECT_EQ(42, giant.value);
|
||||
}
|
||||
|
||||
@ -1180,7 +1018,7 @@ ACTION_TEMPLATE(ReturnSum,
|
||||
|
||||
TEST(ActionTemplateTest, WorksFor10ValueParameters) {
|
||||
const Action<int()> a = ReturnSum<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
EXPECT_EQ(55, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(55, a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests that ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded
|
||||
@ -1214,16 +1052,13 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
|
||||
const Action<int()> a2 = ReturnSum<int>(1, 2);
|
||||
const Action<int()> a3 = ReturnSum<int>(1, 2, 3);
|
||||
const Action<int()> a4 = ReturnSum<int, 10000>(2000, 300, 40, 5);
|
||||
EXPECT_EQ(0, a0.Perform(make_tuple()));
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple()));
|
||||
EXPECT_EQ(3, a2.Perform(make_tuple()));
|
||||
EXPECT_EQ(6, a3.Perform(make_tuple()));
|
||||
EXPECT_EQ(12345, a4.Perform(make_tuple()));
|
||||
EXPECT_EQ(0, a0.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(1, a1.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(3, a2.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(6, a3.Perform(std::make_tuple()));
|
||||
EXPECT_EQ(12345, a4.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gmock_generated_actions_test
|
||||
} // namespace testing
|
||||
|
@ -46,13 +46,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
|
||||
// mock for a function with const arguments, so we don't test such
|
||||
// cases for MSVC versions older than 2008.
|
||||
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_generated_function_mockers_test {
|
||||
|
||||
@ -85,9 +78,7 @@ class FooInterface {
|
||||
|
||||
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
|
||||
virtual std::string TakesConstReference(const int& n) = 0;
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
virtual bool TakesConst(const int x) = 0;
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
virtual int OverloadedOnArgumentNumber() = 0;
|
||||
virtual int OverloadedOnArgumentNumber(int n) = 0;
|
||||
@ -136,10 +127,7 @@ class MockFoo : public FooInterface {
|
||||
|
||||
MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
|
||||
MOCK_METHOD1(TakesConstReference, std::string(const int&));
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
|
||||
#endif
|
||||
|
||||
// Tests that the function return type can contain unprotected comma.
|
||||
MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
|
||||
@ -224,8 +212,8 @@ TEST_F(FunctionMockerTest, MocksBinaryFunction) {
|
||||
|
||||
// Tests mocking a decimal function.
|
||||
TEST_F(FunctionMockerTest, MocksDecimalFunction) {
|
||||
EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(),
|
||||
Lt(100), 5U, NULL, "hi"))
|
||||
EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
|
||||
nullptr, "hi"))
|
||||
.WillOnce(Return(5));
|
||||
|
||||
EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
|
||||
@ -249,7 +237,6 @@ TEST_F(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
|
||||
EXPECT_EQ("Hello", foo_->TakesConstReference(a));
|
||||
}
|
||||
|
||||
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
// Tests mocking a function that takes a const variable.
|
||||
TEST_F(FunctionMockerTest, MocksFunctionWithConstArgument) {
|
||||
EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
|
||||
@ -257,7 +244,6 @@ TEST_F(FunctionMockerTest, MocksFunctionWithConstArgument) {
|
||||
|
||||
EXPECT_FALSE(foo_->TakesConst(5));
|
||||
}
|
||||
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
|
||||
|
||||
// Tests mocking functions overloaded on the number of arguments.
|
||||
TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
|
||||
@ -326,11 +312,11 @@ TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
|
||||
|
||||
// Tests mocking a decimal function with calltype.
|
||||
TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
|
||||
EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(),
|
||||
Lt(100), 5U, NULL, "hi"))
|
||||
EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
|
||||
nullptr, "hi"))
|
||||
.WillOnce(Return(10));
|
||||
|
||||
EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi"));
|
||||
EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
|
||||
}
|
||||
|
||||
// Tests mocking functions overloaded on the const-ness of this object.
|
||||
@ -596,7 +582,6 @@ TEST(MockFunctionTest, WorksFor10Arguments) {
|
||||
EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
TEST(MockFunctionTest, AsStdFunction) {
|
||||
MockFunction<int(int)> foo;
|
||||
auto call = [](const std::function<int(int)> &f, int i) {
|
||||
@ -628,7 +613,6 @@ TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD0(func, void());
|
||||
|
@ -38,7 +38,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using ::testing::tuple;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::internal::CompileAssertTypesEqual;
|
||||
using ::testing::internal::MatcherTuple;
|
||||
@ -48,24 +47,24 @@ using ::testing::internal::IgnoredValue;
|
||||
// Tests the MatcherTuple template struct.
|
||||
|
||||
TEST(MatcherTupleTest, ForSize0) {
|
||||
CompileAssertTypesEqual<tuple<>, MatcherTuple<tuple<> >::type>();
|
||||
CompileAssertTypesEqual<std::tuple<>, MatcherTuple<std::tuple<> >::type>();
|
||||
}
|
||||
|
||||
TEST(MatcherTupleTest, ForSize1) {
|
||||
CompileAssertTypesEqual<tuple<Matcher<int> >,
|
||||
MatcherTuple<tuple<int> >::type>();
|
||||
CompileAssertTypesEqual<std::tuple<Matcher<int> >,
|
||||
MatcherTuple<std::tuple<int> >::type>();
|
||||
}
|
||||
|
||||
TEST(MatcherTupleTest, ForSize2) {
|
||||
CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char> >,
|
||||
MatcherTuple<tuple<int, char> >::type>();
|
||||
CompileAssertTypesEqual<std::tuple<Matcher<int>, Matcher<char> >,
|
||||
MatcherTuple<std::tuple<int, char> >::type>();
|
||||
}
|
||||
|
||||
TEST(MatcherTupleTest, ForSize5) {
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
|
||||
Matcher<char*> >,
|
||||
MatcherTuple<tuple<int, char, bool, double, char*> >::type>();
|
||||
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
|
||||
Matcher<char*> >,
|
||||
MatcherTuple<std::tuple<int, char, bool, double, char*> >::type>();
|
||||
}
|
||||
|
||||
// Tests the Function template struct.
|
||||
@ -73,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) {
|
||||
TEST(FunctionTest, Nullary) {
|
||||
typedef Function<int()> F; // NOLINT
|
||||
CompileAssertTypesEqual<int, F::Result>();
|
||||
CompileAssertTypesEqual<tuple<>, F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<tuple<>, F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(), F::MakeResultVoid>();
|
||||
CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
|
||||
}
|
||||
@ -83,8 +82,9 @@ TEST(FunctionTest, Unary) {
|
||||
typedef Function<int(bool)> F; // NOLINT
|
||||
CompileAssertTypesEqual<int, F::Result>();
|
||||
CompileAssertTypesEqual<bool, F::Argument1>();
|
||||
CompileAssertTypesEqual<tuple<bool>, F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<tuple<Matcher<bool> >, F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
|
||||
CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
|
||||
F::MakeResultIgnoredValue>();
|
||||
@ -95,9 +95,10 @@ TEST(FunctionTest, Binary) {
|
||||
CompileAssertTypesEqual<int, F::Result>();
|
||||
CompileAssertTypesEqual<bool, F::Argument1>();
|
||||
CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT
|
||||
CompileAssertTypesEqual<tuple<bool, const long&>, F::ArgumentTuple>(); // NOLINT
|
||||
CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT
|
||||
F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
|
||||
std::tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
|
||||
CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
|
||||
@ -112,11 +113,12 @@ TEST(FunctionTest, LongArgumentList) {
|
||||
CompileAssertTypesEqual<char*, F::Argument3>();
|
||||
CompileAssertTypesEqual<int&, F::Argument4>();
|
||||
CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT
|
||||
CompileAssertTypesEqual<tuple<bool, int, char*, int&, const long&>, // NOLINT
|
||||
F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
|
||||
Matcher<const long&> >, // NOLINT
|
||||
std::tuple<bool, int, char*, int&, const long&>, // NOLINT
|
||||
F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<
|
||||
std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
|
||||
Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
|
||||
F::MakeResultVoid>();
|
||||
|
@ -62,9 +62,6 @@ using std::pair;
|
||||
using std::set;
|
||||
using std::stringstream;
|
||||
using std::vector;
|
||||
using testing::get;
|
||||
using testing::make_tuple;
|
||||
using testing::tuple;
|
||||
using testing::_;
|
||||
using testing::AllOf;
|
||||
using testing::AnyOf;
|
||||
@ -115,164 +112,16 @@ std::string Explain(const MatcherType& m, const Value& x) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// Tests Args<k0, ..., kn>(m).
|
||||
|
||||
TEST(ArgsTest, AcceptsZeroTemplateArg) {
|
||||
const tuple<int, bool> t(5, true);
|
||||
EXPECT_THAT(t, Args<>(Eq(tuple<>())));
|
||||
EXPECT_THAT(t, Not(Args<>(Ne(tuple<>()))));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsOneTemplateArg) {
|
||||
const tuple<int, bool> t(5, true);
|
||||
EXPECT_THAT(t, Args<0>(Eq(make_tuple(5))));
|
||||
EXPECT_THAT(t, Args<1>(Eq(make_tuple(true))));
|
||||
EXPECT_THAT(t, Not(Args<1>(Eq(make_tuple(false)))));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsTwoTemplateArgs) {
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
|
||||
EXPECT_THAT(t, (Args<0, 1>(Lt())));
|
||||
EXPECT_THAT(t, (Args<1, 2>(Lt())));
|
||||
EXPECT_THAT(t, Not(Args<0, 2>(Gt())));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
EXPECT_THAT(t, (Args<0, 0>(Eq())));
|
||||
EXPECT_THAT(t, Not(Args<1, 1>(Ne())));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
EXPECT_THAT(t, (Args<2, 0>(Gt())));
|
||||
EXPECT_THAT(t, Not(Args<2, 1>(Lt())));
|
||||
}
|
||||
|
||||
// The MATCHER*() macros trigger warning C4100 (unreferenced formal
|
||||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
// is expanded and macro expansion cannot contain #pragma. Therefore
|
||||
// we suppress them here.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
MATCHER(SumIsZero, "") {
|
||||
return get<0>(arg) + get<1>(arg) + get<2>(arg) == 0;
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
|
||||
EXPECT_THAT(make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero())));
|
||||
EXPECT_THAT(make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero())));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, CanBeNested) {
|
||||
const tuple<short, int, long, int> t(4, 5, 6L, 6); // NOLINT
|
||||
EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq()))));
|
||||
EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt()))));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, CanMatchTupleByValue) {
|
||||
typedef tuple<char, int, int> Tuple3;
|
||||
const Matcher<Tuple3> m = Args<1, 2>(Lt());
|
||||
EXPECT_TRUE(m.Matches(Tuple3('a', 1, 2)));
|
||||
EXPECT_FALSE(m.Matches(Tuple3('b', 2, 2)));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, CanMatchTupleByReference) {
|
||||
typedef tuple<char, char, int> Tuple3;
|
||||
const Matcher<const Tuple3&> m = Args<0, 1>(Lt());
|
||||
EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2)));
|
||||
EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2)));
|
||||
}
|
||||
|
||||
// Validates that arg is printed as str.
|
||||
MATCHER_P(PrintsAs, str, "") {
|
||||
return testing::PrintToString(arg) == str;
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsTenTemplateArgs) {
|
||||
EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
|
||||
(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
|
||||
PrintsAs("(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
|
||||
EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9),
|
||||
Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>(
|
||||
PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)"))));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, DescirbesSelfCorrectly) {
|
||||
const Matcher<tuple<int, bool, char> > m = Args<2, 0>(Lt());
|
||||
EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair where "
|
||||
"the first < the second",
|
||||
Describe(m));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, DescirbesNestedArgsCorrectly) {
|
||||
const Matcher<const tuple<int, bool, char, int>&> m =
|
||||
Args<0, 2, 3>(Args<2, 0>(Lt()));
|
||||
EXPECT_EQ("are a tuple whose fields (#0, #2, #3) are a tuple "
|
||||
"whose fields (#2, #0) are a pair where the first < the second",
|
||||
Describe(m));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, DescribesNegationCorrectly) {
|
||||
const Matcher<tuple<int, char> > m = Args<1, 0>(Gt());
|
||||
EXPECT_EQ("are a tuple whose fields (#1, #0) aren't a pair "
|
||||
"where the first > the second",
|
||||
DescribeNegation(m));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) {
|
||||
const Matcher<tuple<bool, int, int> > m = Args<1, 2>(Eq());
|
||||
EXPECT_EQ("whose fields (#1, #2) are (42, 42)",
|
||||
Explain(m, make_tuple(false, 42, 42)));
|
||||
EXPECT_EQ("whose fields (#1, #2) are (42, 43)",
|
||||
Explain(m, make_tuple(false, 42, 43)));
|
||||
}
|
||||
|
||||
// For testing Args<>'s explanation.
|
||||
class LessThanMatcher : public MatcherInterface<tuple<char, int> > {
|
||||
public:
|
||||
virtual void DescribeTo(::std::ostream* os) const {}
|
||||
|
||||
virtual bool MatchAndExplain(tuple<char, int> value,
|
||||
MatchResultListener* listener) const {
|
||||
const int diff = get<0>(value) - get<1>(value);
|
||||
if (diff > 0) {
|
||||
*listener << "where the first value is " << diff
|
||||
<< " more than the second";
|
||||
}
|
||||
return diff < 0;
|
||||
}
|
||||
};
|
||||
|
||||
Matcher<tuple<char, int> > LessThan() {
|
||||
return MakeMatcher(new LessThanMatcher);
|
||||
}
|
||||
|
||||
TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) {
|
||||
const Matcher<tuple<char, int, int> > m = Args<0, 2>(LessThan());
|
||||
EXPECT_EQ("whose fields (#0, #2) are ('a' (97, 0x61), 42), "
|
||||
"where the first value is 55 more than the second",
|
||||
Explain(m, make_tuple('a', 42, 42)));
|
||||
EXPECT_EQ("whose fields (#0, #2) are ('\\0', 43)",
|
||||
Explain(m, make_tuple('\0', 42, 43)));
|
||||
}
|
||||
|
||||
// For testing ExplainMatchResultTo().
|
||||
class GreaterThanMatcher : public MatcherInterface<int> {
|
||||
public:
|
||||
explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
void DescribeTo(::std::ostream* os) const override {
|
||||
*os << "is greater than " << rhs_;
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(int lhs,
|
||||
MatchResultListener* listener) const {
|
||||
bool MatchAndExplain(int lhs, MatchResultListener* listener) const override {
|
||||
const int diff = lhs - rhs_;
|
||||
if (diff > 0) {
|
||||
*listener << "which is " << diff << " more than " << rhs_;
|
||||
@ -517,7 +366,7 @@ class NativeArrayPassedAsPointerAndSize {
|
||||
|
||||
TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
|
||||
int array[] = { 0, 1 };
|
||||
::testing::tuple<int*, size_t> array_as_tuple(array, 2);
|
||||
::std::tuple<int*, size_t> array_as_tuple(array, 2);
|
||||
EXPECT_THAT(array_as_tuple, ElementsAre(0, 1));
|
||||
EXPECT_THAT(array_as_tuple, Not(ElementsAre(0)));
|
||||
|
||||
@ -571,8 +420,8 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
// This should make a copy of x and y.
|
||||
::testing::internal::ElementsAreMatcher<testing::tuple<int, int> >
|
||||
polymorphic_matcher = ElementsAre(x, y);
|
||||
::testing::internal::ElementsAreMatcher<std::tuple<int, int> >
|
||||
polymorphic_matcher = ElementsAre(x, y);
|
||||
// Changing x and y now shouldn't affect the meaning of the above matcher.
|
||||
x = y = 0;
|
||||
const int array1[] = { 1, 2 };
|
||||
@ -640,7 +489,6 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
|
||||
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(ElementsAreArrayTest, TakesInitializerList) {
|
||||
const int a[5] = { 1, 2, 3, 4, 5 };
|
||||
@ -676,7 +524,6 @@ TEST(ElementsAreArrayTest,
|
||||
{ Eq(1), Ne(-2), Ge(3), Le(4), Eq(6) })));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
|
||||
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
|
||||
const int a[] = { 1, 2, 3 };
|
||||
@ -1235,8 +1082,8 @@ TEST(ContainsTest, AcceptsMatcher) {
|
||||
TEST(ContainsTest, WorksForNativeArrayAsTuple) {
|
||||
const int a[] = { 1, 2 };
|
||||
const int* const pointer = a;
|
||||
EXPECT_THAT(make_tuple(pointer, 2), Contains(1));
|
||||
EXPECT_THAT(make_tuple(pointer, 2), Not(Contains(Gt(3))));
|
||||
EXPECT_THAT(std::make_tuple(pointer, 2), Contains(1));
|
||||
EXPECT_THAT(std::make_tuple(pointer, 2), Not(Contains(Gt(3))));
|
||||
}
|
||||
|
||||
TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
|
||||
@ -1290,11 +1137,6 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
|
||||
|
||||
} // namespace adl_test
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
TEST(AllOfTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
@ -1332,7 +1174,6 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) {
|
||||
EXPECT_THAT(p, Not(UniquePointee(2)));
|
||||
}
|
||||
|
||||
#endif // GTEST_LASNG_CXX11
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -123,15 +123,9 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForSmartPointers) {
|
||||
CompileAssertTypesEqual<const char,
|
||||
PointeeOf<internal::linked_ptr<const char> >::type>();
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
CompileAssertTypesEqual<std::string,
|
||||
PointeeOf<std::shared_ptr<std::string> >::type>();
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForRawPointers) {
|
||||
@ -141,20 +135,12 @@ TEST(PointeeOfTest, WorksForRawPointers) {
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForSmartPointers) {
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
const char* const raw_p1 = new const char('a'); // NOLINT
|
||||
const std::unique_ptr<const char> p1(raw_p1);
|
||||
EXPECT_EQ(raw_p1, GetRawPointer(p1));
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
double* const raw_p2 = new double(2.5); // NOLINT
|
||||
const std::shared_ptr<double> p2(raw_p2);
|
||||
EXPECT_EQ(raw_p2, GetRawPointer(p2));
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
|
||||
const char* const raw_p4 = new const char('a'); // NOLINT
|
||||
const internal::linked_ptr<const char> p4(raw_p4);
|
||||
EXPECT_EQ(raw_p4, GetRawPointer(p4));
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForRawPointers) {
|
||||
@ -308,26 +294,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
|
||||
// Tests the TupleMatches() template function.
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize0) {
|
||||
tuple<> matchers;
|
||||
tuple<> values;
|
||||
std::tuple<> matchers;
|
||||
std::tuple<> values;
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values));
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize1) {
|
||||
tuple<Matcher<int> > matchers(Eq(1));
|
||||
tuple<int> values1(1),
|
||||
values2(2);
|
||||
std::tuple<Matcher<int> > matchers(Eq(1));
|
||||
std::tuple<int> values1(1), values2(2);
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
EXPECT_FALSE(TupleMatches(matchers, values2));
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize2) {
|
||||
tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
||||
tuple<int, char> values1(1, 'a'),
|
||||
values2(1, 'b'),
|
||||
values3(2, 'a'),
|
||||
std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
||||
std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
|
||||
values4(2, 'b');
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
@ -337,10 +320,11 @@ TEST(TupleMatchesTest, WorksForSize2) {
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize5) {
|
||||
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT
|
||||
Matcher<std::string> >
|
||||
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
|
||||
Matcher<long>, // NOLINT
|
||||
Matcher<std::string> >
|
||||
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
|
||||
tuple<int, char, bool, long, std::string> // NOLINT
|
||||
std::tuple<int, char, bool, long, std::string> // NOLINT
|
||||
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
|
||||
values3(2, 'a', true, 2L, "hi");
|
||||
|
||||
@ -387,11 +371,9 @@ TEST(ExpectTest, FailsNonfatallyOnFalse) {
|
||||
|
||||
class LogIsVisibleTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
original_verbose_ = GMOCK_FLAG(verbose);
|
||||
}
|
||||
void SetUp() override { original_verbose_ = GMOCK_FLAG(verbose); }
|
||||
|
||||
virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
void TearDown() override { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
|
||||
std::string original_verbose_;
|
||||
};
|
||||
@ -450,11 +432,11 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
|
||||
}
|
||||
|
||||
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
|
||||
virtual std::string CurrentStackTrace(int max_depth, int skip_count) {
|
||||
std::string CurrentStackTrace(int max_depth, int skip_count) override {
|
||||
return (testing::Message() << max_depth << "::" << skip_count << "\n")
|
||||
.GetString();
|
||||
}
|
||||
virtual void UponLeavingGTest() {}
|
||||
void UponLeavingGTest() override {}
|
||||
};
|
||||
|
||||
// Tests that in opt mode, a positive stack_frames_to_skip argument is
|
||||
@ -686,22 +668,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
|
||||
|
||||
TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
|
||||
StaticAssertTypeEq<NativeArray<int>,
|
||||
StlContainerView<tuple<const int*, size_t> >::type>();
|
||||
StaticAssertTypeEq<NativeArray<double>,
|
||||
StlContainerView<tuple<linked_ptr<double>, int> >::type>();
|
||||
StlContainerView<std::tuple<const int*, size_t> >::type>();
|
||||
StaticAssertTypeEq<
|
||||
NativeArray<double>,
|
||||
StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>();
|
||||
|
||||
StaticAssertTypeEq<const NativeArray<int>,
|
||||
StlContainerView<tuple<const int*, int> >::const_reference>();
|
||||
StaticAssertTypeEq<
|
||||
const NativeArray<int>,
|
||||
StlContainerView<std::tuple<const int*, int> >::const_reference>();
|
||||
|
||||
int a1[3] = { 0, 1, 2 };
|
||||
const int* const p1 = a1;
|
||||
NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
|
||||
ConstReference(make_tuple(p1, 3));
|
||||
NativeArray<int> a2 =
|
||||
StlContainerView<std::tuple<const int*, int> >::ConstReference(
|
||||
std::make_tuple(p1, 3));
|
||||
EXPECT_EQ(3U, a2.size());
|
||||
EXPECT_EQ(a1, a2.begin());
|
||||
|
||||
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
|
||||
Copy(make_tuple(static_cast<int*>(a1), 3));
|
||||
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
|
||||
std::make_tuple(static_cast<int*>(a1), 3));
|
||||
ASSERT_EQ(3U, a3.size());
|
||||
EXPECT_EQ(0, a3.begin()[0]);
|
||||
EXPECT_EQ(1, a3.begin()[1]);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,21 +35,17 @@
|
||||
#include "gmock/gmock-more-actions.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_more_actions_test {
|
||||
|
||||
using ::std::plus;
|
||||
using ::std::string;
|
||||
using testing::get;
|
||||
using testing::make_tuple;
|
||||
using testing::tuple;
|
||||
using testing::tuple_element;
|
||||
using testing::_;
|
||||
using testing::Action;
|
||||
using testing::ActionInterface;
|
||||
@ -65,7 +61,6 @@ using testing::StaticAssertTypeEq;
|
||||
using testing::Unused;
|
||||
using testing::WithArg;
|
||||
using testing::WithoutArgs;
|
||||
using testing::internal::linked_ptr;
|
||||
|
||||
// For suppressing compiler warnings on conversion possibly losing precision.
|
||||
inline short Short(short n) { return n; } // NOLINT
|
||||
@ -232,45 +227,46 @@ class Foo {
|
||||
// Tests using Invoke() with a nullary function.
|
||||
TEST(InvokeTest, Nullary) {
|
||||
Action<int()> a = Invoke(Nullary); // NOLINT
|
||||
EXPECT_EQ(1, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a unary function.
|
||||
TEST(InvokeTest, Unary) {
|
||||
Action<bool(int)> a = Invoke(Unary); // NOLINT
|
||||
EXPECT_FALSE(a.Perform(make_tuple(1)));
|
||||
EXPECT_TRUE(a.Perform(make_tuple(-1)));
|
||||
EXPECT_FALSE(a.Perform(std::make_tuple(1)));
|
||||
EXPECT_TRUE(a.Perform(std::make_tuple(-1)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a binary function.
|
||||
TEST(InvokeTest, Binary) {
|
||||
Action<const char*(const char*, short)> a = Invoke(Binary); // NOLINT
|
||||
const char* p = "Hello";
|
||||
EXPECT_EQ(p + 2, a.Perform(make_tuple(p, Short(2))));
|
||||
EXPECT_EQ(p + 2, a.Perform(std::make_tuple(p, Short(2))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a ternary function.
|
||||
TEST(InvokeTest, Ternary) {
|
||||
Action<int(int, char, short)> a = Invoke(Ternary); // NOLINT
|
||||
EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', Short(3))));
|
||||
EXPECT_EQ(6, a.Perform(std::make_tuple(1, '\2', Short(3))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 4-argument function.
|
||||
TEST(InvokeTest, FunctionThatTakes4Arguments) {
|
||||
Action<int(int, int, int, int)> a = Invoke(SumOf4); // NOLINT
|
||||
EXPECT_EQ(1234, a.Perform(make_tuple(1000, 200, 30, 4)));
|
||||
EXPECT_EQ(1234, a.Perform(std::make_tuple(1000, 200, 30, 4)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 5-argument function.
|
||||
TEST(InvokeTest, FunctionThatTakes5Arguments) {
|
||||
Action<int(int, int, int, int, int)> a = Invoke(SumOf5); // NOLINT
|
||||
EXPECT_EQ(12345, a.Perform(make_tuple(10000, 2000, 300, 40, 5)));
|
||||
EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 6-argument function.
|
||||
TEST(InvokeTest, FunctionThatTakes6Arguments) {
|
||||
Action<int(int, int, int, int, int, int)> a = Invoke(SumOf6); // NOLINT
|
||||
EXPECT_EQ(123456, a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6)));
|
||||
EXPECT_EQ(123456,
|
||||
a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
|
||||
}
|
||||
|
||||
// A helper that turns the type of a C-string literal from const
|
||||
@ -283,9 +279,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) {
|
||||
const char*, const char*, const char*)>
|
||||
a = Invoke(Concat7);
|
||||
EXPECT_EQ("1234567",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 8-argument function.
|
||||
@ -294,9 +290,9 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) {
|
||||
const char*, const char*, const char*, const char*)>
|
||||
a = Invoke(Concat8);
|
||||
EXPECT_EQ("12345678",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 9-argument function.
|
||||
@ -305,10 +301,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) {
|
||||
const char*, const char*, const char*, const char*,
|
||||
const char*)>
|
||||
a = Invoke(Concat9);
|
||||
EXPECT_EQ("123456789",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"))));
|
||||
EXPECT_EQ("123456789", a.Perform(std::make_tuple(
|
||||
CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 10-argument function.
|
||||
@ -318,46 +314,46 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) {
|
||||
const char*, const char*)>
|
||||
a = Invoke(Concat10);
|
||||
EXPECT_EQ("1234567890",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"),
|
||||
CharPtr("0"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"),
|
||||
CharPtr("0"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with functions with parameters declared as Unused.
|
||||
TEST(InvokeTest, FunctionWithUnusedParameters) {
|
||||
Action<int(int, int, double, const std::string&)> a1 = Invoke(SumOfFirst2);
|
||||
tuple<int, int, double, std::string> dummy =
|
||||
make_tuple(10, 2, 5.6, std::string("hi"));
|
||||
std::tuple<int, int, double, std::string> dummy =
|
||||
std::make_tuple(10, 2, 5.6, std::string("hi"));
|
||||
EXPECT_EQ(12, a1.Perform(dummy));
|
||||
|
||||
Action<int(int, int, bool, int*)> a2 =
|
||||
Invoke(SumOfFirst2);
|
||||
EXPECT_EQ(23,
|
||||
a2.Perform(make_tuple(20, 3, true, static_cast<int*>(nullptr))));
|
||||
EXPECT_EQ(
|
||||
23, a2.Perform(std::make_tuple(20, 3, true, static_cast<int*>(nullptr))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with methods with parameters declared as Unused.
|
||||
TEST(InvokeTest, MethodWithUnusedParameters) {
|
||||
Foo foo;
|
||||
Action<int(std::string, bool, int, int)> a1 = Invoke(&foo, &Foo::SumOfLast2);
|
||||
EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2)));
|
||||
EXPECT_EQ(12, a1.Perform(std::make_tuple(CharPtr("hi"), true, 10, 2)));
|
||||
|
||||
Action<int(char, double, int, int)> a2 =
|
||||
Invoke(&foo, &Foo::SumOfLast2);
|
||||
EXPECT_EQ(23, a2.Perform(make_tuple('a', 2.5, 20, 3)));
|
||||
EXPECT_EQ(23, a2.Perform(std::make_tuple('a', 2.5, 20, 3)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a functor.
|
||||
TEST(InvokeTest, Functor) {
|
||||
Action<long(long, int)> a = Invoke(plus<long>()); // NOLINT
|
||||
EXPECT_EQ(3L, a.Perform(make_tuple(1, 2)));
|
||||
EXPECT_EQ(3L, a.Perform(std::make_tuple(1, 2)));
|
||||
}
|
||||
|
||||
// Tests using Invoke(f) as an action of a compatible type.
|
||||
TEST(InvokeTest, FunctionWithCompatibleType) {
|
||||
Action<long(int, short, char, bool)> a = Invoke(SumOf4); // NOLINT
|
||||
EXPECT_EQ(4321, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
|
||||
EXPECT_EQ(4321, a.Perform(std::make_tuple(4000, Short(300), Char(20), true)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with an object pointer and a method pointer.
|
||||
@ -366,14 +362,14 @@ TEST(InvokeTest, FunctionWithCompatibleType) {
|
||||
TEST(InvokeMethodTest, Nullary) {
|
||||
Foo foo;
|
||||
Action<int()> a = Invoke(&foo, &Foo::Nullary); // NOLINT
|
||||
EXPECT_EQ(123, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(123, a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a unary method.
|
||||
TEST(InvokeMethodTest, Unary) {
|
||||
Foo foo;
|
||||
Action<short(long)> a = Invoke(&foo, &Foo::Unary); // NOLINT
|
||||
EXPECT_EQ(4123, a.Perform(make_tuple(4000)));
|
||||
EXPECT_EQ(4123, a.Perform(std::make_tuple(4000)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a binary method.
|
||||
@ -381,7 +377,7 @@ TEST(InvokeMethodTest, Binary) {
|
||||
Foo foo;
|
||||
Action<std::string(const std::string&, char)> a = Invoke(&foo, &Foo::Binary);
|
||||
std::string s("Hell");
|
||||
tuple<std::string, char> dummy = make_tuple(s, 'o');
|
||||
std::tuple<std::string, char> dummy = std::make_tuple(s, 'o');
|
||||
EXPECT_EQ("Hello", a.Perform(dummy));
|
||||
}
|
||||
|
||||
@ -389,21 +385,21 @@ TEST(InvokeMethodTest, Binary) {
|
||||
TEST(InvokeMethodTest, Ternary) {
|
||||
Foo foo;
|
||||
Action<int(int, bool, char)> a = Invoke(&foo, &Foo::Ternary); // NOLINT
|
||||
EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, Char(1))));
|
||||
EXPECT_EQ(1124, a.Perform(std::make_tuple(1000, true, Char(1))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 4-argument method.
|
||||
TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
|
||||
Foo foo;
|
||||
Action<int(int, int, int, int)> a = Invoke(&foo, &Foo::SumOf4); // NOLINT
|
||||
EXPECT_EQ(1357, a.Perform(make_tuple(1000, 200, 30, 4)));
|
||||
EXPECT_EQ(1357, a.Perform(std::make_tuple(1000, 200, 30, 4)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 5-argument method.
|
||||
TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
|
||||
Foo foo;
|
||||
Action<int(int, int, int, int, int)> a = Invoke(&foo, &Foo::SumOf5); // NOLINT
|
||||
EXPECT_EQ(12345, a.Perform(make_tuple(10000, 2000, 300, 40, 5)));
|
||||
EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 6-argument method.
|
||||
@ -411,7 +407,8 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) {
|
||||
Foo foo;
|
||||
Action<int(int, int, int, int, int, int)> a = // NOLINT
|
||||
Invoke(&foo, &Foo::SumOf6);
|
||||
EXPECT_EQ(123456, a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6)));
|
||||
EXPECT_EQ(123456,
|
||||
a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6)));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 7-argument method.
|
||||
@ -421,9 +418,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) {
|
||||
const char*, const char*, const char*)>
|
||||
a = Invoke(&foo, &Foo::Concat7);
|
||||
EXPECT_EQ("1234567",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 8-argument method.
|
||||
@ -433,9 +430,9 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) {
|
||||
const char*, const char*, const char*, const char*)>
|
||||
a = Invoke(&foo, &Foo::Concat8);
|
||||
EXPECT_EQ("12345678",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 9-argument method.
|
||||
@ -445,10 +442,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) {
|
||||
const char*, const char*, const char*, const char*,
|
||||
const char*)>
|
||||
a = Invoke(&foo, &Foo::Concat9);
|
||||
EXPECT_EQ("123456789",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"))));
|
||||
EXPECT_EQ("123456789", a.Perform(std::make_tuple(
|
||||
CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a 10-argument method.
|
||||
@ -459,10 +456,10 @@ TEST(InvokeMethodTest, MethodThatTakes10Arguments) {
|
||||
const char*, const char*)>
|
||||
a = Invoke(&foo, &Foo::Concat10);
|
||||
EXPECT_EQ("1234567890",
|
||||
a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"),
|
||||
CharPtr("0"))));
|
||||
a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"),
|
||||
CharPtr("4"), CharPtr("5"), CharPtr("6"),
|
||||
CharPtr("7"), CharPtr("8"), CharPtr("9"),
|
||||
CharPtr("0"))));
|
||||
}
|
||||
|
||||
// Tests using Invoke(f) as an action of a compatible type.
|
||||
@ -470,48 +467,48 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) {
|
||||
Foo foo;
|
||||
Action<long(int, short, char, bool)> a = // NOLINT
|
||||
Invoke(&foo, &Foo::SumOf4);
|
||||
EXPECT_EQ(4444, a.Perform(make_tuple(4000, Short(300), Char(20), true)));
|
||||
EXPECT_EQ(4444, a.Perform(std::make_tuple(4000, Short(300), Char(20), true)));
|
||||
}
|
||||
|
||||
// Tests using WithoutArgs with an action that takes no argument.
|
||||
TEST(WithoutArgsTest, NoArg) {
|
||||
Action<int(int n)> a = WithoutArgs(Invoke(Nullary)); // NOLINT
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(2)));
|
||||
EXPECT_EQ(1, a.Perform(std::make_tuple(2)));
|
||||
}
|
||||
|
||||
// Tests using WithArg with an action that takes 1 argument.
|
||||
TEST(WithArgTest, OneArg) {
|
||||
Action<bool(double x, int n)> b = WithArg<1>(Invoke(Unary)); // NOLINT
|
||||
EXPECT_TRUE(b.Perform(make_tuple(1.5, -1)));
|
||||
EXPECT_FALSE(b.Perform(make_tuple(1.5, 1)));
|
||||
EXPECT_TRUE(b.Perform(std::make_tuple(1.5, -1)));
|
||||
EXPECT_FALSE(b.Perform(std::make_tuple(1.5, 1)));
|
||||
}
|
||||
|
||||
TEST(ReturnArgActionTest, WorksForOneArgIntArg0) {
|
||||
const Action<int(int)> a = ReturnArg<0>();
|
||||
EXPECT_EQ(5, a.Perform(make_tuple(5)));
|
||||
EXPECT_EQ(5, a.Perform(std::make_tuple(5)));
|
||||
}
|
||||
|
||||
TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) {
|
||||
const Action<bool(bool, bool, bool)> a = ReturnArg<0>();
|
||||
EXPECT_TRUE(a.Perform(make_tuple(true, false, false)));
|
||||
EXPECT_TRUE(a.Perform(std::make_tuple(true, false, false)));
|
||||
}
|
||||
|
||||
TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
|
||||
const Action<std::string(int, int, std::string, int)> a = ReturnArg<2>();
|
||||
EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, std::string("seven"), 8)));
|
||||
EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8)));
|
||||
}
|
||||
|
||||
TEST(SaveArgActionTest, WorksForSameType) {
|
||||
int result = 0;
|
||||
const Action<void(int n)> a1 = SaveArg<0>(&result);
|
||||
a1.Perform(make_tuple(5));
|
||||
a1.Perform(std::make_tuple(5));
|
||||
EXPECT_EQ(5, result);
|
||||
}
|
||||
|
||||
TEST(SaveArgActionTest, WorksForCompatibleType) {
|
||||
int result = 0;
|
||||
const Action<void(bool, char)> a1 = SaveArg<1>(&result);
|
||||
a1.Perform(make_tuple(true, 'a'));
|
||||
a1.Perform(std::make_tuple(true, 'a'));
|
||||
EXPECT_EQ('a', result);
|
||||
}
|
||||
|
||||
@ -519,7 +516,7 @@ TEST(SaveArgPointeeActionTest, WorksForSameType) {
|
||||
int result = 0;
|
||||
const int value = 5;
|
||||
const Action<void(const int*)> a1 = SaveArgPointee<0>(&result);
|
||||
a1.Perform(make_tuple(&value));
|
||||
a1.Perform(std::make_tuple(&value));
|
||||
EXPECT_EQ(5, result);
|
||||
}
|
||||
|
||||
@ -527,36 +524,28 @@ TEST(SaveArgPointeeActionTest, WorksForCompatibleType) {
|
||||
int result = 0;
|
||||
char value = 'a';
|
||||
const Action<void(bool, char*)> a1 = SaveArgPointee<1>(&result);
|
||||
a1.Perform(make_tuple(true, &value));
|
||||
a1.Perform(std::make_tuple(true, &value));
|
||||
EXPECT_EQ('a', result);
|
||||
}
|
||||
|
||||
TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) {
|
||||
int result = 0;
|
||||
linked_ptr<int> value(new int(5));
|
||||
const Action<void(linked_ptr<int>)> a1 = SaveArgPointee<0>(&result);
|
||||
a1.Perform(make_tuple(value));
|
||||
EXPECT_EQ(5, result);
|
||||
}
|
||||
|
||||
TEST(SetArgRefereeActionTest, WorksForSameType) {
|
||||
int value = 0;
|
||||
const Action<void(int&)> a1 = SetArgReferee<0>(1);
|
||||
a1.Perform(tuple<int&>(value));
|
||||
a1.Perform(std::tuple<int&>(value));
|
||||
EXPECT_EQ(1, value);
|
||||
}
|
||||
|
||||
TEST(SetArgRefereeActionTest, WorksForCompatibleType) {
|
||||
int value = 0;
|
||||
const Action<void(int, int&)> a1 = SetArgReferee<1>('a');
|
||||
a1.Perform(tuple<int, int&>(0, value));
|
||||
a1.Perform(std::tuple<int, int&>(0, value));
|
||||
EXPECT_EQ('a', value);
|
||||
}
|
||||
|
||||
TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
|
||||
int value = 0;
|
||||
const Action<void(bool, int, int&, const char*)> a1 = SetArgReferee<2>('a');
|
||||
a1.Perform(tuple<bool, int, int&, const char*>(true, 0, value, "hi"));
|
||||
a1.Perform(std::tuple<bool, int, int&, const char*>(true, 0, value, "hi"));
|
||||
EXPECT_EQ('a', value);
|
||||
}
|
||||
|
||||
@ -583,7 +572,7 @@ TEST(DeleteArgActionTest, OneArg) {
|
||||
DeletionTester* t = new DeletionTester(&is_deleted);
|
||||
const Action<void(DeletionTester*)> a1 = DeleteArg<0>(); // NOLINT
|
||||
EXPECT_FALSE(is_deleted);
|
||||
a1.Perform(make_tuple(t));
|
||||
a1.Perform(std::make_tuple(t));
|
||||
EXPECT_TRUE(is_deleted);
|
||||
}
|
||||
|
||||
@ -593,7 +582,7 @@ TEST(DeleteArgActionTest, TenArgs) {
|
||||
const Action<void(bool, int, int, const char*, bool,
|
||||
int, int, int, int, DeletionTester*)> a1 = DeleteArg<9>();
|
||||
EXPECT_FALSE(is_deleted);
|
||||
a1.Perform(make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t));
|
||||
a1.Perform(std::make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t));
|
||||
EXPECT_TRUE(is_deleted);
|
||||
}
|
||||
|
||||
@ -601,19 +590,19 @@ TEST(DeleteArgActionTest, TenArgs) {
|
||||
|
||||
TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {
|
||||
const Action<void(int n)> a = Throw('a');
|
||||
EXPECT_THROW(a.Perform(make_tuple(0)), char);
|
||||
EXPECT_THROW(a.Perform(std::make_tuple(0)), char);
|
||||
}
|
||||
|
||||
class MyException {};
|
||||
|
||||
TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) {
|
||||
const Action<double(char ch)> a = Throw(MyException());
|
||||
EXPECT_THROW(a.Perform(make_tuple('0')), MyException);
|
||||
EXPECT_THROW(a.Perform(std::make_tuple('0')), MyException);
|
||||
}
|
||||
|
||||
TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) {
|
||||
const Action<double()> a = Throw(MyException());
|
||||
EXPECT_THROW(a.Perform(make_tuple()), MyException);
|
||||
EXPECT_THROW(a.Perform(std::make_tuple()), MyException);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
@ -629,7 +618,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
|
||||
int* pn = n;
|
||||
char ch[4] = {};
|
||||
char* pch = ch;
|
||||
a.Perform(make_tuple(true, pn, pch));
|
||||
a.Perform(std::make_tuple(true, pn, pch));
|
||||
EXPECT_EQ(1, n[0]);
|
||||
EXPECT_EQ(2, n[1]);
|
||||
EXPECT_EQ(3, n[2]);
|
||||
@ -644,7 +633,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
|
||||
a = SetArrayArgument<2>(letters.begin(), letters.end());
|
||||
std::fill_n(n, 4, 0);
|
||||
std::fill_n(ch, 4, '\0');
|
||||
a.Perform(make_tuple(true, pn, pch));
|
||||
a.Perform(std::make_tuple(true, pn, pch));
|
||||
EXPECT_EQ(0, n[0]);
|
||||
EXPECT_EQ(0, n[1]);
|
||||
EXPECT_EQ(0, n[2]);
|
||||
@ -663,7 +652,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
|
||||
|
||||
int n[4] = {};
|
||||
int* pn = n;
|
||||
a.Perform(make_tuple(true, pn));
|
||||
a.Perform(std::make_tuple(true, pn));
|
||||
EXPECT_EQ(0, n[0]);
|
||||
EXPECT_EQ(0, n[1]);
|
||||
EXPECT_EQ(0, n[2]);
|
||||
@ -679,7 +668,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
|
||||
|
||||
int codes[4] = { 111, 222, 333, 444 };
|
||||
int* pcodes = codes;
|
||||
a.Perform(make_tuple(true, pcodes));
|
||||
a.Perform(std::make_tuple(true, pcodes));
|
||||
EXPECT_EQ(97, codes[0]);
|
||||
EXPECT_EQ(98, codes[1]);
|
||||
EXPECT_EQ(99, codes[2]);
|
||||
@ -693,17 +682,17 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
|
||||
Action<MyFunction> a = SetArrayArgument<1>(letters.begin(), letters.end());
|
||||
|
||||
std::string s;
|
||||
a.Perform(make_tuple(true, back_inserter(s)));
|
||||
a.Perform(std::make_tuple(true, back_inserter(s)));
|
||||
EXPECT_EQ(letters, s);
|
||||
}
|
||||
|
||||
TEST(ReturnPointeeTest, Works) {
|
||||
int n = 42;
|
||||
const Action<int()> a = ReturnPointee(&n);
|
||||
EXPECT_EQ(42, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(42, a.Perform(std::make_tuple()));
|
||||
|
||||
n = 43;
|
||||
EXPECT_EQ(43, a.Perform(make_tuple()));
|
||||
EXPECT_EQ(43, a.Perform(std::make_tuple()));
|
||||
}
|
||||
|
||||
} // namespace gmock_generated_actions_test
|
||||
|
@ -27,8 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "gmock/gmock-generated-nice-strict.h"
|
||||
#include "gmock/gmock-nice-strict.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -114,23 +113,22 @@ class MockBar {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
|
||||
};
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11
|
||||
|
||||
class MockBaz {
|
||||
public:
|
||||
class MoveOnly {
|
||||
public:
|
||||
MoveOnly() = default;
|
||||
|
||||
MoveOnly(const MoveOnly&) = delete;
|
||||
operator=(const MoveOnly&) = delete;
|
||||
MoveOnly& operator=(const MoveOnly&) = delete;
|
||||
|
||||
MoveOnly(MoveOnly&&) = default;
|
||||
operator=(MoveOnly&&) = default;
|
||||
MoveOnly& operator=(MoveOnly&&) = default;
|
||||
};
|
||||
|
||||
MockBaz(MoveOnly) {}
|
||||
}
|
||||
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
};
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
@ -184,6 +182,13 @@ TEST(RawMockTest, InfoForUninterestingCall) {
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
}
|
||||
|
||||
TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
MockFoo raw_foo;
|
||||
EXPECT_TRUE(Mock::IsNaggy(&raw_foo));
|
||||
EXPECT_FALSE(Mock::IsNice(&raw_foo));
|
||||
EXPECT_FALSE(Mock::IsStrict(&raw_foo));
|
||||
}
|
||||
|
||||
// Tests that a nice mock generates no warning for uninteresting calls.
|
||||
TEST(NiceMockTest, NoWarningForUninterestingCall) {
|
||||
NiceMock<MockFoo> nice_foo;
|
||||
@ -285,14 +290,10 @@ TEST(NiceMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NiceMockTest, MoveOnlyConstructor) {
|
||||
NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly());
|
||||
NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
@ -309,6 +310,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
NiceMock<MockFoo> nice_foo;
|
||||
EXPECT_FALSE(Mock::IsNaggy(&nice_foo));
|
||||
EXPECT_TRUE(Mock::IsNice(&nice_foo));
|
||||
EXPECT_FALSE(Mock::IsStrict(&nice_foo));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Tests that a naggy mock generates warnings for uninteresting calls.
|
||||
@ -393,14 +401,10 @@ TEST(NaggyMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NaggyMockTest, MoveOnlyConstructor) {
|
||||
NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly());
|
||||
NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
@ -417,6 +421,13 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) {
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
NaggyMock<MockFoo> naggy_foo;
|
||||
EXPECT_TRUE(Mock::IsNaggy(&naggy_foo));
|
||||
EXPECT_FALSE(Mock::IsNice(&naggy_foo));
|
||||
EXPECT_FALSE(Mock::IsStrict(&naggy_foo));
|
||||
}
|
||||
|
||||
// Tests that a strict mock allows expected calls.
|
||||
TEST(StrictMockTest, AllowsExpectedCall) {
|
||||
StrictMock<MockFoo> strict_foo;
|
||||
@ -482,14 +493,10 @@ TEST(StrictMockTest, AllowLeak) {
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(StrictMockTest, MoveOnlyConstructor) {
|
||||
StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly());
|
||||
StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly{});
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
@ -506,5 +513,12 @@ TEST(StrictMockTest, AcceptsClassNamedMock) {
|
||||
}
|
||||
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
StrictMock<MockFoo> strict_foo;
|
||||
EXPECT_FALSE(Mock::IsNaggy(&strict_foo));
|
||||
EXPECT_FALSE(Mock::IsNice(&strict_foo));
|
||||
EXPECT_TRUE(Mock::IsStrict(&strict_foo));
|
||||
}
|
||||
|
||||
} // namespace gmock_nice_strict_test
|
||||
} // namespace testing
|
||||
|
206
googlemock/test/gmock-pp-string_test.cc
Normal file
206
googlemock/test/gmock-pp-string_test.cc
Normal file
@ -0,0 +1,206 @@
|
||||
// Copyright 2018, 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 tests the internal preprocessor macro library.
|
||||
#include "gmock/internal/gmock-pp.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace testing {
|
||||
namespace {
|
||||
|
||||
// Matcher to verify that to strings are identical up to whitespace
|
||||
// Not 100% correct, because it treats "AB" as equal to "A B".
|
||||
::testing::Matcher<const std::string&> SameExceptSpaces(const std::string& s) {
|
||||
auto remove_spaces = [](std::string to_split) {
|
||||
to_split.erase(std::remove(to_split.begin(), to_split.end(), ' '),
|
||||
to_split.end());
|
||||
return to_split;
|
||||
};
|
||||
return ::testing::ResultOf(remove_spaces, remove_spaces(s));
|
||||
}
|
||||
|
||||
// Verify that a macro expands to a given text. Ignores whitespace difference.
|
||||
// In MSVC, GMOCK_PP_STRINGIZE() returns nothing, rather than "". So concatenate
|
||||
// with an empty string.
|
||||
#define EXPECT_EXPANSION(Result, Macro) \
|
||||
EXPECT_THAT("" GMOCK_PP_STRINGIZE(Macro), SameExceptSpaces(Result))
|
||||
|
||||
TEST(Macros, Cat) {
|
||||
EXPECT_EXPANSION("14", GMOCK_PP_CAT(1, 4));
|
||||
EXPECT_EXPANSION("+=", GMOCK_PP_CAT(+, =));
|
||||
}
|
||||
|
||||
TEST(Macros, Narg) {
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_NARG());
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_NARG(x));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_NARG(x, y));
|
||||
EXPECT_EXPANSION("3", GMOCK_PP_NARG(x, y, z));
|
||||
EXPECT_EXPANSION("4", GMOCK_PP_NARG(x, y, z, w));
|
||||
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_NARG0());
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_NARG0(x));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_NARG0(x, y));
|
||||
}
|
||||
|
||||
TEST(Macros, Comma) {
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_HAS_COMMA());
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_HAS_COMMA(, ));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_HAS_COMMA((, )));
|
||||
}
|
||||
|
||||
TEST(Macros, IsEmpty) {
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IS_EMPTY());
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_EMPTY(, ));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_EMPTY(a));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_EMPTY(()));
|
||||
|
||||
#define GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IS_EMPTY(GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1));
|
||||
}
|
||||
|
||||
TEST(Macros, If) {
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IF(1, 1, 2));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_IF(0, 1, 2));
|
||||
}
|
||||
|
||||
TEST(Macros, HeadTail) {
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_HEAD(1));
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_HEAD(1, 2));
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_HEAD(1, 2, 3));
|
||||
|
||||
EXPECT_EXPANSION("", GMOCK_PP_TAIL(1));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_TAIL(1, 2));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_HEAD(GMOCK_PP_TAIL(1, 2, 3)));
|
||||
}
|
||||
|
||||
TEST(Macros, Parentheses) {
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_BEGIN_PARENS(sss));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_BEGIN_PARENS(sss()));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_BEGIN_PARENS(sss() sss));
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IS_BEGIN_PARENS((sss)));
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IS_BEGIN_PARENS((sss)ss));
|
||||
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_ENCLOSED_PARENS(sss));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_ENCLOSED_PARENS(sss()));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_ENCLOSED_PARENS(sss() sss));
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_IS_ENCLOSED_PARENS((sss)));
|
||||
EXPECT_EXPANSION("0", GMOCK_PP_IS_ENCLOSED_PARENS((sss)ss));
|
||||
|
||||
EXPECT_EXPANSION("1 + 1", GMOCK_PP_REMOVE_PARENS((1 + 1)));
|
||||
}
|
||||
|
||||
TEST(Macros, Increment) {
|
||||
EXPECT_EXPANSION("1", GMOCK_PP_INC(0));
|
||||
EXPECT_EXPANSION("2", GMOCK_PP_INC(1));
|
||||
EXPECT_EXPANSION("3", GMOCK_PP_INC(2));
|
||||
EXPECT_EXPANSION("4", GMOCK_PP_INC(3));
|
||||
EXPECT_EXPANSION("5", GMOCK_PP_INC(4));
|
||||
|
||||
EXPECT_EXPANSION("16", GMOCK_PP_INC(15));
|
||||
}
|
||||
|
||||
#define JOINER_CAT(a, b) a##b
|
||||
#define JOINER(_N, _Data, _Elem) JOINER_CAT(_Data, _N) = _Elem
|
||||
|
||||
TEST(Macros, Repeat) {
|
||||
EXPECT_EXPANSION("", GMOCK_PP_REPEAT(JOINER, X, 0));
|
||||
EXPECT_EXPANSION("X0=", GMOCK_PP_REPEAT(JOINER, X, 1));
|
||||
EXPECT_EXPANSION("X0= X1=", GMOCK_PP_REPEAT(JOINER, X, 2));
|
||||
EXPECT_EXPANSION("X0= X1= X2=", GMOCK_PP_REPEAT(JOINER, X, 3));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3=", GMOCK_PP_REPEAT(JOINER, X, 4));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4=", GMOCK_PP_REPEAT(JOINER, X, 5));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5=", GMOCK_PP_REPEAT(JOINER, X, 6));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 7));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 8));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7= X8=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 9));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7= X8= X9=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 10));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 11));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 12));
|
||||
EXPECT_EXPANSION("X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 13));
|
||||
EXPECT_EXPANSION(
|
||||
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12= X13=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 14));
|
||||
EXPECT_EXPANSION(
|
||||
"X0= X1= X2= X3= X4= X5= X6= X7= X8= X9= X10= X11= X12= X13= X14=",
|
||||
GMOCK_PP_REPEAT(JOINER, X, 15));
|
||||
}
|
||||
TEST(Macros, ForEach) {
|
||||
EXPECT_EXPANSION("", GMOCK_PP_FOR_EACH(JOINER, X, ()));
|
||||
EXPECT_EXPANSION("X0=a", GMOCK_PP_FOR_EACH(JOINER, X, (a)));
|
||||
EXPECT_EXPANSION("X0=a X1=b", GMOCK_PP_FOR_EACH(JOINER, X, (a, b)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c", GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d X4=e",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d X4=e X5=f",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d X4=e X5=f X6=g",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h)));
|
||||
EXPECT_EXPANSION("X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i, j)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i, j, k)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i, j, k, l)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i, j, k, l, m)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m "
|
||||
"X13=n",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X, (a, b, c, d, e, f, g, h, i, j, k, l, m, n)));
|
||||
EXPECT_EXPANSION(
|
||||
"X0=a X1=b X2=c X3=d X4=e X5=f X6=g X7=h X8=i X9=j X10=k X11=l X12=m "
|
||||
"X13=n X14=o",
|
||||
GMOCK_PP_FOR_EACH(JOINER, X,
|
||||
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace testing
|
73
googlemock/test/gmock-pp_test.cc
Normal file
73
googlemock/test/gmock-pp_test.cc
Normal file
@ -0,0 +1,73 @@
|
||||
#include "gmock/internal/gmock-pp.h"
|
||||
|
||||
// Static assertions.
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
namespace gmockpp {
|
||||
|
||||
static_assert(GMOCK_PP_CAT(1, 4) == 14, "");
|
||||
static_assert(GMOCK_PP_INTERNAL_INTERNAL_16TH(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18) == 16,
|
||||
"");
|
||||
static_assert(GMOCK_PP_NARG() == 1, "");
|
||||
static_assert(GMOCK_PP_NARG(x) == 1, "");
|
||||
static_assert(GMOCK_PP_NARG(x, y) == 2, "");
|
||||
static_assert(GMOCK_PP_NARG(x, y, z) == 3, "");
|
||||
static_assert(GMOCK_PP_NARG(x, y, z, w) == 4, "");
|
||||
static_assert(!GMOCK_PP_HAS_COMMA(), "");
|
||||
static_assert(GMOCK_PP_HAS_COMMA(b, ), "");
|
||||
static_assert(!GMOCK_PP_HAS_COMMA((, )), "");
|
||||
static_assert(!GMOCK_PP_IS_EMPTY(, ), "");
|
||||
static_assert(!GMOCK_PP_IS_EMPTY(a), "");
|
||||
static_assert(!GMOCK_PP_IS_EMPTY(()), "");
|
||||
static_assert(GMOCK_PP_IF(1, 1, 2) == 1, "");
|
||||
static_assert(GMOCK_PP_IF(0, 1, 2) == 2, "");
|
||||
static_assert(GMOCK_PP_NARG0(x) == 1, "");
|
||||
static_assert(GMOCK_PP_NARG0(x, y) == 2, "");
|
||||
static_assert(GMOCK_PP_HEAD(1) == 1, "");
|
||||
static_assert(GMOCK_PP_HEAD(1, 2) == 1, "");
|
||||
static_assert(GMOCK_PP_HEAD(1, 2, 3) == 1, "");
|
||||
static_assert(GMOCK_PP_TAIL(1, 2) == 2, "");
|
||||
static_assert(GMOCK_PP_HEAD(GMOCK_PP_TAIL(1, 2, 3)) == 2, "");
|
||||
static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss), "");
|
||||
static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss()), "");
|
||||
static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss() sss), "");
|
||||
static_assert(GMOCK_PP_IS_BEGIN_PARENS((sss)), "");
|
||||
static_assert(GMOCK_PP_IS_BEGIN_PARENS((sss)ss), "");
|
||||
static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss), "");
|
||||
static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss()), "");
|
||||
static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss() sss), "");
|
||||
static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS((sss)ss), "");
|
||||
static_assert(GMOCK_PP_REMOVE_PARENS((1 + 1)) * 2 == 3, "");
|
||||
static_assert(GMOCK_PP_INC(4) == 5, "");
|
||||
|
||||
template <class... Args>
|
||||
struct Test {
|
||||
static constexpr int kArgs = sizeof...(Args);
|
||||
};
|
||||
#define GMOCK_PP_INTERNAL_TYPE_TEST(_i, _Data, _element) \
|
||||
GMOCK_PP_COMMA_IF(_i) _element
|
||||
static_assert(Test<GMOCK_PP_FOR_EACH(GMOCK_PP_INTERNAL_TYPE_TEST, ~,
|
||||
(int, float, double, char))>::kArgs == 4,
|
||||
"");
|
||||
#define GMOCK_PP_INTERNAL_VAR_TEST_1(_x) 1
|
||||
#define GMOCK_PP_INTERNAL_VAR_TEST_2(_x, _y) 2
|
||||
#define GMOCK_PP_INTERNAL_VAR_TEST_3(_x, _y, _z) 3
|
||||
|
||||
#define GMOCK_PP_INTERNAL_VAR_TEST(...) \
|
||||
GMOCK_PP_VARIADIC_CALL(GMOCK_PP_INTERNAL_VAR_TEST_, __VA_ARGS__)
|
||||
static_assert(GMOCK_PP_INTERNAL_VAR_TEST(x, y) == 2, "");
|
||||
static_assert(GMOCK_PP_INTERNAL_VAR_TEST(silly) == 1, "");
|
||||
static_assert(GMOCK_PP_INTERNAL_VAR_TEST(x, y, z) == 3, "");
|
||||
|
||||
// TODO(iserna): The following asserts fail in --config=lexan.
|
||||
#define GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
|
||||
static_assert(GMOCK_PP_IS_EMPTY(GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1), "");
|
||||
static_assert(GMOCK_PP_IS_EMPTY(), "");
|
||||
static_assert(GMOCK_PP_IS_ENCLOSED_PARENS((sss)), "");
|
||||
static_assert(GMOCK_PP_IS_EMPTY(GMOCK_PP_TAIL(1)), "");
|
||||
static_assert(GMOCK_PP_NARG0() == 0, "");
|
||||
|
||||
} // namespace gmockpp
|
||||
} // namespace internal
|
||||
} // namespace testing
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
|
||||
#include <memory>
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -99,7 +100,6 @@ using testing::internal::kFail;
|
||||
using testing::internal::kInfoVerbosity;
|
||||
using testing::internal::kWarn;
|
||||
using testing::internal::kWarningVerbosity;
|
||||
using testing::internal::linked_ptr;
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
using testing::HasSubstr;
|
||||
@ -172,7 +172,7 @@ class ReferenceHoldingMock {
|
||||
public:
|
||||
ReferenceHoldingMock() {}
|
||||
|
||||
MOCK_METHOD1(AcceptReference, void(linked_ptr<MockA>*));
|
||||
MOCK_METHOD1(AcceptReference, void(std::shared_ptr<MockA>*));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ReferenceHoldingMock);
|
||||
@ -1952,17 +1952,17 @@ TEST(DeletingMockEarlyTest, Failure2) {
|
||||
class EvenNumberCardinality : public CardinalityInterface {
|
||||
public:
|
||||
// Returns true iff call_count calls will satisfy this cardinality.
|
||||
virtual bool IsSatisfiedByCallCount(int call_count) const {
|
||||
bool IsSatisfiedByCallCount(int call_count) const override {
|
||||
return call_count % 2 == 0;
|
||||
}
|
||||
|
||||
// Returns true iff call_count calls will saturate this cardinality.
|
||||
virtual bool IsSaturatedByCallCount(int /* call_count */) const {
|
||||
bool IsSaturatedByCallCount(int /* call_count */) const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Describes self to an ostream.
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
void DescribeTo(::std::ostream* os) const override {
|
||||
*os << "called even number of times";
|
||||
}
|
||||
};
|
||||
@ -2023,7 +2023,9 @@ class VerboseFlagPreservingFixture : public testing::Test {
|
||||
VerboseFlagPreservingFixture()
|
||||
: saved_verbose_flag_(GMOCK_FLAG(verbose)) {}
|
||||
|
||||
~VerboseFlagPreservingFixture() { GMOCK_FLAG(verbose) = saved_verbose_flag_; }
|
||||
~VerboseFlagPreservingFixture() override {
|
||||
GMOCK_FLAG(verbose) = saved_verbose_flag_;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string saved_verbose_flag_;
|
||||
@ -2619,7 +2621,7 @@ TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
|
||||
|
||||
TEST(VerifyAndClearTest,
|
||||
DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
|
||||
linked_ptr<MockA> a(new MockA);
|
||||
std::shared_ptr<MockA> a(new MockA);
|
||||
ReferenceHoldingMock test_mock;
|
||||
|
||||
// EXPECT_CALL stores a reference to a inside test_mock.
|
||||
@ -2639,7 +2641,7 @@ TEST(VerifyAndClearTest,
|
||||
|
||||
TEST(VerifyAndClearTest,
|
||||
DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
|
||||
linked_ptr<MockA> a(new MockA);
|
||||
std::shared_ptr<MockA> a(new MockA);
|
||||
ReferenceHoldingMock test_mock;
|
||||
|
||||
// ON_CALL stores a reference to a inside test_mock.
|
||||
|
@ -414,7 +414,7 @@ TEST(LinkTest, TestThrow) {
|
||||
Mock mock;
|
||||
|
||||
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
|
||||
EXPECT_THROW(mock.VoidFromString(NULL), int);
|
||||
EXPECT_THROW(mock.VoidFromString(nullptr), int);
|
||||
}
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
|
@ -60,87 +60,8 @@ void JoinAndDelete(ThreadWithParam<T>* t) {
|
||||
delete t;
|
||||
}
|
||||
|
||||
using internal::linked_ptr;
|
||||
|
||||
// Helper classes for testing using linked_ptr concurrently.
|
||||
|
||||
class Base {
|
||||
public:
|
||||
explicit Base(int a_x) : x_(a_x) {}
|
||||
virtual ~Base() {}
|
||||
int x() const { return x_; }
|
||||
private:
|
||||
int x_;
|
||||
};
|
||||
|
||||
class Derived1 : public Base {
|
||||
public:
|
||||
Derived1(int a_x, int a_y) : Base(a_x), y_(a_y) {}
|
||||
int y() const { return y_; }
|
||||
private:
|
||||
int y_;
|
||||
};
|
||||
|
||||
class Derived2 : public Base {
|
||||
public:
|
||||
Derived2(int a_x, int a_z) : Base(a_x), z_(a_z) {}
|
||||
int z() const { return z_; }
|
||||
private:
|
||||
int z_;
|
||||
};
|
||||
|
||||
linked_ptr<Derived1> pointer1(new Derived1(1, 2));
|
||||
linked_ptr<Derived2> pointer2(new Derived2(3, 4));
|
||||
|
||||
struct Dummy {};
|
||||
|
||||
// Tests that we can copy from a linked_ptr and read it concurrently.
|
||||
void TestConcurrentCopyAndReadLinkedPtr(Dummy /* dummy */) {
|
||||
// Reads pointer1 and pointer2 while they are being copied from in
|
||||
// another thread.
|
||||
EXPECT_EQ(1, pointer1->x());
|
||||
EXPECT_EQ(2, pointer1->y());
|
||||
EXPECT_EQ(3, pointer2->x());
|
||||
EXPECT_EQ(4, pointer2->z());
|
||||
|
||||
// Copies from pointer1.
|
||||
linked_ptr<Derived1> p1(pointer1);
|
||||
EXPECT_EQ(1, p1->x());
|
||||
EXPECT_EQ(2, p1->y());
|
||||
|
||||
// Assigns from pointer2 where the LHS was empty.
|
||||
linked_ptr<Base> p2;
|
||||
p2 = pointer1;
|
||||
EXPECT_EQ(1, p2->x());
|
||||
|
||||
// Assigns from pointer2 where the LHS was not empty.
|
||||
p2 = pointer2;
|
||||
EXPECT_EQ(3, p2->x());
|
||||
}
|
||||
|
||||
const linked_ptr<Derived1> p0(new Derived1(1, 2));
|
||||
|
||||
// Tests that we can concurrently modify two linked_ptrs that point to
|
||||
// the same object.
|
||||
void TestConcurrentWriteToEqualLinkedPtr(Dummy /* dummy */) {
|
||||
// p1 and p2 point to the same, shared thing. One thread resets p1.
|
||||
// Another thread assigns to p2. This will cause the same
|
||||
// underlying "ring" to be updated concurrently.
|
||||
linked_ptr<Derived1> p1(p0);
|
||||
linked_ptr<Derived1> p2(p0);
|
||||
|
||||
EXPECT_EQ(1, p1->x());
|
||||
EXPECT_EQ(2, p1->y());
|
||||
|
||||
EXPECT_EQ(1, p2->x());
|
||||
EXPECT_EQ(2, p2->y());
|
||||
|
||||
p1.reset();
|
||||
p2 = p0;
|
||||
|
||||
EXPECT_EQ(1, p2->x());
|
||||
EXPECT_EQ(2, p2->y());
|
||||
}
|
||||
|
||||
// Tests that different mock objects can be used in their respective
|
||||
// threads. This should generate no Google Test failure.
|
||||
@ -275,8 +196,6 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
|
||||
// Tests using Google Mock constructs in many threads concurrently.
|
||||
TEST(StressTest, CanUseGMockWithThreads) {
|
||||
void (*test_routines[])(Dummy dummy) = {
|
||||
&TestConcurrentCopyAndReadLinkedPtr,
|
||||
&TestConcurrentWriteToEqualLinkedPtr,
|
||||
&TestConcurrentMockObjects,
|
||||
&TestConcurrentCallsOnSameObject,
|
||||
&TestPartiallyOrderedExpectationsWithThreads,
|
||||
|
@ -110,18 +110,6 @@ set(gtest_build_include_dirs
|
||||
"${gtest_SOURCE_DIR}")
|
||||
include_directories(${gtest_build_include_dirs})
|
||||
|
||||
# Summary of tuple support for Microsoft Visual Studio:
|
||||
# Compiler version(MS) version(cmake) Support
|
||||
# ---------- ----------- -------------- -----------------------------
|
||||
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
|
||||
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
|
||||
# VS 2013 12 1800 std::tr1::tuple
|
||||
# VS 2015 14 1900 std::tuple
|
||||
# VS 2017 15 >= 1910 std::tuple
|
||||
if (MSVC AND MSVC_VERSION EQUAL 1700)
|
||||
add_definitions(/D _VARIADIC_MAX=10)
|
||||
endif()
|
||||
|
||||
########################################################################
|
||||
#
|
||||
# Defines the gtest & gtest_main libraries. User tests should link
|
||||
@ -207,7 +195,6 @@ $env:Path = \"$project_bin;$env:Path\"
|
||||
cxx_test(googletest-death-test-test gtest_main)
|
||||
cxx_test(gtest_environment_test gtest)
|
||||
cxx_test(googletest-filepath-test gtest_main)
|
||||
cxx_test(googletest-linked-ptr-test gtest_main)
|
||||
cxx_test(googletest-listener-test gtest_main)
|
||||
cxx_test(gtest_main_unittest gtest_main)
|
||||
cxx_test(googletest-message-test gtest_main)
|
||||
@ -265,21 +252,6 @@ $env:Path = \"$project_bin;$env:Path\"
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
||||
|
||||
if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
|
||||
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
|
||||
# conflict with our own definitions. Therefore using our own tuple does not
|
||||
# work on those compilers.
|
||||
cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}"
|
||||
src/gtest-all.cc src/gtest_main.cc)
|
||||
|
||||
cxx_test_with_flags(googletest-tuple-test "${cxx_use_own_tuple}"
|
||||
gtest_main_use_own_tuple test/googletest-tuple-test.cc)
|
||||
|
||||
cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}"
|
||||
gtest_main_use_own_tuple
|
||||
test/googletest-param-test-test.cc test/googletest-param-test2-test.cc)
|
||||
endif()
|
||||
|
||||
############################################################
|
||||
# Python tests.
|
||||
|
||||
|
@ -9,7 +9,6 @@ EXTRA_DIST = \
|
||||
LICENSE \
|
||||
include/gtest/gtest-param-test.h.pump \
|
||||
include/gtest/internal/gtest-param-util-generated.h.pump \
|
||||
include/gtest/internal/gtest-tuple.h.pump \
|
||||
include/gtest/internal/gtest-type-util.h.pump \
|
||||
make/Makefile \
|
||||
scripts/fuse_gtest_files.py \
|
||||
@ -49,7 +48,6 @@ EXTRA_DIST += \
|
||||
test/gtest-death-test_ex_test.cc \
|
||||
test/gtest-death-test_test.cc \
|
||||
test/gtest-filepath_test.cc \
|
||||
test/gtest-linked_ptr_test.cc \
|
||||
test/gtest-listener_test.cc \
|
||||
test/gtest-message_test.cc \
|
||||
test/gtest-options_test.cc \
|
||||
@ -62,7 +60,6 @@ EXTRA_DIST += \
|
||||
test/gtest_premature_exit_test.cc \
|
||||
test/gtest-printers_test.cc \
|
||||
test/gtest-test-part_test.cc \
|
||||
test/googletest-tuple-test.cc \
|
||||
test/gtest-typed-test2_test.cc \
|
||||
test/gtest-typed-test_test.cc \
|
||||
test/gtest-typed-test_test.h \
|
||||
@ -202,13 +199,11 @@ pkginclude_internal_HEADERS = \
|
||||
include/gtest/internal/gtest-death-test-internal.h \
|
||||
include/gtest/internal/gtest-filepath.h \
|
||||
include/gtest/internal/gtest-internal.h \
|
||||
include/gtest/internal/gtest-linked_ptr.h \
|
||||
include/gtest/internal/gtest-param-util-generated.h \
|
||||
include/gtest/internal/gtest-param-util.h \
|
||||
include/gtest/internal/gtest-port.h \
|
||||
include/gtest/internal/gtest-port-arch.h \
|
||||
include/gtest/internal/gtest-string.h \
|
||||
include/gtest/internal/gtest-tuple.h \
|
||||
include/gtest/internal/gtest-type-util.h \
|
||||
include/gtest/internal/custom/gtest.h \
|
||||
include/gtest/internal/custom/gtest-port.h \
|
||||
|
@ -18,7 +18,7 @@ with `${GTEST_DIR}/include` in the system header search path and `${GTEST_DIR}`
|
||||
in the normal header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
g++ -std=c++11 -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
ar -rv libgtest.a gtest-all.o
|
||||
|
||||
@ -28,7 +28,7 @@ Next, you should compile your test source file with `${GTEST_DIR}/include` in
|
||||
the system header search path, and link it with gtest and any other necessary
|
||||
libraries:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
|
||||
g++ -std=c++11 -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
|
||||
-o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can use to build
|
||||
@ -124,8 +124,8 @@ include(ExternalProject)
|
||||
ExternalProject_Add(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG master
|
||||
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
|
||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
@ -140,13 +140,13 @@ Existing build's `CMakeLists.txt`:
|
||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
||||
endif()
|
||||
@ -157,8 +157,8 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Add googletest directly to our build. This defines
|
||||
# the gtest and gtest_main targets.
|
||||
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
|
||||
${CMAKE_BINARY_DIR}/googletest-build
|
||||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# The gtest/gtest_main targets carry header search path
|
||||
@ -192,6 +192,15 @@ Google Test already has a CMake option for this: `gtest_force_shared_crt`
|
||||
Enabling this option will make gtest link the runtimes dynamically too, and
|
||||
match the project in which it is included.
|
||||
|
||||
#### C++ Standard Version
|
||||
|
||||
An environment that supports C++11 is required in order to successfully build
|
||||
Google Test. One way to ensure this is to specify the standard in the top-level
|
||||
project, for example by using the `set(CMAKE_CXX_STANDARD 11)` command. If this
|
||||
is not feasible, for example in a C project using Google Test for validation,
|
||||
then it can be specified by adding it to the options for cmake via the
|
||||
`DCMAKE_CXX_FLAGS` option.
|
||||
|
||||
### Legacy Build Scripts
|
||||
|
||||
Before settling on CMake, we have been providing hand-maintained build
|
||||
|
@ -1,5 +1,6 @@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
prefix=${pcfiledir}/../..
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: gtest
|
||||
Description: GoogleTest (without main() function)
|
||||
|
@ -1,5 +1,6 @@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
prefix=${pcfiledir}/../..
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
|
||||
Name: gtest_main
|
||||
Description: GoogleTest (with main() function)
|
||||
|
@ -56,7 +56,6 @@ macro(config_compiler_and_linker)
|
||||
unset(GTEST_HAS_PTHREAD)
|
||||
if (NOT gtest_disable_pthreads AND NOT MINGW)
|
||||
# Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads)
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
set(GTEST_HAS_PTHREAD ON)
|
||||
@ -68,36 +67,14 @@ macro(config_compiler_and_linker)
|
||||
# Newlines inside flags variables break CMake's NMake generator.
|
||||
# TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
|
||||
set(cxx_base_flags "-GS -W4 -WX -wd4251 -wd4275 -nologo -J -Zi")
|
||||
if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005
|
||||
# Suppress spurious warnings MSVC 7.1 sometimes issues.
|
||||
# Forcing value to bool.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4800")
|
||||
# Copy constructor and assignment operator could not be generated.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512")
|
||||
# Compatibility warnings not applicable to Google Test.
|
||||
# Resolved overload was found by argument-dependent lookup.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4675")
|
||||
endif()
|
||||
if (MSVC_VERSION LESS 1500) # 1500 is Visual Studio 2008
|
||||
# Conditional expression is constant.
|
||||
# When compiling with /W4, we get several instances of C4127
|
||||
# (Conditional expression is constant). In our code, we disable that
|
||||
# warning on a case-by-case basis. However, on Visual Studio 2005,
|
||||
# the warning fires on std::list. Therefore on that compiler and earlier,
|
||||
# we disable the warning project-wide.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4127")
|
||||
endif()
|
||||
if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012.
|
||||
# Suppress "unreachable code" warning on VS 2012 and later.
|
||||
# http://stackoverflow.com/questions/3232669 explains the issue.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4702")
|
||||
endif()
|
||||
|
||||
set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
|
||||
set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
|
||||
set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
|
||||
set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
|
||||
set(cxx_no_rtti_flags "-GR-")
|
||||
# Suppress "unreachable code" warning
|
||||
# http://stackoverflow.com/questions/3232669 explains the issue.
|
||||
set(cxx_base_flags "${cxx_base_flags} -wd4702")
|
||||
elseif (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(cxx_base_flags "-Wall -Wshadow -Werror")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
|
||||
@ -148,7 +125,6 @@ macro(config_compiler_and_linker)
|
||||
"${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}")
|
||||
set(cxx_default "${cxx_exception}")
|
||||
set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
|
||||
set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
|
||||
|
||||
# For building the gtest libraries.
|
||||
set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
|
||||
@ -220,7 +196,7 @@ endfunction()
|
||||
# is built from the given source files with the given compiler flags.
|
||||
function(cxx_executable_with_flags name cxx_flags libs)
|
||||
add_executable(${name} ${ARGN})
|
||||
if (MSVC AND (NOT (MSVC_VERSION LESS 1700))) # 1700 is Visual Studio 2012.
|
||||
if (MSVC)
|
||||
# BigObj required for tests.
|
||||
set(cxx_flags "${cxx_flags} -bigobj")
|
||||
endif()
|
||||
@ -353,7 +329,7 @@ function(install_project)
|
||||
get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG)
|
||||
get_target_property(t_pdb_output_directory ${t} PDB_OUTPUT_DIRECTORY)
|
||||
install(FILES
|
||||
"${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<IF:$<CONFIG:Debug>,${t_pdb_name_debug},${t_pdb_name}>.pdb"
|
||||
"${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<$<CONFIG:Debug>:${t_pdb_name_debug}>$<$<NOT:$<CONFIG:Debug>>:${t_pdb_name}>.pdb"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
OPTIONAL)
|
||||
endforeach()
|
||||
|
@ -1487,7 +1487,7 @@ returns the value of `testing::PrintToString(GetParam())`. It does not work for
|
||||
|
||||
NOTE: test names must be non-empty, unique, and may only contain ASCII
|
||||
alphanumeric characters. In particular, they [should not contain
|
||||
underscores](https://g3doc.corp.google.com/third_party/googletest/googletest/g3doc/faq.md#no-underscores).
|
||||
underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-case-names-and-test-names-not-contain-underscore).
|
||||
|
||||
```c++
|
||||
class MyTestCase : public testing::TestWithParam<int> {};
|
||||
|
817
googletest/include/gtest/gtest-matchers.h
Normal file
817
googletest/include/gtest/gtest-matchers.h
Normal file
@ -0,0 +1,817 @@
|
||||
// Copyright 2007, 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.
|
||||
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file implements just enough of the matcher interface to allow
|
||||
// EXPECT_DEATH and friends to accept a matcher argument.
|
||||
|
||||
// IWYU pragma: private, include "testing/base/public/gunit.h"
|
||||
// IWYU pragma: friend third_party/googletest/googlemock/.*
|
||||
// IWYU pragma: friend third_party/googletest/googletest/.*
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(
|
||||
4251 5046 /* class A needs to have dll-interface to be used by clients of
|
||||
class B */
|
||||
/* Symbol involving type with internal linkage not defined */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// To implement a matcher Foo for type T, define:
|
||||
// 1. a class FooMatcherImpl that implements the
|
||||
// MatcherInterface<T> interface, and
|
||||
// 2. a factory function that creates a Matcher<T> object from a
|
||||
// FooMatcherImpl*.
|
||||
//
|
||||
// The two-level delegation design makes it possible to allow a user
|
||||
// to write "v" instead of "Eq(v)" where a Matcher is expected, which
|
||||
// is impossible if we pass matchers by pointers. It also eases
|
||||
// ownership management as Matcher objects can now be copied like
|
||||
// plain values.
|
||||
|
||||
// MatchResultListener is an abstract class. Its << operator can be
|
||||
// used by a matcher to explain why a value matches or doesn't match.
|
||||
//
|
||||
// FIXME: add method
|
||||
// bool InterestedInWhy(bool result) const;
|
||||
// to indicate whether the listener is interested in why the match
|
||||
// result is 'result'.
|
||||
class MatchResultListener {
|
||||
public:
|
||||
// Creates a listener object with the given underlying ostream. The
|
||||
// listener does not own the ostream, and does not dereference it
|
||||
// in the constructor or destructor.
|
||||
explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
|
||||
virtual ~MatchResultListener() = 0; // Makes this class abstract.
|
||||
|
||||
// Streams x to the underlying ostream; does nothing if the ostream
|
||||
// is NULL.
|
||||
template <typename T>
|
||||
MatchResultListener& operator<<(const T& x) {
|
||||
if (stream_ != nullptr) *stream_ << x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Returns the underlying ostream.
|
||||
::std::ostream* stream() { return stream_; }
|
||||
|
||||
// Returns true iff the listener is interested in an explanation of
|
||||
// the match result. A matcher's MatchAndExplain() method can use
|
||||
// this information to avoid generating the explanation when no one
|
||||
// intends to hear it.
|
||||
bool IsInterested() const { return stream_ != nullptr; }
|
||||
|
||||
private:
|
||||
::std::ostream* const stream_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
|
||||
};
|
||||
|
||||
inline MatchResultListener::~MatchResultListener() {
|
||||
}
|
||||
|
||||
// An instance of a subclass of this knows how to describe itself as a
|
||||
// matcher.
|
||||
class MatcherDescriberInterface {
|
||||
public:
|
||||
virtual ~MatcherDescriberInterface() {}
|
||||
|
||||
// Describes this matcher to an ostream. The function should print
|
||||
// a verb phrase that describes the property a value matching this
|
||||
// matcher should have. The subject of the verb phrase is the value
|
||||
// being matched. For example, the DescribeTo() method of the Gt(7)
|
||||
// matcher prints "is greater than 7".
|
||||
virtual void DescribeTo(::std::ostream* os) const = 0;
|
||||
|
||||
// Describes the negation of this matcher to an ostream. For
|
||||
// example, if the description of this matcher is "is greater than
|
||||
// 7", the negated description could be "is not greater than 7".
|
||||
// You are not required to override this when implementing
|
||||
// MatcherInterface, but it is highly advised so that your matcher
|
||||
// can produce good error messages.
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "not (";
|
||||
DescribeTo(os);
|
||||
*os << ")";
|
||||
}
|
||||
};
|
||||
|
||||
// The implementation of a matcher.
|
||||
template <typename T>
|
||||
class MatcherInterface : public MatcherDescriberInterface {
|
||||
public:
|
||||
// Returns true iff the matcher matches x; also explains the match
|
||||
// result to 'listener' if necessary (see the next paragraph), in
|
||||
// the form of a non-restrictive relative clause ("which ...",
|
||||
// "whose ...", etc) that describes x. For example, the
|
||||
// MatchAndExplain() method of the Pointee(...) matcher should
|
||||
// generate an explanation like "which points to ...".
|
||||
//
|
||||
// Implementations of MatchAndExplain() should add an explanation of
|
||||
// the match result *if and only if* they can provide additional
|
||||
// information that's not already present (or not obvious) in the
|
||||
// print-out of x and the matcher's description. Whether the match
|
||||
// succeeds is not a factor in deciding whether an explanation is
|
||||
// needed, as sometimes the caller needs to print a failure message
|
||||
// when the match succeeds (e.g. when the matcher is used inside
|
||||
// Not()).
|
||||
//
|
||||
// For example, a "has at least 10 elements" matcher should explain
|
||||
// what the actual element count is, regardless of the match result,
|
||||
// as it is useful information to the reader; on the other hand, an
|
||||
// "is empty" matcher probably only needs to explain what the actual
|
||||
// size is when the match fails, as it's redundant to say that the
|
||||
// size is 0 when the value is already known to be empty.
|
||||
//
|
||||
// You should override this method when defining a new matcher.
|
||||
//
|
||||
// It's the responsibility of the caller (Google Test) to guarantee
|
||||
// that 'listener' is not NULL. This helps to simplify a matcher's
|
||||
// implementation when it doesn't care about the performance, as it
|
||||
// can talk to 'listener' without checking its validity first.
|
||||
// However, in order to implement dummy listeners efficiently,
|
||||
// listener->stream() may be NULL.
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
|
||||
|
||||
// Inherits these methods from MatcherDescriberInterface:
|
||||
// virtual void DescribeTo(::std::ostream* os) const = 0;
|
||||
// virtual void DescribeNegationTo(::std::ostream* os) const;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Converts a MatcherInterface<T> to a MatcherInterface<const T&>.
|
||||
template <typename T>
|
||||
class MatcherInterfaceAdapter : public MatcherInterface<const T&> {
|
||||
public:
|
||||
explicit MatcherInterfaceAdapter(const MatcherInterface<T>* impl)
|
||||
: impl_(impl) {}
|
||||
~MatcherInterfaceAdapter() override { delete impl_; }
|
||||
|
||||
void DescribeTo(::std::ostream* os) const override { impl_->DescribeTo(os); }
|
||||
|
||||
void DescribeNegationTo(::std::ostream* os) const override {
|
||||
impl_->DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
bool MatchAndExplain(const T& x,
|
||||
MatchResultListener* listener) const override {
|
||||
return impl_->MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
private:
|
||||
const MatcherInterface<T>* const impl_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter);
|
||||
};
|
||||
|
||||
struct AnyEq {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a == b; }
|
||||
};
|
||||
struct AnyNe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a != b; }
|
||||
};
|
||||
struct AnyLt {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a < b; }
|
||||
};
|
||||
struct AnyGt {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a > b; }
|
||||
};
|
||||
struct AnyLe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a <= b; }
|
||||
};
|
||||
struct AnyGe {
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const { return a >= b; }
|
||||
};
|
||||
|
||||
// A match result listener that ignores the explanation.
|
||||
class DummyMatchResultListener : public MatchResultListener {
|
||||
public:
|
||||
DummyMatchResultListener() : MatchResultListener(nullptr) {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
|
||||
};
|
||||
|
||||
// A match result listener that forwards the explanation to a given
|
||||
// ostream. The difference between this and MatchResultListener is
|
||||
// that the former is concrete.
|
||||
class StreamMatchResultListener : public MatchResultListener {
|
||||
public:
|
||||
explicit StreamMatchResultListener(::std::ostream* os)
|
||||
: MatchResultListener(os) {}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
|
||||
};
|
||||
|
||||
// An internal class for implementing Matcher<T>, which will derive
|
||||
// from it. We put functionalities common to all Matcher<T>
|
||||
// specializations here to avoid code duplication.
|
||||
template <typename T>
|
||||
class MatcherBase {
|
||||
public:
|
||||
// Returns true iff the matcher matches x; also explains the match
|
||||
// result to 'listener'.
|
||||
bool MatchAndExplain(const T& x, MatchResultListener* listener) const {
|
||||
return impl_->MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
// Returns true iff this matcher matches x.
|
||||
bool Matches(const T& x) const {
|
||||
DummyMatchResultListener dummy;
|
||||
return MatchAndExplain(x, &dummy);
|
||||
}
|
||||
|
||||
// Describes this matcher to an ostream.
|
||||
void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
|
||||
|
||||
// Describes the negation of this matcher to an ostream.
|
||||
void DescribeNegationTo(::std::ostream* os) const {
|
||||
impl_->DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
// Explains why x matches, or doesn't match, the matcher.
|
||||
void ExplainMatchResultTo(const T& x, ::std::ostream* os) const {
|
||||
StreamMatchResultListener listener(os);
|
||||
MatchAndExplain(x, &listener);
|
||||
}
|
||||
|
||||
// Returns the describer for this matcher object; retains ownership
|
||||
// of the describer, which is only guaranteed to be alive when
|
||||
// this matcher object is alive.
|
||||
const MatcherDescriberInterface* GetDescriber() const {
|
||||
return impl_.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
MatcherBase() {}
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit MatcherBase(const MatcherInterface<const T&>* impl) : impl_(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit MatcherBase(
|
||||
const MatcherInterface<U>* impl,
|
||||
typename internal::EnableIf<
|
||||
!internal::IsSame<U, const U&>::value>::type* = nullptr)
|
||||
: impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
|
||||
|
||||
virtual ~MatcherBase() {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<const MatcherInterface<const T&>> impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that can check whether a value of type T matches. The
|
||||
// implementation of Matcher<T> is just a std::shared_ptr to const
|
||||
// MatcherInterface<T>. Don't inherit from Matcher!
|
||||
template <typename T>
|
||||
class Matcher : public internal::MatcherBase<T> {
|
||||
public:
|
||||
// Constructs a null matcher. Needed for storing Matcher objects in STL
|
||||
// containers. A default-constructed matcher is not yet initialized. You
|
||||
// cannot use it until a valid value has been assigned to it.
|
||||
explicit Matcher() {} // NOLINT
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit Matcher(const MatcherInterface<const T&>* impl)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
template <typename U>
|
||||
explicit Matcher(const MatcherInterface<U>* impl,
|
||||
typename internal::EnableIf<
|
||||
!internal::IsSame<U, const U&>::value>::type* = nullptr)
|
||||
: internal::MatcherBase<T>(impl) {}
|
||||
|
||||
// Implicit constructor here allows people to write
|
||||
// EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes
|
||||
Matcher(T value); // NOLINT
|
||||
};
|
||||
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const std::string&>
|
||||
: public internal::MatcherBase<const std::string&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||
: internal::MatcherBase<const std::string&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<std::string>
|
||||
: public internal::MatcherBase<std::string> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<std::string>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a ::string
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const ::string&>
|
||||
: public internal::MatcherBase<const ::string&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const ::string&>* impl)
|
||||
: internal::MatcherBase<const ::string&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher< ::string>
|
||||
: public internal::MatcherBase< ::string> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const ::string&>* impl)
|
||||
: internal::MatcherBase< ::string>(impl) {}
|
||||
explicit Matcher(const MatcherInterface< ::string>* impl)
|
||||
: internal::MatcherBase< ::string>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const absl::string_view&>
|
||||
: public internal::MatcherBase<const absl::string_view&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<const absl::string_view&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<absl::string_view>
|
||||
: public internal::MatcherBase<absl::string_view> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<absl::string_view>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Prints a matcher in a human-readable format.
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
|
||||
matcher.DescribeTo(&os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// The PolymorphicMatcher class template makes it easy to implement a
|
||||
// polymorphic matcher (i.e. a matcher that can match values of more
|
||||
// than one type, e.g. Eq(n) and NotNull()).
|
||||
//
|
||||
// To define a polymorphic matcher, a user should provide an Impl
|
||||
// class that has a DescribeTo() method and a DescribeNegationTo()
|
||||
// method, and define a member function (or member function template)
|
||||
//
|
||||
// bool MatchAndExplain(const Value& value,
|
||||
// MatchResultListener* listener) const;
|
||||
//
|
||||
// See the definition of NotNull() for a complete example.
|
||||
template <class Impl>
|
||||
class PolymorphicMatcher {
|
||||
public:
|
||||
explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
|
||||
|
||||
// Returns a mutable reference to the underlying matcher
|
||||
// implementation object.
|
||||
Impl& mutable_impl() { return impl_; }
|
||||
|
||||
// Returns an immutable reference to the underlying matcher
|
||||
// implementation object.
|
||||
const Impl& impl() const { return impl_; }
|
||||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new MonomorphicImpl<const T&>(impl_));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
class MonomorphicImpl : public MatcherInterface<T> {
|
||||
public:
|
||||
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const { impl_.DescribeTo(os); }
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
impl_.DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
||||
return impl_.MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
private:
|
||||
const Impl impl_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
|
||||
};
|
||||
|
||||
Impl impl_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
|
||||
};
|
||||
|
||||
// Creates a matcher from its implementation. This is easier to use
|
||||
// than the Matcher<T> constructor as it doesn't require you to
|
||||
// explicitly write the template argument, e.g.
|
||||
//
|
||||
// MakeMatcher(foo);
|
||||
// vs
|
||||
// Matcher<const string&>(foo);
|
||||
template <typename T>
|
||||
inline Matcher<T> MakeMatcher(const MatcherInterface<T>* impl) {
|
||||
return Matcher<T>(impl);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher from its implementation. This is
|
||||
// easier to use than the PolymorphicMatcher<Impl> constructor as it
|
||||
// doesn't require you to explicitly write the template argument, e.g.
|
||||
//
|
||||
// MakePolymorphicMatcher(foo);
|
||||
// vs
|
||||
// PolymorphicMatcher<TypeOfFoo>(foo);
|
||||
template <class Impl>
|
||||
inline PolymorphicMatcher<Impl> MakePolymorphicMatcher(const Impl& impl) {
|
||||
return PolymorphicMatcher<Impl>(impl);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
// Implements a matcher that compares a given value with a
|
||||
// pre-supplied value using one of the ==, <=, <, etc, operators. The
|
||||
// two values being compared don't have to have the same type.
|
||||
//
|
||||
// The matcher defined here is polymorphic (for example, Eq(5) can be
|
||||
// used to match an int, a short, a double, etc). Therefore we use
|
||||
// a template type conversion operator in the implementation.
|
||||
//
|
||||
// The following template definition assumes that the Rhs parameter is
|
||||
// a "bare" type (i.e. neither 'const T' nor 'T&').
|
||||
template <typename D, typename Rhs, typename Op>
|
||||
class ComparisonBase {
|
||||
public:
|
||||
explicit ComparisonBase(const Rhs& rhs) : rhs_(rhs) {}
|
||||
template <typename Lhs>
|
||||
operator Matcher<Lhs>() const {
|
||||
return MakeMatcher(new Impl<Lhs>(rhs_));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Lhs>
|
||||
class Impl : public MatcherInterface<Lhs> {
|
||||
public:
|
||||
explicit Impl(const Rhs& rhs) : rhs_(rhs) {}
|
||||
bool MatchAndExplain(Lhs lhs,
|
||||
MatchResultListener* /* listener */) const override {
|
||||
return Op()(lhs, rhs_);
|
||||
}
|
||||
void DescribeTo(::std::ostream* os) const override {
|
||||
*os << D::Desc() << " ";
|
||||
UniversalPrint(rhs_, os);
|
||||
}
|
||||
void DescribeNegationTo(::std::ostream* os) const override {
|
||||
*os << D::NegatedDesc() << " ";
|
||||
UniversalPrint(rhs_, os);
|
||||
}
|
||||
|
||||
private:
|
||||
Rhs rhs_;
|
||||
GTEST_DISALLOW_ASSIGN_(Impl);
|
||||
};
|
||||
Rhs rhs_;
|
||||
GTEST_DISALLOW_ASSIGN_(ComparisonBase);
|
||||
};
|
||||
|
||||
template <typename Rhs>
|
||||
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> {
|
||||
public:
|
||||
explicit EqMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) { }
|
||||
static const char* Desc() { return "is equal to"; }
|
||||
static const char* NegatedDesc() { return "isn't equal to"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> {
|
||||
public:
|
||||
explicit NeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) { }
|
||||
static const char* Desc() { return "isn't equal to"; }
|
||||
static const char* NegatedDesc() { return "is equal to"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> {
|
||||
public:
|
||||
explicit LtMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) { }
|
||||
static const char* Desc() { return "is <"; }
|
||||
static const char* NegatedDesc() { return "isn't <"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> {
|
||||
public:
|
||||
explicit GtMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) { }
|
||||
static const char* Desc() { return "is >"; }
|
||||
static const char* NegatedDesc() { return "isn't >"; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> {
|
||||
public:
|
||||
explicit LeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) { }
|
||||
static const char* Desc() { return "is <="; }
|
||||
static const char* NegatedDesc() { return "isn't <="; }
|
||||
};
|
||||
template <typename Rhs>
|
||||
class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> {
|
||||
public:
|
||||
explicit GeMatcher(const Rhs& rhs)
|
||||
: ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) { }
|
||||
static const char* Desc() { return "is >="; }
|
||||
static const char* NegatedDesc() { return "isn't >="; }
|
||||
};
|
||||
|
||||
// Implements polymorphic matchers MatchesRegex(regex) and
|
||||
// ContainsRegex(regex), which can be used as a Matcher<T> as long as
|
||||
// T can be converted to a string.
|
||||
class MatchesRegexMatcher {
|
||||
public:
|
||||
MatchesRegexMatcher(const RE* regex, bool full_match)
|
||||
: regex_(regex), full_match_(full_match) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
return MatchAndExplain(string(s), listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
// const wchar_t*
|
||||
// wchar_t*
|
||||
template <typename CharType>
|
||||
bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
|
||||
return s != nullptr && MatchAndExplain(std::string(s), listener);
|
||||
}
|
||||
|
||||
// Matches anything that can convert to std::string.
|
||||
//
|
||||
// This is a template, not just a plain function with const std::string&,
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <class MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
const std::string& s2(s);
|
||||
return full_match_ ? RE::FullMatch(s2, *regex_)
|
||||
: RE::PartialMatch(s2, *regex_);
|
||||
}
|
||||
|
||||
void DescribeTo(::std::ostream* os) const {
|
||||
*os << (full_match_ ? "matches" : "contains") << " regular expression ";
|
||||
UniversalPrinter<std::string>::Print(regex_->pattern(), os);
|
||||
}
|
||||
|
||||
void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "doesn't " << (full_match_ ? "match" : "contain")
|
||||
<< " regular expression ";
|
||||
UniversalPrinter<std::string>::Print(regex_->pattern(), os);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<const RE> regex_;
|
||||
const bool full_match_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
// Matches a string that fully matches regular expression 'regex'.
|
||||
// The matcher takes ownership of 'regex'.
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
|
||||
const internal::RE* regex) {
|
||||
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
|
||||
}
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
|
||||
const std::string& regex) {
|
||||
return MatchesRegex(new internal::RE(regex));
|
||||
}
|
||||
|
||||
// Matches a string that contains regular expression 'regex'.
|
||||
// The matcher takes ownership of 'regex'.
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
|
||||
const internal::RE* regex) {
|
||||
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
|
||||
}
|
||||
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
|
||||
const std::string& regex) {
|
||||
return ContainsRegex(new internal::RE(regex));
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything equal to x.
|
||||
// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
|
||||
// wouldn't compile.
|
||||
template <typename T>
|
||||
inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
|
||||
|
||||
// Constructs a Matcher<T> from a 'value' of type T. The constructed
|
||||
// matcher matches any value that's equal to 'value'.
|
||||
template <typename T>
|
||||
Matcher<T>::Matcher(T value) { *this = Eq(value); }
|
||||
|
||||
// Creates a monomorphic matcher that matches anything with type Lhs
|
||||
// and equal to rhs. A user may need to use this instead of Eq(...)
|
||||
// in order to resolve an overloading ambiguity.
|
||||
//
|
||||
// TypedEq<T>(x) is just a convenient short-hand for Matcher<T>(Eq(x))
|
||||
// or Matcher<T>(x), but more readable than the latter.
|
||||
//
|
||||
// We could define similar monomorphic matchers for other comparison
|
||||
// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do
|
||||
// it yet as those are used much less than Eq() in practice. A user
|
||||
// can always write Matcher<T>(Lt(5)) to be explicit about the type,
|
||||
// for example.
|
||||
template <typename Lhs, typename Rhs>
|
||||
inline Matcher<Lhs> TypedEq(const Rhs& rhs) { return Eq(rhs); }
|
||||
|
||||
// Creates a polymorphic matcher that matches anything >= x.
|
||||
template <typename Rhs>
|
||||
inline internal::GeMatcher<Rhs> Ge(Rhs x) {
|
||||
return internal::GeMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything > x.
|
||||
template <typename Rhs>
|
||||
inline internal::GtMatcher<Rhs> Gt(Rhs x) {
|
||||
return internal::GtMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything <= x.
|
||||
template <typename Rhs>
|
||||
inline internal::LeMatcher<Rhs> Le(Rhs x) {
|
||||
return internal::LeMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything < x.
|
||||
template <typename Rhs>
|
||||
inline internal::LtMatcher<Rhs> Lt(Rhs x) {
|
||||
return internal::LtMatcher<Rhs>(x);
|
||||
}
|
||||
|
||||
// Creates a polymorphic matcher that matches anything != x.
|
||||
template <typename Rhs>
|
||||
inline internal::NeMatcher<Rhs> Ne(Rhs x) {
|
||||
return internal::NeMatcher<Rhs>(x);
|
||||
}
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
|
@ -48,6 +48,7 @@
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
@ -207,7 +208,7 @@ class GTEST_API_ Message {
|
||||
// tr1::type_traits-like is_pointer works, and we can overload on that.
|
||||
template <typename T>
|
||||
inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
|
||||
if (pointer == NULL) {
|
||||
if (pointer == nullptr) {
|
||||
*ss_ << "(null)";
|
||||
} else {
|
||||
*ss_ << pointer;
|
||||
@ -224,7 +225,7 @@ class GTEST_API_ Message {
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
|
||||
// We'll hold the text streamed to this object here.
|
||||
const internal::scoped_ptr< ::std::stringstream> ss_;
|
||||
const std::unique_ptr< ::std::stringstream> ss_;
|
||||
|
||||
// We declare (but don't implement) this to prevent the compiler
|
||||
// from implementing the assignment operator.
|
||||
|
@ -336,859 +336,10 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
//
|
||||
// Currently, Values() supports from 1 to 50 parameters.
|
||||
//
|
||||
template <typename T1>
|
||||
internal::ValueArray1<T1> Values(T1 v1) {
|
||||
return internal::ValueArray1<T1>(v1);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
internal::ValueArray2<T1, T2> Values(T1 v1, T2 v2) {
|
||||
return internal::ValueArray2<T1, T2>(v1, v2);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
internal::ValueArray3<T1, T2, T3> Values(T1 v1, T2 v2, T3 v3) {
|
||||
return internal::ValueArray3<T1, T2, T3>(v1, v2, v3);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
internal::ValueArray4<T1, T2, T3, T4> Values(T1 v1, T2 v2, T3 v3, T4 v4) {
|
||||
return internal::ValueArray4<T1, T2, T3, T4>(v1, v2, v3, v4);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
internal::ValueArray5<T1, T2, T3, T4, T5> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5) {
|
||||
return internal::ValueArray5<T1, T2, T3, T4, T5>(v1, v2, v3, v4, v5);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6>
|
||||
internal::ValueArray6<T1, T2, T3, T4, T5, T6> Values(T1 v1, T2 v2, T3 v3,
|
||||
T4 v4, T5 v5, T6 v6) {
|
||||
return internal::ValueArray6<T1, T2, T3, T4, T5, T6>(v1, v2, v3, v4, v5, v6);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7>
|
||||
internal::ValueArray7<T1, T2, T3, T4, T5, T6, T7> Values(T1 v1, T2 v2, T3 v3,
|
||||
T4 v4, T5 v5, T6 v6, T7 v7) {
|
||||
return internal::ValueArray7<T1, T2, T3, T4, T5, T6, T7>(v1, v2, v3, v4, v5,
|
||||
v6, v7);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8>
|
||||
internal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8) {
|
||||
return internal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8>(v1, v2, v3, v4,
|
||||
v5, v6, v7, v8);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9>
|
||||
internal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9) {
|
||||
return internal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(v1, v2, v3,
|
||||
v4, v5, v6, v7, v8, v9);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
internal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Values(T1 v1,
|
||||
T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10) {
|
||||
return internal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(v1,
|
||||
v2, v3, v4, v5, v6, v7, v8, v9, v10);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11>
|
||||
internal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
|
||||
T11> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11) {
|
||||
return internal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
|
||||
T11>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12>
|
||||
internal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12) {
|
||||
return internal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13>
|
||||
internal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
|
||||
T13> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13) {
|
||||
return internal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14>
|
||||
internal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) {
|
||||
return internal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
|
||||
v14);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15>
|
||||
internal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
|
||||
T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) {
|
||||
return internal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
|
||||
v13, v14, v15);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16>
|
||||
internal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16) {
|
||||
return internal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
|
||||
v12, v13, v14, v15, v16);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17>
|
||||
internal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17) {
|
||||
return internal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
|
||||
v11, v12, v13, v14, v15, v16, v17);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18>
|
||||
internal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
|
||||
T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18) {
|
||||
return internal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
|
||||
v10, v11, v12, v13, v14, v15, v16, v17, v18);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19>
|
||||
internal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
|
||||
T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
|
||||
T15 v15, T16 v16, T17 v17, T18 v18, T19 v19) {
|
||||
return internal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19>(v1, v2, v3, v4, v5, v6, v7, v8,
|
||||
v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20>
|
||||
internal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
|
||||
T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20) {
|
||||
return internal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20>(v1, v2, v3, v4, v5, v6, v7,
|
||||
v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21>
|
||||
internal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
|
||||
T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21) {
|
||||
return internal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(v1, v2, v3, v4, v5, v6,
|
||||
v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22>
|
||||
internal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22> Values(T1 v1, T2 v2, T3 v3,
|
||||
T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22) {
|
||||
return internal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22>(v1, v2, v3, v4,
|
||||
v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
|
||||
v20, v21, v22);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23>
|
||||
internal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22, T23 v23) {
|
||||
return internal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23>(v1, v2, v3,
|
||||
v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
|
||||
v20, v21, v22, v23);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24>
|
||||
internal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22, T23 v23, T24 v24) {
|
||||
return internal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24>(v1, v2,
|
||||
v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,
|
||||
v19, v20, v21, v22, v23, v24);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25>
|
||||
internal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Values(T1 v1,
|
||||
T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,
|
||||
T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,
|
||||
T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25) {
|
||||
return internal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25>(v1,
|
||||
v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,
|
||||
v18, v19, v20, v21, v22, v23, v24, v25);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26>
|
||||
internal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26) {
|
||||
return internal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
|
||||
v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27>
|
||||
internal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
|
||||
T27> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27) {
|
||||
return internal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,
|
||||
v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28>
|
||||
internal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
|
||||
T28> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28) {
|
||||
return internal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
|
||||
v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,
|
||||
v28);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29>
|
||||
internal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28, T29 v29) {
|
||||
return internal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
|
||||
v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,
|
||||
v27, v28, v29);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30>
|
||||
internal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
|
||||
T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,
|
||||
T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,
|
||||
T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) {
|
||||
return internal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
|
||||
v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,
|
||||
v26, v27, v28, v29, v30);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31>
|
||||
internal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) {
|
||||
return internal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
|
||||
v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,
|
||||
v25, v26, v27, v28, v29, v30, v31);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32>
|
||||
internal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
|
||||
T32 v32) {
|
||||
return internal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
|
||||
v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
|
||||
v24, v25, v26, v27, v28, v29, v30, v31, v32);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33>
|
||||
internal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
|
||||
T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
|
||||
T32 v32, T33 v33) {
|
||||
return internal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33>(v1, v2, v3, v4, v5, v6, v7, v8,
|
||||
v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
|
||||
v24, v25, v26, v27, v28, v29, v30, v31, v32, v33);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34>
|
||||
internal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
|
||||
T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
|
||||
T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,
|
||||
T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,
|
||||
T31 v31, T32 v32, T33 v33, T34 v34) {
|
||||
return internal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34>(v1, v2, v3, v4, v5, v6, v7,
|
||||
v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,
|
||||
v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35>
|
||||
internal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
|
||||
T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
|
||||
T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
|
||||
T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35) {
|
||||
return internal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35>(v1, v2, v3, v4, v5, v6,
|
||||
v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
|
||||
v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36>
|
||||
internal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
|
||||
T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
|
||||
T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
|
||||
T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36) {
|
||||
return internal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36>(v1, v2, v3, v4,
|
||||
v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
|
||||
v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
|
||||
v34, v35, v36);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37>
|
||||
internal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37> Values(T1 v1, T2 v2, T3 v3,
|
||||
T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
|
||||
T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
|
||||
T37 v37) {
|
||||
return internal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37>(v1, v2, v3,
|
||||
v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
|
||||
v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
|
||||
v34, v35, v36, v37);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38>
|
||||
internal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
|
||||
T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
|
||||
T37 v37, T38 v38) {
|
||||
return internal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38>(v1, v2,
|
||||
v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,
|
||||
v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32,
|
||||
v33, v34, v35, v36, v37, v38);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39>
|
||||
internal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Values(T1 v1, T2 v2,
|
||||
T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
|
||||
T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
|
||||
T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
|
||||
T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
|
||||
T37 v37, T38 v38, T39 v39) {
|
||||
return internal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39>(v1,
|
||||
v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,
|
||||
v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
|
||||
v32, v33, v34, v35, v36, v37, v38, v39);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40>
|
||||
internal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Values(T1 v1,
|
||||
T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,
|
||||
T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,
|
||||
T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27,
|
||||
T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35,
|
||||
T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) {
|
||||
return internal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
|
||||
v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29,
|
||||
v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41>
|
||||
internal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
|
||||
T41> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
|
||||
T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41) {
|
||||
return internal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,
|
||||
v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28,
|
||||
v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42>
|
||||
internal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
|
||||
T42> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
|
||||
T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
|
||||
T42 v42) {
|
||||
return internal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
|
||||
v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,
|
||||
v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41,
|
||||
v42);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43>
|
||||
internal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
|
||||
T43> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
|
||||
T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
|
||||
T42 v42, T43 v43) {
|
||||
return internal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
|
||||
v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,
|
||||
v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,
|
||||
v41, v42, v43);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44>
|
||||
internal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
|
||||
T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
|
||||
T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
|
||||
T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
|
||||
T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
|
||||
T42 v42, T43 v43, T44 v44) {
|
||||
return internal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
|
||||
v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,
|
||||
v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39,
|
||||
v40, v41, v42, v43, v44);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45>
|
||||
internal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
|
||||
T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,
|
||||
T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,
|
||||
T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32,
|
||||
T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40,
|
||||
T41 v41, T42 v42, T43 v43, T44 v44, T45 v45) {
|
||||
return internal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
|
||||
v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,
|
||||
v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38,
|
||||
v39, v40, v41, v42, v43, v44, v45);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45,
|
||||
typename T46>
|
||||
internal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45, T46> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
|
||||
T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
|
||||
T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) {
|
||||
return internal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45, T46>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
|
||||
v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
|
||||
v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,
|
||||
v38, v39, v40, v41, v42, v43, v44, v45, v46);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45,
|
||||
typename T46, typename T47>
|
||||
internal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45, T46, T47> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
|
||||
T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
|
||||
T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
|
||||
T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) {
|
||||
return internal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45, T46, T47>(v1, v2, v3, v4, v5, v6, v7, v8,
|
||||
v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
|
||||
v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,
|
||||
v38, v39, v40, v41, v42, v43, v44, v45, v46, v47);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45,
|
||||
typename T46, typename T47, typename T48>
|
||||
internal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45, T46, T47, T48> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
|
||||
T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
|
||||
T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
|
||||
T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
|
||||
T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
|
||||
T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47,
|
||||
T48 v48) {
|
||||
return internal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45, T46, T47, T48>(v1, v2, v3, v4, v5, v6, v7,
|
||||
v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,
|
||||
v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36,
|
||||
v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45,
|
||||
typename T46, typename T47, typename T48, typename T49>
|
||||
internal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45, T46, T47, T48, T49> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
|
||||
T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
|
||||
T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,
|
||||
T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,
|
||||
T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38,
|
||||
T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46,
|
||||
T47 v47, T48 v48, T49 v49) {
|
||||
return internal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45, T46, T47, T48, T49>(v1, v2, v3, v4, v5, v6,
|
||||
v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
|
||||
v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35,
|
||||
v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13, typename T14, typename T15,
|
||||
typename T16, typename T17, typename T18, typename T19, typename T20,
|
||||
typename T21, typename T22, typename T23, typename T24, typename T25,
|
||||
typename T26, typename T27, typename T28, typename T29, typename T30,
|
||||
typename T31, typename T32, typename T33, typename T34, typename T35,
|
||||
typename T36, typename T37, typename T38, typename T39, typename T40,
|
||||
typename T41, typename T42, typename T43, typename T44, typename T45,
|
||||
typename T46, typename T47, typename T48, typename T49, typename T50>
|
||||
internal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
|
||||
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
|
||||
T44, T45, T46, T47, T48, T49, T50> Values(T1 v1, T2 v2, T3 v3, T4 v4,
|
||||
T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
|
||||
T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
|
||||
T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
|
||||
T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37,
|
||||
T38 v38, T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45,
|
||||
T46 v46, T47 v47, T48 v48, T49 v49, T50 v50) {
|
||||
return internal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
|
||||
T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
|
||||
T40, T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>(v1, v2, v3, v4,
|
||||
v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
|
||||
v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
|
||||
v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47,
|
||||
v48, v49, v50);
|
||||
template <typename... T>
|
||||
internal::ValueArray<T...> Values(T... v) {
|
||||
return internal::ValueArray<T...>(std::move(v)...);
|
||||
}
|
||||
|
||||
// Bool() allows generating tests with parameters in a set of (false, true).
|
||||
@ -1215,7 +366,6 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
// Combine() allows the user to combine two or more sequences to produce
|
||||
// values of a Cartesian product of those sequences' elements.
|
||||
//
|
||||
@ -1224,12 +374,10 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// - returns a generator producing sequences with elements coming from
|
||||
// the Cartesian product of elements from the sequences generated by
|
||||
// gen1, gen2, ..., genN. The sequence elements will have a type of
|
||||
// tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
|
||||
// std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
|
||||
// of elements from sequences produces by gen1, gen2, ..., genN.
|
||||
//
|
||||
// Combine can have up to 10 arguments. This number is currently limited
|
||||
// by the maximum number of elements in the tuple implementation used by Google
|
||||
// Test.
|
||||
// Combine can have up to 10 arguments.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
@ -1239,7 +387,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// enum Color { BLACK, GRAY, WHITE };
|
||||
// class AnimalTest
|
||||
// : public testing::TestWithParam<tuple<const char*, Color> > {...};
|
||||
// : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
|
||||
//
|
||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||
//
|
||||
@ -1251,10 +399,10 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// Boolean flags:
|
||||
//
|
||||
// class FlagDependentTest
|
||||
// : public testing::TestWithParam<tuple<bool, bool> > {
|
||||
// : public testing::TestWithParam<std::tuple<bool, bool> > {
|
||||
// virtual void SetUp() {
|
||||
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
|
||||
// tie(external_flag_1, external_flag_2) = GetParam();
|
||||
// std::tie(external_flag_1, external_flag_2) = GetParam();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
@ -1367,7 +515,6 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
Generator10>(
|
||||
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
|
||||
}
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
|
@ -335,19 +335,12 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
//
|
||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||
//
|
||||
// Currently, Values() supports from 1 to $n parameters.
|
||||
//
|
||||
$range i 1..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
|
||||
template <$for j, [[typename T$j]]>
|
||||
internal::ValueArray$i<$for j, [[T$j]]> Values($for j, [[T$j v$j]]) {
|
||||
return internal::ValueArray$i<$for j, [[T$j]]>($for j, [[v$j]]);
|
||||
template <typename... T>
|
||||
internal::ValueArray<T...> Values(T... v) {
|
||||
return internal::ValueArray<T...>(std::move(v)...);
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
// Bool() allows generating tests with parameters in a set of (false, true).
|
||||
//
|
||||
// Synopsis:
|
||||
@ -372,7 +365,6 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
// Combine() allows the user to combine two or more sequences to produce
|
||||
// values of a Cartesian product of those sequences' elements.
|
||||
//
|
||||
@ -381,12 +373,10 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// - returns a generator producing sequences with elements coming from
|
||||
// the Cartesian product of elements from the sequences generated by
|
||||
// gen1, gen2, ..., genN. The sequence elements will have a type of
|
||||
// tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
|
||||
// std::tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
|
||||
// of elements from sequences produces by gen1, gen2, ..., genN.
|
||||
//
|
||||
// Combine can have up to $maxtuple arguments. This number is currently limited
|
||||
// by the maximum number of elements in the tuple implementation used by Google
|
||||
// Test.
|
||||
// Combine can have up to $maxtuple arguments.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
@ -396,7 +386,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
//
|
||||
// enum Color { BLACK, GRAY, WHITE };
|
||||
// class AnimalTest
|
||||
// : public testing::TestWithParam<tuple<const char*, Color> > {...};
|
||||
// : public testing::TestWithParam<std::tuple<const char*, Color> > {...};
|
||||
//
|
||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||
//
|
||||
@ -408,10 +398,10 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
// Boolean flags:
|
||||
//
|
||||
// class FlagDependentTest
|
||||
// : public testing::TestWithParam<tuple<bool, bool> > {
|
||||
// : public testing::TestWithParam<std::tuple<bool, bool> > {
|
||||
// virtual void SetUp() {
|
||||
// // Assigns external_flag_1 and external_flag_2 values from the tuple.
|
||||
// tie(external_flag_1, external_flag_2) = GetParam();
|
||||
// std::tie(external_flag_1, external_flag_2) = GetParam();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
@ -433,7 +423,6 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
}
|
||||
|
||||
]]
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
|
@ -104,14 +104,12 @@
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
# include <tuple>
|
||||
#endif
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#include "absl/strings/string_view.h"
|
||||
@ -643,95 +641,31 @@ void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
|
||||
PrintTo(ref.get(), os);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T& t, ::std::ostream* os);
|
||||
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
void PrintTupleTo(const T&, std::integral_constant<size_t, 0>,
|
||||
::std::ostream*) {}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
||||
// which are packed as tuples.
|
||||
|
||||
// Overloaded PrintTo() for tuples of various arities. We support
|
||||
// tuples of up-to 10 fields. The following implementation works
|
||||
// regardless of whether tr1::tuple is implemented using the
|
||||
// non-standard variadic template feature or not.
|
||||
|
||||
inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
template <typename T, size_t I>
|
||||
void PrintTupleTo(const T& t, std::integral_constant<size_t, I>,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, std::integral_constant<size_t, I - 1>(), os);
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (I > 1) {
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
*os << ", ";
|
||||
}
|
||||
UniversalPrinter<typename std::tuple_element<I - 1, T>::type>::Print(
|
||||
std::get<I - 1>(t), os);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
void PrintTo(
|
||||
const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
template <typename... Types>
|
||||
void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
*os << "(";
|
||||
PrintTupleTo(t, std::integral_constant<size_t, sizeof...(Types)>(), os);
|
||||
*os << ")";
|
||||
}
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
// Overload for std::pair.
|
||||
template <typename T1, typename T2>
|
||||
@ -962,109 +896,20 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
|
||||
|
||||
typedef ::std::vector< ::std::string> Strings;
|
||||
|
||||
// TuplePolicy<TupleT> must provide:
|
||||
// - tuple_size
|
||||
// size of tuple TupleT.
|
||||
// - get<size_t I>(const TupleT& t)
|
||||
// static function extracting element I of tuple TupleT.
|
||||
// - tuple_element<size_t I>::type
|
||||
// type of element I of tuple TupleT.
|
||||
template <typename TupleT>
|
||||
struct TuplePolicy;
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
template <typename TupleT>
|
||||
struct TuplePolicy {
|
||||
typedef TupleT Tuple;
|
||||
static const size_t tuple_size = ::std::tr1::tuple_size<Tuple>::value;
|
||||
|
||||
template <size_t I>
|
||||
struct tuple_element : ::std::tr1::tuple_element<static_cast<int>(I), Tuple> {
|
||||
};
|
||||
|
||||
template <size_t I>
|
||||
static typename AddReference<const typename ::std::tr1::tuple_element<
|
||||
static_cast<int>(I), Tuple>::type>::type
|
||||
get(const Tuple& tuple) {
|
||||
return ::std::tr1::get<I>(tuple);
|
||||
}
|
||||
};
|
||||
template <typename TupleT>
|
||||
const size_t TuplePolicy<TupleT>::tuple_size;
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
template <typename... Types>
|
||||
struct TuplePolicy< ::std::tuple<Types...> > {
|
||||
typedef ::std::tuple<Types...> Tuple;
|
||||
static const size_t tuple_size = ::std::tuple_size<Tuple>::value;
|
||||
|
||||
template <size_t I>
|
||||
struct tuple_element : ::std::tuple_element<I, Tuple> {};
|
||||
|
||||
template <size_t I>
|
||||
static const typename ::std::tuple_element<I, Tuple>::type& get(
|
||||
const Tuple& tuple) {
|
||||
return ::std::get<I>(tuple);
|
||||
}
|
||||
};
|
||||
template <typename... Types>
|
||||
const size_t TuplePolicy< ::std::tuple<Types...> >::tuple_size;
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
// This helper template allows PrintTo() for tuples and
|
||||
// UniversalTersePrintTupleFieldsToStrings() to be defined by
|
||||
// induction on the number of tuple fields. The idea is that
|
||||
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
|
||||
// fields in tuple t, and can be defined in terms of
|
||||
// TuplePrefixPrinter<N - 1>.
|
||||
//
|
||||
// The inductive case.
|
||||
template <size_t N>
|
||||
struct TuplePrefixPrinter {
|
||||
// Prints the first N fields of a tuple.
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (N > 1) {
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
*os << ", ";
|
||||
}
|
||||
UniversalPrinter<
|
||||
typename TuplePolicy<Tuple>::template tuple_element<N - 1>::type>
|
||||
::Print(TuplePolicy<Tuple>::template get<N - 1>(t), os);
|
||||
}
|
||||
|
||||
// Tersely prints the first N fields of a tuple to a string vector,
|
||||
// one element for each field.
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(TuplePolicy<Tuple>::template get<N - 1>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
// Base case.
|
||||
template <>
|
||||
struct TuplePrefixPrinter<0> {
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
|
||||
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
|
||||
};
|
||||
|
||||
// Helper function for printing a tuple.
|
||||
// Tuple must be either std::tr1::tuple or std::tuple type.
|
||||
template <typename Tuple>
|
||||
void PrintTupleTo(const Tuple& t, ::std::ostream* os) {
|
||||
*os << "(";
|
||||
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::PrintPrefixTo(t, os);
|
||||
*os << ")";
|
||||
void TersePrintPrefixToStrings(const Tuple&, std::integral_constant<size_t, 0>,
|
||||
Strings*) {}
|
||||
template <typename Tuple, size_t I>
|
||||
void TersePrintPrefixToStrings(const Tuple& t,
|
||||
std::integral_constant<size_t, I>,
|
||||
Strings* strings) {
|
||||
TersePrintPrefixToStrings(t, std::integral_constant<size_t, I - 1>(),
|
||||
strings);
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(std::get<I - 1>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
|
||||
// Prints the fields of a tuple tersely to a string vector, one
|
||||
@ -1073,11 +918,11 @@ void PrintTupleTo(const Tuple& t, ::std::ostream* os) {
|
||||
template <typename Tuple>
|
||||
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
||||
Strings result;
|
||||
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::
|
||||
TersePrintPrefixToStrings(value, &result);
|
||||
TersePrintPrefixToStrings(
|
||||
value, std::integral_constant<size_t, std::tuple_size<Tuple>::value>(),
|
||||
&result);
|
||||
return result;
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
@ -72,14 +72,15 @@ class GTEST_API_ ScopedFakeTestPartResultReporter
|
||||
TestPartResultArray* result);
|
||||
|
||||
// The d'tor restores the previous test part result reporter.
|
||||
virtual ~ScopedFakeTestPartResultReporter();
|
||||
~ScopedFakeTestPartResultReporter() override;
|
||||
|
||||
// Appends the TestPartResult object to the TestPartResultArray
|
||||
// received in the constructor.
|
||||
//
|
||||
// This method is from the TestPartResultReporterInterface
|
||||
// interface.
|
||||
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
|
@ -165,8 +165,8 @@ class GTEST_API_ HasNewFatalFailureHelper
|
||||
: public TestPartResultReporterInterface {
|
||||
public:
|
||||
HasNewFatalFailureHelper();
|
||||
virtual ~HasNewFatalFailureHelper();
|
||||
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||
~HasNewFatalFailureHelper() override;
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
|
||||
private:
|
||||
bool has_new_fatal_failure_;
|
||||
|
@ -53,12 +53,14 @@
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/gtest-death-test.h"
|
||||
#include "gtest/gtest-matchers.h"
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/gtest-param-test.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
@ -361,7 +363,7 @@ class GTEST_API_ AssertionResult {
|
||||
// construct is not satisfied with the predicate's outcome.
|
||||
// Referenced via a pointer to avoid taking too much stack frame space
|
||||
// with test assertions.
|
||||
internal::scoped_ptr< ::std::string> message_;
|
||||
std::unique_ptr< ::std::string> message_;
|
||||
};
|
||||
|
||||
// Makes a successful assertion result.
|
||||
@ -493,7 +495,7 @@ class GTEST_API_ Test {
|
||||
// internal method to avoid clashing with names used in user TESTs.
|
||||
void DeleteSelf_() { delete this; }
|
||||
|
||||
const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
|
||||
const std::unique_ptr<GTEST_FLAG_SAVER_> gtest_flag_saver_;
|
||||
|
||||
// Often a user misspells SetUp() as Setup() and spends a long time
|
||||
// wondering why it is never called by Google Test. The declaration of
|
||||
@ -796,10 +798,10 @@ class GTEST_API_ TestInfo {
|
||||
const std::string name_; // Test name
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> type_param_;
|
||||
const std::unique_ptr<const ::std::string> type_param_;
|
||||
// Text representation of the value parameter, or NULL if this is not a
|
||||
// value-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> value_param_;
|
||||
const std::unique_ptr<const ::std::string> value_param_;
|
||||
internal::CodeLocation location_;
|
||||
const internal::TypeId fixture_class_id_; // ID of the test fixture class
|
||||
bool should_run_; // True iff this test should run
|
||||
@ -983,7 +985,7 @@ class GTEST_API_ TestCase {
|
||||
std::string name_;
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> type_param_;
|
||||
const std::unique_ptr<const ::std::string> type_param_;
|
||||
// The vector of TestInfos in their original order. It owns the
|
||||
// elements in the vector.
|
||||
std::vector<TestInfo*> test_info_list_;
|
||||
@ -1109,21 +1111,21 @@ class TestEventListener {
|
||||
// above.
|
||||
class EmptyTestEventListener : public TestEventListener {
|
||||
public:
|
||||
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
|
||||
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int /*iteration*/) {}
|
||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
|
||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
|
||||
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
|
||||
virtual void OnTestStart(const TestInfo& /*test_info*/) {}
|
||||
virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
|
||||
virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
|
||||
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
|
||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
|
||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
|
||||
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int /*iteration*/) {}
|
||||
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
|
||||
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
|
||||
void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int /*iteration*/) override {}
|
||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
|
||||
void OnTestCaseStart(const TestCase& /*test_case*/) override {}
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
|
||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
|
||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int /*iteration*/) override {}
|
||||
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
|
||||
};
|
||||
|
||||
// TestEventListeners lets users add listeners to track events in Google Test.
|
||||
@ -1449,6 +1451,13 @@ AssertionResult CmpHelperEQFailure(const char* lhs_expression,
|
||||
false);
|
||||
}
|
||||
|
||||
// This block of code defines operator==/!=
|
||||
// to block lexical scope lookup.
|
||||
// It prevents using invalid operator==/!= defined at namespace scope.
|
||||
struct faketype {};
|
||||
inline bool operator==(faketype, faketype) { return true; }
|
||||
inline bool operator!=(faketype, faketype) { return false; }
|
||||
|
||||
// The helper function for {ASSERT|EXPECT}_EQ.
|
||||
template <typename T1, typename T2>
|
||||
AssertionResult CmpHelperEQ(const char* lhs_expression,
|
||||
@ -2345,6 +2354,92 @@ GTEST_API_ std::string TempDir();
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// Dynamically registers a test with the framework.
|
||||
//
|
||||
// This is an advanced API only to be used when the `TEST` macros are
|
||||
// insufficient. The macros should be preferred when possible, as they avoid
|
||||
// most of the complexity of calling this function.
|
||||
//
|
||||
// The `factory` argument is a factory callable (move-constructible) object or
|
||||
// function pointer that creates a new instance of the Test object. It
|
||||
// handles ownership to the caller. The signature of the callable is
|
||||
// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
|
||||
// tests registered with the same `test_case_name` must return the same
|
||||
// fixture type. This is checked at runtime.
|
||||
//
|
||||
// The framework will infer the fixture class from the factory and will call
|
||||
// the `SetUpTestCase` and `TearDownTestCase` for it.
|
||||
//
|
||||
// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
|
||||
// undefined.
|
||||
//
|
||||
// Use case example:
|
||||
//
|
||||
// class MyFixture : public ::testing::Test {
|
||||
// public:
|
||||
// // All of these optional, just like in regular macro usage.
|
||||
// static void SetUpTestCase() { ... }
|
||||
// static void TearDownTestCase() { ... }
|
||||
// void SetUp() override { ... }
|
||||
// void TearDown() override { ... }
|
||||
// };
|
||||
//
|
||||
// class MyTest : public MyFixture {
|
||||
// public:
|
||||
// explicit MyTest(int data) : data_(data) {}
|
||||
// void TestBody() override { ... }
|
||||
//
|
||||
// private:
|
||||
// int data_;
|
||||
// };
|
||||
//
|
||||
// void RegisterMyTests(const std::vector<int>& values) {
|
||||
// for (int v : values) {
|
||||
// ::testing::RegisterTest(
|
||||
// "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr,
|
||||
// std::to_string(v).c_str(),
|
||||
// __FILE__, __LINE__,
|
||||
// // Important to use the fixture type as the return type here.
|
||||
// [=]() -> MyFixture* { return new MyTest(v); });
|
||||
// }
|
||||
// }
|
||||
// ...
|
||||
// int main(int argc, char** argv) {
|
||||
// std::vector<int> values_to_test = LoadValuesFromConfig();
|
||||
// RegisterMyTests(values_to_test);
|
||||
// ...
|
||||
// return RUN_ALL_TESTS();
|
||||
// }
|
||||
//
|
||||
template <int&... ExplicitParameterBarrier, typename Factory>
|
||||
TestInfo* RegisterTest(const char* test_case_name, const char* test_name,
|
||||
const char* type_param, const char* value_param,
|
||||
const char* file, int line, Factory factory) {
|
||||
using TestT = typename std::remove_pointer<decltype(factory())>::type;
|
||||
|
||||
// Helper class to get SetUpTestCase and TearDownTestCase when they are in a
|
||||
// protected scope.
|
||||
struct Helper : TestT {
|
||||
using TestT::SetUpTestCase;
|
||||
using TestT::TearDownTestCase;
|
||||
};
|
||||
|
||||
class FactoryImpl : public internal::TestFactoryBase {
|
||||
public:
|
||||
explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
|
||||
Test* CreateTest() override { return factory_(); }
|
||||
|
||||
private:
|
||||
Factory factory_;
|
||||
};
|
||||
|
||||
return internal::MakeAndRegisterTestInfo(
|
||||
test_case_name, test_name, type_param, value_param,
|
||||
internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
|
||||
&Helper::SetUpTestCase, &Helper::TearDownTestCase,
|
||||
new FactoryImpl{std::move(factory)});
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Use this function in main() to run all tests. It returns 0 if all
|
||||
|
@ -36,9 +36,11 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
|
||||
#include "gtest/gtest-matchers.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -78,7 +80,7 @@ class GTEST_API_ DeathTest {
|
||||
// argument is set. If the death test should be skipped, the pointer
|
||||
// is set to NULL; otherwise, it is set to the address of a new concrete
|
||||
// DeathTest object that controls the execution of the current test.
|
||||
static bool Create(const char* statement, const RE* regex,
|
||||
static bool Create(const char* statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line, DeathTest** test);
|
||||
DeathTest();
|
||||
virtual ~DeathTest() { }
|
||||
@ -144,21 +146,50 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
class DeathTestFactory {
|
||||
public:
|
||||
virtual ~DeathTestFactory() { }
|
||||
virtual bool Create(const char* statement, const RE* regex,
|
||||
const char* file, int line, DeathTest** test) = 0;
|
||||
virtual bool Create(const char* statement,
|
||||
Matcher<const std::string&> matcher, const char* file,
|
||||
int line, DeathTest** test) = 0;
|
||||
};
|
||||
|
||||
// A concrete DeathTestFactory implementation for normal use.
|
||||
class DefaultDeathTestFactory : public DeathTestFactory {
|
||||
public:
|
||||
virtual bool Create(const char* statement, const RE* regex,
|
||||
const char* file, int line, DeathTest** test);
|
||||
bool Create(const char* statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line, DeathTest** test) override;
|
||||
};
|
||||
|
||||
// Returns true if exit_status describes a process that was terminated
|
||||
// by a signal, or exited normally with a nonzero exit code.
|
||||
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
|
||||
// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
|
||||
// and interpreted as a regex (rather than an Eq matcher) for legacy
|
||||
// compatibility.
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
::testing::internal::RE regex) {
|
||||
return ContainsRegex(regex.pattern());
|
||||
}
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(const char* regex) {
|
||||
return ContainsRegex(regex);
|
||||
}
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
const ::std::string& regex) {
|
||||
return ContainsRegex(regex);
|
||||
}
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
const ::string& regex) {
|
||||
return ContainsRegex(regex);
|
||||
}
|
||||
#endif
|
||||
|
||||
// If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
|
||||
// used directly.
|
||||
inline Matcher<const ::std::string&> MakeDeathTestMatcher(
|
||||
Matcher<const ::std::string&> matcher) {
|
||||
return matcher;
|
||||
}
|
||||
|
||||
// Traps C++ exceptions escaping statement and reports them as test
|
||||
// failures. Note that trapping SEH exceptions is not implemented here.
|
||||
# if GTEST_HAS_EXCEPTIONS
|
||||
@ -186,38 +217,38 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
|
||||
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
|
||||
// ASSERT_EXIT*, and EXPECT_EXIT*.
|
||||
# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
const ::testing::internal::RE& gtest_regex = (regex); \
|
||||
::testing::internal::DeathTest* gtest_dt; \
|
||||
if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \
|
||||
__FILE__, __LINE__, >est_dt)) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
if (gtest_dt != NULL) { \
|
||||
::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
|
||||
gtest_dt_ptr(gtest_dt); \
|
||||
switch (gtest_dt->AssumeRole()) { \
|
||||
case ::testing::internal::DeathTest::OVERSEE_TEST: \
|
||||
if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
break; \
|
||||
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
|
||||
::testing::internal::DeathTest::ReturnSentinel \
|
||||
gtest_sentinel(gtest_dt); \
|
||||
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
|
||||
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
|
||||
fail(::testing::internal::DeathTest::LastMessage())
|
||||
#define GTEST_DEATH_TEST_(statement, predicate, regex_or_matcher, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
::testing::internal::DeathTest* gtest_dt; \
|
||||
if (!::testing::internal::DeathTest::Create( \
|
||||
#statement, \
|
||||
::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \
|
||||
__FILE__, __LINE__, >est_dt)) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
if (gtest_dt != nullptr) { \
|
||||
std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \
|
||||
switch (gtest_dt->AssumeRole()) { \
|
||||
case ::testing::internal::DeathTest::OVERSEE_TEST: \
|
||||
if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
|
||||
} \
|
||||
break; \
|
||||
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
|
||||
::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
|
||||
gtest_dt); \
|
||||
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
|
||||
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \
|
||||
: fail(::testing::internal::DeathTest::LastMessage())
|
||||
// The symbol "fail" here expands to something into which a message
|
||||
// can be streamed.
|
||||
|
||||
@ -226,14 +257,13 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
// must accept a streamed message even though the message is never printed.
|
||||
// The regex object is not evaluated, but it is used to prevent "unused"
|
||||
// warnings and to avoid an expression that doesn't compile in debug mode.
|
||||
#define GTEST_EXECUTE_STATEMENT_(statement, regex) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} else if (!::testing::internal::AlwaysTrue()) { \
|
||||
const ::testing::internal::RE& gtest_regex = (regex); \
|
||||
static_cast<void>(gtest_regex); \
|
||||
} else \
|
||||
#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} else if (!::testing::internal::AlwaysTrue()) { \
|
||||
::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
// A class representing the parsed contents of the
|
||||
|
@ -469,7 +469,7 @@ class TestFactoryBase {
|
||||
template <class TestClass>
|
||||
class TestFactoryImpl : public TestFactoryBase {
|
||||
public:
|
||||
virtual Test* CreateTest() { return new TestClass; }
|
||||
Test* CreateTest() override { return new TestClass; }
|
||||
};
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
@ -840,16 +840,6 @@ struct RemoveConst<const T[N]> {
|
||||
typedef typename RemoveConst<T>::type type[N];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||
// This is the only specialization that allows VC++ 7.1 to remove const in
|
||||
// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC
|
||||
// and thus needs to be conditionally compiled.
|
||||
template <typename T, size_t N>
|
||||
struct RemoveConst<T[N]> {
|
||||
typedef typename RemoveConst<T>::type type[N];
|
||||
};
|
||||
#endif
|
||||
|
||||
// A handy wrapper around RemoveConst that works when the argument
|
||||
// T depends on template parameters.
|
||||
#define GTEST_REMOVE_CONST_(T) \
|
||||
@ -977,37 +967,24 @@ struct IsHashTable {
|
||||
template <typename T>
|
||||
const bool IsHashTable<T>::value;
|
||||
|
||||
template<typename T>
|
||||
struct VoidT {
|
||||
typedef void value_type;
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct HasValueType : false_type {};
|
||||
template <typename T>
|
||||
struct HasValueType<T, VoidT<typename T::value_type> > : true_type {
|
||||
};
|
||||
|
||||
template <typename C,
|
||||
bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer),
|
||||
bool = HasValueType<C>::value>
|
||||
bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer)>
|
||||
struct IsRecursiveContainerImpl;
|
||||
|
||||
template <typename C, bool HV>
|
||||
struct IsRecursiveContainerImpl<C, false, HV> : public false_type {};
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, false> : public false_type {};
|
||||
|
||||
// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
|
||||
// obey the same inconsistencies as the IsContainerTest, namely check if
|
||||
// something is a container is relying on only const_iterator in C++11 and
|
||||
// is relying on both const_iterator and iterator otherwise
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, false> : public false_type {};
|
||||
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, true> {
|
||||
typedef typename IteratorTraits<typename C::const_iterator>::value_type
|
||||
value_type;
|
||||
typedef is_same<value_type, C> type;
|
||||
struct IsRecursiveContainerImpl<C, true> {
|
||||
using value_type = decltype(*std::declval<typename C::const_iterator>());
|
||||
using type =
|
||||
is_same<typename std::remove_const<
|
||||
typename std::remove_reference<value_type>::type>::type,
|
||||
C>;
|
||||
};
|
||||
|
||||
// IsRecursiveContainer<Type> is a unary compile-time predicate that
|
||||
@ -1176,6 +1153,112 @@ class NativeArray {
|
||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||
};
|
||||
|
||||
// Backport of std::index_sequence.
|
||||
template <size_t... Is>
|
||||
struct IndexSequence {
|
||||
using type = IndexSequence;
|
||||
};
|
||||
|
||||
// Double the IndexSequence, and one if plus_one is true.
|
||||
template <bool plus_one, typename T, size_t sizeofT>
|
||||
struct DoubleSequence;
|
||||
template <size_t... I, size_t sizeofT>
|
||||
struct DoubleSequence<true, IndexSequence<I...>, sizeofT> {
|
||||
using type = IndexSequence<I..., (sizeofT + I)..., 2 * sizeofT>;
|
||||
};
|
||||
template <size_t... I, size_t sizeofT>
|
||||
struct DoubleSequence<false, IndexSequence<I...>, sizeofT> {
|
||||
using type = IndexSequence<I..., (sizeofT + I)...>;
|
||||
};
|
||||
|
||||
// Backport of std::make_index_sequence.
|
||||
// It uses O(ln(N)) instantiation depth.
|
||||
template <size_t N>
|
||||
struct MakeIndexSequence
|
||||
: DoubleSequence<N % 2 == 1, typename MakeIndexSequence<N / 2>::type,
|
||||
N / 2>::type {};
|
||||
|
||||
template <>
|
||||
struct MakeIndexSequence<0> : IndexSequence<> {};
|
||||
|
||||
// FIXME: This implementation of ElemFromList is O(1) in instantiation depth,
|
||||
// but it is O(N^2) in total instantiations. Not sure if this is the best
|
||||
// tradeoff, as it will make it somewhat slow to compile.
|
||||
template <typename T, size_t, size_t>
|
||||
struct ElemFromListImpl {};
|
||||
|
||||
template <typename T, size_t I>
|
||||
struct ElemFromListImpl<T, I, I> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
// Get the Nth element from T...
|
||||
// It uses O(1) instantiation depth.
|
||||
template <size_t N, typename I, typename... T>
|
||||
struct ElemFromList;
|
||||
|
||||
template <size_t N, size_t... I, typename... T>
|
||||
struct ElemFromList<N, IndexSequence<I...>, T...>
|
||||
: ElemFromListImpl<T, N, I>... {};
|
||||
|
||||
template <typename... T>
|
||||
class FlatTuple;
|
||||
|
||||
template <typename Derived, size_t I>
|
||||
struct FlatTupleElemBase;
|
||||
|
||||
template <typename... T, size_t I>
|
||||
struct FlatTupleElemBase<FlatTuple<T...>, I> {
|
||||
using value_type =
|
||||
typename ElemFromList<I, typename MakeIndexSequence<sizeof...(T)>::type,
|
||||
T...>::type;
|
||||
FlatTupleElemBase() = default;
|
||||
explicit FlatTupleElemBase(value_type t) : value(std::move(t)) {}
|
||||
value_type value;
|
||||
};
|
||||
|
||||
template <typename Derived, typename Idx>
|
||||
struct FlatTupleBase;
|
||||
|
||||
template <size_t... Idx, typename... T>
|
||||
struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>>
|
||||
: FlatTupleElemBase<FlatTuple<T...>, Idx>... {
|
||||
using Indices = IndexSequence<Idx...>;
|
||||
FlatTupleBase() = default;
|
||||
explicit FlatTupleBase(T... t)
|
||||
: FlatTupleElemBase<FlatTuple<T...>, Idx>(std::move(t))... {}
|
||||
};
|
||||
|
||||
// Analog to std::tuple but with different tradeoffs.
|
||||
// This class minimizes the template instantiation depth, thus allowing more
|
||||
// elements that std::tuple would. std::tuple has been seen to require an
|
||||
// instantiation depth of more than 10x the number of elements in some
|
||||
// implementations.
|
||||
// FlatTuple and ElemFromList are not recursive and have a fixed depth
|
||||
// regardless of T...
|
||||
// MakeIndexSequence, on the other hand, it is recursive but with an
|
||||
// instantiation depth of O(ln(N)).
|
||||
template <typename... T>
|
||||
class FlatTuple
|
||||
: private FlatTupleBase<FlatTuple<T...>,
|
||||
typename MakeIndexSequence<sizeof...(T)>::type> {
|
||||
using Indices = typename FlatTuple::FlatTupleBase::Indices;
|
||||
|
||||
public:
|
||||
FlatTuple() = default;
|
||||
explicit FlatTuple(T... t) : FlatTuple::FlatTupleBase(std::move(t)...) {}
|
||||
|
||||
template <size_t I>
|
||||
const typename ElemFromList<I, Indices, T...>::type& Get() const {
|
||||
return static_cast<const FlatTupleElemBase<FlatTuple, I>*>(this)->value;
|
||||
}
|
||||
|
||||
template <size_t I>
|
||||
typename ElemFromList<I, Indices, T...>::type& Get() {
|
||||
return static_cast<FlatTupleElemBase<FlatTuple, I>*>(this)->value;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
@ -1294,27 +1377,42 @@ class NativeArray {
|
||||
test_case_name##_##test_name##_Test
|
||||
|
||||
// Helper macro for defining tests.
|
||||
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||
public:\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
|
||||
private:\
|
||||
virtual void TestBody();\
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
|
||||
};\
|
||||
\
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
|
||||
::test_info_ =\
|
||||
::testing::internal::MakeAndRegisterTestInfo(\
|
||||
#test_case_name, #test_name, NULL, NULL, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||
(parent_id), \
|
||||
parent_class::SetUpTestCase, \
|
||||
parent_class::TearDownTestCase, \
|
||||
new ::testing::internal::TestFactoryImpl<\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public parent_class { \
|
||||
public: \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
||||
\
|
||||
private: \
|
||||
virtual void TestBody(); \
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
test_name)); \
|
||||
}; \
|
||||
\
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
test_name)::test_info_ = \
|
||||
::testing::internal::MakeAndRegisterTestInfo( \
|
||||
#test_case_name, #test_name, nullptr, nullptr, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
|
||||
parent_class::SetUpTestCase, parent_class::TearDownTestCase, \
|
||||
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
|
||||
test_case_name, test_name)>); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
|
||||
// Internal Macro to mark an API deprecated, for googletest usage only
|
||||
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
|
||||
// GTEST_INTERNAL_DEPRECATED(message) <return_type> myFunction(); Every usage of
|
||||
// a deprecated entity will trigger a warning when compiled with
|
||||
// `-Wdeprecated-declarations` option (clang, gcc, any __GNUC__ compiler).
|
||||
// For msvc /W3 option will need to be used
|
||||
// Note that for 'other' compilers this macro evaluates to nothing to prevent
|
||||
// compilations errors.
|
||||
#if defined(_MSC_VER)
|
||||
#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message))
|
||||
#elif defined(__GNUC__)
|
||||
#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
#else
|
||||
#define GTEST_INTERNAL_DEPRECATED(message)
|
||||
#endif
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
|
@ -1,243 +0,0 @@
|
||||
// Copyright 2003 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.
|
||||
//
|
||||
// A "smart" pointer type with reference tracking. Every pointer to a
|
||||
// particular object is kept on a circular linked list. When the last pointer
|
||||
// to an object is destroyed or reassigned, the object is deleted.
|
||||
//
|
||||
// Used properly, this deletes the object when the last reference goes away.
|
||||
// There are several caveats:
|
||||
// - Like all reference counting schemes, cycles lead to leaks.
|
||||
// - Each smart pointer is actually two pointers (8 bytes instead of 4).
|
||||
// - Every time a pointer is assigned, the entire list of pointers to that
|
||||
// object is traversed. This class is therefore NOT SUITABLE when there
|
||||
// will often be more than two or three pointers to a particular object.
|
||||
// - References are only tracked as long as linked_ptr<> objects are copied.
|
||||
// If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS
|
||||
// will happen (double deletion).
|
||||
//
|
||||
// A good use of this class is storing object references in STL containers.
|
||||
// You can safely put linked_ptr<> in a vector<>.
|
||||
// Other uses may not be as good.
|
||||
//
|
||||
// Note: If you use an incomplete type with linked_ptr<>, the class
|
||||
// *containing* linked_ptr<> must have a constructor and destructor (even
|
||||
// if they do nothing!).
|
||||
//
|
||||
// Bill Gibbons suggested we use something like this.
|
||||
//
|
||||
// Thread Safety:
|
||||
// Unlike other linked_ptr implementations, in this implementation
|
||||
// a linked_ptr object is thread-safe in the sense that:
|
||||
// - it's safe to copy linked_ptr objects concurrently,
|
||||
// - it's safe to copy *from* a linked_ptr and read its underlying
|
||||
// raw pointer (e.g. via get()) concurrently, and
|
||||
// - it's safe to write to two linked_ptrs that point to the same
|
||||
// shared object concurrently.
|
||||
// FIXME: rename this to safe_linked_ptr to avoid
|
||||
// confusion with normal linked_ptr.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Protects copying of all linked_ptr objects.
|
||||
GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);
|
||||
|
||||
// This is used internally by all instances of linked_ptr<>. It needs to be
|
||||
// a non-template class because different types of linked_ptr<> can refer to
|
||||
// the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)).
|
||||
// So, it needs to be possible for different types of linked_ptr to participate
|
||||
// in the same circular linked list, so we need a single class type here.
|
||||
//
|
||||
// DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>.
|
||||
class linked_ptr_internal {
|
||||
public:
|
||||
// Create a new circle that includes only this instance.
|
||||
void join_new() {
|
||||
next_ = this;
|
||||
}
|
||||
|
||||
// Many linked_ptr operations may change p.link_ for some linked_ptr
|
||||
// variable p in the same circle as this object. Therefore we need
|
||||
// to prevent two such operations from occurring concurrently.
|
||||
//
|
||||
// Note that different types of linked_ptr objects can coexist in a
|
||||
// circle (e.g. linked_ptr<Base>, linked_ptr<Derived1>, and
|
||||
// linked_ptr<Derived2>). Therefore we must use a single mutex to
|
||||
// protect all linked_ptr objects. This can create serious
|
||||
// contention in production code, but is acceptable in a testing
|
||||
// framework.
|
||||
|
||||
// Join an existing circle.
|
||||
void join(linked_ptr_internal const* ptr)
|
||||
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
|
||||
MutexLock lock(&g_linked_ptr_mutex);
|
||||
|
||||
linked_ptr_internal const* p = ptr;
|
||||
while (p->next_ != ptr) {
|
||||
assert(p->next_ != this &&
|
||||
"Trying to join() a linked ring we are already in. "
|
||||
"Is GMock thread safety enabled?");
|
||||
p = p->next_;
|
||||
}
|
||||
p->next_ = this;
|
||||
next_ = ptr;
|
||||
}
|
||||
|
||||
// Leave whatever circle we're part of. Returns true if we were the
|
||||
// last member of the circle. Once this is done, you can join() another.
|
||||
bool depart()
|
||||
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
|
||||
MutexLock lock(&g_linked_ptr_mutex);
|
||||
|
||||
if (next_ == this) return true;
|
||||
linked_ptr_internal const* p = next_;
|
||||
while (p->next_ != this) {
|
||||
assert(p->next_ != next_ &&
|
||||
"Trying to depart() a linked ring we are not in. "
|
||||
"Is GMock thread safety enabled?");
|
||||
p = p->next_;
|
||||
}
|
||||
p->next_ = next_;
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable linked_ptr_internal const* next_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class linked_ptr {
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
// Take over ownership of a raw pointer. This should happen as soon as
|
||||
// possible after the object is created.
|
||||
explicit linked_ptr(T* ptr = nullptr) { capture(ptr); }
|
||||
~linked_ptr() { depart(); }
|
||||
|
||||
// Copy an existing linked_ptr<>, adding ourselves to the list of references.
|
||||
template <typename U> linked_ptr(linked_ptr<U> const& ptr) { copy(&ptr); }
|
||||
linked_ptr(linked_ptr const& ptr) { // NOLINT
|
||||
assert(&ptr != this);
|
||||
copy(&ptr);
|
||||
}
|
||||
|
||||
// Assignment releases the old value and acquires the new.
|
||||
template <typename U> linked_ptr& operator=(linked_ptr<U> const& ptr) {
|
||||
depart();
|
||||
copy(&ptr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
linked_ptr& operator=(linked_ptr const& ptr) {
|
||||
if (&ptr != this) {
|
||||
depart();
|
||||
copy(&ptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Smart pointer members.
|
||||
void reset(T* ptr = nullptr) {
|
||||
depart();
|
||||
capture(ptr);
|
||||
}
|
||||
T* get() const { return value_; }
|
||||
T* operator->() const { return value_; }
|
||||
T& operator*() const { return *value_; }
|
||||
|
||||
bool operator==(T* p) const { return value_ == p; }
|
||||
bool operator!=(T* p) const { return value_ != p; }
|
||||
template <typename U>
|
||||
bool operator==(linked_ptr<U> const& ptr) const {
|
||||
return value_ == ptr.get();
|
||||
}
|
||||
template <typename U>
|
||||
bool operator!=(linked_ptr<U> const& ptr) const {
|
||||
return value_ != ptr.get();
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename U>
|
||||
friend class linked_ptr;
|
||||
|
||||
T* value_;
|
||||
linked_ptr_internal link_;
|
||||
|
||||
void depart() {
|
||||
if (link_.depart()) delete value_;
|
||||
}
|
||||
|
||||
void capture(T* ptr) {
|
||||
value_ = ptr;
|
||||
link_.join_new();
|
||||
}
|
||||
|
||||
template <typename U> void copy(linked_ptr<U> const* ptr) {
|
||||
value_ = ptr->get();
|
||||
if (value_)
|
||||
link_.join(&ptr->link_);
|
||||
else
|
||||
link_.join_new();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> inline
|
||||
bool operator==(T* ptr, const linked_ptr<T>& x) {
|
||||
return ptr == x.get();
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
bool operator!=(T* ptr, const linked_ptr<T>& x) {
|
||||
return ptr != x.get();
|
||||
}
|
||||
|
||||
// A function to convert T* into linked_ptr<T>
|
||||
// Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation
|
||||
// for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
|
||||
template <typename T>
|
||||
linked_ptr<T> make_linked_ptr(T* ptr) {
|
||||
return linked_ptr<T>(ptr);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
|
File diff suppressed because it is too large
Load Diff
@ -43,6 +43,10 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
|
||||
|
||||
@ -51,54 +55,7 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Forward declarations of ValuesIn(), which is implemented in
|
||||
// include/gtest/gtest-param-test.h.
|
||||
template <typename ForwardIterator>
|
||||
internal::ParamGenerator<
|
||||
typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
|
||||
ValuesIn(ForwardIterator begin, ForwardIterator end);
|
||||
|
||||
template <typename T, size_t N>
|
||||
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
|
||||
|
||||
template <class Container>
|
||||
internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
const Container& container);
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Used in the Values() function to provide polymorphic capabilities.
|
||||
$range i 1..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
|
||||
template <$for j, [[typename T$j]]>
|
||||
class ValueArray$i {
|
||||
public:
|
||||
$if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
|
||||
|
||||
template <typename T>
|
||||
operator ParamGenerator<T>() const {
|
||||
const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
|
||||
return ValuesIn(array);
|
||||
}
|
||||
|
||||
ValueArray$i(const ValueArray$i& other) : $for j, [[v$(j)_(other.v$(j)_)]] {}
|
||||
|
||||
private:
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const ValueArray$i& other);
|
||||
|
||||
$for j [[
|
||||
|
||||
const T$j v$(j)_;
|
||||
]]
|
||||
|
||||
};
|
||||
|
||||
]]
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Generates values from the Cartesian product of values produced
|
||||
@ -111,18 +68,18 @@ $range k 2..i
|
||||
|
||||
template <$for j, [[typename T$j]]>
|
||||
class CartesianProductGenerator$i
|
||||
: public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
|
||||
: public ParamGeneratorInterface< ::std::tuple<$for j, [[T$j]]> > {
|
||||
public:
|
||||
typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
|
||||
typedef ::std::tuple<$for j, [[T$j]]> ParamType;
|
||||
|
||||
CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
|
||||
: $for j, [[g$(j)_(g$j)]] {}
|
||||
virtual ~CartesianProductGenerator$i() {}
|
||||
~CartesianProductGenerator$i() override {}
|
||||
|
||||
virtual ParamIteratorInterface<ParamType>* Begin() const {
|
||||
ParamIteratorInterface<ParamType>* Begin() const override {
|
||||
return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
|
||||
}
|
||||
virtual ParamIteratorInterface<ParamType>* End() const {
|
||||
ParamIteratorInterface<ParamType>* End() const override {
|
||||
return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
|
||||
}
|
||||
|
||||
@ -140,14 +97,14 @@ $for j, [[
|
||||
]] {
|
||||
ComputeCurrentValue();
|
||||
}
|
||||
virtual ~Iterator() {}
|
||||
~Iterator() override {}
|
||||
|
||||
virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
|
||||
const ParamGeneratorInterface<ParamType>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
// Advance should not be called on beyond-of-range iterators
|
||||
// so no component iterators must be beyond end of range, either.
|
||||
virtual void Advance() {
|
||||
void Advance() override {
|
||||
assert(!AtEnd());
|
||||
++current$(i)_;
|
||||
|
||||
@ -160,11 +117,11 @@ $for k [[
|
||||
]]
|
||||
ComputeCurrentValue();
|
||||
}
|
||||
virtual ParamIteratorInterface<ParamType>* Clone() const {
|
||||
ParamIteratorInterface<ParamType>* Clone() const override {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
virtual const ParamType* Current() const { return current_value_.get(); }
|
||||
virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
|
||||
const ParamType* Current() const override { return current_value_.get(); }
|
||||
bool Equals(const ParamIteratorInterface<ParamType>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
@ -220,7 +177,7 @@ $for j [[
|
||||
typename ParamGenerator<T$j>::iterator current$(j)_;
|
||||
]]
|
||||
|
||||
linked_ptr<ParamType> current_value_;
|
||||
std::shared_ptr<ParamType> current_value_;
|
||||
}; // class CartesianProductGenerator$i::Iterator
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
@ -252,8 +209,8 @@ class CartesianProductHolder$i {
|
||||
CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
|
||||
: $for j, [[g$(j)_(g$j)]] {}
|
||||
template <$for j, [[typename T$j]]>
|
||||
operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const {
|
||||
return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >(
|
||||
operator ParamGenerator< ::std::tuple<$for j, [[T$j]]> >() const {
|
||||
return ParamGenerator< ::std::tuple<$for j, [[T$j]]> >(
|
||||
new CartesianProductGenerator$i<$for j, [[T$j]]>(
|
||||
$for j,[[
|
||||
|
||||
@ -274,8 +231,6 @@ $for j [[
|
||||
|
||||
]]
|
||||
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
|
@ -38,17 +38,17 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Input to a parameterized test name generator, describing a test parameter.
|
||||
// Consists of the parameter value and the integer parameter index.
|
||||
template <class ParamType>
|
||||
@ -72,7 +72,8 @@ struct PrintToStringParamName {
|
||||
namespace internal {
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Utility Functions
|
||||
|
||||
// Outputs a message explaining invalid registration of different
|
||||
// fixture class for the same test case. This may happen when
|
||||
// TEST_P macro is used to define two tests with the same name
|
||||
@ -153,7 +154,7 @@ class ParamIterator {
|
||||
private:
|
||||
friend class ParamGenerator<T>;
|
||||
explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
|
||||
scoped_ptr<ParamIteratorInterface<T> > impl_;
|
||||
std::unique_ptr<ParamIteratorInterface<T> > impl_;
|
||||
};
|
||||
|
||||
// ParamGeneratorInterface<T> is the binary interface to access generators
|
||||
@ -192,7 +193,7 @@ class ParamGenerator {
|
||||
iterator end() const { return iterator(impl_->End()); }
|
||||
|
||||
private:
|
||||
linked_ptr<const ParamGeneratorInterface<T> > impl_;
|
||||
std::shared_ptr<const ParamGeneratorInterface<T> > impl_;
|
||||
};
|
||||
|
||||
// Generates values from a range of two comparable values. Can be used to
|
||||
@ -205,12 +206,12 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||
RangeGenerator(T begin, T end, IncrementT step)
|
||||
: begin_(begin), end_(end),
|
||||
step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
|
||||
virtual ~RangeGenerator() {}
|
||||
~RangeGenerator() override {}
|
||||
|
||||
virtual ParamIteratorInterface<T>* Begin() const {
|
||||
ParamIteratorInterface<T>* Begin() const override {
|
||||
return new Iterator(this, begin_, 0, step_);
|
||||
}
|
||||
virtual ParamIteratorInterface<T>* End() const {
|
||||
ParamIteratorInterface<T>* End() const override {
|
||||
return new Iterator(this, end_, end_index_, step_);
|
||||
}
|
||||
|
||||
@ -220,20 +221,20 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||
Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
|
||||
IncrementT step)
|
||||
: base_(base), value_(value), index_(index), step_(step) {}
|
||||
virtual ~Iterator() {}
|
||||
~Iterator() override {}
|
||||
|
||||
virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
|
||||
const ParamGeneratorInterface<T>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
virtual void Advance() {
|
||||
void Advance() override {
|
||||
value_ = static_cast<T>(value_ + step_);
|
||||
index_++;
|
||||
}
|
||||
virtual ParamIteratorInterface<T>* Clone() const {
|
||||
ParamIteratorInterface<T>* Clone() const override {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
virtual const T* Current() const { return &value_; }
|
||||
virtual bool Equals(const ParamIteratorInterface<T>& other) const {
|
||||
const T* Current() const override { return &value_; }
|
||||
bool Equals(const ParamIteratorInterface<T>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
@ -290,12 +291,12 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
template <typename ForwardIterator>
|
||||
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
|
||||
: container_(begin, end) {}
|
||||
virtual ~ValuesInIteratorRangeGenerator() {}
|
||||
~ValuesInIteratorRangeGenerator() override {}
|
||||
|
||||
virtual ParamIteratorInterface<T>* Begin() const {
|
||||
ParamIteratorInterface<T>* Begin() const override {
|
||||
return new Iterator(this, container_.begin());
|
||||
}
|
||||
virtual ParamIteratorInterface<T>* End() const {
|
||||
ParamIteratorInterface<T>* End() const override {
|
||||
return new Iterator(this, container_.end());
|
||||
}
|
||||
|
||||
@ -307,16 +308,16 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
Iterator(const ParamGeneratorInterface<T>* base,
|
||||
typename ContainerType::const_iterator iterator)
|
||||
: base_(base), iterator_(iterator) {}
|
||||
virtual ~Iterator() {}
|
||||
~Iterator() override {}
|
||||
|
||||
virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
|
||||
const ParamGeneratorInterface<T>* BaseGenerator() const override {
|
||||
return base_;
|
||||
}
|
||||
virtual void Advance() {
|
||||
void Advance() override {
|
||||
++iterator_;
|
||||
value_.reset();
|
||||
}
|
||||
virtual ParamIteratorInterface<T>* Clone() const {
|
||||
ParamIteratorInterface<T>* Clone() const override {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
// We need to use cached value referenced by iterator_ because *iterator_
|
||||
@ -326,11 +327,11 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
// can advance iterator_ beyond the end of the range, and we cannot
|
||||
// detect that fact. The client code, on the other hand, is
|
||||
// responsible for not calling Current() on an out-of-range iterator.
|
||||
virtual const T* Current() const {
|
||||
const T* Current() const override {
|
||||
if (value_.get() == nullptr) value_.reset(new T(*iterator_));
|
||||
return value_.get();
|
||||
}
|
||||
virtual bool Equals(const ParamIteratorInterface<T>& other) const {
|
||||
bool Equals(const ParamIteratorInterface<T>& other) const override {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
|
||||
@ -353,9 +354,9 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
// A cached value of *iterator_. We keep it here to allow access by
|
||||
// pointer in the wrapping iterator's operator->().
|
||||
// value_ needs to be mutable to be accessed in Current().
|
||||
// Use of scoped_ptr helps manage cached value's lifetime,
|
||||
// Use of std::unique_ptr helps manage cached value's lifetime,
|
||||
// which is bound by the lifespan of the iterator itself.
|
||||
mutable scoped_ptr<const T> value_;
|
||||
mutable std::unique_ptr<const T> value_;
|
||||
}; // class ValuesInIteratorRangeGenerator::Iterator
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
@ -405,7 +406,7 @@ class ParameterizedTestFactory : public TestFactoryBase {
|
||||
typedef typename TestClass::ParamType ParamType;
|
||||
explicit ParameterizedTestFactory(ParamType parameter) :
|
||||
parameter_(parameter) {}
|
||||
virtual Test* CreateTest() {
|
||||
Test* CreateTest() override {
|
||||
TestClass::SetParam(¶meter_);
|
||||
return new TestClass();
|
||||
}
|
||||
@ -444,7 +445,7 @@ class TestMetaFactory
|
||||
|
||||
TestMetaFactory() {}
|
||||
|
||||
virtual TestFactoryBase* CreateTestFactory(ParamType parameter) {
|
||||
TestFactoryBase* CreateTestFactory(ParamType parameter) override {
|
||||
return new ParameterizedTestFactory<TestCase>(parameter);
|
||||
}
|
||||
|
||||
@ -506,9 +507,11 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
: test_case_name_(name), code_location_(code_location) {}
|
||||
|
||||
// Test case base name for display purposes.
|
||||
virtual const std::string& GetTestCaseName() const { return test_case_name_; }
|
||||
const std::string& GetTestCaseName() const override {
|
||||
return test_case_name_;
|
||||
}
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
|
||||
TypeId GetTestCaseTypeId() const override { return GetTypeId<TestCase>(); }
|
||||
// TEST_P macro uses AddTestPattern() to record information
|
||||
// about a single test in a LocalTestInfo structure.
|
||||
// test_case_name is the base name of the test case (without invocation
|
||||
@ -518,9 +521,8 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
void AddTestPattern(const char* test_case_name,
|
||||
const char* test_base_name,
|
||||
TestMetaFactoryBase<ParamType>* meta_factory) {
|
||||
tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name,
|
||||
test_base_name,
|
||||
meta_factory)));
|
||||
tests_.push_back(std::shared_ptr<TestInfo>(
|
||||
new TestInfo(test_case_name, test_base_name, meta_factory)));
|
||||
}
|
||||
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
|
||||
// about a generator.
|
||||
@ -537,10 +539,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
// This method should not be called more then once on any single
|
||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
||||
// UnitTest has a guard to prevent from calling this method more then once.
|
||||
virtual void RegisterTests() {
|
||||
void RegisterTests() override {
|
||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||
test_it != tests_.end(); ++test_it) {
|
||||
linked_ptr<TestInfo> test_info = *test_it;
|
||||
std::shared_ptr<TestInfo> test_info = *test_it;
|
||||
for (typename InstantiationContainer::iterator gen_it =
|
||||
instantiations_.begin(); gen_it != instantiations_.end();
|
||||
++gen_it) {
|
||||
@ -587,7 +589,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
} // for param_it
|
||||
} // for gen_it
|
||||
} // for test_it
|
||||
} // RegisterTests
|
||||
} // RegisterTests
|
||||
|
||||
private:
|
||||
// LocalTestInfo structure keeps information about a single test registered
|
||||
@ -602,9 +604,9 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
|
||||
const std::string test_case_base_name;
|
||||
const std::string test_base_name;
|
||||
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
};
|
||||
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
|
||||
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
|
||||
// Records data received from INSTANTIATE_TEST_CASE_P macros:
|
||||
// <Instantiation name, Sequence generator creation function,
|
||||
// Name generator function, Source file, Source line>
|
||||
@ -714,6 +716,36 @@ class ParameterizedTestCaseRegistry {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Forward declarations of ValuesIn(), which is implemented in
|
||||
// include/gtest/gtest-param-test.h.
|
||||
template <class Container>
|
||||
internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
const Container& container);
|
||||
|
||||
namespace internal {
|
||||
// Used in the Values() function to provide polymorphic capabilities.
|
||||
|
||||
template <typename... Ts>
|
||||
class ValueArray {
|
||||
public:
|
||||
ValueArray(Ts... v) : v_{std::move(v)...} {}
|
||||
|
||||
template <typename T>
|
||||
operator ParamGenerator<T>() const { // NOLINT
|
||||
return ValuesIn(MakeVector<T>(MakeIndexSequence<sizeof...(Ts)>()));
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T, size_t... I>
|
||||
std::vector<T> MakeVector(IndexSequence<I...>) const {
|
||||
return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
|
||||
}
|
||||
|
||||
FlatTuple<Ts...> v_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
|
@ -66,6 +66,8 @@
|
||||
# else
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# endif // _WIN32_WCE
|
||||
#elif defined __OS2__
|
||||
# define GTEST_OS_OS2 1
|
||||
#elif defined __APPLE__
|
||||
# define GTEST_OS_MAC 1
|
||||
# if TARGET_OS_IPHONE
|
||||
|
@ -85,8 +85,6 @@
|
||||
// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
|
||||
// std::wstring does/doesn't work (Google Test can
|
||||
// be used where std::wstring is unavailable).
|
||||
// GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
|
||||
// is/isn't available.
|
||||
// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
|
||||
// compiler supports Microsoft's "Structured
|
||||
// Exception Handling".
|
||||
@ -94,12 +92,6 @@
|
||||
// - Define it to 1/0 to indicate whether the
|
||||
// platform supports I/O stream redirection using
|
||||
// dup() and dup2().
|
||||
// GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
|
||||
// Test's own tr1 tuple implementation should be
|
||||
// used. Unused when the user sets
|
||||
// GTEST_HAS_TR1_TUPLE to 0.
|
||||
// GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
|
||||
// is building in C++11/C++98 mode.
|
||||
// GTEST_LINKED_AS_SHARED_LIBRARY
|
||||
// - Define to 1 when compiling tests that use
|
||||
// Google Test as a shared library (known as
|
||||
@ -135,6 +127,7 @@
|
||||
// GTEST_OS_NACL - Google Native Client (NaCl)
|
||||
// GTEST_OS_NETBSD - NetBSD
|
||||
// GTEST_OS_OPENBSD - OpenBSD
|
||||
// GTEST_OS_OS2 - OS/2
|
||||
// GTEST_OS_QNX - QNX
|
||||
// GTEST_OS_SOLARIS - Sun Solaris
|
||||
// GTEST_OS_SYMBIAN - Symbian
|
||||
@ -172,8 +165,6 @@
|
||||
// EXPECT_DEATH(DoSomethingDeadly());
|
||||
// #endif
|
||||
//
|
||||
// GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
|
||||
// tests)
|
||||
// GTEST_HAS_DEATH_TEST - death tests
|
||||
// GTEST_HAS_TYPED_TEST - typed tests
|
||||
// GTEST_HAS_TYPED_TEST_P - type-parameterized tests
|
||||
@ -210,11 +201,6 @@
|
||||
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
|
||||
// is suppressed.
|
||||
//
|
||||
// C++11 feature wrappers:
|
||||
//
|
||||
// testing::internal::forward - portability wrapper for std::forward.
|
||||
// testing::internal::move - portability wrapper for std::move.
|
||||
//
|
||||
// Synchronization:
|
||||
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
|
||||
// - synchronization primitives.
|
||||
@ -224,8 +210,6 @@
|
||||
// IteratorTraits - partial implementation of std::iterator_traits, which
|
||||
// is not available in libCstd when compiled with Sun C++.
|
||||
//
|
||||
// Smart pointers:
|
||||
// scoped_ptr - as in TR2.
|
||||
//
|
||||
// Regular expressions:
|
||||
// RE - a simple regular expression class using the POSIX
|
||||
@ -265,9 +249,11 @@
|
||||
|
||||
#include <ctype.h> // for isspace, etc
|
||||
#include <stddef.h> // for ptrdiff_t
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
@ -280,10 +266,11 @@
|
||||
|
||||
// Brings in the definition of HAS_GLOBAL_STRING. This must be done
|
||||
// BEFORE we test HAS_GLOBAL_STRING.
|
||||
#include <string> // NOLINT
|
||||
#include <string> // NOLINT
|
||||
#include <algorithm> // NOLINT
|
||||
#include <iostream> // NOLINT
|
||||
#include <sstream> // NOLINT
|
||||
#include <iostream> // NOLINT
|
||||
#include <sstream> // NOLINT
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector> // NOLINT
|
||||
|
||||
@ -315,14 +302,14 @@
|
||||
// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
|
||||
// /* code that triggers warnings C4800 and C4385 */
|
||||
// GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#if _MSC_VER >= 1400
|
||||
#if defined(_MSC_VER)
|
||||
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: warnings))
|
||||
# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
// Older versions of MSVC don't have __pragma.
|
||||
// Not all compilers are MSVC
|
||||
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
|
||||
# define GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#endif
|
||||
@ -343,69 +330,6 @@
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#endif
|
||||
|
||||
#define GTEST_LANG_CXX11 1
|
||||
|
||||
// Distinct from C++11 language support, some environments don't provide
|
||||
// proper C++11 library support. Notably, it's possible to build in
|
||||
// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
|
||||
// with no C++11 support.
|
||||
//
|
||||
// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
|
||||
// 20110325, but maintenance releases in the 4.4 and 4.5 series followed
|
||||
// this date, so check for those versions by their date stamps.
|
||||
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
|
||||
#if GTEST_LANG_CXX11 && \
|
||||
(!defined(__GLIBCXX__) || ( \
|
||||
__GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \
|
||||
/* Blacklist of patch releases of older branches: */ \
|
||||
__GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \
|
||||
__GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \
|
||||
__GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \
|
||||
__GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */
|
||||
# define GTEST_STDLIB_CXX11 1
|
||||
#endif
|
||||
|
||||
// Only use C++11 library features if the library provides them.
|
||||
#if GTEST_STDLIB_CXX11
|
||||
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
|
||||
# define GTEST_HAS_STD_FORWARD_LIST_ 1
|
||||
# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824)
|
||||
// works only with VS2015U2 and better
|
||||
# define GTEST_HAS_STD_FUNCTION_ 1
|
||||
# endif
|
||||
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
|
||||
# define GTEST_HAS_STD_MOVE_ 1
|
||||
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
|
||||
# define GTEST_HAS_STD_SHARED_PTR_ 1
|
||||
# define GTEST_HAS_UNORDERED_MAP_ 1
|
||||
# define GTEST_HAS_UNORDERED_SET_ 1
|
||||
#endif
|
||||
|
||||
// C++11 specifies that <tuple> provides std::tuple.
|
||||
// Some platforms still might not have it, however.
|
||||
#if GTEST_LANG_CXX11
|
||||
# define GTEST_HAS_STD_TUPLE_ 1
|
||||
# if defined(__clang__)
|
||||
// Inspired by
|
||||
// https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros
|
||||
# if defined(__has_include) && !__has_include(<tuple>)
|
||||
# undef GTEST_HAS_STD_TUPLE_
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
// Inspired by boost/config/stdlib/dinkumware.hpp
|
||||
# if defined(_CPPLIB_VER) && _CPPLIB_VER < 520
|
||||
# undef GTEST_HAS_STD_TUPLE_
|
||||
# endif
|
||||
# elif defined(__GLIBCXX__)
|
||||
// Inspired by boost/config/stdlib/libstdcpp3.hpp,
|
||||
// http://gcc.gnu.org/gcc-4.2/changes.html and
|
||||
// https://web.archive.org/web/20140227044429/gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x
|
||||
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
|
||||
# undef GTEST_HAS_STD_TUPLE_
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Brings in definitions for functions used in the testing::internal::posix
|
||||
// namespace (read, write, close, chdir, isatty, stat). We do not currently
|
||||
// use them on Windows Mobile.
|
||||
@ -638,136 +562,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
# include <time.h> // NOLINT
|
||||
#endif
|
||||
|
||||
// Determines if hash_map/hash_set are available.
|
||||
// Only used for testing against those containers.
|
||||
#if !defined(GTEST_HAS_HASH_MAP_)
|
||||
# if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available.
|
||||
# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available.
|
||||
# endif // _MSC_VER
|
||||
#endif // !defined(GTEST_HAS_HASH_MAP_)
|
||||
|
||||
// Determines whether Google Test can use tr1/tuple. You can define
|
||||
// this macro to 0 to prevent Google Test from using tuple (any
|
||||
// feature depending on tuple with be disabled in this mode).
|
||||
#ifndef GTEST_HAS_TR1_TUPLE
|
||||
# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
|
||||
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
|
||||
// Prevent `warning C4996: 'std::tr1': warning STL4002:
|
||||
// The non-Standard std::tr1 namespace and TR1-only machinery
|
||||
// are deprecated and will be REMOVED.`
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
|
||||
// libc++ doesn't support TR1.
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# else
|
||||
// The user didn't tell us not to do it, so we assume it's OK.
|
||||
# define GTEST_HAS_TR1_TUPLE 1
|
||||
# endif
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
// Determines whether Google Test's own tr1 tuple implementation
|
||||
// should be used.
|
||||
#ifndef GTEST_USE_OWN_TR1_TUPLE
|
||||
// We use our own tuple implementation on Symbian.
|
||||
# if GTEST_OS_SYMBIAN
|
||||
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||
# else
|
||||
// The user didn't tell us, so we need to figure it out.
|
||||
|
||||
// We use our own TR1 tuple if we aren't sure the user has an
|
||||
// implementation of it already. At this time, libstdc++ 4.0.0+ and
|
||||
// MSVC 2010 are the only mainstream standard libraries that come
|
||||
// with a TR1 tuple implementation. NVIDIA's CUDA NVCC compiler
|
||||
// pretends to be GCC by defining __GNUC__ and friends, but cannot
|
||||
// compile GCC's tuple implementation. MSVC 2008 (9.0) provides TR1
|
||||
// tuple in a 323 MB Feature Pack download, which we cannot assume the
|
||||
// user has. QNX's QCC compiler is a modified GCC but it doesn't
|
||||
// support TR1 tuple. libc++ only provides std::tuple, in C++11 mode,
|
||||
// and it can be used with some compilers that define __GNUC__.
|
||||
# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
|
||||
&& !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) \
|
||||
|| (_MSC_VER >= 1600 && _MSC_VER < 1900)
|
||||
# define GTEST_ENV_HAS_TR1_TUPLE_ 1
|
||||
# endif
|
||||
|
||||
// C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
|
||||
// in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
|
||||
// can build with clang but need to use gcc4.2's libstdc++).
|
||||
# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
|
||||
# define GTEST_ENV_HAS_STD_TUPLE_ 1
|
||||
# endif
|
||||
|
||||
# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
|
||||
# define GTEST_USE_OWN_TR1_TUPLE 0
|
||||
# else
|
||||
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||
# endif
|
||||
# endif // GTEST_OS_SYMBIAN
|
||||
#endif // GTEST_USE_OWN_TR1_TUPLE
|
||||
|
||||
// To avoid conditional compilation we make it gtest-port.h's responsibility
|
||||
// to #include the header implementing tuple.
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
# include <tuple> // IWYU pragma: export
|
||||
# define GTEST_TUPLE_NAMESPACE_ ::std
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
// We include tr1::tuple even if std::tuple is available to define printers for
|
||||
// them.
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
# ifndef GTEST_TUPLE_NAMESPACE_
|
||||
# define GTEST_TUPLE_NAMESPACE_ ::std::tr1
|
||||
# endif // GTEST_TUPLE_NAMESPACE_
|
||||
|
||||
# if GTEST_USE_OWN_TR1_TUPLE
|
||||
# include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
|
||||
# elif GTEST_OS_SYMBIAN
|
||||
|
||||
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
|
||||
// use STLport's tuple implementation, which unfortunately doesn't
|
||||
// work as the copy of STLport distributed with Symbian is incomplete.
|
||||
// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
|
||||
// use its own tuple implementation.
|
||||
# ifdef BOOST_HAS_TR1_TUPLE
|
||||
# undef BOOST_HAS_TR1_TUPLE
|
||||
# endif // BOOST_HAS_TR1_TUPLE
|
||||
|
||||
// This prevents <boost/tr1/detail/config.hpp>, which defines
|
||||
// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
|
||||
# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
|
||||
# include <tuple> // IWYU pragma: export // NOLINT
|
||||
|
||||
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
|
||||
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
|
||||
// not conform to the TR1 spec, which requires the header to be <tuple>.
|
||||
|
||||
# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
|
||||
// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
|
||||
// which is #included by <tr1/tuple>, to not compile when RTTI is
|
||||
// disabled. _TR1_FUNCTIONAL is the header guard for
|
||||
// <tr1/functional>. Hence the following #define is used to prevent
|
||||
// <tr1/functional> from being included.
|
||||
# define _TR1_FUNCTIONAL 1
|
||||
# include <tr1/tuple>
|
||||
# undef _TR1_FUNCTIONAL // Allows the user to #include
|
||||
// <tr1/functional> if they choose to.
|
||||
# else
|
||||
# include <tr1/tuple> // NOLINT
|
||||
# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
|
||||
|
||||
// VS 2010 now has tr1 support.
|
||||
# elif _MSC_VER >= 1600
|
||||
# include <tuple> // IWYU pragma: export // NOLINT
|
||||
|
||||
# else // GTEST_USE_OWN_TR1_TUPLE
|
||||
# include <tr1/tuple> // IWYU pragma: export // NOLINT
|
||||
# endif // GTEST_USE_OWN_TR1_TUPLE
|
||||
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
// Determines whether clone(2) is supported.
|
||||
// Usually it will only be available on Linux, excluding
|
||||
// Linux on the Itanium architecture.
|
||||
@ -810,12 +604,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Determines whether to support death tests.
|
||||
// Google Test does not support death tests for VC 7.1 and earlier as
|
||||
// abort() in a VC 7.1 application compiled as GUI in debug config
|
||||
// pops up a dialog window that cannot be suppressed programmatically.
|
||||
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
|
||||
(GTEST_OS_MAC && !GTEST_OS_IOS) || \
|
||||
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
|
||||
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || \
|
||||
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
|
||||
GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \
|
||||
GTEST_OS_NETBSD || GTEST_OS_FUCHSIA)
|
||||
@ -826,23 +618,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
|
||||
// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
|
||||
// Sun Pro CC, IBM Visual Age, and HP aCC support.
|
||||
#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
|
||||
#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
|
||||
defined(__IBMCPP__) || defined(__HP_aCC)
|
||||
# define GTEST_HAS_TYPED_TEST 1
|
||||
# define GTEST_HAS_TYPED_TEST_P 1
|
||||
#endif
|
||||
|
||||
// Determines whether to support Combine(). This only makes sense when
|
||||
// value-parameterized tests are enabled. The implementation doesn't
|
||||
// work on Sun Studio since it doesn't understand templated conversion
|
||||
// operators.
|
||||
#if (GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_) && !defined(__SUNPRO_CC)
|
||||
# define GTEST_HAS_COMBINE 1
|
||||
#endif
|
||||
|
||||
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
|
||||
#define GTEST_WIDE_STRING_USES_UTF16_ \
|
||||
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
|
||||
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || \
|
||||
GTEST_OS_AIX || GTEST_OS_OS2)
|
||||
|
||||
// Determines whether test results can be streamed to a socket.
|
||||
#if GTEST_OS_LINUX
|
||||
@ -887,12 +672,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
# define GTEST_ATTRIBUTE_UNUSED_
|
||||
#endif
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
# define GTEST_CXX11_EQUALS_DELETE_ = delete
|
||||
#else // GTEST_LANG_CXX11
|
||||
# define GTEST_CXX11_EQUALS_DELETE_
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// Use this annotation before a function that takes a printf format string.
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
|
||||
# if defined(__MINGW_PRINTF_FORMAT)
|
||||
@ -914,12 +693,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
// A macro to disallow operator=
|
||||
// This should be used in the private: declarations for a class.
|
||||
#define GTEST_DISALLOW_ASSIGN_(type) \
|
||||
void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_
|
||||
void operator=(type const &) = delete
|
||||
|
||||
// A macro to disallow copy constructor and operator=
|
||||
// This should be used in the private: declarations for a class.
|
||||
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
|
||||
type(type const &) GTEST_CXX11_EQUALS_DELETE_; \
|
||||
type(type const &) = delete; \
|
||||
GTEST_DISALLOW_ASSIGN_(type)
|
||||
|
||||
// Tell the compiler to warn about unused return values for functions declared
|
||||
@ -960,13 +739,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
||||
# define GTEST_HAS_SEH 0
|
||||
# endif
|
||||
|
||||
#define GTEST_IS_THREADSAFE \
|
||||
(GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ \
|
||||
|| (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \
|
||||
|| GTEST_HAS_PTHREAD)
|
||||
|
||||
#endif // GTEST_HAS_SEH
|
||||
|
||||
#ifndef GTEST_IS_THREADSAFE
|
||||
|
||||
#define GTEST_IS_THREADSAFE \
|
||||
(GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
|
||||
(GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \
|
||||
GTEST_HAS_PTHREAD)
|
||||
|
||||
#endif // GTEST_IS_THREADSAFE
|
||||
|
||||
// GTEST_API_ qualifies all symbols that must be exported. The definitions below
|
||||
// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in
|
||||
// gtest/internal/custom/gtest-port.h
|
||||
@ -1049,16 +832,13 @@ namespace testing {
|
||||
|
||||
class Message;
|
||||
|
||||
#if defined(GTEST_TUPLE_NAMESPACE_)
|
||||
// Import tuple and friends into the ::testing namespace.
|
||||
// It is part of our interface, having them in ::testing allows us to change
|
||||
// their types as needed.
|
||||
using GTEST_TUPLE_NAMESPACE_::get;
|
||||
using GTEST_TUPLE_NAMESPACE_::make_tuple;
|
||||
using GTEST_TUPLE_NAMESPACE_::tuple;
|
||||
using GTEST_TUPLE_NAMESPACE_::tuple_size;
|
||||
using GTEST_TUPLE_NAMESPACE_::tuple_element;
|
||||
#endif // defined(GTEST_TUPLE_NAMESPACE_)
|
||||
// Legacy imports for backwards compatibility.
|
||||
// New code should use std:: names directly.
|
||||
using std::get;
|
||||
using std::make_tuple;
|
||||
using std::tuple;
|
||||
using std::tuple_element;
|
||||
using std::tuple_size;
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -1067,75 +847,16 @@ namespace internal {
|
||||
// Secret object, which is what we want.
|
||||
class Secret;
|
||||
|
||||
// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
|
||||
// expression is true. For example, you could use it to verify the
|
||||
// size of a static array:
|
||||
// The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile
|
||||
// time expression is true (in new code, use static_assert instead). For
|
||||
// example, you could use it to verify the size of a static array:
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
|
||||
// names_incorrect_size);
|
||||
//
|
||||
// or to make sure a struct is smaller than a certain size:
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
|
||||
//
|
||||
// The second argument to the macro is the name of the variable. If
|
||||
// the expression is false, most compilers will issue a warning/error
|
||||
// containing the name of the variable.
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
|
||||
#else // !GTEST_LANG_CXX11
|
||||
template <bool>
|
||||
struct CompileAssert {
|
||||
};
|
||||
|
||||
# define GTEST_COMPILE_ASSERT_(expr, msg) \
|
||||
typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
|
||||
msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
|
||||
#endif // !GTEST_LANG_CXX11
|
||||
|
||||
// Implementation details of GTEST_COMPILE_ASSERT_:
|
||||
//
|
||||
// (In C++11, we simply use static_assert instead of the following)
|
||||
//
|
||||
// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
|
||||
// elements (and thus is invalid) when the expression is false.
|
||||
//
|
||||
// - The simpler definition
|
||||
//
|
||||
// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
|
||||
//
|
||||
// does not work, as gcc supports variable-length arrays whose sizes
|
||||
// are determined at run-time (this is gcc's extension and not part
|
||||
// of the C++ standard). As a result, gcc fails to reject the
|
||||
// following code with the simple definition:
|
||||
//
|
||||
// int foo;
|
||||
// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
|
||||
// // not a compile-time constant.
|
||||
//
|
||||
// - By using the type CompileAssert<(bool(expr))>, we ensures that
|
||||
// expr is a compile-time constant. (Template arguments must be
|
||||
// determined at compile-time.)
|
||||
//
|
||||
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
|
||||
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
|
||||
//
|
||||
// CompileAssert<bool(expr)>
|
||||
//
|
||||
// instead, these compilers will refuse to compile
|
||||
//
|
||||
// GTEST_COMPILE_ASSERT_(5 > 0, some_message);
|
||||
//
|
||||
// (They seem to think the ">" in "5 > 0" marks the end of the
|
||||
// template argument list.)
|
||||
//
|
||||
// - The array size is (bool(expr) ? 1 : -1), instead of simply
|
||||
//
|
||||
// ((expr) ? 1 : -1).
|
||||
//
|
||||
// This is to avoid running into a bug in MS VC 7.1, which
|
||||
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
|
||||
// The second argument to the macro must be a valid C++ identifier. If the
|
||||
// expression is false, compiler will issue an error containing this identifier.
|
||||
#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
|
||||
|
||||
// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
|
||||
//
|
||||
@ -1177,48 +898,6 @@ typedef ::std::wstring wstring;
|
||||
// returns 'condition'.
|
||||
GTEST_API_ bool IsTrue(bool condition);
|
||||
|
||||
// Defines scoped_ptr.
|
||||
|
||||
// This implementation of scoped_ptr is PARTIAL - it only contains
|
||||
// enough stuff to satisfy Google Test's need.
|
||||
template <typename T>
|
||||
class scoped_ptr {
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
explicit scoped_ptr(T* p = nullptr) : ptr_(p) {}
|
||||
~scoped_ptr() { reset(); }
|
||||
|
||||
T& operator*() const { return *ptr_; }
|
||||
T* operator->() const { return ptr_; }
|
||||
T* get() const { return ptr_; }
|
||||
|
||||
T* release() {
|
||||
T* const ptr = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void reset(T* p = nullptr) {
|
||||
if (p != ptr_) {
|
||||
if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type.
|
||||
delete ptr_;
|
||||
}
|
||||
ptr_ = p;
|
||||
}
|
||||
}
|
||||
|
||||
friend void swap(scoped_ptr& a, scoped_ptr& b) {
|
||||
using std::swap;
|
||||
swap(a.ptr_, b.ptr_);
|
||||
}
|
||||
|
||||
private:
|
||||
T* ptr_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
|
||||
};
|
||||
|
||||
// Defines RE.
|
||||
|
||||
#if GTEST_USES_PCRE
|
||||
@ -1419,28 +1098,6 @@ struct ConstRef<T&> { typedef T& type; };
|
||||
#define GTEST_REFERENCE_TO_CONST_(T) \
|
||||
typename ::testing::internal::ConstRef<T>::type
|
||||
|
||||
#if GTEST_HAS_STD_MOVE_
|
||||
using std::forward;
|
||||
using std::move;
|
||||
|
||||
template <typename T>
|
||||
struct RvalueRef {
|
||||
typedef T&& type;
|
||||
};
|
||||
#else // GTEST_HAS_STD_MOVE_
|
||||
template <typename T>
|
||||
const T& move(const T& t) {
|
||||
return t;
|
||||
}
|
||||
template <typename T>
|
||||
GTEST_ADD_REFERENCE_(T) forward(GTEST_ADD_REFERENCE_(T) t) { return t; }
|
||||
|
||||
template <typename T>
|
||||
struct RvalueRef {
|
||||
typedef const T& type;
|
||||
};
|
||||
#endif // GTEST_HAS_STD_MOVE_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Use ImplicitCast_ as a safe version of static_cast for upcasting in
|
||||
@ -1494,13 +1151,13 @@ inline To DownCast_(From* f) { // so we only accept pointers
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (false) {
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
const To to = NULL;
|
||||
::testing::internal::ImplicitCast_<From*>(to);
|
||||
const To to = nullptr;
|
||||
::testing::internal::ImplicitCast_<From*>(to);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_RTTI
|
||||
// RTTI: debug mode only!
|
||||
GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != NULL);
|
||||
GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != nullptr);
|
||||
#endif
|
||||
return static_cast<To>(f);
|
||||
}
|
||||
@ -1730,7 +1387,7 @@ class ThreadWithParam : public ThreadWithParamBase {
|
||||
GTEST_CHECK_POSIX_SUCCESS_(
|
||||
pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base));
|
||||
}
|
||||
~ThreadWithParam() { Join(); }
|
||||
~ThreadWithParam() override { Join(); }
|
||||
|
||||
void Join() {
|
||||
if (!finished_) {
|
||||
@ -1739,7 +1396,7 @@ class ThreadWithParam : public ThreadWithParamBase {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Run() {
|
||||
void Run() override {
|
||||
if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification();
|
||||
func_(param_);
|
||||
}
|
||||
@ -2034,7 +1691,7 @@ class ThreadLocal : public ThreadLocalBase {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory);
|
||||
};
|
||||
|
||||
scoped_ptr<ValueHolderFactory> default_factory_;
|
||||
std::unique_ptr<ValueHolderFactory> default_factory_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
|
||||
};
|
||||
@ -2245,7 +1902,7 @@ class GTEST_API_ ThreadLocal {
|
||||
|
||||
// A key pthreads uses for looking up per-thread values.
|
||||
const pthread_key_t key_;
|
||||
scoped_ptr<ValueHolderFactory> default_factory_;
|
||||
std::unique_ptr<ValueHolderFactory> default_factory_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
|
||||
};
|
||||
@ -2523,12 +2180,12 @@ inline const char* GetEnv(const char* name) {
|
||||
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
|
||||
// We are on Windows CE, which has no environment variables.
|
||||
static_cast<void>(name); // To prevent 'unused argument' warning.
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
|
||||
// Environment variables which we programmatically clear will be set to the
|
||||
// empty string rather than unset (NULL). Handle that case.
|
||||
const char* const env = getenv(name);
|
||||
return (env != NULL && env[0] != '\0') ? env : NULL;
|
||||
return (env != nullptr && env[0] != '\0') ? env : nullptr;
|
||||
#else
|
||||
return getenv(name);
|
||||
#endif
|
||||
@ -2540,9 +2197,9 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_()
|
||||
// Windows CE has no C library. The abort() function is used in
|
||||
// several places in Google Test. This implementation provides a reasonable
|
||||
// imitation of standard behaviour.
|
||||
void Abort();
|
||||
[[noreturn]] void Abort();
|
||||
#else
|
||||
inline void Abort() { abort(); }
|
||||
[[noreturn]] inline void Abort() { abort(); }
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
} // namespace posix
|
||||
@ -2552,13 +2209,12 @@ inline void Abort() { abort(); }
|
||||
// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
|
||||
// function in order to achieve that. We use macro definition here because
|
||||
// snprintf is a variadic function.
|
||||
#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
|
||||
#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
|
||||
// MSVC 2005 and above support variadic macros.
|
||||
# define GTEST_SNPRINTF_(buffer, size, format, ...) \
|
||||
_snprintf_s(buffer, size, size, format, __VA_ARGS__)
|
||||
#elif defined(_MSC_VER)
|
||||
// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
|
||||
// complain about _snprintf.
|
||||
// Windows CE does not define _snprintf_s
|
||||
# define GTEST_SNPRINTF_ _snprintf
|
||||
#else
|
||||
# define GTEST_SNPRINTF_ snprintf
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,348 +0,0 @@
|
||||
$$ -*- mode: c++; -*-
|
||||
$var n = 10 $$ Maximum number of tuple fields we want to support.
|
||||
$$ This meta comment fixes auto-indentation in Emacs. }}
|
||||
// Copyright 2009 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.
|
||||
|
||||
|
||||
// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
|
||||
#include <utility> // For ::std::pair.
|
||||
|
||||
// The compiler used in Symbian has a bug that prevents us from declaring the
|
||||
// tuple template as a friend (it complains that tuple is redefined). This
|
||||
// bypasses the bug by declaring the members that should otherwise be
|
||||
// private as public.
|
||||
// Sun Studio versions < 12 also have the above bug.
|
||||
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
|
||||
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
|
||||
#else
|
||||
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
|
||||
template <GTEST_$(n)_TYPENAMES_(U)> friend class tuple; \
|
||||
private:
|
||||
#endif
|
||||
|
||||
// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
|
||||
// with our own definitions. Therefore using our own tuple does not work on
|
||||
// those compilers.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */
|
||||
# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \
|
||||
GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers."
|
||||
#endif
|
||||
|
||||
|
||||
$range i 0..n-1
|
||||
$range j 0..n
|
||||
$range k 1..n
|
||||
// GTEST_n_TUPLE_(T) is the type of an n-tuple.
|
||||
#define GTEST_0_TUPLE_(T) tuple<>
|
||||
|
||||
$for k [[
|
||||
$range m 0..k-1
|
||||
$range m2 k..n-1
|
||||
#define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]>
|
||||
|
||||
]]
|
||||
|
||||
// GTEST_n_TYPENAMES_(T) declares a list of n typenames.
|
||||
|
||||
$for j [[
|
||||
$range m 0..j-1
|
||||
#define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]]
|
||||
|
||||
|
||||
]]
|
||||
|
||||
// In theory, defining stuff in the ::std namespace is undefined
|
||||
// behavior. We can do this as we are playing the role of a standard
|
||||
// library vendor.
|
||||
namespace std {
|
||||
namespace tr1 {
|
||||
|
||||
template <$for i, [[typename T$i = void]]>
|
||||
class tuple;
|
||||
|
||||
// Anything in namespace gtest_internal is Google Test's INTERNAL
|
||||
// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
|
||||
namespace gtest_internal {
|
||||
|
||||
// ByRef<T>::type is T if T is a reference; otherwise it's const T&.
|
||||
template <typename T>
|
||||
struct ByRef { typedef const T& type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct ByRef<T&> { typedef T& type; }; // NOLINT
|
||||
|
||||
// A handy wrapper for ByRef.
|
||||
#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
|
||||
|
||||
// AddRef<T>::type is T if T is a reference; otherwise it's T&. This
|
||||
// is the same as tr1::add_reference<T>::type.
|
||||
template <typename T>
|
||||
struct AddRef { typedef T& type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct AddRef<T&> { typedef T& type; }; // NOLINT
|
||||
|
||||
// A handy wrapper for AddRef.
|
||||
#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
|
||||
|
||||
// A helper for implementing get<k>().
|
||||
template <int k> class Get;
|
||||
|
||||
// A helper for implementing tuple_element<k, T>. kIndexValid is true
|
||||
// iff k < the number of fields in tuple type T.
|
||||
template <bool kIndexValid, int kIndex, class Tuple>
|
||||
struct TupleElement;
|
||||
|
||||
|
||||
$for i [[
|
||||
template <GTEST_$(n)_TYPENAMES_(T)>
|
||||
struct TupleElement<true, $i, GTEST_$(n)_TUPLE_(T) > {
|
||||
typedef T$i type;
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
} // namespace gtest_internal
|
||||
|
||||
template <>
|
||||
class tuple<> {
|
||||
public:
|
||||
tuple() {}
|
||||
tuple(const tuple& /* t */) {}
|
||||
tuple& operator=(const tuple& /* t */) { return *this; }
|
||||
};
|
||||
|
||||
|
||||
$for k [[
|
||||
$range m 0..k-1
|
||||
template <GTEST_$(k)_TYPENAMES_(T)>
|
||||
class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] {
|
||||
public:
|
||||
template <int k> friend class gtest_internal::Get;
|
||||
|
||||
tuple() : $for m, [[f$(m)_()]] {}
|
||||
|
||||
explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]]
|
||||
$for m, [[f$(m)_(f$m)]] {}
|
||||
|
||||
tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
|
||||
|
||||
template <GTEST_$(k)_TYPENAMES_(U)>
|
||||
tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
|
||||
|
||||
$if k == 2 [[
|
||||
template <typename U0, typename U1>
|
||||
tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
|
||||
|
||||
]]
|
||||
|
||||
tuple& operator=(const tuple& t) { return CopyFrom(t); }
|
||||
|
||||
template <GTEST_$(k)_TYPENAMES_(U)>
|
||||
tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) {
|
||||
return CopyFrom(t);
|
||||
}
|
||||
|
||||
$if k == 2 [[
|
||||
template <typename U0, typename U1>
|
||||
tuple& operator=(const ::std::pair<U0, U1>& p) {
|
||||
f0_ = p.first;
|
||||
f1_ = p.second;
|
||||
return *this;
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
GTEST_DECLARE_TUPLE_AS_FRIEND_
|
||||
|
||||
template <GTEST_$(k)_TYPENAMES_(U)>
|
||||
tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) {
|
||||
|
||||
$for m [[
|
||||
f$(m)_ = t.f$(m)_;
|
||||
|
||||
]]
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
$for m [[
|
||||
T$m f$(m)_;
|
||||
|
||||
]]
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
// 6.1.3.2 Tuple creation functions.
|
||||
|
||||
// Known limitations: we don't support passing an
|
||||
// std::tr1::reference_wrapper<T> to make_tuple(). And we don't
|
||||
// implement tie().
|
||||
|
||||
inline tuple<> make_tuple() { return tuple<>(); }
|
||||
|
||||
$for k [[
|
||||
$range m 0..k-1
|
||||
|
||||
template <GTEST_$(k)_TYPENAMES_(T)>
|
||||
inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) {
|
||||
return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]);
|
||||
}
|
||||
|
||||
]]
|
||||
|
||||
// 6.1.3.3 Tuple helper classes.
|
||||
|
||||
template <typename Tuple> struct tuple_size;
|
||||
|
||||
|
||||
$for j [[
|
||||
template <GTEST_$(j)_TYPENAMES_(T)>
|
||||
struct tuple_size<GTEST_$(j)_TUPLE_(T) > {
|
||||
static const int value = $j;
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
template <int k, class Tuple>
|
||||
struct tuple_element {
|
||||
typedef typename gtest_internal::TupleElement<
|
||||
k < (tuple_size<Tuple>::value), k, Tuple>::type type;
|
||||
};
|
||||
|
||||
#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
|
||||
|
||||
// 6.1.3.4 Element access.
|
||||
|
||||
namespace gtest_internal {
|
||||
|
||||
|
||||
$for i [[
|
||||
template <>
|
||||
class Get<$i> {
|
||||
public:
|
||||
template <class Tuple>
|
||||
static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
|
||||
Field(Tuple& t) { return t.f$(i)_; } // NOLINT
|
||||
|
||||
template <class Tuple>
|
||||
static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
|
||||
ConstField(const Tuple& t) { return t.f$(i)_; }
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
} // namespace gtest_internal
|
||||
|
||||
template <int k, GTEST_$(n)_TYPENAMES_(T)>
|
||||
GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
|
||||
get(GTEST_$(n)_TUPLE_(T)& t) {
|
||||
return gtest_internal::Get<k>::Field(t);
|
||||
}
|
||||
|
||||
template <int k, GTEST_$(n)_TYPENAMES_(T)>
|
||||
GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
|
||||
get(const GTEST_$(n)_TUPLE_(T)& t) {
|
||||
return gtest_internal::Get<k>::ConstField(t);
|
||||
}
|
||||
|
||||
// 6.1.3.5 Relational operators
|
||||
|
||||
// We only implement == and !=, as we don't have a need for the rest yet.
|
||||
|
||||
namespace gtest_internal {
|
||||
|
||||
// SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
|
||||
// first k fields of t1 equals the first k fields of t2.
|
||||
// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
|
||||
// k1 != k2.
|
||||
template <int kSize1, int kSize2>
|
||||
struct SameSizeTuplePrefixComparator;
|
||||
|
||||
template <>
|
||||
struct SameSizeTuplePrefixComparator<0, 0> {
|
||||
template <class Tuple1, class Tuple2>
|
||||
static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <int k>
|
||||
struct SameSizeTuplePrefixComparator<k, k> {
|
||||
template <class Tuple1, class Tuple2>
|
||||
static bool Eq(const Tuple1& t1, const Tuple2& t2) {
|
||||
return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
|
||||
::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gtest_internal
|
||||
|
||||
template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
|
||||
inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t,
|
||||
const GTEST_$(n)_TUPLE_(U)& u) {
|
||||
return gtest_internal::SameSizeTuplePrefixComparator<
|
||||
tuple_size<GTEST_$(n)_TUPLE_(T) >::value,
|
||||
tuple_size<GTEST_$(n)_TUPLE_(U) >::value>::Eq(t, u);
|
||||
}
|
||||
|
||||
template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
|
||||
inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t,
|
||||
const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); }
|
||||
|
||||
// 6.1.4 Pairs.
|
||||
// Unimplemented.
|
||||
|
||||
} // namespace tr1
|
||||
} // namespace std
|
||||
|
||||
|
||||
$for j [[
|
||||
#undef GTEST_$(j)_TUPLE_
|
||||
|
||||
]]
|
||||
|
||||
|
||||
$for j [[
|
||||
#undef GTEST_$(j)_TYPENAMES_
|
||||
|
||||
]]
|
||||
|
||||
#undef GTEST_DECLARE_TUPLE_AS_FRIEND_
|
||||
#undef GTEST_BY_REF_
|
||||
#undef GTEST_ADD_REF_
|
||||
#undef GTEST_TUPLE_ELEMENT_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
@ -87,7 +87,7 @@ std::string GetTypeName() {
|
||||
# if GTEST_HAS_CXXABI_H_
|
||||
using abi::__cxa_demangle;
|
||||
# endif // GTEST_HAS_CXXABI_H_
|
||||
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
||||
char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status);
|
||||
const std::string name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return CanonicalizeForStdLibVersioning(name_str);
|
||||
|
@ -25,7 +25,7 @@ USER_DIR = ../samples
|
||||
CPPFLAGS += -isystem $(GTEST_DIR)/include
|
||||
|
||||
# Flags passed to the C++ compiler.
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
|
@ -54,7 +54,7 @@ class PrimeTable {
|
||||
// Implementation #1 calculates the primes on-the-fly.
|
||||
class OnTheFlyPrimeTable : public PrimeTable {
|
||||
public:
|
||||
virtual bool IsPrime(int n) const {
|
||||
bool IsPrime(int n) const override {
|
||||
if (n <= 1) return false;
|
||||
|
||||
for (int i = 2; i*i <= n; i++) {
|
||||
@ -65,7 +65,7 @@ class OnTheFlyPrimeTable : public PrimeTable {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual int GetNextPrime(int p) const {
|
||||
int GetNextPrime(int p) const override {
|
||||
for (int n = p + 1; n > 0; n++) {
|
||||
if (IsPrime(n)) return n;
|
||||
}
|
||||
@ -83,13 +83,13 @@ class PreCalculatedPrimeTable : public PrimeTable {
|
||||
: is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
|
||||
CalculatePrimesUpTo(max);
|
||||
}
|
||||
virtual ~PreCalculatedPrimeTable() { delete[] is_prime_; }
|
||||
~PreCalculatedPrimeTable() override { delete[] is_prime_; }
|
||||
|
||||
virtual bool IsPrime(int n) const {
|
||||
bool IsPrime(int n) const override {
|
||||
return 0 <= n && n < is_prime_size_ && is_prime_[n];
|
||||
}
|
||||
|
||||
virtual int GetNextPrime(int p) const {
|
||||
int GetNextPrime(int p) const override {
|
||||
for (int n = p + 1; n < is_prime_size_; n++) {
|
||||
if (is_prime_[n]) return n;
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ int Water::allocated_ = 0;
|
||||
class LeakChecker : public EmptyTestEventListener {
|
||||
private:
|
||||
// Called before a test starts.
|
||||
virtual void OnTestStart(const TestInfo& /* test_info */) {
|
||||
void OnTestStart(const TestInfo& /* test_info */) override {
|
||||
initially_allocated_ = Water::allocated();
|
||||
}
|
||||
|
||||
// Called after a test ends.
|
||||
virtual void OnTestEnd(const TestInfo& /* test_info */) {
|
||||
void OnTestEnd(const TestInfo& /* test_info */) override {
|
||||
int difference = Water::allocated() - initially_allocated_;
|
||||
|
||||
// You can generate a failure in any event handler except
|
||||
|
@ -71,7 +71,7 @@ class QueueTestSmpl3 : public testing::Test {
|
||||
// virtual void SetUp() will be called before each test is run. You
|
||||
// should define it if you need to initialize the variables.
|
||||
// Otherwise, this can be skipped.
|
||||
virtual void SetUp() {
|
||||
void SetUp() override {
|
||||
q1_.Enqueue(1);
|
||||
q2_.Enqueue(2);
|
||||
q2_.Enqueue(3);
|
||||
|
@ -63,11 +63,11 @@ class QuickTest : public testing::Test {
|
||||
protected:
|
||||
// Remember that SetUp() is run immediately before a test starts.
|
||||
// This is a good place to record the start time.
|
||||
virtual void SetUp() { start_time_ = time(nullptr); }
|
||||
void SetUp() override { start_time_ = time(nullptr); }
|
||||
|
||||
// TearDown() is invoked immediately after a test finishes. Here we
|
||||
// check if the test was too slow.
|
||||
virtual void TearDown() {
|
||||
void TearDown() override {
|
||||
// Gets the time when the test finishes
|
||||
const time_t end_time = time(nullptr);
|
||||
|
||||
@ -140,7 +140,7 @@ TEST_F(IntegerFunctionTest, IsPrime) {
|
||||
// stuff inside the body of the test fixture, as usual.
|
||||
class QueueTest : public QuickTest {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
void SetUp() override {
|
||||
// First, we need to set up the super fixture (QuickTest).
|
||||
QuickTest::SetUp();
|
||||
|
||||
|
@ -61,7 +61,7 @@ class PrimeTableTest : public testing::Test {
|
||||
// implemented by T.
|
||||
PrimeTableTest() : table_(CreatePrimeTable<T>()) {}
|
||||
|
||||
virtual ~PrimeTableTest() { delete table_; }
|
||||
~PrimeTableTest() override { delete table_; }
|
||||
|
||||
// Note that we test an implementation via the base interface
|
||||
// instead of the actual implementation class. This is important
|
||||
|
@ -65,9 +65,9 @@ PrimeTable* CreatePreCalculatedPrimeTable() {
|
||||
// create and store an instance of PrimeTable.
|
||||
class PrimeTableTestSmpl7 : public TestWithParam<CreatePrimeTableFunc*> {
|
||||
public:
|
||||
virtual ~PrimeTableTestSmpl7() { delete table_; }
|
||||
virtual void SetUp() { table_ = (*GetParam())(); }
|
||||
virtual void TearDown() {
|
||||
~PrimeTableTestSmpl7() override { delete table_; }
|
||||
void SetUp() override { table_ = (*GetParam())(); }
|
||||
void TearDown() override {
|
||||
delete table_;
|
||||
table_ = nullptr;
|
||||
}
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
namespace {
|
||||
#if GTEST_HAS_COMBINE
|
||||
|
||||
// Suppose we want to introduce a new, improved implementation of PrimeTable
|
||||
// which combines speed of PrecalcPrimeTable and versatility of
|
||||
@ -54,19 +53,19 @@ class HybridPrimeTable : public PrimeTable {
|
||||
? nullptr
|
||||
: new PreCalculatedPrimeTable(max_precalculated)),
|
||||
max_precalculated_(max_precalculated) {}
|
||||
virtual ~HybridPrimeTable() {
|
||||
~HybridPrimeTable() override {
|
||||
delete on_the_fly_impl_;
|
||||
delete precalc_impl_;
|
||||
}
|
||||
|
||||
virtual bool IsPrime(int n) const {
|
||||
bool IsPrime(int n) const override {
|
||||
if (precalc_impl_ != nullptr && n < max_precalculated_)
|
||||
return precalc_impl_->IsPrime(n);
|
||||
else
|
||||
return on_the_fly_impl_->IsPrime(n);
|
||||
}
|
||||
|
||||
virtual int GetNextPrime(int p) const {
|
||||
int GetNextPrime(int p) const override {
|
||||
int next_prime = -1;
|
||||
if (precalc_impl_ != nullptr && p < max_precalculated_)
|
||||
next_prime = precalc_impl_->GetNextPrime(p);
|
||||
@ -90,22 +89,15 @@ using ::testing::Combine;
|
||||
// PreCalculatedPrimeTable disabled. We do this by defining fixture which will
|
||||
// accept different combinations of parameters for instantiating a
|
||||
// HybridPrimeTable instance.
|
||||
class PrimeTableTest : public TestWithParam< ::testing::tuple<bool, int> > {
|
||||
class PrimeTableTest : public TestWithParam< ::std::tuple<bool, int> > {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
// This can be written as
|
||||
//
|
||||
// bool force_on_the_fly;
|
||||
// int max_precalculated;
|
||||
// tie(force_on_the_fly, max_precalculated) = GetParam();
|
||||
//
|
||||
// once the Google C++ Style Guide allows use of ::std::tr1::tie.
|
||||
//
|
||||
bool force_on_the_fly = ::testing::get<0>(GetParam());
|
||||
int max_precalculated = ::testing::get<1>(GetParam());
|
||||
void SetUp() override {
|
||||
bool force_on_the_fly;
|
||||
int max_precalculated;
|
||||
std::tie(force_on_the_fly, max_precalculated) = GetParam();
|
||||
table_ = new HybridPrimeTable(force_on_the_fly, max_precalculated);
|
||||
}
|
||||
virtual void TearDown() {
|
||||
void TearDown() override {
|
||||
delete table_;
|
||||
table_ = nullptr;
|
||||
}
|
||||
@ -160,15 +152,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
|
||||
PrimeTableTest,
|
||||
Combine(Bool(), Values(1, 10)));
|
||||
|
||||
#else
|
||||
|
||||
// Google Test may not support Combine() with some compilers. If we
|
||||
// use conditional compilation to compile out all code referring to
|
||||
// the gtest_main library, MSVC linker will not link that library at
|
||||
// all and consequently complain about missing entry point defined in
|
||||
// that library (fatal error LNK1561: entry point must be
|
||||
// defined). This dummy test keeps gtest_main linked in.
|
||||
TEST(DummyTest, CombineIsNotSupportedOnThisPlatform) {}
|
||||
|
||||
#endif // GTEST_HAS_COMBINE
|
||||
} // namespace
|
||||
|
@ -49,16 +49,16 @@ namespace {
|
||||
class TersePrinter : public EmptyTestEventListener {
|
||||
private:
|
||||
// Called before any test activity starts.
|
||||
virtual void OnTestProgramStart(const UnitTest& /* unit_test */) {}
|
||||
void OnTestProgramStart(const UnitTest& /* unit_test */) override {}
|
||||
|
||||
// Called after all test activities have ended.
|
||||
virtual void OnTestProgramEnd(const UnitTest& unit_test) {
|
||||
void OnTestProgramEnd(const UnitTest& unit_test) override {
|
||||
fprintf(stdout, "TEST %s\n", unit_test.Passed() ? "PASSED" : "FAILED");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// Called before a test starts.
|
||||
virtual void OnTestStart(const TestInfo& test_info) {
|
||||
void OnTestStart(const TestInfo& test_info) override {
|
||||
fprintf(stdout,
|
||||
"*** Test %s.%s starting.\n",
|
||||
test_info.test_case_name(),
|
||||
@ -67,7 +67,7 @@ class TersePrinter : public EmptyTestEventListener {
|
||||
}
|
||||
|
||||
// Called after a failed assertion or a SUCCEED() invocation.
|
||||
virtual void OnTestPartResult(const TestPartResult& test_part_result) {
|
||||
void OnTestPartResult(const TestPartResult& test_part_result) override {
|
||||
fprintf(stdout,
|
||||
"%s in %s:%d\n%s\n",
|
||||
test_part_result.failed() ? "*** Failure" : "Success",
|
||||
@ -78,7 +78,7 @@ class TersePrinter : public EmptyTestEventListener {
|
||||
}
|
||||
|
||||
// Called after a test ends.
|
||||
virtual void OnTestEnd(const TestInfo& test_info) {
|
||||
void OnTestEnd(const TestInfo& test_info) override {
|
||||
fprintf(stdout,
|
||||
"*** Test %s.%s ending.\n",
|
||||
test_info.test_case_name(),
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "src/gtest.cc"
|
||||
#include "src/gtest-death-test.cc"
|
||||
#include "src/gtest-filepath.cc"
|
||||
#include "src/gtest-matchers.cc"
|
||||
#include "src/gtest-port.cc"
|
||||
#include "src/gtest-printers.cc"
|
||||
#include "src/gtest-test-part.cc"
|
||||
|
@ -31,6 +31,9 @@
|
||||
// This file implements death tests.
|
||||
|
||||
#include "gtest/gtest-death-test.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/custom/gtest.h"
|
||||
|
||||
@ -64,8 +67,13 @@
|
||||
# if GTEST_OS_FUCHSIA
|
||||
# include <lib/fdio/io.h>
|
||||
# include <lib/fdio/spawn.h>
|
||||
# include <lib/fdio/util.h>
|
||||
# include <lib/zx/socket.h>
|
||||
# include <lib/zx/port.h>
|
||||
# include <lib/zx/process.h>
|
||||
# include <zircon/processargs.h>
|
||||
# include <zircon/syscalls.h>
|
||||
# include <zircon/syscalls/policy.h>
|
||||
# include <zircon/syscalls/port.h>
|
||||
# endif // GTEST_OS_FUCHSIA
|
||||
|
||||
@ -369,10 +377,11 @@ DeathTest::DeathTest() {
|
||||
|
||||
// Creates and returns a death test by dispatching to the current
|
||||
// death test factory.
|
||||
bool DeathTest::Create(const char* statement, const RE* regex,
|
||||
const char* file, int line, DeathTest** test) {
|
||||
bool DeathTest::Create(const char* statement,
|
||||
Matcher<const std::string&> matcher, const char* file,
|
||||
int line, DeathTest** test) {
|
||||
return GetUnitTestImpl()->death_test_factory()->Create(
|
||||
statement, regex, file, line, test);
|
||||
statement, std::move(matcher), file, line, test);
|
||||
}
|
||||
|
||||
const char* DeathTest::LastMessage() {
|
||||
@ -388,9 +397,9 @@ std::string DeathTest::last_death_test_message_;
|
||||
// Provides cross platform implementation for some death functionality.
|
||||
class DeathTestImpl : public DeathTest {
|
||||
protected:
|
||||
DeathTestImpl(const char* a_statement, const RE* a_regex)
|
||||
DeathTestImpl(const char* a_statement, Matcher<const std::string&> matcher)
|
||||
: statement_(a_statement),
|
||||
regex_(a_regex),
|
||||
matcher_(std::move(matcher)),
|
||||
spawned_(false),
|
||||
status_(-1),
|
||||
outcome_(IN_PROGRESS),
|
||||
@ -398,13 +407,12 @@ class DeathTestImpl : public DeathTest {
|
||||
write_fd_(-1) {}
|
||||
|
||||
// read_fd_ is expected to be closed and cleared by a derived class.
|
||||
~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
|
||||
~DeathTestImpl() override { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
|
||||
|
||||
void Abort(AbortReason reason);
|
||||
virtual bool Passed(bool status_ok);
|
||||
void Abort(AbortReason reason) override;
|
||||
bool Passed(bool status_ok) override;
|
||||
|
||||
const char* statement() const { return statement_; }
|
||||
const RE* regex() const { return regex_; }
|
||||
bool spawned() const { return spawned_; }
|
||||
void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
|
||||
int status() const { return status_; }
|
||||
@ -422,13 +430,15 @@ class DeathTestImpl : public DeathTest {
|
||||
// case of unexpected codes.
|
||||
void ReadAndInterpretStatusByte();
|
||||
|
||||
// Returns stderr output from the child process.
|
||||
virtual std::string GetErrorLogs();
|
||||
|
||||
private:
|
||||
// The textual content of the code this object is testing. This class
|
||||
// doesn't own this string and should not attempt to delete it.
|
||||
const char* const statement_;
|
||||
// The regular expression which test output must match. DeathTestImpl
|
||||
// doesn't own this object and should not attempt to delete it.
|
||||
const RE* const regex_;
|
||||
// A matcher that's expected to match the stderr output by the child process.
|
||||
Matcher<const std::string&> matcher_;
|
||||
// True if the death test child process has been successfully spawned.
|
||||
bool spawned_;
|
||||
// The exit status of the child process.
|
||||
@ -490,6 +500,10 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
|
||||
set_read_fd(-1);
|
||||
}
|
||||
|
||||
std::string DeathTestImpl::GetErrorLogs() {
|
||||
return GetCapturedStderr();
|
||||
}
|
||||
|
||||
// Signals that the death test code which should have exited, didn't.
|
||||
// Should be called only in a death test child process.
|
||||
// Writes a status byte to the child's status file descriptor, then
|
||||
@ -543,9 +557,8 @@ static ::std::string FormatDeathTestOutput(const ::std::string& output) {
|
||||
// in the format specified by wait(2). On Windows, this is the
|
||||
// value supplied to the ExitProcess() API or a numeric code
|
||||
// of the exception that terminated the program.
|
||||
// regex: A regular expression object to be applied to
|
||||
// the test's captured standard error output; the death test
|
||||
// fails if it does not match.
|
||||
// matcher_: A matcher that's expected to match the stderr output by the child
|
||||
// process.
|
||||
//
|
||||
// Argument:
|
||||
// status_ok: true if exit_status is acceptable in the context of
|
||||
@ -558,7 +571,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
if (!spawned())
|
||||
return false;
|
||||
|
||||
const std::string error_message = GetCapturedStderr();
|
||||
const std::string error_message = GetErrorLogs();
|
||||
|
||||
bool success = false;
|
||||
Message buffer;
|
||||
@ -579,18 +592,15 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
break;
|
||||
case DIED:
|
||||
if (status_ok) {
|
||||
# if GTEST_USES_PCRE
|
||||
// PCRE regexes support embedded NULs.
|
||||
const bool matched = RE::PartialMatch(error_message, *regex());
|
||||
# else
|
||||
const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
|
||||
# endif // GTEST_USES_PCRE
|
||||
if (matched) {
|
||||
if (matcher_.Matches(error_message)) {
|
||||
success = true;
|
||||
} else {
|
||||
std::ostringstream stream;
|
||||
matcher_.DescribeTo(&stream);
|
||||
buffer << " Result: died but not with expected error.\n"
|
||||
<< " Expected: " << regex()->pattern() << "\n"
|
||||
<< "Actual msg:\n" << FormatDeathTestOutput(error_message);
|
||||
<< " Expected: " << stream.str() << "\n"
|
||||
<< "Actual msg:\n"
|
||||
<< FormatDeathTestOutput(error_message);
|
||||
}
|
||||
} else {
|
||||
buffer << " Result: died but not with expected exit code:\n"
|
||||
@ -639,11 +649,11 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
//
|
||||
class WindowsDeathTest : public DeathTestImpl {
|
||||
public:
|
||||
WindowsDeathTest(const char* a_statement,
|
||||
const RE* a_regex,
|
||||
const char* file,
|
||||
int line)
|
||||
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
|
||||
WindowsDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line)
|
||||
: DeathTestImpl(a_statement, std::move(matcher)),
|
||||
file_(file),
|
||||
line_(line) {}
|
||||
|
||||
// All of these virtual functions are inherited from DeathTest.
|
||||
virtual int Wait();
|
||||
@ -720,7 +730,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
const TestInfo* const info = impl->current_test_info();
|
||||
const int death_test_index = info->result()->death_test_count();
|
||||
|
||||
if (flag != NULL) {
|
||||
if (flag != nullptr) {
|
||||
// ParseInternalRunDeathTestFlag() has performed all the necessary
|
||||
// processing.
|
||||
set_write_fd(flag->write_fd());
|
||||
@ -729,8 +739,8 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
|
||||
// WindowsDeathTest uses an anonymous pipe to communicate results of
|
||||
// a death test.
|
||||
SECURITY_ATTRIBUTES handles_are_inheritable = {
|
||||
sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
|
||||
SECURITY_ATTRIBUTES handles_are_inheritable = {sizeof(SECURITY_ATTRIBUTES),
|
||||
nullptr, TRUE};
|
||||
HANDLE read_handle, write_handle;
|
||||
GTEST_DEATH_TEST_CHECK_(
|
||||
::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
|
||||
@ -741,10 +751,10 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
write_handle_.Reset(write_handle);
|
||||
event_handle_.Reset(::CreateEvent(
|
||||
&handles_are_inheritable,
|
||||
TRUE, // The event will automatically reset to non-signaled state.
|
||||
FALSE, // The initial state is non-signalled.
|
||||
NULL)); // The even is unnamed.
|
||||
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
|
||||
TRUE, // The event will automatically reset to non-signaled state.
|
||||
FALSE, // The initial state is non-signalled.
|
||||
nullptr)); // The even is unnamed.
|
||||
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
|
||||
const std::string filter_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
|
||||
info->test_case_name() + "." + info->name();
|
||||
@ -760,10 +770,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
"|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
|
||||
|
||||
char executable_path[_MAX_PATH + 1]; // NOLINT
|
||||
GTEST_DEATH_TEST_CHECK_(
|
||||
_MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
|
||||
executable_path,
|
||||
_MAX_PATH));
|
||||
GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr,
|
||||
executable_path,
|
||||
_MAX_PATH));
|
||||
|
||||
std::string command_line =
|
||||
std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
|
||||
@ -784,17 +793,16 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
PROCESS_INFORMATION process_info;
|
||||
GTEST_DEATH_TEST_CHECK_(::CreateProcessA(
|
||||
executable_path,
|
||||
const_cast<char*>(command_line.c_str()),
|
||||
NULL, // Retuned process handle is not inheritable.
|
||||
NULL, // Retuned thread handle is not inheritable.
|
||||
TRUE, // Child inherits all inheritable handles (for write_handle_).
|
||||
0x0, // Default creation flags.
|
||||
NULL, // Inherit the parent's environment.
|
||||
UnitTest::GetInstance()->original_working_dir(),
|
||||
&startup_info,
|
||||
&process_info) != FALSE);
|
||||
GTEST_DEATH_TEST_CHECK_(
|
||||
::CreateProcessA(
|
||||
executable_path, const_cast<char*>(command_line.c_str()),
|
||||
nullptr, // Retuned process handle is not inheritable.
|
||||
nullptr, // Retuned thread handle is not inheritable.
|
||||
TRUE, // Child inherits all inheritable handles (for write_handle_).
|
||||
0x0, // Default creation flags.
|
||||
nullptr, // Inherit the parent's environment.
|
||||
UnitTest::GetInstance()->original_working_dir(), &startup_info,
|
||||
&process_info) != FALSE);
|
||||
child_handle_.Reset(process_info.hProcess);
|
||||
::CloseHandle(process_info.hThread);
|
||||
set_spawned(true);
|
||||
@ -805,38 +813,34 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
|
||||
class FuchsiaDeathTest : public DeathTestImpl {
|
||||
public:
|
||||
FuchsiaDeathTest(const char* a_statement,
|
||||
const RE* a_regex,
|
||||
const char* file,
|
||||
int line)
|
||||
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
|
||||
virtual ~FuchsiaDeathTest() {
|
||||
zx_status_t status = zx_handle_close(child_process_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
status = zx_handle_close(port_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
}
|
||||
FuchsiaDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line)
|
||||
: DeathTestImpl(a_statement, std::move(matcher)),
|
||||
file_(file),
|
||||
line_(line) {}
|
||||
|
||||
// All of these virtual functions are inherited from DeathTest.
|
||||
virtual int Wait();
|
||||
virtual TestRole AssumeRole();
|
||||
int Wait() override;
|
||||
TestRole AssumeRole() override;
|
||||
std::string GetErrorLogs() override;
|
||||
|
||||
private:
|
||||
// The name of the file in which the death test is located.
|
||||
const char* const file_;
|
||||
// The line number on which the death test is located.
|
||||
const int line_;
|
||||
// The stderr data captured by the child process.
|
||||
std::string captured_stderr_;
|
||||
|
||||
zx_handle_t child_process_ = ZX_HANDLE_INVALID;
|
||||
zx_handle_t port_ = ZX_HANDLE_INVALID;
|
||||
zx::process child_process_;
|
||||
zx::port port_;
|
||||
zx::socket stderr_socket_;
|
||||
};
|
||||
|
||||
// Utility class for accumulating command-line arguments.
|
||||
class Arguments {
|
||||
public:
|
||||
Arguments() {
|
||||
args_.push_back(NULL);
|
||||
}
|
||||
Arguments() { args_.push_back(nullptr); }
|
||||
|
||||
~Arguments() {
|
||||
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
|
||||
@ -872,51 +876,74 @@ class Arguments {
|
||||
// status, or 0 if no child process exists. As a side effect, sets the
|
||||
// outcome data member.
|
||||
int FuchsiaDeathTest::Wait() {
|
||||
const int kProcessKey = 0;
|
||||
const int kSocketKey = 1;
|
||||
|
||||
if (!spawned())
|
||||
return 0;
|
||||
|
||||
// Register to wait for the child process to terminate.
|
||||
zx_status_t status_zx;
|
||||
status_zx = zx_object_wait_async(child_process_,
|
||||
port_,
|
||||
0 /* key */,
|
||||
ZX_PROCESS_TERMINATED,
|
||||
ZX_WAIT_ASYNC_ONCE);
|
||||
status_zx = child_process_.wait_async(
|
||||
port_, kProcessKey, ZX_PROCESS_TERMINATED, ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
// Register to wait for the socket to be readable or closed.
|
||||
status_zx = stderr_socket_.wait_async(
|
||||
port_, kSocketKey, ZX_SOCKET_READABLE | ZX_SOCKET_PEER_CLOSED,
|
||||
ZX_WAIT_ASYNC_REPEATING);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Wait for it to terminate, or an exception to be received.
|
||||
zx_port_packet_t packet;
|
||||
status_zx = zx_port_wait(port_, ZX_TIME_INFINITE, &packet);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
if (ZX_PKT_IS_EXCEPTION(packet.type)) {
|
||||
// Process encountered an exception. Kill it directly rather than letting
|
||||
// other handlers process the event.
|
||||
status_zx = zx_task_kill(child_process_);
|
||||
bool process_terminated = false;
|
||||
bool socket_closed = false;
|
||||
do {
|
||||
zx_port_packet_t packet = {};
|
||||
status_zx = port_.wait(zx::time::infinite(), &packet);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Now wait for |child_process_| to terminate.
|
||||
zx_signals_t signals = 0;
|
||||
status_zx = zx_object_wait_one(
|
||||
child_process_, ZX_PROCESS_TERMINATED, ZX_TIME_INFINITE, &signals);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
GTEST_DEATH_TEST_CHECK_(signals & ZX_PROCESS_TERMINATED);
|
||||
} else {
|
||||
// Process terminated.
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
|
||||
}
|
||||
if (packet.key == kProcessKey) {
|
||||
if (ZX_PKT_IS_EXCEPTION(packet.type)) {
|
||||
// Process encountered an exception. Kill it directly rather than
|
||||
// letting other handlers process the event. We will get a second
|
||||
// kProcessKey event when the process actually terminates.
|
||||
status_zx = child_process_.kill();
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
} else {
|
||||
// Process terminated.
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
|
||||
process_terminated = true;
|
||||
}
|
||||
} else if (packet.key == kSocketKey) {
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_REP(packet.type));
|
||||
if (packet.signal.observed & ZX_SOCKET_READABLE) {
|
||||
// Read data from the socket.
|
||||
constexpr size_t kBufferSize = 1024;
|
||||
do {
|
||||
size_t old_length = captured_stderr_.length();
|
||||
size_t bytes_read = 0;
|
||||
captured_stderr_.resize(old_length + kBufferSize);
|
||||
status_zx = stderr_socket_.read(
|
||||
0, &captured_stderr_.front() + old_length, kBufferSize,
|
||||
&bytes_read);
|
||||
captured_stderr_.resize(old_length + bytes_read);
|
||||
} while (status_zx == ZX_OK);
|
||||
if (status_zx == ZX_ERR_PEER_CLOSED) {
|
||||
socket_closed = true;
|
||||
} else {
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_ERR_SHOULD_WAIT);
|
||||
}
|
||||
} else {
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_SOCKET_PEER_CLOSED);
|
||||
socket_closed = true;
|
||||
}
|
||||
}
|
||||
} while (!process_terminated && !socket_closed);
|
||||
|
||||
ReadAndInterpretStatusByte();
|
||||
|
||||
zx_info_process_t buffer;
|
||||
status_zx = zx_object_get_info(
|
||||
child_process_,
|
||||
ZX_INFO_PROCESS,
|
||||
&buffer,
|
||||
sizeof(buffer),
|
||||
nullptr,
|
||||
nullptr);
|
||||
status_zx = child_process_.get_info(
|
||||
ZX_INFO_PROCESS, &buffer, sizeof(buffer), nullptr, nullptr);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
GTEST_DEATH_TEST_CHECK_(buffer.exited);
|
||||
@ -936,14 +963,13 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
||||
const TestInfo* const info = impl->current_test_info();
|
||||
const int death_test_index = info->result()->death_test_count();
|
||||
|
||||
if (flag != NULL) {
|
||||
if (flag != nullptr) {
|
||||
// ParseInternalRunDeathTestFlag() has performed all the necessary
|
||||
// processing.
|
||||
set_write_fd(kFuchsiaReadPipeFd);
|
||||
return EXECUTE_TEST;
|
||||
}
|
||||
|
||||
CaptureStderr();
|
||||
// Flush the log buffers since the log streams are shared with the child.
|
||||
FlushInfoLog();
|
||||
|
||||
@ -970,29 +996,65 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
||||
set_read_fd(status);
|
||||
|
||||
// Set the pipe handle for the child.
|
||||
fdio_spawn_action_t add_handle_action = {};
|
||||
add_handle_action.action = FDIO_SPAWN_ACTION_ADD_HANDLE;
|
||||
add_handle_action.h.id = PA_HND(type, kFuchsiaReadPipeFd);
|
||||
add_handle_action.h.handle = child_pipe_handle;
|
||||
fdio_spawn_action_t spawn_actions[2] = {};
|
||||
fdio_spawn_action_t* add_handle_action = &spawn_actions[0];
|
||||
add_handle_action->action = FDIO_SPAWN_ACTION_ADD_HANDLE;
|
||||
add_handle_action->h.id = PA_HND(type, kFuchsiaReadPipeFd);
|
||||
add_handle_action->h.handle = child_pipe_handle;
|
||||
|
||||
// Spawn the child process.
|
||||
status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL,
|
||||
args.Argv()[0], args.Argv(), nullptr, 1,
|
||||
&add_handle_action, &child_process_, nullptr);
|
||||
// Create a socket pair will be used to receive the child process' stderr.
|
||||
zx::socket stderr_producer_socket;
|
||||
status =
|
||||
zx::socket::create(0, &stderr_producer_socket, &stderr_socket_);
|
||||
GTEST_DEATH_TEST_CHECK_(status >= 0);
|
||||
int stderr_producer_fd = -1;
|
||||
zx_handle_t producer_handle[1] = { stderr_producer_socket.release() };
|
||||
uint32_t producer_handle_type[1] = { PA_FDIO_SOCKET };
|
||||
status = fdio_create_fd(
|
||||
producer_handle, producer_handle_type, 1, &stderr_producer_fd);
|
||||
GTEST_DEATH_TEST_CHECK_(status >= 0);
|
||||
|
||||
// Make the stderr socket nonblocking.
|
||||
GTEST_DEATH_TEST_CHECK_(fcntl(stderr_producer_fd, F_SETFL, 0) == 0);
|
||||
|
||||
fdio_spawn_action_t* add_stderr_action = &spawn_actions[1];
|
||||
add_stderr_action->action = FDIO_SPAWN_ACTION_CLONE_FD;
|
||||
add_stderr_action->fd.local_fd = stderr_producer_fd;
|
||||
add_stderr_action->fd.target_fd = STDERR_FILENO;
|
||||
|
||||
// Create a child job.
|
||||
zx_handle_t child_job = ZX_HANDLE_INVALID;
|
||||
status = zx_job_create(zx_job_default(), 0, & child_job);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
zx_policy_basic_t policy;
|
||||
policy.condition = ZX_POL_NEW_ANY;
|
||||
policy.policy = ZX_POL_ACTION_ALLOW;
|
||||
status = zx_job_set_policy(
|
||||
child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, &policy, 1);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
// Create an exception port and attach it to the |child_process_|, to allow
|
||||
// Create an exception port and attach it to the |child_job|, to allow
|
||||
// us to suppress the system default exception handler from firing.
|
||||
status = zx_port_create(0, &port_);
|
||||
status = zx::port::create(0, &port_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
status = zx_task_bind_exception_port(
|
||||
child_process_, port_, 0 /* key */, 0 /*options */);
|
||||
child_job, port_.get(), 0 /* key */, 0 /*options */);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
// Spawn the child process.
|
||||
status = fdio_spawn_etc(
|
||||
child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), nullptr,
|
||||
2, spawn_actions, child_process_.reset_and_get_address(), nullptr);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
set_spawned(true);
|
||||
return OVERSEE_TEST;
|
||||
}
|
||||
|
||||
std::string FuchsiaDeathTest::GetErrorLogs() {
|
||||
return captured_stderr_;
|
||||
}
|
||||
|
||||
#else // We are neither on Windows, nor on Fuchsia.
|
||||
|
||||
// ForkingDeathTest provides implementations for most of the abstract
|
||||
@ -1000,10 +1062,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
||||
// left undefined.
|
||||
class ForkingDeathTest : public DeathTestImpl {
|
||||
public:
|
||||
ForkingDeathTest(const char* statement, const RE* regex);
|
||||
ForkingDeathTest(const char* statement, Matcher<const std::string&> matcher);
|
||||
|
||||
// All of these virtual functions are inherited from DeathTest.
|
||||
virtual int Wait();
|
||||
int Wait() override;
|
||||
|
||||
protected:
|
||||
void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
|
||||
@ -1014,9 +1076,9 @@ class ForkingDeathTest : public DeathTestImpl {
|
||||
};
|
||||
|
||||
// Constructs a ForkingDeathTest.
|
||||
ForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex)
|
||||
: DeathTestImpl(a_statement, a_regex),
|
||||
child_pid_(-1) {}
|
||||
ForkingDeathTest::ForkingDeathTest(const char* a_statement,
|
||||
Matcher<const std::string&> matcher)
|
||||
: DeathTestImpl(a_statement, std::move(matcher)), child_pid_(-1) {}
|
||||
|
||||
// Waits for the child in a death test to exit, returning its exit
|
||||
// status, or 0 if no child process exists. As a side effect, sets the
|
||||
@ -1037,9 +1099,9 @@ int ForkingDeathTest::Wait() {
|
||||
// in the child process.
|
||||
class NoExecDeathTest : public ForkingDeathTest {
|
||||
public:
|
||||
NoExecDeathTest(const char* a_statement, const RE* a_regex) :
|
||||
ForkingDeathTest(a_statement, a_regex) { }
|
||||
virtual TestRole AssumeRole();
|
||||
NoExecDeathTest(const char* a_statement, Matcher<const std::string&> matcher)
|
||||
: ForkingDeathTest(a_statement, std::move(matcher)) {}
|
||||
TestRole AssumeRole() override;
|
||||
};
|
||||
|
||||
// The AssumeRole process for a fork-and-run death test. It implements a
|
||||
@ -1092,10 +1154,13 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
|
||||
// only this specific death test to be run.
|
||||
class ExecDeathTest : public ForkingDeathTest {
|
||||
public:
|
||||
ExecDeathTest(const char* a_statement, const RE* a_regex,
|
||||
const char* file, int line) :
|
||||
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
|
||||
virtual TestRole AssumeRole();
|
||||
ExecDeathTest(const char* a_statement, Matcher<const std::string&> matcher,
|
||||
const char* file, int line)
|
||||
: ForkingDeathTest(a_statement, std::move(matcher)),
|
||||
file_(file),
|
||||
line_(line) {}
|
||||
TestRole AssumeRole() override;
|
||||
|
||||
private:
|
||||
static ::std::vector<std::string> GetArgvsForDeathTestChildProcess() {
|
||||
::std::vector<std::string> args = GetInjectableArgvs();
|
||||
@ -1260,7 +1325,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
|
||||
fd_flags | FD_CLOEXEC));
|
||||
struct inheritance inherit = {0};
|
||||
// spawn is a system call.
|
||||
child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
|
||||
child_pid =
|
||||
spawn(args.argv[0], 0, nullptr, &inherit, args.argv, GetEnviron());
|
||||
// Restores the current working directory.
|
||||
GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
|
||||
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
|
||||
@ -1382,7 +1448,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
||||
// by the "test" argument to its address. If the test should be
|
||||
// skipped, sets that pointer to NULL. Returns true, unless the
|
||||
// flag is set to an invalid value.
|
||||
bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||
bool DefaultDeathTestFactory::Create(const char* statement,
|
||||
Matcher<const std::string&> matcher,
|
||||
const char* file, int line,
|
||||
DeathTest** test) {
|
||||
UnitTestImpl* const impl = GetUnitTestImpl();
|
||||
@ -1411,22 +1478,22 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
|
||||
GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new WindowsDeathTest(statement, regex, file, line);
|
||||
*test = new WindowsDeathTest(statement, std::move(matcher), file, line);
|
||||
}
|
||||
|
||||
# elif GTEST_OS_FUCHSIA
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
|
||||
GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new FuchsiaDeathTest(statement, regex, file, line);
|
||||
*test = new FuchsiaDeathTest(statement, std::move(matcher), file, line);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe") {
|
||||
*test = new ExecDeathTest(statement, regex, file, line);
|
||||
*test = new ExecDeathTest(statement, std::move(matcher), file, line);
|
||||
} else if (GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new NoExecDeathTest(statement, regex);
|
||||
*test = new NoExecDeathTest(statement, std::move(matcher));
|
||||
}
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
@ -101,7 +101,7 @@ FilePath FilePath::GetCurrentDir() {
|
||||
return FilePath(kCurrentDirectoryString);
|
||||
#elif GTEST_OS_WINDOWS
|
||||
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
||||
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
||||
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
|
||||
#else
|
||||
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
||||
char* result = getcwd(cwd, sizeof(cwd));
|
||||
@ -109,7 +109,7 @@ FilePath FilePath::GetCurrentDir() {
|
||||
// getcwd will likely fail in NaCl due to the sandbox, so return something
|
||||
// reasonable. The user may have provided a shim implementation for getcwd,
|
||||
// however, so fallback only when failure is detected.
|
||||
return FilePath(result == NULL ? kCurrentDirectoryString : cwd);
|
||||
return FilePath(result == nullptr ? kCurrentDirectoryString : cwd);
|
||||
# endif // GTEST_OS_NACL
|
||||
return FilePath(result == nullptr ? "" : cwd);
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
@ -136,8 +136,8 @@ const char* FilePath::FindLastPathSeparator() const {
|
||||
#if GTEST_HAS_ALT_PATH_SEP_
|
||||
const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
|
||||
// Comparing two pointers of which only one is NULL is undefined.
|
||||
if (last_alt_sep != NULL &&
|
||||
(last_sep == NULL || last_alt_sep > last_sep)) {
|
||||
if (last_alt_sep != nullptr &&
|
||||
(last_sep == nullptr || last_alt_sep > last_sep)) {
|
||||
return last_alt_sep;
|
||||
}
|
||||
#endif
|
||||
@ -324,7 +324,7 @@ bool FilePath::CreateFolder() const {
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
FilePath removed_sep(this->RemoveTrailingPathSeparator());
|
||||
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
|
||||
int result = CreateDirectory(unicode, NULL) ? 0 : -1;
|
||||
int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
|
||||
delete [] unicode;
|
||||
#elif GTEST_OS_WINDOWS
|
||||
int result = _mkdir(pathname_.c_str());
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <string.h> // For memmove.
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -442,8 +443,8 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
||||
public:
|
||||
OsStackTraceGetter() {}
|
||||
|
||||
virtual std::string CurrentStackTrace(int max_depth, int skip_count);
|
||||
virtual void UponLeavingGTest();
|
||||
std::string CurrentStackTrace(int max_depth, int skip_count) override;
|
||||
void UponLeavingGTest() override;
|
||||
|
||||
private:
|
||||
#if GTEST_HAS_ABSL
|
||||
@ -474,7 +475,7 @@ class DefaultGlobalTestPartResultReporter
|
||||
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
|
||||
// Implements the TestPartResultReporterInterface. Reports the test part
|
||||
// result in the current test.
|
||||
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
|
||||
private:
|
||||
UnitTestImpl* const unit_test_;
|
||||
@ -490,7 +491,7 @@ class DefaultPerThreadTestPartResultReporter
|
||||
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
|
||||
// Implements the TestPartResultReporterInterface. The implementation just
|
||||
// delegates to the current global test part result reporter of *unit_test_.
|
||||
virtual void ReportTestPartResult(const TestPartResult& result);
|
||||
void ReportTestPartResult(const TestPartResult& result) override;
|
||||
|
||||
private:
|
||||
UnitTestImpl* const unit_test_;
|
||||
@ -913,8 +914,8 @@ class GTEST_API_ UnitTestImpl {
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
// The decomposed components of the gtest_internal_run_death_test flag,
|
||||
// parsed when RUN_ALL_TESTS is called.
|
||||
internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
|
||||
internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
|
||||
std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
|
||||
std::unique_ptr<internal::DeathTestFactory> death_test_factory_;
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// A per-thread stack of traces created by the SCOPED_TRACE() macro.
|
||||
@ -1062,13 +1063,13 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
MakeConnection();
|
||||
}
|
||||
|
||||
virtual ~SocketWriter() {
|
||||
~SocketWriter() override {
|
||||
if (sockfd_ != -1)
|
||||
CloseConnection();
|
||||
}
|
||||
|
||||
// Sends a string to the socket.
|
||||
virtual void Send(const std::string& message) {
|
||||
void Send(const std::string& message) override {
|
||||
GTEST_CHECK_(sockfd_ != -1)
|
||||
<< "Send() can be called only when there is a connection.";
|
||||
|
||||
@ -1085,7 +1086,7 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
void MakeConnection();
|
||||
|
||||
// Closes the socket.
|
||||
void CloseConnection() {
|
||||
void CloseConnection() override {
|
||||
GTEST_CHECK_(sockfd_ != -1)
|
||||
<< "CloseConnection() can be called only when there is a connection.";
|
||||
|
||||
@ -1111,11 +1112,11 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
explicit StreamingListener(AbstractSocketWriter* socket_writer)
|
||||
: socket_writer_(socket_writer) { Start(); }
|
||||
|
||||
void OnTestProgramStart(const UnitTest& /* unit_test */) {
|
||||
void OnTestProgramStart(const UnitTest& /* unit_test */) override {
|
||||
SendLn("event=TestProgramStart");
|
||||
}
|
||||
|
||||
void OnTestProgramEnd(const UnitTest& unit_test) {
|
||||
void OnTestProgramEnd(const UnitTest& unit_test) override {
|
||||
// Note that Google Test current only report elapsed time for each
|
||||
// test iteration, not for the entire test program.
|
||||
SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
|
||||
@ -1124,39 +1125,41 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
socket_writer_->CloseConnection();
|
||||
}
|
||||
|
||||
void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
|
||||
void OnTestIterationStart(const UnitTest& /* unit_test */,
|
||||
int iteration) override {
|
||||
SendLn("event=TestIterationStart&iteration=" +
|
||||
StreamableToString(iteration));
|
||||
}
|
||||
|
||||
void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
|
||||
void OnTestIterationEnd(const UnitTest& unit_test,
|
||||
int /* iteration */) override {
|
||||
SendLn("event=TestIterationEnd&passed=" +
|
||||
FormatBool(unit_test.Passed()) + "&elapsed_time=" +
|
||||
StreamableToString(unit_test.elapsed_time()) + "ms");
|
||||
}
|
||||
|
||||
void OnTestCaseStart(const TestCase& test_case) {
|
||||
void OnTestCaseStart(const TestCase& test_case) override {
|
||||
SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
|
||||
}
|
||||
|
||||
void OnTestCaseEnd(const TestCase& test_case) {
|
||||
void OnTestCaseEnd(const TestCase& test_case) override {
|
||||
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
|
||||
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
|
||||
+ "ms");
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& test_info) {
|
||||
void OnTestStart(const TestInfo& test_info) override {
|
||||
SendLn(std::string("event=TestStart&name=") + test_info.name());
|
||||
}
|
||||
|
||||
void OnTestEnd(const TestInfo& test_info) {
|
||||
void OnTestEnd(const TestInfo& test_info) override {
|
||||
SendLn("event=TestEnd&passed=" +
|
||||
FormatBool((test_info.result())->Passed()) +
|
||||
"&elapsed_time=" +
|
||||
StreamableToString((test_info.result())->elapsed_time()) + "ms");
|
||||
}
|
||||
|
||||
void OnTestPartResult(const TestPartResult& test_part_result) {
|
||||
void OnTestPartResult(const TestPartResult& test_part_result) override {
|
||||
const char* file_name = test_part_result.file_name();
|
||||
if (file_name == nullptr) file_name = "";
|
||||
SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
|
||||
@ -1174,7 +1177,7 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
|
||||
std::string FormatBool(bool value) { return value ? "1" : "0"; }
|
||||
|
||||
const scoped_ptr<AbstractSocketWriter> socket_writer_;
|
||||
const std::unique_ptr<AbstractSocketWriter> socket_writer_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
|
||||
}; // class StreamingListener
|
||||
|
152
googletest/src/gtest-matchers.cc
Normal file
152
googletest/src/gtest-matchers.cc
Normal file
@ -0,0 +1,152 @@
|
||||
// Copyright 2007, 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.
|
||||
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file implements just enough of the matcher interface to allow
|
||||
// EXPECT_DEATH and friends to accept a matcher argument.
|
||||
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-matchers.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const ::string& s) {
|
||||
*this = Eq(static_cast<std::string>(s));
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a const std::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const std::string&>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const ::string& s) {
|
||||
*this = Eq(static_cast<std::string>(s));
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a std::string whose value is equal to
|
||||
// s.
|
||||
Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const std::string& s) {
|
||||
*this = Eq(static_cast<::string>(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
|
||||
// Constructs a matcher that matches a const ::string& whose value is
|
||||
// equal to s.
|
||||
Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||
|
||||
// Constructs a matcher that matches a ::string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const std::string& s) {
|
||||
*this = Eq(static_cast<::string>(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a ::string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
|
||||
// Constructs a matcher that matches a string whose value is equal to s.
|
||||
Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const std::string& s) {
|
||||
*this = Eq(s);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
} // namespace testing
|
@ -31,16 +31,20 @@
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# include <windows.h>
|
||||
# include <io.h>
|
||||
# include <sys/stat.h>
|
||||
# include <map> // Used in ThreadLocal.
|
||||
# ifdef _MSC_VER
|
||||
# include <crtdbg.h>
|
||||
# endif // _MSC_VER
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
@ -138,7 +142,7 @@ size_t GetThreadCount() {
|
||||
}
|
||||
procfs_info process_info;
|
||||
const int status =
|
||||
devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), NULL);
|
||||
devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), nullptr);
|
||||
close(fd);
|
||||
if (status == EOK) {
|
||||
return static_cast<size_t>(process_info.num_threads);
|
||||
@ -152,7 +156,7 @@ size_t GetThreadCount() {
|
||||
size_t GetThreadCount() {
|
||||
struct procentry64 entry;
|
||||
pid_t pid = getpid();
|
||||
int status = getprocs64(&entry, sizeof(entry), NULL, 0, &pid, 1);
|
||||
int status = getprocs64(&entry, sizeof(entry), nullptr, 0, &pid, 1);
|
||||
if (status == 1) {
|
||||
return entry.pi_thcount;
|
||||
} else {
|
||||
@ -230,15 +234,15 @@ void AutoHandle::Reset(HANDLE handle) {
|
||||
bool AutoHandle::IsCloseable() const {
|
||||
// Different Windows APIs may use either of these values to represent an
|
||||
// invalid handle.
|
||||
return handle_ != NULL && handle_ != INVALID_HANDLE_VALUE;
|
||||
return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
Notification::Notification()
|
||||
: event_(::CreateEvent(NULL, // Default security attributes.
|
||||
TRUE, // Do not reset automatically.
|
||||
FALSE, // Initially unset.
|
||||
NULL)) { // Anonymous event.
|
||||
GTEST_CHECK_(event_.Get() != NULL);
|
||||
: event_(::CreateEvent(nullptr, // Default security attributes.
|
||||
TRUE, // Do not reset automatically.
|
||||
FALSE, // Initially unset.
|
||||
nullptr)) { // Anonymous event.
|
||||
GTEST_CHECK_(event_.Get() != nullptr);
|
||||
}
|
||||
|
||||
void Notification::Notify() {
|
||||
@ -267,7 +271,7 @@ Mutex::~Mutex() {
|
||||
if (type_ == kDynamic) {
|
||||
::DeleteCriticalSection(critical_section_);
|
||||
delete critical_section_;
|
||||
critical_section_ = NULL;
|
||||
critical_section_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,15 +390,15 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
|
||||
DWORD thread_id;
|
||||
// FIXME: Consider to use _beginthreadex instead.
|
||||
HANDLE thread_handle = ::CreateThread(
|
||||
NULL, // Default security.
|
||||
0, // Default stack size.
|
||||
nullptr, // Default security.
|
||||
0, // Default stack size.
|
||||
&ThreadWithParamSupport::ThreadMain,
|
||||
param, // Parameter to ThreadMainStatic
|
||||
0x0, // Default creation flags.
|
||||
param, // Parameter to ThreadMainStatic
|
||||
0x0, // Default creation flags.
|
||||
&thread_id); // Need a valid pointer for the call to work under Win98.
|
||||
GTEST_CHECK_(thread_handle != NULL) << "CreateThread failed with error "
|
||||
<< ::GetLastError() << ".";
|
||||
if (thread_handle == NULL) {
|
||||
GTEST_CHECK_(thread_handle != nullptr)
|
||||
<< "CreateThread failed with error " << ::GetLastError() << ".";
|
||||
if (thread_handle == nullptr) {
|
||||
delete param;
|
||||
}
|
||||
return thread_handle;
|
||||
@ -406,15 +410,15 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
|
||||
: runnable_(runnable),
|
||||
thread_can_start_(thread_can_start) {
|
||||
}
|
||||
scoped_ptr<Runnable> runnable_;
|
||||
std::unique_ptr<Runnable> runnable_;
|
||||
// Does not own.
|
||||
Notification* thread_can_start_;
|
||||
};
|
||||
|
||||
static DWORD WINAPI ThreadMain(void* ptr) {
|
||||
// Transfers ownership.
|
||||
scoped_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
|
||||
if (param->thread_can_start_ != NULL)
|
||||
std::unique_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
|
||||
if (param->thread_can_start_ != nullptr)
|
||||
param->thread_can_start_->WaitForNotification();
|
||||
param->runnable_->Run();
|
||||
return 0;
|
||||
@ -472,7 +476,7 @@ class ThreadLocalRegistryImpl {
|
||||
thread_local_values
|
||||
.insert(std::make_pair(
|
||||
thread_local_instance,
|
||||
linked_ptr<ThreadLocalValueHolderBase>(
|
||||
std::shared_ptr<ThreadLocalValueHolderBase>(
|
||||
thread_local_instance->NewValueForCurrentThread())))
|
||||
.first;
|
||||
}
|
||||
@ -481,7 +485,7 @@ class ThreadLocalRegistryImpl {
|
||||
|
||||
static void OnThreadLocalDestroyed(
|
||||
const ThreadLocalBase* thread_local_instance) {
|
||||
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
std::vector<std::shared_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
// Clean up the ThreadLocalValues data structure while holding the lock, but
|
||||
// defer the destruction of the ThreadLocalValueHolderBases.
|
||||
{
|
||||
@ -509,7 +513,7 @@ class ThreadLocalRegistryImpl {
|
||||
|
||||
static void OnThreadExit(DWORD thread_id) {
|
||||
GTEST_CHECK_(thread_id != 0) << ::GetLastError();
|
||||
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
std::vector<std::shared_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
// Clean up the ThreadIdToThreadLocals data structure while holding the
|
||||
// lock, but defer the destruction of the ThreadLocalValueHolderBases.
|
||||
{
|
||||
@ -536,7 +540,8 @@ class ThreadLocalRegistryImpl {
|
||||
private:
|
||||
// In a particular thread, maps a ThreadLocal object to its value.
|
||||
typedef std::map<const ThreadLocalBase*,
|
||||
linked_ptr<ThreadLocalValueHolderBase> > ThreadLocalValues;
|
||||
std::shared_ptr<ThreadLocalValueHolderBase> >
|
||||
ThreadLocalValues;
|
||||
// Stores all ThreadIdToThreadLocals having values in a thread, indexed by
|
||||
// thread's ID.
|
||||
typedef std::map<DWORD, ThreadLocalValues> ThreadIdToThreadLocals;
|
||||
@ -551,18 +556,17 @@ class ThreadLocalRegistryImpl {
|
||||
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
|
||||
FALSE,
|
||||
thread_id);
|
||||
GTEST_CHECK_(thread != NULL);
|
||||
GTEST_CHECK_(thread != nullptr);
|
||||
// We need to pass a valid thread ID pointer into CreateThread for it
|
||||
// to work correctly under Win98.
|
||||
DWORD watcher_thread_id;
|
||||
HANDLE watcher_thread = ::CreateThread(
|
||||
NULL, // Default security.
|
||||
0, // Default stack size
|
||||
nullptr, // Default security.
|
||||
0, // Default stack size
|
||||
&ThreadLocalRegistryImpl::WatcherThreadFunc,
|
||||
reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
|
||||
CREATE_SUSPENDED,
|
||||
&watcher_thread_id);
|
||||
GTEST_CHECK_(watcher_thread != NULL);
|
||||
CREATE_SUSPENDED, &watcher_thread_id);
|
||||
GTEST_CHECK_(watcher_thread != nullptr);
|
||||
// Give the watcher thread the same priority as ours to avoid being
|
||||
// blocked by it.
|
||||
::SetThreadPriority(watcher_thread,
|
||||
@ -682,7 +686,7 @@ void RE::Init(const char* regex) {
|
||||
// Returns true iff ch appears anywhere in str (excluding the
|
||||
// terminating '\0' character).
|
||||
bool IsInSet(char ch, const char* str) {
|
||||
return ch != '\0' && strchr(str, ch) != NULL;
|
||||
return ch != '\0' && strchr(str, ch) != nullptr;
|
||||
}
|
||||
|
||||
// Returns true iff ch belongs to the given classification. Unlike
|
||||
@ -736,7 +740,7 @@ static std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||
// Generates non-fatal failures and returns false if regex is invalid;
|
||||
// otherwise returns true.
|
||||
bool ValidateRegex(const char* regex) {
|
||||
if (regex == NULL) {
|
||||
if (regex == nullptr) {
|
||||
// FIXME: fix the source file location in the
|
||||
// assertion failures to match where the regex is used in user
|
||||
// code.
|
||||
@ -862,8 +866,7 @@ bool MatchRegexAtHead(const char* regex, const char* str) {
|
||||
// exponential with respect to the regex length + the string length,
|
||||
// but usually it's must faster (often close to linear).
|
||||
bool MatchRegexAnywhere(const char* regex, const char* str) {
|
||||
if (regex == NULL || str == NULL)
|
||||
return false;
|
||||
if (regex == nullptr || str == nullptr) return false;
|
||||
|
||||
if (*regex == '^')
|
||||
return MatchRegexAtHead(regex + 1, str);
|
||||
@ -896,8 +899,8 @@ bool RE::PartialMatch(const char* str, const RE& re) {
|
||||
|
||||
// Initializes an RE from its string representation.
|
||||
void RE::Init(const char* regex) {
|
||||
pattern_ = full_pattern_ = NULL;
|
||||
if (regex != NULL) {
|
||||
pattern_ = full_pattern_ = nullptr;
|
||||
if (regex != nullptr) {
|
||||
pattern_ = posix::StrDup(regex);
|
||||
}
|
||||
|
||||
@ -1254,8 +1257,8 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||
return string_value == NULL ?
|
||||
default_value : strcmp(string_value, "0") != 0;
|
||||
return string_value == nullptr ? default_value
|
||||
: strcmp(string_value, "0") != 0;
|
||||
#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
|
||||
}
|
||||
|
||||
@ -1268,7 +1271,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||
if (string_value == NULL) {
|
||||
if (string_value == nullptr) {
|
||||
// The environment variable is not set.
|
||||
return default_value;
|
||||
}
|
||||
@ -1311,7 +1314,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_value) {
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const value = posix::GetEnv(env_var.c_str());
|
||||
return value == NULL ? default_value : value;
|
||||
return value == nullptr ? default_value : value;
|
||||
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user