diff --git a/doc/building.html b/doc/building.html
index e0cca9534bd..034cd77d9a7 100644
--- a/doc/building.html
+++ b/doc/building.html
@@ -495,6 +495,11 @@
Running Tests
Most of the JDK tests are using the JTReg test framework. Make sure that your configuration knows where to find your installation of JTReg. If this is not picked up automatically, use the --with-jtreg=<path to jtreg home>
option to point to the JTReg framework. Note that this option should point to the JTReg home, i.e. the top directory, containing lib/jtreg.jar
etc.
The Adoption Group provides recent builds of jtreg here. Download the latest .tar.gz
file, unpack it, and point --with-jtreg
to the jtreg
directory that you just unpacked.
+Building of Hotspot Gtest suite requires the source code of Google Test framework. The top directory, which contains both googletest
and googlemock
directories, should be specified via --with-gtest
. The supported version of Google Test is 1.8.1, whose source code can be obtained:
+
+- by downloading and unpacking the source bundle from here
+- or by checking out
release-1.8.1
tag of googletest
project: git clone -b release-1.8.1 https://github.com/google/googletest
+
To execute the most basic tests (tier 1), use:
make run-test-tier1
For more details on how to run tests, please see the Testing the JDK document.
diff --git a/doc/building.md b/doc/building.md
index 850f6f07da2..3990a9b9d71 100644
--- a/doc/building.md
+++ b/doc/building.md
@@ -829,6 +829,14 @@ https://ci.adoptopenjdk.net/view/Dependencies/job/jtreg/lastSuccessfulBuild/arti
Download the latest `.tar.gz` file, unpack it, and point `--with-jtreg` to the
`jtreg` directory that you just unpacked.
+Building of Hotspot Gtest suite requires the source code of Google Test framework.
+The top directory, which contains both `googletest` and `googlemock`
+directories, should be specified via `--with-gtest`.
+The supported version of Google Test is 1.8.1, whose source code can be obtained:
+
+ * by downloading and unpacking the source bundle from [here](https://github.com/google/googletest/releases/tag/release-1.8.1)
+ * or by checking out `release-1.8.1` tag of `googletest` project: `git clone -b release-1.8.1 https://github.com/google/googletest`
+
To execute the most basic tests (tier 1), use:
```
make run-test-tier1
diff --git a/make/Main.gmk b/make/Main.gmk
index bbe41cbc5c0..14ae6213653 100644
--- a/make/Main.gmk
+++ b/make/Main.gmk
@@ -652,7 +652,7 @@ $(eval $(call SetupTarget, test-image-hotspot-jtreg-graal, \
DEPS := build-test-hotspot-jtreg-graal, \
))
-ifeq ($(BUILD_GTEST), true)
+ifneq ($GTEST_FRAMEWORK_SRC), )
$(eval $(call SetupTarget, test-image-hotspot-gtest, \
MAKEFILE := hotspot/test/GtestImage, \
DEPS := hotspot, \
@@ -1109,7 +1109,7 @@ ifneq ($(JVM_TEST_IMAGE_TARGETS), )
test-image: $(JVM_TEST_IMAGE_TARGETS)
else
test-image: test-image-hotspot-jtreg-native
- ifeq ($(BUILD_GTEST), true)
+ ifneq ($(GTEST_FRAMEWORK_SRC), )
test-image: test-image-hotspot-gtest
endif
diff --git a/make/RunTestsPrebuiltSpec.gmk b/make/RunTestsPrebuiltSpec.gmk
index 33953c2b7d9..30cb6d85946 100644
--- a/make/RunTestsPrebuiltSpec.gmk
+++ b/make/RunTestsPrebuiltSpec.gmk
@@ -82,7 +82,6 @@ SHELL := $(BASH) $(BASH_ARGS)
# Set some reasonable defaults for features
DEBUG_LEVEL := release
HOTSPOT_DEBUG_LEVEL := release
-BUILD_GTEST := true
BUILD_FAILURE_HANDLER := true
################################################################################
diff --git a/make/autoconf/buildjdk-spec.gmk.in b/make/autoconf/buildjdk-spec.gmk.in
index 07d2b0b1503..7134e34bcee 100644
--- a/make/autoconf/buildjdk-spec.gmk.in
+++ b/make/autoconf/buildjdk-spec.gmk.in
@@ -91,9 +91,6 @@ DISABLE_WARNING_PREFIX := @BUILD_CC_DISABLE_WARNING_PREFIX@
# Save speed and disk space by not enabling debug symbols for the buildjdk
ENABLE_DEBUG_SYMBOLS := false
-# Control whether Hotspot builds gtest tests
-BUILD_GTEST := false
-
JVM_VARIANTS := server
JVM_VARIANT_MAIN := server
JVM_FEATURES_server := cds compiler1 compiler2 g1gc serialgc
diff --git a/make/autoconf/configure.ac b/make/autoconf/configure.ac
index 4c95dd362ef..16e4bcfebaa 100644
--- a/make/autoconf/configure.ac
+++ b/make/autoconf/configure.ac
@@ -234,7 +234,6 @@ LIB_SETUP_LIBRARIES
JVM_FEATURES_PARSE_OPTIONS
JVM_FEATURES_SETUP
-HOTSPOT_ENABLE_DISABLE_GTEST
HOTSPOT_SETUP_MISC
###############################################################################
diff --git a/make/autoconf/hotspot.m4 b/make/autoconf/hotspot.m4
index f4dd27126d1..43653c115be 100644
--- a/make/autoconf/hotspot.m4
+++ b/make/autoconf/hotspot.m4
@@ -111,28 +111,6 @@ AC_DEFUN_ONCE([HOTSPOT_SETUP_JVM_VARIANTS],
AC_SUBST(JVM_VARIANT_MAIN)
])
-###############################################################################
-# Check if gtest should be built
-#
-AC_DEFUN_ONCE([HOTSPOT_ENABLE_DISABLE_GTEST],
-[
- GTEST_AVAILABLE=true
-
- AC_MSG_CHECKING([if Hotspot gtest test source is present])
- if test -e "${TOPDIR}/test/hotspot/gtest"; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no, cannot build gtest])
- GTEST_AVAILABLE=false
- fi
-
- UTIL_ARG_ENABLE(NAME: hotspot-gtest, DEFAULT: auto,
- RESULT: BUILD_GTEST, AVAILABLE: $GTEST_AVAILABLE,
- DEFAULT_DESC: [enabled if possible to build],
- DESC: [enable building of the Hotspot unit tests])
- AC_SUBST(BUILD_GTEST)
-])
-
###############################################################################
# Misc hotspot setup that does not fit elsewhere.
#
@@ -162,4 +140,7 @@ AC_DEFUN_ONCE([HOTSPOT_SETUP_MISC],
# --with-cpu-port is no longer supported
UTIL_DEPRECATED_ARG_WITH(with-cpu-port)
+
+ # in jdk15 hotspot-gtest was replaced with --with-gtest
+ UTIL_DEPRECATED_ARG_ENABLE(hotspot-gtest)
])
diff --git a/make/autoconf/lib-tests.m4 b/make/autoconf/lib-tests.m4
index 4512291a4f0..aa0a5d9cbde 100644
--- a/make/autoconf/lib-tests.m4
+++ b/make/autoconf/lib-tests.m4
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -55,6 +55,39 @@ AC_DEFUN_ONCE([LIB_TESTS_SETUP_GRAALUNIT],
AC_SUBST(GRAALUNIT_LIB)
])
+###############################################################################
+#
+# Setup and check for gtest framework source files
+#
+AC_DEFUN_ONCE([LIB_TESTS_SETUP_GTEST],
+[
+ AC_ARG_WITH(gtest, [AS_HELP_STRING([--with-gtest],
+ [specify prefix directory for the gtest framework])])
+
+ if test "x${with_gtest}" != x; then
+ AC_MSG_CHECKING([for gtest])
+ if test "x${with_gtest}" = xno; then
+ AC_MSG_RESULT([no, disabled])
+ elif test "x${with_gtest}" = xyes; then
+ AC_MSG_RESULT([no, error])
+ AC_MSG_ERROR([--with-gtest must have a value])
+ else
+ if ! test -s "${with_gtest}/googletest/include/gtest/gtest.h"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Can't find 'googletest/include/gtest/gtest.h' under ${with_gtest} given with the --with-gtest option.])
+ elif ! test -s "${with_gtest}/googlemock/include/gmock/gmock.h"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Can't find 'googlemock/include/gmock/gmock.h' under ${with_gtest} given with the --with-gtest option.])
+ else
+ GTEST_FRAMEWORK_SRC=${with_gtest}
+ AC_MSG_RESULT([$GTEST_FRAMEWORK_SRC])
+ fi
+ fi
+ fi
+
+ AC_SUBST(GTEST_FRAMEWORK_SRC)
+])
+
###############################################################################
#
# Setup and check the Java Microbenchmark Harness
diff --git a/make/autoconf/libraries.m4 b/make/autoconf/libraries.m4
index 0002dba1604..5120918aed2 100644
--- a/make/autoconf/libraries.m4
+++ b/make/autoconf/libraries.m4
@@ -102,6 +102,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
LIB_SETUP_BUNDLED_LIBS
LIB_SETUP_MISC_LIBS
LIB_TESTS_SETUP_GRAALUNIT
+ LIB_TESTS_SETUP_GTEST
BASIC_JDKLIB_LIBS=""
if test "x$TOOLCHAIN_TYPE" != xmicrosoft; then
diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in
index 98c5132832e..ed4e860e01c 100644
--- a/make/autoconf/spec.gmk.in
+++ b/make/autoconf/spec.gmk.in
@@ -292,9 +292,6 @@ JVM_FEATURES_custom := @JVM_FEATURES_custom@
VALID_JVM_FEATURES := @VALID_JVM_FEATURES@
VALID_JVM_VARIANTS := @VALID_JVM_VARIANTS@
-# Control whether Hotspot builds gtest tests
-BUILD_GTEST := @BUILD_GTEST@
-
# Allow overriding the default hotspot library path
HOTSPOT_OVERRIDE_LIBPATH := @HOTSPOT_OVERRIDE_LIBPATH@
@@ -392,6 +389,8 @@ JMH_JOPT_SIMPLE_JAR := @JMH_JOPT_SIMPLE_JAR@
JMH_COMMONS_MATH_JAR := @JMH_COMMONS_MATH_JAR@
JMH_VERSION := @JMH_VERSION@
+GTEST_FRAMEWORK_SRC := @GTEST_FRAMEWORK_SRC@
+
# Source file for cacerts
CACERTS_FILE=@CACERTS_FILE@
diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js
index befee0d95b8..a070909f397 100644
--- a/make/conf/jib-profiles.js
+++ b/make/conf/jib-profiles.js
@@ -404,7 +404,7 @@ var getJibProfilesProfiles = function (input, common, data) {
"linux-x64": {
target_os: "linux",
target_cpu: "x64",
- dependencies: ["devkit", "graphviz", "pandoc", "graalunit_lib"],
+ dependencies: ["devkit", "gtest", "graphviz", "pandoc", "graalunit_lib"],
configure_args: concat(common.configure_args_64bit,
"--enable-full-docs", "--with-zlib=system",
(isWsl(input) ? [ "--host=x86_64-unknown-linux-gnu",
@@ -416,7 +416,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "x86",
build_cpu: "x64",
- dependencies: ["devkit"],
+ dependencies: ["devkit", "gtest"],
configure_args: concat(common.configure_args_32bit,
"--with-jvm-variants=minimal,server", "--with-zlib=system"),
},
@@ -424,7 +424,7 @@ var getJibProfilesProfiles = function (input, common, data) {
"macosx-x64": {
target_os: "macosx",
target_cpu: "x64",
- dependencies: ["devkit", "pandoc", "graalunit_lib"],
+ dependencies: ["devkit", "gtest", "pandoc", "graalunit_lib"],
configure_args: concat(common.configure_args_64bit, "--with-zlib=system",
"--with-macosx-version-max=10.9.0"),
},
@@ -432,7 +432,7 @@ var getJibProfilesProfiles = function (input, common, data) {
"windows-x64": {
target_os: "windows",
target_cpu: "x64",
- dependencies: ["devkit", "pandoc", "graalunit_lib"],
+ dependencies: ["devkit", "gtest", "pandoc", "graalunit_lib"],
configure_args: concat(common.configure_args_64bit),
},
@@ -440,7 +440,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "windows",
target_cpu: "x86",
build_cpu: "x64",
- dependencies: ["devkit"],
+ dependencies: ["devkit", "gtest"],
configure_args: concat(common.configure_args_32bit),
},
@@ -448,7 +448,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "aarch64",
build_cpu: "x64",
- dependencies: ["devkit", "build_devkit", "pandoc"],
+ dependencies: ["devkit", "gtest", "build_devkit", "pandoc"],
configure_args: [
"--openjdk-target=aarch64-linux-gnu",
"--disable-jvm-feature-jvmci",
@@ -461,7 +461,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "arm",
build_cpu: "x64",
- dependencies: ["devkit", "build_devkit"],
+ dependencies: ["devkit", "gtest", "build_devkit"],
configure_args: [
"--openjdk-target=arm-linux-gnueabihf", "--with-freetype=bundled",
"--with-abi-profile=arm-vfp-hflt", "--disable-warnings-as-errors"
@@ -472,7 +472,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "ppc64le",
build_cpu: "x64",
- dependencies: ["devkit", "build_devkit"],
+ dependencies: ["devkit", "gtest", "build_devkit"],
configure_args: [
"--openjdk-target=ppc64le-linux-gnu", "--with-freetype=bundled",
"--disable-warnings-as-errors"
@@ -483,7 +483,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "s390x",
build_cpu: "x64",
- dependencies: ["devkit", "build_devkit"],
+ dependencies: ["devkit", "gtest", "build_devkit"],
configure_args: [
"--openjdk-target=s390x-linux-gnu", "--with-freetype=bundled",
"--disable-warnings-as-errors"
@@ -538,7 +538,7 @@ var getJibProfilesProfiles = function (input, common, data) {
"linux-x64-zero": {
target_os: "linux",
target_cpu: "x64",
- dependencies: ["devkit"],
+ dependencies: ["devkit", "gtest"],
configure_args: concat(common.configure_args_64bit, [
"--with-zlib=system",
"--with-jvm-variants=zero",
@@ -550,7 +550,7 @@ var getJibProfilesProfiles = function (input, common, data) {
target_os: "linux",
target_cpu: "x86",
build_cpu: "x64",
- dependencies: ["devkit"],
+ dependencies: ["devkit", "gtest"],
configure_args: concat(common.configure_args_32bit, [
"--with-zlib=system",
"--with-jvm-variants=zero",
@@ -573,7 +573,7 @@ var getJibProfilesProfiles = function (input, common, data) {
"linux-x64-debug-nopch": {
target_os: "linux",
target_cpu: "x64",
- dependencies: ["devkit"],
+ dependencies: ["devkit", "gtest"],
configure_args: concat(common.configure_args_64bit,
"--with-zlib=system", "--disable-precompiled-headers"),
},
@@ -1148,6 +1148,12 @@ var getJibProfilesDependencies = function (input, common) {
configure_args: "--with-graalunit-lib=" + input.get("graalunit_lib", "install_path"),
environment_name: "GRAALUNIT_LIB"
},
+
+ gtest: {
+ organization: common.organization,
+ ext: "tar.gz",
+ revision: "1.8.1"
+ },
};
return dependencies;
diff --git a/make/hotspot/lib/CompileGtest.gmk b/make/hotspot/lib/CompileGtest.gmk
index 238956ab45a..bf3a9e2ba24 100644
--- a/make/hotspot/lib/CompileGtest.gmk
+++ b/make/hotspot/lib/CompileGtest.gmk
@@ -27,7 +27,6 @@ $(eval $(call IncludeCustomExtension, hotspot/lib/CompileGtest.gmk))
GTEST_TEST_SRC += $(TOPDIR)/test/hotspot/gtest
GTEST_LAUNCHER_SRC := $(TOPDIR)/test/hotspot/gtest/gtestLauncher.cpp
-GTEST_FRAMEWORK_SRC := $(TOPDIR)/test/fmw/gtest
# On Windows, there are no internal debug symbols so must set copying to true
# to get any at all.
@@ -39,6 +38,36 @@ endif
################################################################################
+# Disabling all warnings in gtest source code
+
+$(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBGTEST, \
+ NAME := gtest, \
+ TYPE := STATIC_LIBRARY, \
+ TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
+ OUTPUT_DIR := $(JVM_OUTPUTDIR)/libgtest, \
+ OBJECT_DIR := $(JVM_OUTPUTDIR)/libgtest/objs, \
+ SRC := \
+ $(GTEST_FRAMEWORK_SRC)/googletest/src \
+ $(GTEST_FRAMEWORK_SRC)/googlemock/src, \
+ INCLUDE_FILES := gtest-all.cc gmock-all.cc, \
+ CFLAGS := $(filter-out $(WARNING_CFLAGS_JVM), $(JVM_CFLAGS)) \
+ -w \
+ -I$(GTEST_FRAMEWORK_SRC)/googletest \
+ -I$(GTEST_FRAMEWORK_SRC)/googletest/include \
+ -I$(GTEST_FRAMEWORK_SRC)/googlemock \
+ -I$(GTEST_FRAMEWORK_SRC)/googlemock/include, \
+ CFLAGS_windows := -EHsc, \
+ CFLAGS_macosx := -DGTEST_OS_MAC=1, \
+ OPTIMIZATION := $(JVM_OPTIMIZATION), \
+ COPY_DEBUG_SYMBOLS := $(GTEST_COPY_DEBUG_SYMBOLS), \
+ ZIP_EXTERNAL_DEBUG_SYMBOLS := false, \
+ STRIP_SYMBOLS := false, \
+))
+
+TARGETS += $(BUILD_GTEST_LIBGTEST)
+
+################################################################################
+
ifeq ($(call isTargetOs, windows), true)
GTEST_JVM_MAPFILE := $(JVM_MAPFILE)
else
@@ -64,15 +93,10 @@ $(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \
EXCLUDES := $(JVM_EXCLUDES), \
EXCLUDE_FILES := gtestLauncher.cpp, \
EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
- EXTRA_FILES := \
- $(GTEST_FRAMEWORK_SRC)/googletest/src/gtest-all.cc \
- $(GTEST_FRAMEWORK_SRC)/googlemock/src/gmock-all.cc, \
EXTRA_OBJECT_FILES := $(filter-out %/operator_new$(OBJ_SUFFIX), \
$(BUILD_LIBJVM_ALL_OBJS)), \
CFLAGS := $(JVM_CFLAGS) \
- -I$(GTEST_FRAMEWORK_SRC)/googletest \
-I$(GTEST_FRAMEWORK_SRC)/googletest/include \
- -I$(GTEST_FRAMEWORK_SRC)/googlemock \
-I$(GTEST_FRAMEWORK_SRC)/googlemock/include \
$(addprefix -I,$(GTEST_TEST_SRC)), \
CFLAGS_windows := -EHsc, \
@@ -83,7 +107,10 @@ $(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \
undef switch format-nonliteral tautological-undefined-compare \
self-assign-overloaded, \
LDFLAGS := $(JVM_LDFLAGS), \
+ LDFLAGS_unix := -L$(JVM_OUTPUTDIR)/libgtest, \
LIBS := $(JVM_LIBS), \
+ LIBS_unix := -lgtest, \
+ LIBS_windows := $(JVM_OUTPUTDIR)/libgtest/gtest.lib, \
OPTIMIZATION := $(JVM_OPTIMIZATION), \
MAPFILE := $(GTEST_JVM_MAPFILE), \
USE_MAPFILE_FOR_SYMBOLS := true, \
@@ -91,9 +118,11 @@ $(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \
ZIP_EXTERNAL_DEBUG_SYMBOLS := false, \
STRIP_SYMBOLS := false, \
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
- PRECOMPILED_HEADER_EXCLUDE := gtest-all.cc gmock-all.cc gtestMain.cpp, \
+ PRECOMPILED_HEADER_EXCLUDE := gtestMain.cpp, \
))
+$(BUILD_GTEST_LIBJVM) : $(BUILD_GTEST_LIBGTEST)
+
TARGETS += $(BUILD_GTEST_LIBJVM)
################################################################################
diff --git a/make/hotspot/lib/CompileLibraries.gmk b/make/hotspot/lib/CompileLibraries.gmk
index 9f68d7033ad..6b1e6529cd0 100644
--- a/make/hotspot/lib/CompileLibraries.gmk
+++ b/make/hotspot/lib/CompileLibraries.gmk
@@ -33,7 +33,7 @@ include HotspotCommon.gmk
include lib/CompileJvm.gmk
-ifeq ($(BUILD_GTEST), true)
+ifneq ($(GTEST_FRAMEWORK_SRC), )
include lib/CompileGtest.gmk
endif
diff --git a/test/fmw/gtest/googlemock/CHANGES b/test/fmw/gtest/googlemock/CHANGES
deleted file mode 100644
index 4328ece3d3a..00000000000
--- a/test/fmw/gtest/googlemock/CHANGES
+++ /dev/null
@@ -1,126 +0,0 @@
-Changes for 1.7.0:
-
-* All new improvements in Google Test 1.7.0.
-* New feature: matchers DoubleNear(), FloatNear(),
- NanSensitiveDoubleNear(), NanSensitiveFloatNear(),
- UnorderedElementsAre(), UnorderedElementsAreArray(), WhenSorted(),
- WhenSortedBy(), IsEmpty(), and SizeIs().
-* Improvement: Google Mock can now be built as a DLL.
-* Improvement: when compiled by a C++11 compiler, matchers AllOf()
- and AnyOf() can accept an arbitrary number of matchers.
-* Improvement: when compiled by a C++11 compiler, matchers
- ElementsAreArray() can accept an initializer list.
-* Improvement: when exceptions are enabled, a mock method with no
- default action now throws instead crashing the test.
-* Improvement: added class testing::StringMatchResultListener to aid
- definition of composite matchers.
-* Improvement: function return types used in MOCK_METHOD*() macros can
- now contain unprotected commas.
-* Improvement (potentially breaking): EXPECT_THAT() and ASSERT_THAT()
- are now more strict in ensuring that the value type and the matcher
- type are compatible, catching potential bugs in tests.
-* Improvement: Pointee() now works on an optional.
-* Improvement: the ElementsAreArray() matcher can now take a vector or
- iterator range as input, and makes a copy of its input elements
- before the conversion to a Matcher.
-* Improvement: the Google Mock Generator can now generate mocks for
- some class templates.
-* Bug fix: mock object destruction triggerred by another mock object's
- destruction no longer hangs.
-* Improvement: Google Mock Doctor works better with newer Clang and
- GCC now.
-* Compatibility fixes.
-* Bug/warning fixes.
-
-Changes for 1.6.0:
-
-* Compilation is much faster and uses much less memory, especially
- when the constructor and destructor of a mock class are moved out of
- the class body.
-* New matchers: Pointwise(), Each().
-* New actions: ReturnPointee() and ReturnRefOfCopy().
-* CMake support.
-* Project files for Visual Studio 2010.
-* AllOf() and AnyOf() can handle up-to 10 arguments now.
-* Google Mock doctor understands Clang error messages now.
-* SetArgPointee<> now accepts string literals.
-* gmock_gen.py handles storage specifier macros and template return
- types now.
-* Compatibility fixes.
-* Bug fixes and implementation clean-ups.
-* Potentially incompatible changes: disables the harmful 'make install'
- command in autotools.
-
-Potentially breaking changes:
-
-* The description string for MATCHER*() changes from Python-style
- interpolation to an ordinary C++ string expression.
-* SetArgumentPointee is deprecated in favor of SetArgPointee.
-* Some non-essential project files for Visual Studio 2005 are removed.
-
-Changes for 1.5.0:
-
- * New feature: Google Mock can be safely used in multi-threaded tests
- on platforms having pthreads.
- * New feature: function for printing a value of arbitrary type.
- * New feature: function ExplainMatchResult() for easy definition of
- composite matchers.
- * The new matcher API lets user-defined matchers generate custom
- explanations more directly and efficiently.
- * Better failure messages all around.
- * NotNull() and IsNull() now work with smart pointers.
- * Field() and Property() now work when the matcher argument is a pointer
- passed by reference.
- * Regular expression matchers on all platforms.
- * Added GCC 4.0 support for Google Mock Doctor.
- * Added gmock_all_test.cc for compiling most Google Mock tests
- in a single file.
- * Significantly cleaned up compiler warnings.
- * Bug fixes, better test coverage, and implementation clean-ups.
-
- Potentially breaking changes:
-
- * Custom matchers defined using MatcherInterface or MakePolymorphicMatcher()
- need to be updated after upgrading to Google Mock 1.5.0; matchers defined
- using MATCHER or MATCHER_P* aren't affected.
- * Dropped support for 'make install'.
-
-Changes for 1.4.0 (we skipped 1.2.* and 1.3.* to match the version of
-Google Test):
-
- * Works in more environments: Symbian and minGW, Visual C++ 7.1.
- * Lighter weight: comes with our own implementation of TR1 tuple (no
- more dependency on Boost!).
- * New feature: --gmock_catch_leaked_mocks for detecting leaked mocks.
- * New feature: ACTION_TEMPLATE for defining templatized actions.
- * New feature: the .After() clause for specifying expectation order.
- * New feature: the .With() clause for specifying inter-argument
- constraints.
- * New feature: actions ReturnArg(), ReturnNew(...), and
- DeleteArg().
- * New feature: matchers Key(), Pair(), Args<...>(), AllArgs(), IsNull(),
- and Contains().
- * New feature: utility class MockFunction, useful for checkpoints, etc.
- * New feature: functions Value(x, m) and SafeMatcherCast(m).
- * New feature: copying a mock object is rejected at compile time.
- * New feature: a script for fusing all Google Mock and Google Test
- source files for easy deployment.
- * Improved the Google Mock doctor to diagnose more diseases.
- * Improved the Google Mock generator script.
- * Compatibility fixes for Mac OS X and gcc.
- * Bug fixes and implementation clean-ups.
-
-Changes for 1.1.0:
-
- * New feature: ability to use Google Mock with any testing framework.
- * New feature: macros for easily defining new matchers
- * New feature: macros for easily defining new actions.
- * New feature: more container matchers.
- * New feature: actions for accessing function arguments and throwing
- exceptions.
- * Improved the Google Mock doctor script for diagnosing compiler errors.
- * Bug fixes and implementation clean-ups.
-
-Changes for 1.0.0:
-
- * Initial Open Source release of Google Mock
diff --git a/test/fmw/gtest/googlemock/CONTRIBUTORS b/test/fmw/gtest/googlemock/CONTRIBUTORS
deleted file mode 100644
index 6e9ae362b60..00000000000
--- a/test/fmw/gtest/googlemock/CONTRIBUTORS
+++ /dev/null
@@ -1,40 +0,0 @@
-# This file contains a list of people who've made non-trivial
-# contribution to the Google C++ Mocking Framework project. People
-# who commit code to the project are encouraged to add their names
-# here. Please keep the list sorted by first names.
-
-Benoit Sigoure
-Bogdan Piloca
-Chandler Carruth
-Dave MacLachlan
-David Anderson
-Dean Sturtevant
-Gene Volovich
-Hal Burch
-Jeffrey Yasskin
-Jim Keller
-Joe Walnes
-Jon Wray
-Keir Mierle
-Keith Ray
-Kostya Serebryany
-Lev Makhlis
-Manuel Klimek
-Mario Tanev
-Mark Paskin
-Markus Heule
-Matthew Simmons
-Mike Bland
-Neal Norwitz
-Nermin Ozkiranartli
-Owen Carlsen
-Paneendra Ba
-Paul Menage
-Piotr Kaminski
-Russ Rufer
-Sverre Sundsdal
-Takeshi Yoshino
-Vadim Berman
-Vlad Losev
-Wolfgang Klier
-Zhanyong Wan
diff --git a/test/fmw/gtest/googlemock/LICENSE b/test/fmw/gtest/googlemock/LICENSE
deleted file mode 100644
index 1941a11f8ce..00000000000
--- a/test/fmw/gtest/googlemock/LICENSE
+++ /dev/null
@@ -1,28 +0,0 @@
-Copyright 2008, Google Inc.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/test/fmw/gtest/googlemock/README.md b/test/fmw/gtest/googlemock/README.md
deleted file mode 100644
index e5bb2116ac4..00000000000
--- a/test/fmw/gtest/googlemock/README.md
+++ /dev/null
@@ -1,322 +0,0 @@
-## Google Mock ##
-
-The Google C++ mocking framework.
-
-### Overview ###
-
-Google's framework for writing and using C++ mock classes.
-It can help you derive better designs of your system and write better tests.
-
-It is inspired by:
-
- * [jMock](http://www.jmock.org/),
- * [EasyMock](http://www.easymock.org/), and
- * [Hamcrest](http://code.google.com/p/hamcrest/),
-
-and designed with C++'s specifics in mind.
-
-Google mock:
-
- * lets you create mock classes trivially using simple macros.
- * supports a rich set of matchers and actions.
- * handles unordered, partially ordered, or completely ordered expectations.
- * is extensible by users.
-
-We hope you find it useful!
-
-### Features ###
-
- * Provides a declarative syntax for defining mocks.
- * Can easily define partial (hybrid) mocks, which are a cross of real
- and mock objects.
- * Handles functions of arbitrary types and overloaded functions.
- * Comes with a rich set of matchers for validating function arguments.
- * Uses an intuitive syntax for controlling the behavior of a mock.
- * 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.
- * Does not use exceptions.
- * Is easy to learn and use.
-
-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 (irc.oftc.net) #gtest available. Please
-join us!
-
-Please note that code under [scripts/generator](scripts/generator/) is
-from [cppclean](http://code.google.com/p/cppclean/) and released under
-the Apache License, which is different from Google Mock's license.
-
-## Getting Started ##
-
-If you are new to the project, we suggest that you read the user
-documentation in the following order:
-
- * Learn the [basics](../googletest/docs/primer.md) of
- Google Test, if you choose to use Google Mock with it (recommended).
- * Read [Google Mock for Dummies](../googlemock/docs/ForDummies.md).
- * Read the instructions below on how to build Google Mock.
-
-You can also watch Zhanyong's [talk](http://www.youtube.com/watch?v=sYpCyLI47rM) on Google Mock's usage and implementation.
-
-Once you understand the basics, check out the rest of the docs:
-
- * [CheatSheet](../googlemock/docs/CheatSheet.md) - all the commonly used stuff
- at a glance.
- * [CookBook](../googlemock/docs/CookBook.md) - recipes for getting things done,
- including advanced techniques.
-
-If you need help, please check the
-[KnownIssues](docs/KnownIssues.md) and
-[FrequentlyAskedQuestions](docs/FrequentlyAskedQuestions.md) before
-posting a question on the
-[discussion group](http://groups.google.com/group/googlemock).
-
-
-### Using Google Mock Without Google Test ###
-
-Google Mock is not a testing framework itself. Instead, it needs a
-testing framework for writing tests. Google Mock works seamlessly
-with [Google Test](https://github.com/google/googletest), but
-you can also use it with [any C++ testing framework](../googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework).
-
-### Requirements for End Users ###
-
-Google Mock is implemented on top of [Google Test](
-http://github.com/google/googletest/), and depends on it.
-You must use the bundled version of Google Test when using Google Mock.
-
-You can also easily configure Google Mock to work with another testing
-framework, although it will still need Google Test. Please read
-["Using_Google_Mock_with_Any_Testing_Framework"](
- ../googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework)
-for instructions.
-
-Google Mock depends on advanced C++ features and thus requires a more
-modern compiler. The following are needed to use Google Mock:
-
-#### Linux Requirements ####
-
- * GNU-compatible Make or "gmake"
- * POSIX-standard shell
- * POSIX(-2) Regular Expressions (regex.h)
- * C++98-standard-compliant compiler (e.g. GCC 3.4 or newer)
-
-#### Windows Requirements ####
-
- * Microsoft Visual C++ 8.0 SP1 or newer
-
-#### Mac OS X Requirements ####
-
- * Mac OS X 10.4 Tiger or newer
- * Developer Tools Installed
-
-### Requirements for Contributors ###
-
-We welcome patches. If you plan to contribute a patch, you need to
-build Google Mock and its tests, which has further requirements:
-
- * Automake version 1.9 or newer
- * Autoconf version 2.59 or newer
- * Libtool / Libtoolize
- * Python version 2.3 or newer (for running some of the tests and
- re-generating certain source files from templates)
-
-### Building Google Mock ###
-
-#### Using CMake ####
-
-If you have CMake available, it is recommended that you follow the
-[build instructions][gtest_cmakebuild]
-as described for Google Test.
-
-If are using Google Mock with an
-existing CMake project, the section
-[Incorporating Into An Existing CMake Project][gtest_incorpcmake]
-may be of particular interest.
-To make it work for Google Mock you will need to change
-
- target_link_libraries(example gtest_main)
-
-to
-
- target_link_libraries(example gmock_main)
-
-This works because `gmock_main` library is compiled with Google Test.
-
-#### Preparing to Build (Unix only) ####
-
-If you are using a Unix system and plan to use the GNU Autotools build
-system to build Google Mock (described below), you'll need to
-configure it now.
-
-To prepare the Autotools build system:
-
- cd googlemock
- autoreconf -fvi
-
-To build Google Mock and your tests that use it, you need to tell your
-build system where to find its headers and source files. The exact
-way to do it depends on which build system you use, and is usually
-straightforward.
-
-This section shows how you can integrate Google Mock into your
-existing build system.
-
-Suppose you put Google Mock in directory `${GMOCK_DIR}` and Google Test
-in `${GTEST_DIR}` (the latter is `${GMOCK_DIR}/gtest` by default). To
-build Google Mock, create a library build target (or a project as
-called by Visual Studio and Xcode) to compile
-
- ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
-
-with
-
- ${GTEST_DIR}/include and ${GMOCK_DIR}/include
-
-in the system header search path, and
-
- ${GTEST_DIR} and ${GMOCK_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} \
- -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
- -pthread -c ${GTEST_DIR}/src/gtest-all.cc
- g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
- -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
- -pthread -c ${GMOCK_DIR}/src/gmock-all.cc
- ar -rv libgmock.a gtest-all.o gmock-all.o
-
-(We need -pthread as Google Test and Google Mock use threads.)
-
-Next, you should compile your test source file with
-${GTEST\_DIR}/include and ${GMOCK\_DIR}/include in the header search
-path, and link it with gmock and any other necessary libraries:
-
- g++ -isystem ${GTEST_DIR}/include -isystem ${GMOCK_DIR}/include \
- -pthread path/to/your_test.cc libgmock.a -o your_test
-
-As an example, the make/ directory contains a Makefile that you can
-use to build Google Mock on systems where GNU make is available
-(e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google
-Mock's own tests. Instead, it just builds the Google Mock library and
-a sample test. You can use it as a starting point for your own build
-script.
-
-If the default settings are correct for your environment, the
-following commands should succeed:
-
- cd ${GMOCK_DIR}/make
- make
- ./gmock_test
-
-If you see errors, try to tweak the contents of
-[make/Makefile](make/Makefile) to make them go away.
-
-### Windows ###
-
-The msvc/2005 directory contains VC++ 2005 projects and the msvc/2010
-directory contains VC++ 2010 projects for building Google Mock and
-selected tests.
-
-Change to the appropriate directory and run "msbuild gmock.sln" to
-build the library and tests (or open the gmock.sln in the MSVC IDE).
-If you want to create your own project to use with Google Mock, you'll
-have to configure it to use the `gmock_config` propety sheet. For that:
-
- * Open the Property Manager window (View | Other Windows | Property Manager)
- * Right-click on your project and select "Add Existing Property Sheet..."
- * Navigate to `gmock_config.vsprops` or `gmock_config.props` and select it.
- * In Project Properties | Configuration Properties | General | Additional
- Include Directories, type /include.
-
-### Tweaking Google Mock ###
-
-Google Mock can be used in diverse environments. The default
-configuration may not work (or may not work well) out of the box in
-some environments. However, you can easily tweak Google Mock by
-defining control macros on the compiler command line. Generally,
-these macros are named like `GTEST_XYZ` and you define them to either 1
-or 0 to enable or disable a certain feature.
-
-We list the most frequently used macros below. For a complete list,
-see file [${GTEST\_DIR}/include/gtest/internal/gtest-port.h](
-../googletest/include/gtest/internal/gtest-port.h).
-
-### Choosing a TR1 Tuple Library ###
-
-Google Mock uses the C++ Technical Report 1 (TR1) tuple library
-heavily. Unfortunately TR1 tuple is not yet widely available with all
-compilers. The good news is that Google Test 1.4.0+ implements a
-subset of TR1 tuple that's enough for Google Mock's need. Google Mock
-will automatically use that implementation when the compiler doesn't
-provide TR1 tuple.
-
-Usually you don't need to care about which tuple library Google Test
-and Google Mock use. However, if your project already uses TR1 tuple,
-you need to tell Google Test and Google Mock to use the same TR1 tuple
-library the rest of your project uses, or the two tuple
-implementations will clash. To do that, add
-
- -DGTEST_USE_OWN_TR1_TUPLE=0
-
-to the compiler flags while compiling Google Test, Google Mock, and
-your tests. If you want to force Google Test and Google Mock to use
-their own tuple library, just add
-
- -DGTEST_USE_OWN_TR1_TUPLE=1
-
-to the compiler flags instead.
-
-If you want to use Boost's TR1 tuple library with Google Mock, please
-refer to the Boost website (http://www.boost.org/) for how to obtain
-it and set it up.
-
-### As a Shared Library (DLL) ###
-
-Google Mock is compact, so most users can build and link it as a static
-library for the simplicity. Google Mock can be used as a DLL, but the
-same DLL must contain Google Test as well. See
-[Google Test's README][gtest_readme]
-for instructions on how to set up necessary compiler settings.
-
-### Tweaking Google Mock ###
-
-Most of Google Test's control macros apply to Google Mock as well.
-Please see [Google Test's README][gtest_readme] for how to tweak them.
-
-### Upgrading from an Earlier Version ###
-
-We strive to keep Google Mock releases backward compatible.
-Sometimes, though, we have to make some breaking changes for the
-users' long-term benefits. This section describes what you'll need to
-do if you are upgrading from an earlier version of Google Mock.
-
-#### Upgrading from 1.1.0 or Earlier ####
-
-You may need to explicitly enable or disable Google Test's own TR1
-tuple library. See the instructions in section "[Choosing a TR1 Tuple
-Library](#choosing-a-tr1-tuple-library)".
-
-#### Upgrading from 1.4.0 or Earlier ####
-
-On platforms where the pthread library is available, Google Test and
-Google Mock use it in order to be thread-safe. For this to work, you
-may need to tweak your compiler and/or linker flags. Please see the
-"[Multi-threaded Tests](../googletest/README.md#multi-threaded-tests)" section in file Google Test's README for what you may need to do.
-
-If you have custom matchers defined using `MatcherInterface` or
-`MakePolymorphicMatcher()`, you'll need to update their definitions to
-use the new matcher API (
-[monomorphic](./docs/CookBook.md#writing-new-monomorphic-matchers),
-[polymorphic](./docs/CookBook.md#writing-new-polymorphic-matchers)).
-Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected.
-
-Happy testing!
-
-[gtest_readme]: ../googletest/README.md "googletest"
-[gtest_cmakebuild]: ../googletest/README.md#using-cmake "Using CMake"
-[gtest_incorpcmake]: ../googletest/README.md#incorporating-into-an-existing-cmake-project "Incorporating Into An Existing CMake Project"
diff --git a/test/fmw/gtest/googlemock/include/gmock/gmock-actions.h b/test/fmw/gtest/googlemock/include/gmock/gmock-actions.h
deleted file mode 100644
index b82313d5b05..00000000000
--- a/test/fmw/gtest/googlemock/include/gmock/gmock-actions.h
+++ /dev/null
@@ -1,1263 +0,0 @@
-// 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 implements some commonly used actions.
-
-// GOOGLETEST_CM0002 DO NOT DELETE
-
-#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
-#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
-
-#ifndef _WIN32_WCE
-# include
-#endif
-
-#include
-#include
-
-#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
-#include
-#endif // GTEST_LANG_CXX11
-
-namespace testing {
-
-// To implement an action Foo, define:
-// 1. a class FooAction that implements the ActionInterface interface, and
-// 2. a factory function that creates an Action object from a
-// const FooAction*.
-//
-// The two-level delegation design follows that of Matcher, providing
-// consistency for extension developers. It also eases ownership
-// management as Action objects can now be copied like plain values.
-
-namespace internal {
-
-template
-class ActionAdaptor;
-
-// BuiltInDefaultValueGetter::Get() returns a
-// default-constructed T value. BuiltInDefaultValueGetter::Get() crashes with an error.
-//
-// This primary template is used when kDefaultConstructible is true.
-template
-struct BuiltInDefaultValueGetter {
- static T Get() { return T(); }
-};
-template
-struct BuiltInDefaultValueGetter {
- static T Get() {
- Assert(false, __FILE__, __LINE__,
- "Default action undefined for the function return type.");
- return internal::Invalid();
- // The above statement will never be reached, but is required in
- // order for this function to compile.
- }
-};
-
-// BuiltInDefaultValue::Get() returns the "built-in" default value
-// for type T, which is NULL when T is a raw pointer type, 0 when T is
-// a numeric type, false when T is bool, or "" when T is string or
-// std::string. In addition, in C++11 and above, it turns a
-// default-constructed T value if T is default constructible. For any
-// other type T, the built-in default T value is undefined, and the
-// function will abort the process.
-template
-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::value;
- }
-
- static T Get() {
- return BuiltInDefaultValueGetter<
- T, ::std::is_default_constructible::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::Get();
- }
-
-#endif // GTEST_LANG_CXX11
-};
-
-// This partial specialization says that we use the same built-in
-// default value for T and const T.
-template
-class BuiltInDefaultValue {
- public:
- static bool Exists() { return BuiltInDefaultValue::Exists(); }
- static T Get() { return BuiltInDefaultValue::Get(); }
-};
-
-// This partial specialization defines the default values for pointer
-// types.
-template
-class BuiltInDefaultValue {
- public:
- static bool Exists() { return true; }
- static T* Get() { return NULL; }
-};
-
-// The following specializations define the default values for
-// specific types we care about.
-#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \
- template <> \
- class BuiltInDefaultValue { \
- public: \
- static bool Exists() { return true; } \
- static type Get() { return value; } \
- }
-
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
-#if GTEST_HAS_GLOBAL_STRING
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
-#endif // GTEST_HAS_GLOBAL_STRING
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
-
-// There's no need for a default action for signed wchar_t, as that
-// type is the same as wchar_t for gcc, and invalid for MSVC.
-//
-// There's also no need for a default action for unsigned wchar_t, as
-// that type is the same as unsigned int for gcc, and invalid for
-// MSVC.
-#if GMOCK_WCHAR_T_IS_NATIVE_
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT
-#endif
-
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
-
-#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_
-
-} // namespace internal
-
-// When an unexpected function call is encountered, Google Mock will
-// let it return a default value if the user has specified one for its
-// return type, or if the return type has a built-in default value;
-// otherwise Google Mock won't know what value to return and will have
-// to abort the process.
-//
-// The DefaultValue class allows a user to specify the
-// default value for a type T that is both copyable and publicly
-// destructible (i.e. anything that can be used as a function return
-// type). The usage is:
-//
-// // Sets the default value for type T to be foo.
-// DefaultValue::Set(foo);
-template
-class DefaultValue {
- public:
- // Sets the default value for type T; requires T to be
- // copy-constructable and have a public destructor.
- static void Set(T x) {
- delete producer_;
- producer_ = new FixedValueProducer(x);
- }
-
- // Provides a factory function to be called to generate the default value.
- // This method can be used even if T is only move-constructible, but it is not
- // limited to that case.
- typedef T (*FactoryFunction)();
- static void SetFactory(FactoryFunction factory) {
- delete producer_;
- producer_ = new FactoryValueProducer(factory);
- }
-
- // Unsets the default value for type T.
- static void Clear() {
- delete producer_;
- producer_ = NULL;
- }
-
- // Returns true iff the user has set the default value for type T.
- static bool IsSet() { return producer_ != NULL; }
-
- // Returns true if T has a default return value set by the user or there
- // exists a built-in default value.
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue::Exists();
- }
-
- // Returns the default value for type T if the user has set one;
- // otherwise returns the built-in default value. Requires that Exists()
- // is true, which ensures that the return value is well-defined.
- static T Get() {
- return producer_ == NULL ?
- internal::BuiltInDefaultValue::Get() : producer_->Produce();
- }
-
- private:
- class ValueProducer {
- public:
- virtual ~ValueProducer() {}
- virtual T Produce() = 0;
- };
-
- class FixedValueProducer : public ValueProducer {
- public:
- explicit FixedValueProducer(T value) : value_(value) {}
- virtual T Produce() { return value_; }
-
- private:
- const T value_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
- };
-
- class FactoryValueProducer : public ValueProducer {
- public:
- explicit FactoryValueProducer(FactoryFunction factory)
- : factory_(factory) {}
- virtual T Produce() { return factory_(); }
-
- private:
- const FactoryFunction factory_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
- };
-
- static ValueProducer* producer_;
-};
-
-// This partial specialization allows a user to set default values for
-// reference types.
-template
-class DefaultValue {
- public:
- // Sets the default value for type T&.
- static void Set(T& x) { // NOLINT
- address_ = &x;
- }
-
- // Unsets the default value for type T&.
- static void Clear() {
- address_ = NULL;
- }
-
- // Returns true iff the user has set the default value for type T&.
- static bool IsSet() { return address_ != NULL; }
-
- // Returns true if T has a default return value set by the user or there
- // exists a built-in default value.
- static bool Exists() {
- return IsSet() || internal::BuiltInDefaultValue::Exists();
- }
-
- // Returns the default value for type T& if the user has set one;
- // otherwise returns the built-in default value if there is one;
- // otherwise aborts the process.
- static T& Get() {
- return address_ == NULL ?
- internal::BuiltInDefaultValue::Get() : *address_;
- }
-
- private:
- static T* address_;
-};
-
-// This specialization allows DefaultValue::Get() to
-// compile.
-template <>
-class DefaultValue {
- public:
- static bool Exists() { return true; }
- static void Get() {}
-};
-
-// Points to the user-set default value for type T.
-template
-typename DefaultValue::ValueProducer* DefaultValue::producer_ = NULL;
-
-// Points to the user-set default value for type T&.
-template
-T* DefaultValue::address_ = NULL;
-
-// Implement this interface to define an action for function type F.
-template
-class ActionInterface {
- public:
- typedef typename internal::Function::Result Result;
- typedef typename internal::Function::ArgumentTuple ArgumentTuple;
-
- ActionInterface() {}
- virtual ~ActionInterface() {}
-
- // Performs the action. This method is not const, as in general an
- // action can have side effects and be stateful. For example, a
- // get-the-next-element-from-the-collection action will need to
- // remember the current element.
- virtual Result Perform(const ArgumentTuple& args) = 0;
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
-};
-
-// An Action 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 is just a
-// linked_ptr to const ActionInterface, so copying is fairly cheap.
-// Don't inherit from Action!
-//
-// You can view an object implementing ActionInterface as a
-// concrete action (including its current state), and an Action
-// object as a handle to it.
-template
-class Action {
- public:
- typedef typename internal::Function::Result Result;
- typedef typename internal::Function::ArgumentTuple ArgumentTuple;
-
- // Constructs a null Action. Needed for storing Action objects in
- // 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).
- template , G>::value>::type>
- Action(G&& fun) : fun_(::std::forward(fun)) {} // NOLINT
-#endif
-
- // Constructs an Action from its implementation.
- explicit Action(ActionInterface* impl) : impl_(impl) {}
-
- // This constructor allows us to turn an Action object into an
- // Action, 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.
- template
- explicit Action(const Action& action);
-
- // 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
- }
-
- // Performs the action. Note that this method is const even though
- // the corresponding method in ActionInterface is not. The reason
- // is that a const Action means that it cannot be re-bound to
- // another concrete action, not that the concrete action it binds to
- // cannot change state. (Think of the difference between a const
- // pointer and a pointer to const.)
- Result Perform(ArgumentTuple args) const {
- 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);
- }
-
- private:
- template
- friend class internal::ActionAdaptor;
-
- template
- 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
- ::std::function fun_;
-#endif
- internal::linked_ptr > impl_;
-};
-
-// The PolymorphicAction class template makes it easy to implement a
-// polymorphic action (i.e. an action that can be used in mock
-// functions of than one type, e.g. Return()).
-//
-// To define a polymorphic action, a user first provides a COPYABLE
-// implementation class that has a Perform() method template:
-//
-// class FooAction {
-// public:
-// template
-// Result Perform(const ArgumentTuple& args) const {
-// // Processes the arguments and returns a result, using
-// // tr1::get(args) to get the N-th (0-based) argument in the tuple.
-// }
-// ...
-// };
-//
-// Then the user creates the polymorphic action using
-// MakePolymorphicAction(object) where object has type FooAction. See
-// the definition of Return(void) and SetArgumentPointee(value) for
-// complete examples.
-template
-class PolymorphicAction {
- public:
- explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
-
- template
- operator Action() const {
- return Action(new MonomorphicImpl(impl_));
- }
-
- private:
- template
- class MonomorphicImpl : public ActionInterface {
- public:
- typedef typename internal::Function::Result Result;
- typedef typename internal::Function::ArgumentTuple ArgumentTuple;
-
- explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
-
- virtual Result Perform(const ArgumentTuple& args) {
- return impl_.template Perform(args);
- }
-
- private:
- Impl impl_;
-
- GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
- };
-
- Impl impl_;
-
- GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
-};
-
-// Creates an Action from its implementation and returns it. The
-// created Action object owns the implementation.
-template
-Action MakeAction(ActionInterface* impl) {
- return Action(impl);
-}
-
-// Creates a polymorphic action from its implementation. This is
-// easier to use than the PolymorphicAction constructor as it
-// doesn't require you to explicitly write the template argument, e.g.
-//
-// MakePolymorphicAction(foo);
-// vs
-// PolymorphicAction(foo);
-template
-inline PolymorphicAction MakePolymorphicAction(const Impl& impl) {
- return PolymorphicAction(impl);
-}
-
-namespace internal {
-
-// Allows an Action object to pose as an Action, as long as F2
-// and F1 are compatible.
-template
-class ActionAdaptor : public ActionInterface {
- public:
- typedef typename internal::Function::Result Result;
- typedef typename internal::Function::ArgumentTuple ArgumentTuple;
-
- explicit ActionAdaptor(const Action& from) : impl_(from.impl_) {}
-
- virtual Result Perform(const ArgumentTuple& args) {
- return impl_->Perform(args);
- }
-
- private:
- const internal::linked_ptr > 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
-struct ByMoveWrapper {
- explicit ByMoveWrapper(T value) : payload(internal::move(value)) {}
- T payload;
-};
-
-// Implements the polymorphic Return(x) action, which can be used in
-// any function that returns the type of x, regardless of the argument
-// types.
-//
-// Note: The value passed into Return must be converted into
-// Function::Result when this action is cast to Action rather than
-// when that action is performed. This is important in scenarios like
-//
-// MOCK_METHOD1(Method, T(U));
-// ...
-// {
-// Foo foo;
-// X x(&foo);
-// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
-// }
-//
-// In the example above the variable x holds reference to foo which leaves
-// scope and gets destroyed. If copying X just copies a reference to foo,
-// that copy will be left with a hanging reference. If conversion to T
-// makes a copy of foo, the above code is safe. To support that scenario, we
-// need to make sure that the type conversion happens inside the EXPECT_CALL
-// statement, and conversion of the result of Return to Action is a
-// good place for that.
-//
-// The real life example of the above scenario happens when an invocation
-// of gtl::Container() is passed into Return.
-//
-template
-class ReturnAction {
- public:
- // 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))) {}
-
- // This template type conversion operator allows Return(x) to be
- // used in ANY function that returns x's type.
- template
- operator Action() const {
- // Assert statement belongs here because this is the best place to verify
- // conditions on F. It produces the clearest error messages
- // in most compilers.
- // Impl really belongs in this scope as a local class but can't
- // because MSVC produces duplicate symbols in different translation units
- // in this case. Until MS fixes that bug we put Impl into the class scope
- // and put the typedef both here (for use in assert statement) and
- // in the Impl class. But both definitions must be the same.
- typedef typename Function::Result Result;
- GTEST_COMPILE_ASSERT_(
- !is_reference::value,
- use_ReturnRef_instead_of_Return_to_return_a_reference);
- return Action(new Impl(value_));
- }
-
- private:
- // Implements the Return(x) action for a particular function type F.
- template
- class Impl : public ActionInterface {
- public:
- typedef typename Function::Result Result;
- typedef typename Function::ArgumentTuple ArgumentTuple;
-
- // The implicit cast is necessary when Result has more than one
- // single-argument constructor (e.g. Result is std::vector) and R
- // has a type conversion operator template. In that case, value_(value)
- // won't compile as the compiler doesn't known which constructor of
- // 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& value)
- : value_before_cast_(*value),
- value_(ImplicitCast_(value_before_cast_)) {}
-
- virtual Result Perform(const ArgumentTuple&) { return value_; }
-
- private:
- GTEST_COMPILE_ASSERT_(!is_reference::value,
- Result_cannot_be_a_reference_type);
- // We save the value before casting just in case it is being cast to a
- // wrapper type.
- R value_before_cast_;
- Result value_;
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
- };
-
- // Partially specialize for ByMoveWrapper. This version of ReturnAction will
- // move its contents instead.
- template
- class Impl, F> : public ActionInterface {
- public:
- typedef typename Function::Result Result;
- typedef typename Function::ArgumentTuple ArgumentTuple;
-
- explicit Impl(const linked_ptr& wrapper)
- : performed_(false), wrapper_(wrapper) {}
-
- virtual Result Perform(const ArgumentTuple&) {
- GTEST_CHECK_(!performed_)
- << "A ByMove() action should only be performed once.";
- performed_ = true;
- return internal::move(wrapper_->payload);
- }
-
- private:
- bool performed_;
- const linked_ptr wrapper_;
-
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
-
- const linked_ptr value_;
-
- GTEST_DISALLOW_ASSIGN_(ReturnAction);
-};
-
-// Implements the ReturnNull() action.
-class ReturnNullAction {
- public:
- // Allows ReturnNull() to be used in any pointer-returning function. In C++11
- // this is enforced by returning nullptr, and in non-C++11 by asserting a
- // pointer type on compile time.
- template
- static Result Perform(const ArgumentTuple&) {
-#if GTEST_LANG_CXX11
- return nullptr;
-#else
- GTEST_COMPILE_ASSERT_(internal::is_pointer::value,
- ReturnNull_can_be_used_to_return_a_pointer_only);
- return NULL;
-#endif // GTEST_LANG_CXX11
- }
-};
-
-// Implements the Return() action.
-class ReturnVoidAction {
- public:
- // Allows Return() to be used in any void-returning function.
- template
- static void Perform(const ArgumentTuple&) {
- CompileAssertTypesEqual();
- }
-};
-
-// Implements the polymorphic ReturnRef(x) action, which can be used
-// in any function that returns a reference to the type of x,
-// regardless of the argument types.
-template
-class ReturnRefAction {
- public:
- // Constructs a ReturnRefAction object from the reference to be returned.
- explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
-
- // This template type conversion operator allows ReturnRef(x) to be
- // used in ANY function that returns a reference to x's type.
- template
- operator Action() const {
- typedef typename Function::Result Result;
- // Asserts that the function return type is a reference. This
- // catches the user error of using ReturnRef(x) when Return(x)
- // should be used, and generates some helpful error message.
- GTEST_COMPILE_ASSERT_(internal::is_reference::value,
- use_Return_instead_of_ReturnRef_to_return_a_value);
- return Action(new Impl(ref_));
- }
-
- private:
- // Implements the ReturnRef(x) action for a particular function type F.
- template
- class Impl : public ActionInterface {
- public:
- typedef typename Function::Result Result;
- typedef typename Function::ArgumentTuple ArgumentTuple;
-
- explicit Impl(T& ref) : ref_(ref) {} // NOLINT
-
- virtual Result Perform(const ArgumentTuple&) {
- return ref_;
- }
-
- private:
- T& ref_;
-
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
-
- T& ref_;
-
- GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
-};
-
-// Implements the polymorphic ReturnRefOfCopy(x) action, which can be
-// used in any function that returns a reference to the type of x,
-// regardless of the argument types.
-template
-class ReturnRefOfCopyAction {
- public:
- // Constructs a ReturnRefOfCopyAction object from the reference to
- // be returned.
- explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT
-
- // This template type conversion operator allows ReturnRefOfCopy(x) to be
- // used in ANY function that returns a reference to x's type.
- template
- operator Action() const {
- typedef typename Function::Result Result;
- // Asserts that the function return type is a reference. This
- // catches the user error of using ReturnRefOfCopy(x) when Return(x)
- // should be used, and generates some helpful error message.
- GTEST_COMPILE_ASSERT_(
- internal::is_reference::value,
- use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
- return Action(new Impl(value_));
- }
-
- private:
- // Implements the ReturnRefOfCopy(x) action for a particular function type F.
- template
- class Impl : public ActionInterface {
- public:
- typedef typename Function::Result Result;
- typedef typename Function::ArgumentTuple ArgumentTuple;
-
- explicit Impl(const T& value) : value_(value) {} // NOLINT
-
- virtual Result Perform(const ArgumentTuple&) {
- return value_;
- }
-
- private:
- T value_;
-
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
-
- const T value_;
-
- GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
-};
-
-// Implements the polymorphic DoDefault() action.
-class DoDefaultAction {
- public:
- // This template type conversion operator allows DoDefault() to be
- // used in any function.
- template
- operator Action() const { return Action(); } // NOLINT
-};
-
-// Implements the Assign action to set a given pointer referent to a
-// particular value.
-template
-class AssignAction {
- public:
- AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
-
- template
- void Perform(const ArgumentTuple& /* args */) const {
- *ptr_ = value_;
- }
-
- private:
- T1* const ptr_;
- const T2 value_;
-
- GTEST_DISALLOW_ASSIGN_(AssignAction);
-};
-
-#if !GTEST_OS_WINDOWS_MOBILE
-
-// Implements the SetErrnoAndReturn action to simulate return from
-// various system calls and libc functions.
-template
-class SetErrnoAndReturnAction {
- public:
- SetErrnoAndReturnAction(int errno_value, T result)
- : errno_(errno_value),
- result_(result) {}
- template
- Result Perform(const ArgumentTuple& /* args */) const {
- errno = errno_;
- return result_;
- }
-
- private:
- const int errno_;
- const T result_;
-
- GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
-};
-
-#endif // !GTEST_OS_WINDOWS_MOBILE
-
-// Implements the SetArgumentPointee(x) action for any function
-// whose N-th argument (0-based) is a pointer to x's type. The
-// template parameter kIsProto is true iff type A is ProtocolMessage,
-// proto2::Message, or a sub-class of those.
-template
-class SetArgumentPointeeAction {
- public:
- // Constructs an action that sets the variable pointed to by the
- // N-th function argument to 'value'.
- explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
-
- template
- void Perform(const ArgumentTuple& args) const {
- CompileAssertTypesEqual();
- *::testing::get(args) = value_;
- }
-
- private:
- const A value_;
-
- GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
-};
-
-template
-class SetArgumentPointeeAction {
- public:
- // Constructs an action that sets the variable pointed to by the
- // N-th function argument to 'proto'. Both ProtocolMessage and
- // proto2::Message have the CopyFrom() method, so the same
- // implementation works for both.
- explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
- proto_->CopyFrom(proto);
- }
-
- template
- void Perform(const ArgumentTuple& args) const {
- CompileAssertTypesEqual();
- ::testing::get(args)->CopyFrom(*proto_);
- }
-
- private:
- const internal::linked_ptr proto_;
-
- GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
-};
-
-// Implements the InvokeWithoutArgs(f) action. The template argument
-// FunctionImpl is the implementation type of f, which can be either a
-// function pointer or a functor. InvokeWithoutArgs(f) can be used as an
-// Action as long as f's type is compatible with F (i.e. f can be
-// assigned to a tr1::function).
-template
-class InvokeWithoutArgsAction {
- public:
- // The c'tor makes a copy of function_impl (either a function
- // pointer or a functor).
- explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
- : function_impl_(function_impl) {}
-
- // Allows InvokeWithoutArgs(f) to be used as any action whose type is
- // compatible with f.
- template
- Result Perform(const ArgumentTuple&) { return function_impl_(); }
-
- private:
- FunctionImpl function_impl_;
-
- GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
-};
-
-// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
-template
-class InvokeMethodWithoutArgsAction {
- public:
- InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
- : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
-
- template
- Result Perform(const ArgumentTuple&) const {
- return (obj_ptr_->*method_ptr_)();
- }
-
- private:
- Class* const obj_ptr_;
- const MethodPtr method_ptr_;
-
- GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
-};
-
-// Implements the InvokeWithoutArgs(callback) action.
-template
-class InvokeCallbackWithoutArgsAction {
- public:
- // The c'tor takes ownership of the callback.
- explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
- : callback_(callback) {
- callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
- }
-
- // This type conversion operator template allows Invoke(callback) to
- // be used wherever the callback's return type can be implicitly
- // converted to that of the mock function.
- template
- Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
-
- private:
- const internal::linked_ptr callback_;
-
- GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
-};
-
-// Implements the IgnoreResult(action) action.
-template
-class IgnoreResultAction {
- public:
- explicit IgnoreResultAction(const A& action) : action_(action) {}
-
- template
- operator Action() const {
- // Assert statement belongs here because this is the best place to verify
- // conditions on F. It produces the clearest error messages
- // in most compilers.
- // Impl really belongs in this scope as a local class but can't
- // because MSVC produces duplicate symbols in different translation units
- // in this case. Until MS fixes that bug we put Impl into the class scope
- // and put the typedef both here (for use in assert statement) and
- // in the Impl class. But both definitions must be the same.
- typedef typename internal::Function::Result Result;
-
- // Asserts at compile time that F returns void.
- CompileAssertTypesEqual();
-
- return Action(new Impl(action_));
- }
-
- private:
- template
- class Impl : public ActionInterface {
- public:
- typedef typename internal::Function::Result Result;
- typedef typename internal::Function::ArgumentTuple ArgumentTuple;
-
- explicit Impl(const A& action) : action_(action) {}
-
- virtual void Perform(const ArgumentTuple& args) {
- // Performs the action and ignores its result.
- action_.Perform(args);
- }
-
- private:
- // Type OriginalFunction is the same as F except that its return
- // type is IgnoredValue.
- typedef typename internal::Function::MakeResultIgnoredValue
- OriginalFunction;
-
- const Action action_;
-
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
-
- const A action_;
-
- GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
-};
-
-// A ReferenceWrapper object represents a reference to type T,
-// which can be either const or not. It can be explicitly converted
-// from, and implicitly converted to, a T&. Unlike a reference,
-// ReferenceWrapper can be copied and can survive template type
-// inference. This is used to support by-reference arguments in the
-// InvokeArgument(...) action. The idea was from "reference
-// wrappers" in tr1, which we don't have in our source tree yet.
-template
-class ReferenceWrapper {
- public:
- // Constructs a ReferenceWrapper object from a T&.
- explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT
-
- // Allows a ReferenceWrapper object to be implicitly converted to
- // a T&.
- operator T&() const { return *pointer_; }
- private:
- T* pointer_;
-};
-
-// Allows the expression ByRef(x) to be printed as a reference to x.
-template
-void PrintTo(const ReferenceWrapper& ref, ::std::ostream* os) {
- T& value = ref;
- UniversalPrinter::Print(value, os);
-}
-
-// Does two actions sequentially. Used for implementing the DoAll(a1,
-// a2, ...) action.
-template
-class DoBothAction {
- public:
- DoBothAction(Action1 action1, Action2 action2)
- : action1_(action1), action2_(action2) {}
-
- // This template type conversion operator allows DoAll(a1, ..., a_n)
- // to be used in ANY function of compatible type.
- template
- operator Action() const {
- return Action(new Impl(action1_, action2_));
- }
-
- private:
- // Implements the DoAll(...) action for a particular function type F.
- template
- class Impl : public ActionInterface {
- public:
- typedef typename Function::Result Result;
- typedef typename Function::ArgumentTuple ArgumentTuple;
- typedef typename Function::MakeResultVoid VoidResult;
-
- Impl(const Action& action1, const Action& action2)
- : action1_(action1), action2_(action2) {}
-
- virtual Result Perform(const ArgumentTuple& args) {
- action1_.Perform(args);
- return action2_.Perform(args);
- }
-
- private:
- const Action action1_;
- const Action action2_;
-
- GTEST_DISALLOW_ASSIGN_(Impl);
- };
-
- Action1 action1_;
- Action2 action2_;
-
- GTEST_DISALLOW_ASSIGN_(DoBothAction);
-};
-
-} // namespace internal
-
-// An Unused object can be implicitly constructed from ANY value.
-// This is handy when defining actions that ignore some or all of the
-// mock function arguments. For example, given
-//
-// MOCK_METHOD3(Foo, double(const string& label, double x, double y));
-// MOCK_METHOD3(Bar, double(int index, double x, double y));
-//
-// instead of
-//
-// double DistanceToOriginWithLabel(const string& label, double x, double y) {
-// return sqrt(x*x + y*y);
-// }
-// double DistanceToOriginWithIndex(int index, double x, double y) {
-// return sqrt(x*x + y*y);
-// }
-// ...
-// EXPECT_CALL(mock, Foo("abc", _, _))
-// .WillOnce(Invoke(DistanceToOriginWithLabel));
-// EXPECT_CALL(mock, Bar(5, _, _))
-// .WillOnce(Invoke(DistanceToOriginWithIndex));
-//
-// you could write
-//
-// // We can declare any uninteresting argument as Unused.
-// double DistanceToOrigin(Unused, double x, double y) {
-// return sqrt(x*x + y*y);
-// }
-// ...
-// EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
-// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
-typedef internal::IgnoredValue Unused;
-
-// This constructor allows us to turn an Action object into an
-// Action, 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
-template
-Action::Action(const Action