Skip to content
Snippets Groups Projects
Commit d568ae9e authored by Soeren Peters's avatar Soeren Peters
Browse files

Merge branch 'feature/updating_googletest' into develop

* feature/updating_googletest:
  Update Googletest to v1.10.0. Put 3rdParty targets in msvc subfolder "3rd".
parents 5b2ce1a3 2c3ca90e
No related branches found
No related tags found
No related merge requests found
Showing
with 3227 additions and 6044 deletions
cmake_minimum_required(VERSION 2.6.4) # Note: CMake support is community-based. The maintainers do not use CMake
# internally.
cmake_minimum_required(VERSION 2.8.8)
if (POLICY CMP0048) if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048) endif (POLICY CMP0048)
project( googletest-distribution ) project(googletest-distribution)
set(GOOGLETEST_VERSION 1.10.0)
enable_testing()
include(CMakeDependentOption) if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_VERSION VERSION_LESS 2.8.5) add_definitions(-std=c++11)
set(CMAKE_INSTALL_BINDIR "bin" CACHE STRING "User executables (bin)")
set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}" CACHE STRING "Object code libraries (lib)")
set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE STRING "C header files (include)")
mark_as_advanced(CMAKE_INSTALL_BINDIR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
else() else()
include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CYGWIN)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endif() endif()
#option(BUILD_GTEST "Builds the googletest subproject" OFF) enable_testing()
include(CMakeDependentOption)
include(GNUInstallDirs)
#Note that googlemock target already builds googletest #Note that googlemock target already builds googletest
#option(BUILD_GMOCK "Builds the googlemock subproject" ON) #option(BUILD_GMOCK "Builds the googlemock subproject" ON)
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" OFF)
cmake_dependent_option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON "BUILD_GTEST OR BUILD_GMOCK" OFF)
cmake_dependent_option(INSTALL_GMOCK "Enable installation of googlemock. (Projects embedding googlemock may want to turn this OFF.)" ON "BUILD_GMOCK" OFF)
#if(BUILD_GMOCK) #if(BUILD_GMOCK)
add_subdirectory( googlemock ) add_subdirectory( googlemock )
#elseif(BUILD_GTEST) #else()
# add_subdirectory( googletest ) # add_subdirectory( googletest )
#endif() #endif()
groupTarget(gmock ${thirdFolder}/googletest)
groupTarget(gmock_main ${thirdFolder}/googletest)
groupTarget(gtest ${thirdFolder}/googletest)
groupTarget(gtest_main ${thirdFolder}/googletest)
\ No newline at end of file
######################################################################## ########################################################################
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.
#
# CMake build script for Google Mock. # CMake build script for Google Mock.
# #
# To run the tests for Google Mock itself on Linux, use 'make test' or # To run the tests for Google Mock itself on Linux, use 'make test' or
# ctest. You can select which tests to run using 'ctest -R regex'. # ctest. You can select which tests to run using 'ctest -R regex'.
# For more options, run 'ctest --help'. # For more options, run 'ctest --help'.
#option(gmock_build_tests "Build all of Google Mock's own tests." OFF) option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
# A directory to find Google Test sources. # A directory to find Google Test sources.
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
...@@ -37,7 +40,7 @@ if (CMAKE_VERSION VERSION_LESS 3.0) ...@@ -37,7 +40,7 @@ if (CMAKE_VERSION VERSION_LESS 3.0)
project(gmock CXX C) project(gmock CXX C)
else() else()
cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0048 NEW)
project(gmock VERSION 1.9.0 LANGUAGES CXX C) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
endif() endif()
cmake_minimum_required(VERSION 2.6.4) cmake_minimum_required(VERSION 2.6.4)
...@@ -49,7 +52,17 @@ endif() ...@@ -49,7 +52,17 @@ endif()
# targets to the current scope. We are placing Google Test's binary # targets to the current scope. We are placing Google Test's binary
# directory in a subdirectory of our own as VC compilation may break # directory in a subdirectory of our own as VC compilation may break
# if they are the same (the default). # if they are the same (the default).
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest") add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
# These commands only run if this is the main project
if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
# make it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
else()
mark_as_advanced(gmock_build_tests)
endif()
# Although Google Test's CMakeLists.txt calls this function, the # Although Google Test's CMakeLists.txt calls this function, the
# changes there don't affect the current scope. Therefore we have to # changes there don't affect the current scope. Therefore we have to
...@@ -57,22 +70,13 @@ add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest") ...@@ -57,22 +70,13 @@ add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
# Adds Google Mock's and Google Test's header directories to the search path. # Adds Google Mock's and Google Test's header directories to the search path.
include_directories("${gmock_SOURCE_DIR}/include" set(gmock_build_include_dirs
"${gmock_SOURCE_DIR}" "${gmock_SOURCE_DIR}/include"
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}"
# This directory is needed to build directly from Google "${gtest_SOURCE_DIR}/include"
# Test sources. # This directory is needed to build directly from Google Test sources.
"${gtest_SOURCE_DIR}") "${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
if (MSVC AND MSVC_VERSION EQUAL 1700)
add_definitions(/D _VARIADIC_MAX=10)
endif()
######################################################################## ########################################################################
# #
...@@ -82,51 +86,39 @@ endif() ...@@ -82,51 +86,39 @@ endif()
# Google Mock libraries. We build them using more strict warnings than what # Google Mock libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that Google Mock can be compiled by # are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings. # a user aggressive about warnings.
cxx_library(gmock if (MSVC)
"${cxx_strict}" cxx_library(gmock
"${gtest_dir}/src/gtest-all.cc" "${cxx_strict}"
src/gmock-all.cc) "${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc)
cxx_library(gmock_main
"${cxx_strict}" cxx_library(gmock_main
"${gtest_dir}/src/gtest-all.cc" "${cxx_strict}"
src/gmock-all.cc "${gtest_dir}/src/gtest-all.cc"
src/gmock_main.cc) src/gmock-all.cc
src/gmock_main.cc)
set_property( TARGET gmock PROPERTY FOLDER ${thirdPartyFolder}/gmock ) else()
set_property( TARGET gmock_main PROPERTY FOLDER ${thirdPartyFolder}/gmock ) cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
target_link_libraries(gmock PUBLIC gtest)
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
target_link_libraries(gmock_main PUBLIC gmock)
endif()
# If the CMake version supports it, attach header directory information # If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled # to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build). # in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(gmock INTERFACE "${gmock_SOURCE_DIR}/include") target_include_directories(gmock SYSTEM INTERFACE
target_include_directories(gmock_main INTERFACE "${gmock_SOURCE_DIR}/include") "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif() endif()
######################################################################## ########################################################################
# #
# Install rules # Install rules
if(INSTALL_GMOCK) install_project(gmock gmock_main)
install(TARGETS gmock gmock_main
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ${gmock_SOURCE_DIR}/include/gmock
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# configure and install pkgconfig files
configure_file(
cmake/gmock.pc.in
"${CMAKE_BINARY_DIR}/gmock.pc"
@ONLY)
configure_file(
cmake/gmock_main.pc.in
"${CMAKE_BINARY_DIR}/gmock_main.pc"
@ONLY)
install(FILES "${CMAKE_BINARY_DIR}/gmock.pc" "${CMAKE_BINARY_DIR}/gmock_main.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
######################################################################## ########################################################################
# #
...@@ -144,15 +136,37 @@ if (gmock_build_tests) ...@@ -144,15 +136,37 @@ if (gmock_build_tests)
# 'make test' or ctest. # 'make test' or ctest.
enable_testing() enable_testing()
if (WIN32)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/RunTest.ps1"
CONTENT
"$project_bin = \"${CMAKE_BINARY_DIR}/bin/$<CONFIG>\"
$env:Path = \"$project_bin;$env:Path\"
& $args")
elseif (MINGW OR CYGWIN)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/RunTest.ps1"
CONTENT
"$project_bin = (cygpath --windows ${CMAKE_BINARY_DIR}/bin)
$env:Path = \"$project_bin;$env:Path\"
& $args")
endif()
if (MINGW OR CYGWIN)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
add_compile_options("-Wa,-mbig-obj")
else()
add_definitions("-Wa,-mbig-obj")
endif()
endif()
############################################################ ############################################################
# C++ tests built with standard compiler flags. # C++ tests built with standard compiler flags.
cxx_test(gmock-actions_test gmock_main) cxx_test(gmock-actions_test gmock_main)
cxx_test(gmock-cardinalities_test gmock_main) cxx_test(gmock-cardinalities_test gmock_main)
cxx_test(gmock_ex_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-actions_test gmock_main)
cxx_test(gmock-generated-function-mockers_test gmock_main) cxx_test(gmock-generated-function-mockers_test gmock_main)
cxx_test(gmock-generated-internal-utils_test gmock_main)
cxx_test(gmock-generated-matchers_test gmock_main) cxx_test(gmock-generated-matchers_test gmock_main)
cxx_test(gmock-internal-utils_test gmock_main) cxx_test(gmock-internal-utils_test gmock_main)
cxx_test(gmock-matchers_test gmock_main) cxx_test(gmock-matchers_test gmock_main)
...@@ -174,23 +188,20 @@ if (gmock_build_tests) ...@@ -174,23 +188,20 @@ if (gmock_build_tests)
############################################################ ############################################################
# C++ tests built with non-standard compiler flags. # C++ tests built with non-standard compiler flags.
cxx_library(gmock_main_no_exception "${cxx_no_exception}" if (MSVC)
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) cxx_library(gmock_main_no_exception "${cxx_no_exception}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
# 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) "${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}" else()
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc) cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
endif() 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)
endif()
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
gmock_main_no_exception test/gmock-more-actions_test.cc) gmock_main_no_exception test/gmock-more-actions_test.cc)
......
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ prefix=${pcfiledir}/../..
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gmock Name: gmock
Description: GoogleMock (without main() function) Description: GoogleMock (without main() function)
Version: @PROJECT_VERSION@ Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest URL: https://github.com/google/googletest
Requires: gtest
Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ prefix=${pcfiledir}/../..
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: gmock_main Name: gmock_main
Description: GoogleMock (with main() function) Description: GoogleMock (with main() function)
Version: @PROJECT_VERSION@ Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest URL: https://github.com/google/googletest
Requires: gmock
Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@ Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -35,14 +34,20 @@ ...@@ -35,14 +34,20 @@
// cardinalities can be defined by the user implementing the // cardinalities can be defined by the user implementing the
// CardinalityInterface interface if necessary. // CardinalityInterface interface if necessary.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
#include <limits.h> #include <limits.h>
#include <memory>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
namespace testing { namespace testing {
// To implement a cardinality Foo, define: // To implement a cardinality Foo, define:
...@@ -65,10 +70,12 @@ class CardinalityInterface { ...@@ -65,10 +70,12 @@ class CardinalityInterface {
virtual int ConservativeLowerBound() const { return 0; } virtual int ConservativeLowerBound() const { return 0; }
virtual int ConservativeUpperBound() const { return INT_MAX; } virtual int ConservativeUpperBound() const { return INT_MAX; }
// Returns true iff call_count calls will satisfy this cardinality. // Returns true if and only if call_count calls will satisfy this
// cardinality.
virtual bool IsSatisfiedByCallCount(int call_count) const = 0; virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
// Returns true iff call_count calls will saturate this cardinality. // Returns true if and only if call_count calls will saturate this
// cardinality.
virtual bool IsSaturatedByCallCount(int call_count) const = 0; virtual bool IsSaturatedByCallCount(int call_count) const = 0;
// Describes self to an ostream. // Describes self to an ostream.
...@@ -77,9 +84,8 @@ class CardinalityInterface { ...@@ -77,9 +84,8 @@ class CardinalityInterface {
// A Cardinality is a copyable and IMMUTABLE (except by assignment) // A Cardinality is a copyable and IMMUTABLE (except by assignment)
// object that specifies how many times a mock function is expected to // object that specifies how many times a mock function is expected to
// be called. The implementation of Cardinality is just a linked_ptr // be called. The implementation of Cardinality is just a std::shared_ptr
// to const CardinalityInterface, so copying is fairly cheap. // to const CardinalityInterface. Don't inherit from Cardinality!
// Don't inherit from Cardinality!
class GTEST_API_ Cardinality { class GTEST_API_ Cardinality {
public: public:
// Constructs a null cardinality. Needed for storing Cardinality // Constructs a null cardinality. Needed for storing Cardinality
...@@ -94,17 +100,19 @@ class GTEST_API_ Cardinality { ...@@ -94,17 +100,19 @@ class GTEST_API_ Cardinality {
int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
// Returns true iff call_count calls will satisfy this cardinality. // Returns true if and only if call_count calls will satisfy this
// cardinality.
bool IsSatisfiedByCallCount(int call_count) const { bool IsSatisfiedByCallCount(int call_count) const {
return impl_->IsSatisfiedByCallCount(call_count); return impl_->IsSatisfiedByCallCount(call_count);
} }
// Returns true iff call_count calls will saturate this cardinality. // Returns true if and only if call_count calls will saturate this
// cardinality.
bool IsSaturatedByCallCount(int call_count) const { bool IsSaturatedByCallCount(int call_count) const {
return impl_->IsSaturatedByCallCount(call_count); return impl_->IsSaturatedByCallCount(call_count);
} }
// Returns true iff call_count calls will over-saturate this // Returns true if and only if call_count calls will over-saturate this
// cardinality, i.e. exceed the maximum number of allowed calls. // cardinality, i.e. exceed the maximum number of allowed calls.
bool IsOverSaturatedByCallCount(int call_count) const { bool IsOverSaturatedByCallCount(int call_count) const {
return impl_->IsSaturatedByCallCount(call_count) && return impl_->IsSaturatedByCallCount(call_count) &&
...@@ -119,7 +127,7 @@ class GTEST_API_ Cardinality { ...@@ -119,7 +127,7 @@ class GTEST_API_ Cardinality {
::std::ostream* os); ::std::ostream* os);
private: private:
internal::linked_ptr<const CardinalityInterface> impl_; std::shared_ptr<const CardinalityInterface> impl_;
}; };
// Creates a cardinality that allows at least n calls. // Creates a cardinality that allows at least n calls.
...@@ -144,4 +152,6 @@ inline Cardinality MakeCardinality(const CardinalityInterface* c) { ...@@ -144,4 +152,6 @@ inline Cardinality MakeCardinality(const CardinalityInterface* c) {
} // namespace testing } // namespace testing
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
$$ -*- mode: c++; -*- $$ -*- mode: c++; -*-
$$ This is a Pump source file. Please use Pump to convert it to $$ This is a Pump source file. Please use Pump to convert it to
$$ gmock-generated-actions.h. $$ gmock-generated-actions.h.
$$ $$
$var n = 10 $$ The maximum arity we support. $var n = 10 $$ The maximum arity we support.
...@@ -32,145 +32,26 @@ $$}} This meta comment fixes auto-indentation in editors. ...@@ -32,145 +32,26 @@ $$}} This meta comment fixes auto-indentation in editors.
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements some commonly used variadic actions. // This file implements some commonly used variadic actions.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
#define 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/gmock-actions.h"
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
// function or method with the unpacked values, where F is a function
// type that takes N arguments.
template <typename Result, typename ArgumentTuple>
class InvokeHelper;
$range i 0..n
$for i [[
$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)]]]]
template <typename R$types>
class InvokeHelper<R, ::testing::tuple<$as> > {
public:
template <typename Function>
static R Invoke(Function function, const ::testing::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) {
return (obj_ptr->*method_ptr)($gets);
}
};
]]
// 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);
};
// A macro from the ACTION* family (defined later in this file) // A macro from the ACTION* family (defined later in this file)
// defines an action that can be used in a mock function. Typically, // defines an action that can be used in a mock function. Typically,
// these actions only care about a subset of the arguments of the mock // these actions only care about a subset of the arguments of the mock
...@@ -201,12 +82,12 @@ $range j 0..i-1 ...@@ -201,12 +82,12 @@ $range j 0..i-1
]]]] ]]]]
$range j 0..i-1 $range j 0..i-1
$var As = [[$for j, [[A$j]]]] $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 $range k 1..n-i
$var eas = [[$for k, [[ExcessiveArg()]]]] $var eas = [[$for k, [[ExcessiveArg()]]]]
$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]] $var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
$template $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); return impl->template gmock_PerformImpl<$As>(args, $arg_list);
} }
...@@ -214,53 +95,6 @@ $template ...@@ -214,53 +95,6 @@ $template
}; };
} // namespace internal } // 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 } // namespace testing
// The ACTION* family of macros can be used in a namespace scope to // The ACTION* family of macros can be used in a namespace scope to
...@@ -348,16 +182,15 @@ $range j2 2..i ...@@ -348,16 +182,15 @@ $range j2 2..i
// //
// CAVEAT: // CAVEAT:
// //
// ACTION*() can only be used in a namespace scope. The reason is // ACTION*() can only be used in a namespace scope as templates cannot be
// that C++ doesn't yet allow function-local types to be used to // declared inside of a local class.
// instantiate templates. The up-coming C++0x standard will fix this. // Users can, however, define any local functors (e.g. a lambda) that
// Once that's done, we'll consider supporting using ACTION*() inside // can be used as actions.
// a function.
// //
// MORE INFORMATION: // MORE INFORMATION:
// //
// To learn more about using these macros, please search for 'ACTION' // To learn more about using these macros, please search for 'ACTION' on
// on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md
$range i 0..n $range i 0..n
$range k 0..n-1 $range k 0..n-1
...@@ -366,7 +199,7 @@ $range k 0..n-1 ...@@ -366,7 +199,7 @@ $range k 0..n-1
#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
const args_type& args GTEST_ATTRIBUTE_UNUSED_ const args_type& args GTEST_ATTRIBUTE_UNUSED_
$for k [[, \ $for k [[, \
arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]] const arg$k[[]]_type& arg$k GTEST_ATTRIBUTE_UNUSED_]]
// Sometimes you want to give an action explicit template parameters // Sometimes you want to give an action explicit template parameters
...@@ -393,7 +226,7 @@ $for k [[, \ ...@@ -393,7 +226,7 @@ $for k [[, \
// ACTION_TEMPLATE(DuplicateArg, // ACTION_TEMPLATE(DuplicateArg,
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
// AND_1_VALUE_PARAMS(output)) { // AND_1_VALUE_PARAMS(output)) {
// *output = T(::testing::get<k>(args)); // *output = T(::std::get<k>(args));
// } // }
// ... // ...
// int n; // int n;
...@@ -486,7 +319,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]] ...@@ -486,7 +319,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
$for i [[ $for i [[
$range j 0..i-1 $range j 0..i-1
#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\ #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(gmock_p$j)]] ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::std::move(gmock_p$j))]]
]] ]]
...@@ -568,7 +401,7 @@ $range k 0..n-1 ...@@ -568,7 +401,7 @@ $range k 0..n-1
}\ }\
template <$for k, [[typename arg$k[[]]_type]]>\ template <$for k, [[typename arg$k[[]]_type]]>\
return_type gmock_PerformImpl(const args_type& args[[]] return_type gmock_PerformImpl(const args_type& args[[]]
$for k [[, arg$k[[]]_type arg$k]]) const;\ $for k [[, const arg$k[[]]_type& arg$k]]) const;\
GMOCK_INTERNAL_DEFN_##value_params\ GMOCK_INTERNAL_DEFN_##value_params\
private:\ private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
...@@ -619,7 +452,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] ...@@ -619,7 +452,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
$range j 0..i-1 $range j 0..i-1
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] $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 param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(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 $var param_field_decls = [[$for j
[[ [[
...@@ -633,7 +466,7 @@ $var param_field_decls2 = [[$for j ...@@ -633,7 +466,7 @@ $var param_field_decls2 = [[$for j
$var params = [[$for j, [[p$j]]]] $var params = [[$for j, [[p$j]]]]
$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
$var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]] $var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]]
$var arg_types_and_names = [[$for k, [[arg$k[[]]_type arg$k]]]] $var arg_types_and_names = [[$for k, [[const arg$k[[]]_type& arg$k]]]]
$var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
$else [[ACTION_P$i]]]] $else [[ACTION_P$i]]]]
...@@ -757,7 +590,7 @@ ACTION_TEMPLATE(InvokeArgument, ...@@ -757,7 +590,7 @@ ACTION_TEMPLATE(InvokeArgument,
using internal::invoke_argument::InvokeArgumentAdl; using internal::invoke_argument::InvokeArgumentAdl;
return InvokeArgumentAdl<return_type>( return InvokeArgumentAdl<return_type>(
internal::invoke_argument::AdlTag(), internal::invoke_argument::AdlTag(),
::testing::get<k>(args)$for j [[, p$j]]); ::std::get<k>(args)$for j [[, p$j]]);
} }
]] ]]
......
$$ -*- mode: c++; -*- $$ -*- mode: c++; -*-
$$ This is a Pump source file. Please use Pump to convert it to $$ This is a Pump source file. Please use Pump to convert
$$ gmock-generated-function-mockers.h. $$ it to gmock-generated-function-mockers.h.
$$ $$
$var n = 10 $$ The maximum arity we support. $var n = 10 $$ The maximum arity we support.
// Copyright 2007, Google Inc. // Copyright 2007, Google Inc.
...@@ -31,74 +31,79 @@ $var n = 10 $$ The maximum arity we support. ...@@ -31,74 +31,79 @@ $var n = 10 $$ The maximum arity we support.
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements function mockers of various arities. // This file implements function mockers of various arities.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
#define 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/gmock-spec-builders.h"
#include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-internal-utils.h"
#if GTEST_HAS_STD_FUNCTION_
# include <functional>
#endif
namespace testing { namespace testing {
namespace internal { 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 $range i 0..n
$for i [[ // Removes the given pointer; this is a helper for the expectation setter method
$range j 1..i // for parameterless matchers.
$var typename_As = [[$for j [[, typename A$j]]]] //
$var As = [[$for j, [[A$j]]]] // We want to make sure that the user cannot set a parameterless expectation on
$var as = [[$for j, [[a$j]]]] // overloaded methods, including methods which are overloaded on const. Example:
$var Aas = [[$for j, [[A$j a$j]]]] //
$var ms = [[$for j, [[m$j]]]] // class MockClass {
$var matchers = [[$for j, [[const Matcher<A$j>& m$j]]]] // MOCK_METHOD0(GetName, string&());
template <typename R$typename_As> // MOCK_CONST_METHOD0(GetName, const string&());
class FunctionMocker<R($As)> : public // };
internal::FunctionMockerBase<R($As)> { //
public: // TEST() {
typedef R F($As); // // This should be an error, as it's not clear which overload is expected.
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; // EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value));
// }
MockSpec<F>& With($matchers) { //
// Here are the generated expectation-setter methods:
$if i >= 1 [[ //
this->current_spec().SetMatchers(::testing::make_tuple($ms)); // class MockClass {
// // Overload 1
]] // MockSpec<string&()> gmock_GetName() { ... }
return this->current_spec(); // // Overload 2. Declared const so that the compiler will generate an
} // // error when trying to resolve between this and overload 4 in
// // 'gmock_GetName(WithoutMatchers(), nullptr)'.
R Invoke($Aas) { // MockSpec<string&()> gmock_GetName(
// Even though gcc and MSVC don't enforce it, 'this->' is required // const WithoutMatchers&, const Function<string&()>*) const {
// by the C++ standard [14.6.4] here, as the base class type is // // Removes const from this, calls overload 1
// dependent on the template argument (and thus shouldn't be // return AdjustConstness_(this)->gmock_GetName();
// looked into when resolving InvokeWith). // }
return this->InvokeWith(ArgumentTuple($as)); //
} // // Overload 3
}; // const string& gmock_GetName() const { ... }
// // Overload 4
// MockSpec<const string&()> gmock_GetName(
// const WithoutMatchers&, const Function<const string&()>*) const {
// // Does not remove const, calls overload 3
// return AdjustConstness_const(this)->gmock_GetName();
// }
// }
//
template <typename MockType>
const MockType* AdjustConstness_const(const MockType* mock) {
return mock;
}
// Removes const from and returns the given pointer; this is a helper for the
// expectation setter method for parameterless matchers.
template <typename MockType>
MockType* AdjustConstness_(const MockType* mock) {
return const_cast<MockType*>(mock);
}
]]
} // namespace internal } // namespace internal
// The style guide prohibits "using" statements in a namespace scope // The style guide prohibits "using" statements in a namespace scope
...@@ -119,7 +124,7 @@ using internal::FunctionMocker; ...@@ -119,7 +124,7 @@ using internal::FunctionMocker;
// The type of argument N of the given function type. // The type of argument N of the given function type.
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_ARG_(tn, N, ...) \ #define GMOCK_ARG_(tn, N, ...) \
tn ::testing::internal::Function<__VA_ARGS__>::Argument##N tn ::testing::internal::Function<__VA_ARGS__>::template Arg<N-1>::type
// The matcher type for argument N of the given function type. // The matcher type for argument N of the given function type.
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
...@@ -134,26 +139,33 @@ using internal::FunctionMocker; ...@@ -134,26 +139,33 @@ using internal::FunctionMocker;
$for i [[ $for i [[
$range j 1..i $range j 1..i
$var arg_as = [[$for j, \ $var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
[[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] $var as = [[$for j, \
$var as = [[$for j, [[gmock_a$j]]]] [[::std::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
$var matcher_as = [[$for j, \ $var matcher_arg_as = [[$for j, \
[[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
$var matcher_as = [[$for j, [[gmock_a$j]]]]
$var anything_matchers = [[$for j, \
[[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]]
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
static_assert($i == ::testing::internal::Function<__VA_ARGS__>::ArgumentCount, "MOCK_METHOD<N> must match argument count.");\
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
$arg_as) constness { \ $arg_as) constness { \
GTEST_COMPILE_ASSERT_((::testing::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); \ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method($matcher_as) constness { \ gmock_##Method($matcher_arg_as) constness { \
GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_($i, constness, Method).With($as); \ return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \
gmock_##Method($anything_matchers); \
} \
mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method)
...@@ -210,82 +222,6 @@ $for i [[ ...@@ -210,82 +222,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 ArgNames = [[$for 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($ArgNames);
};
}
#endif // GTEST_HAS_STD_FUNCTION_
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
};
]]
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
// 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.
//
// Author: wan@google.com (Zhanyong Wan)
// 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, with up-to 10 arguments. 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.
//
// Another known limitation is that the constructors of the base mock
// cannot have arguments passed by non-const reference, which are
// banned by the Google C++ style guide anyway.
#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:
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
NiceMock() {
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it 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));
}
virtual ~NiceMock() {
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(this));
}
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
};
template <class MockClass>
class NaggyMock : public MockClass {
public:
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
NaggyMock() {
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it 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));
}
virtual ~NaggyMock() {
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(this));
}
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
};
template <class MockClass>
class StrictMock : public MockClass {
public:
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
StrictMock() {
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it 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));
}
virtual ~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_
This diff is collapsed.
This diff is collapsed.
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// pump.py gmock-generated-actions.h.pump // pump.py gmock-generated-actions.h.pump
// DO NOT EDIT BY HAND!!! // DO NOT EDIT BY HAND!!!
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment