Commit d93ce9d6 authored by drgler's avatar drgler
Browse files

Merge branch 'master' of github.com:Dani-Hub/googletest

parents 6404d45a 8304d061
# Ignore CI build directory # Ignore CI build directory
build/ build/
xcuserdata xcuserdata
cmake-build-debug/
.idea/
bazel-bin
bazel-genfiles
bazel-googletest
bazel-out
bazel-testlogs
# Copyright 2017 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: misterg@google.com (Gennadiy Civil)
#
# Bazel Build for Google C++ Testing Framework(Google Test)
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
config_setting(
name = "win",
values = {"cpu": "x64_windows_msvc"},
)
# Google Test including Google Mock
cc_library(
name = "gtest",
srcs = glob(
include = [
"googletest/src/*.cc",
"googletest/src/*.h",
"googletest/include/gtest/**/*.h",
"googlemock/src/*.cc",
"googlemock/include/gmock/**/*.h",
],
exclude = [
"googletest/src/gtest-all.cc",
"googletest/src/gtest_main.cc",
"googlemock/src/gmock-all.cc",
"googlemock/src/gmock_main.cc",
],
),
hdrs =glob([
"googletest/include/gtest/*.h",
"googlemock/include/gmock/*.h",
]),
copts = select(
{
":win": [],
"//conditions:default": ["-pthread"],
},
),
includes = [
"googlemock",
"googlemock/include",
"googletest",
"googletest/include",
],
linkopts = select({
":win": [],
"//conditions:default": [
"-pthread",
],
}),
)
cc_library(
name = "gtest_main",
srcs = [
"googlemock/src/gmock_main.cc",
],
deps = ["//:gtest"],
)
# The following rules build samples of how to use gTest.
cc_library(
name = "gtest_sample_lib",
srcs = [
"googletest/samples/sample1.cc",
"googletest/samples/sample2.cc",
"googletest/samples/sample4.cc",
],
hdrs = [
"googletest/samples/prime_tables.h",
"googletest/samples/sample1.h",
"googletest/samples/sample2.h",
"googletest/samples/sample3-inl.h",
"googletest/samples/sample4.h",
],
)
cc_test(
name = "gtest_samples",
size = "small",
#All Samples except:
#sample9 ( main )
#sample10 (main and takes a command line option and needs to be separate)
srcs = [
"googletest/samples/sample1_unittest.cc",
"googletest/samples/sample2_unittest.cc",
"googletest/samples/sample3_unittest.cc",
"googletest/samples/sample4_unittest.cc",
"googletest/samples/sample5_unittest.cc",
"googletest/samples/sample6_unittest.cc",
"googletest/samples/sample7_unittest.cc",
"googletest/samples/sample8_unittest.cc",
],
deps = [
"gtest_sample_lib",
":gtest_main",
],
)
cc_test(
name = "sample9_unittest",
size = "small",
srcs = ["googletest/samples/sample9_unittest.cc"],
deps = [":gtest"],
)
cc_test(
name = "sample10_unittest",
size = "small",
srcs = ["googletest/samples/sample10_unittest.cc"],
deps = [
":gtest",
],
)
cmake_minimum_required(VERSION 2.6.4) cmake_minimum_required(VERSION 2.6.4)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
project( googletest-distribution ) project( googletest-distribution )
enable_testing() enable_testing()
include(CMakeDependentOption)
if (CMAKE_VERSION VERSION_LESS 2.8.5)
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()
include(GNUInstallDirs)
endif()
option(BUILD_GTEST "Builds the googletest subproject" OFF) option(BUILD_GTEST "Builds the googletest subproject" OFF)
#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)
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) elseif(BUILD_GTEST)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Google Test # # Google Test #
[![Build Status](https://travis-ci.org/google/googletest.svg?branch=master)](https://travis-ci.org/google/googletest) [![Build Status](https://travis-ci.org/google/googletest.svg?branch=master)](https://travis-ci.org/google/googletest)
[![Build status](https://ci.appveyor.com/api/projects/status/4o38plt0xbo1ubc8/branch/master?svg=true)](https://ci.appveyor.com/project/BillyDonahue/googletest/branch/master) [![Build status](https://ci.appveyor.com/api/projects/status/4o38plt0xbo1ubc8/branch/master?svg=true)](https://ci.appveyor.com/project/GoogleTestAppVeyor/googletest/branch/master)
Welcome to **Google Test**, Google's C++ test framework! Welcome to **Google Test**, Google's C++ test framework!
...@@ -12,7 +12,7 @@ maintain and release them together. ...@@ -12,7 +12,7 @@ maintain and release them together.
Please see the project page above for more information as well as the Please see the project page above for more information as well as the
mailing list for questions, discussions, and development. There is mailing list for questions, discussions, and development. There is
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please also an IRC channel on [OFTC](https://webchat.oftc.net/) (irc.oftc.net) #gtest available. Please
join us! join us!
Getting started information for **Google Test** is available in the Getting started information for **Google Test** is available in the
...@@ -60,9 +60,12 @@ the following notable projects: ...@@ -60,9 +60,12 @@ the following notable projects:
* [Protocol Buffers](https://github.com/google/protobuf), Google's data * [Protocol Buffers](https://github.com/google/protobuf), Google's data
interchange format. interchange format.
* The [OpenCV](http://opencv.org/) computer vision library. * The [OpenCV](http://opencv.org/) computer vision library.
* [tiny-dnn](https://github.com/tiny-dnn/tiny-dnn): header only, dependency-free deep learning framework in C++11.
## Related Open Source Projects ## ## Related Open Source Projects ##
[GTest Runner](https://github.com/nholthaus/gtest-runner) is a Qt5 based automated test-runner and Graphical User Interface with powerful features for Windows and Linux platforms.
[Google Test UI](https://github.com/ospector/gtest-gbar) is test runner that runs [Google Test UI](https://github.com/ospector/gtest-gbar) is test runner that runs
your test binary, allows you to track its progress via a progress bar, and your test binary, allows you to track its progress via a progress bar, and
displays a list of test failures. Clicking on one shows failure text. Google displays a list of test failures. Clicking on one shows failure text. Google
...@@ -73,6 +76,9 @@ listener for Google Test that implements the ...@@ -73,6 +76,9 @@ listener for Google Test that implements the
[TAP protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol) for test [TAP protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol) for test
result output. If your test runner understands TAP, you may find it useful. result output. If your test runner understands TAP, you may find it useful.
[gtest-parallel](https://github.com/google/gtest-parallel) is a test runner that
runs tests from your binary in parallel to provide significant speed-up.
## Requirements ## ## Requirements ##
Google Test is designed to have fairly minimal requirements to build Google Test is designed to have fairly minimal requirements to build
...@@ -82,7 +88,7 @@ effort to support other platforms (e.g. Solaris, AIX, and z/OS). ...@@ -82,7 +88,7 @@ effort to support other platforms (e.g. Solaris, AIX, and z/OS).
However, since core members of the Google Test project have no access However, since core members of the Google Test project have no access
to these platforms, Google Test may have outstanding issues there. If to these platforms, Google Test may have outstanding issues there. If
you notice any problems on your platform, please notify you notice any problems on your platform, please notify
<googletestframework@googlegroups.com>. Patches for fixing them are [googletestframework@googlegroups.com](https://groups.google.com/forum/#!forum/googletestframework). Patches for fixing them are
even more welcome! even more welcome!
### Linux Requirements ### ### Linux Requirements ###
...@@ -97,7 +103,7 @@ package (as described below): ...@@ -97,7 +103,7 @@ package (as described below):
### Windows Requirements ### ### Windows Requirements ###
* Microsoft Visual C++ v7.1 or newer * Microsoft Visual C++ 2010 or newer
### Cygwin Requirements ### ### Cygwin Requirements ###
......
workspace(name = "com_google_googletest")
...@@ -94,7 +94,7 @@ Google Test): ...@@ -94,7 +94,7 @@ Google Test):
* New feature: --gmock_catch_leaked_mocks for detecting leaked mocks. * New feature: --gmock_catch_leaked_mocks for detecting leaked mocks.
* New feature: ACTION_TEMPLATE for defining templatized actions. * New feature: ACTION_TEMPLATE for defining templatized actions.
* New feature: the .After() clause for specifying expectation order. * New feature: the .After() clause for specifying expectation order.
* New feature: the .With() clause for for specifying inter-argument * New feature: the .With() clause for specifying inter-argument
constraints. constraints.
* New feature: actions ReturnArg<k>(), ReturnNew<T>(...), and * New feature: actions ReturnArg<k>(), ReturnNew<T>(...), and
DeleteArg<k>(). DeleteArg<k>().
......
...@@ -37,7 +37,12 @@ endif() ...@@ -37,7 +37,12 @@ endif()
# as ${gmock_SOURCE_DIR} and to the root binary directory as # as ${gmock_SOURCE_DIR} and to the root binary directory as
# ${gmock_BINARY_DIR}. # ${gmock_BINARY_DIR}.
# Language "C" is required for find_package(Threads). # Language "C" is required for find_package(Threads).
project(gmock CXX C) if (CMAKE_VERSION VERSION_LESS 3.0)
project(gmock CXX C)
else()
cmake_policy(SET CMP0048 NEW)
project(gmock VERSION 1.9.0 LANGUAGES CXX C)
endif()
cmake_minimum_required(VERSION 2.6.4) cmake_minimum_required(VERSION 2.6.4)
if (COMMAND set_up_hermetic_build) if (COMMAND set_up_hermetic_build)
...@@ -103,10 +108,26 @@ endif() ...@@ -103,10 +108,26 @@ endif()
######################################################################## ########################################################################
# #
# Install rules # Install rules
install(TARGETS gmock gmock_main if(INSTALL_GMOCK)
DESTINATION lib) install(TARGETS gmock gmock_main
install(DIRECTORY ${gmock_SOURCE_DIR}/include/gmock RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
DESTINATION include) 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()
######################################################################## ########################################################################
# #
......
...@@ -35,7 +35,7 @@ We hope you find it useful! ...@@ -35,7 +35,7 @@ We hope you find it useful!
* Does automatic verification of expectations (no record-and-replay needed). * Does automatic verification of expectations (no record-and-replay needed).
* Allows arbitrary (partial) ordering constraints on * Allows arbitrary (partial) ordering constraints on
function calls to be expressed,. function calls to be expressed,.
* Lets a user extend it by defining new matchers and actions. * Lets an user extend it by defining new matchers and actions.
* Does not use exceptions. * Does not use exceptions.
* Is easy to learn and use. * Is easy to learn and use.
...@@ -125,13 +125,46 @@ build Google Mock and its tests, which has further requirements: ...@@ -125,13 +125,46 @@ build Google Mock and its tests, which has further requirements:
### Building Google Mock ### ### Building Google Mock ###
#### Using CMake ####
If you have CMake available, it is recommended that you follow the If you have CMake available, it is recommended that you follow the
[build instructions][gtest_cmakebuild] [build instructions][gtest_cmakebuild]
as described for Google Test. If are using Google Mock with an as described for Google Test.
If are using Google Mock with an
existing CMake project, the section existing CMake project, the section
[Incorporating Into An Existing CMake Project][gtest_incorpcmake] [Incorporating Into An Existing CMake Project][gtest_incorpcmake]
may be of particular interest. Otherwise, the following sections may be of particular interest.
detail how to build Google Mock without CMake. 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.
However, it does not automatically add Google Test includes.
Therefore you will also have to change
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
to
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories(BEFORE SYSTEM
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
else()
target_include_directories(gmock_main SYSTEM BEFORE INTERFACE
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
endif()
This will addtionally mark Google Mock includes as system, which will
silence compiler warnings when compiling your tests using clang with
`-Wpedantic -Wall -Wextra -Wconversion`.
#### Preparing to Build (Unix only) #### #### Preparing to Build (Unix only) ####
......
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gmock
Description: GoogleMock (without main() function)
Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gmock_main
Description: GoogleMock (with main() function)
Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest
Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ @CMAKE_THREAD_LIBS_INIT@
...@@ -130,7 +130,7 @@ AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"], ...@@ -130,7 +130,7 @@ AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"],
GTEST_LIBS=`${GTEST_CONFIG} --libs` GTEST_LIBS=`${GTEST_CONFIG} --libs`
GTEST_VERSION=`${GTEST_CONFIG} --version`], GTEST_VERSION=`${GTEST_CONFIG} --version`],
[AC_CONFIG_SUBDIRS([../googletest]) [AC_CONFIG_SUBDIRS([../googletest])
# GTEST_CONFIG needs to be executable both in a Makefile environmont and # GTEST_CONFIG needs to be executable both in a Makefile environment and
# in a shell script environment, so resolve an absolute path for it here. # in a shell script environment, so resolve an absolute path for it here.
GTEST_CONFIG="`pwd -P`/../googletest/scripts/gtest-config" GTEST_CONFIG="`pwd -P`/../googletest/scripts/gtest-config"
GTEST_CPPFLAGS='-I$(top_srcdir)/../googletest/include' GTEST_CPPFLAGS='-I$(top_srcdir)/../googletest/include'
......
...@@ -18,8 +18,9 @@ You must always put a mock method definition (`MOCK_METHOD*`) in a ...@@ -18,8 +18,9 @@ You must always put a mock method definition (`MOCK_METHOD*`) in a
`public:` section of the mock class, regardless of the method being `public:` section of the mock class, regardless of the method being
mocked being `public`, `protected`, or `private` in the base class. mocked being `public`, `protected`, or `private` in the base class.
This allows `ON_CALL` and `EXPECT_CALL` to reference the mock function This allows `ON_CALL` and `EXPECT_CALL` to reference the mock function
from outside of the mock class. (Yes, C++ allows a subclass to change from outside of the mock class. (Yes, C++ allows a subclass to specify
the access level of a virtual function in the base class.) Example: a different access level than the base class on a virtual function.)
Example:
``` ```
class Foo { class Foo {
...@@ -294,7 +295,7 @@ There are some caveats though (I don't like them just as much as the ...@@ -294,7 +295,7 @@ There are some caveats though (I don't like them just as much as the
next guy, but sadly they are side effects of C++'s limitations): next guy, but sadly they are side effects of C++'s limitations):
1. `NiceMock<MockFoo>` and `StrictMock<MockFoo>` only work 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` and `StrictMock` (e.g. `NiceMock<StrictMock<MockFoo> >`) is **not** supported. 1. `NiceMock<MockFoo>` and `StrictMock<MockFoo>` only work 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` and `StrictMock` (e.g. `NiceMock<StrictMock<MockFoo> >`) is **not** supported.
1. The constructors of the base mock (`MockFoo`) cannot have arguments passed by non-const reference, which happens to be banned by the [Google C++ style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 1. The constructors of the base mock (`MockFoo`) cannot have arguments passed by non-const reference, which happens to be banned by the [Google C++ style guide](https://google.github.io/styleguide/cppguide.html).
1. During the constructor or destructor of `MockFoo`, the mock object is _not_ nice or strict. This may cause surprises if the constructor or destructor calls a mock method on `this` object. (This behavior, however, is consistent with C++'s general rule: if a constructor or destructor calls a virtual method of `this` object, that method is treated as non-virtual. In other words, to the base class's constructor or destructor, `this` object behaves like an instance of the base class, not the derived class. This rule is required for safety. Otherwise a base constructor may use members of a derived class before they are initialized, or a base destructor may use members of a derived class after they have been destroyed.) 1. During the constructor or destructor of `MockFoo`, the mock object is _not_ nice or strict. This may cause surprises if the constructor or destructor calls a mock method on `this` object. (This behavior, however, is consistent with C++'s general rule: if a constructor or destructor calls a virtual method of `this` object, that method is treated as non-virtual. In other words, to the base class's constructor or destructor, `this` object behaves like an instance of the base class, not the derived class. This rule is required for safety. Otherwise a base constructor may use members of a derived class before they are initialized, or a base destructor may use members of a derived class after they have been destroyed.)
Finally, you should be **very cautious** about when to use naggy or strict mocks, as they tend to make tests more brittle and harder to maintain. When you refactor your code without changing its externally visible behavior, ideally you should't need to update any tests. If your code interacts with a naggy mock, however, you may start to get spammed with warnings as the result of your change. Worse, if your code interacts with a strict mock, your tests may start to fail and you'll be forced to fix them. Our general recommendation is to use nice mocks (not yet the default) most of the time, use naggy mocks (the current default) when developing or debugging tests, and use strict mocks only as the last resort. Finally, you should be **very cautious** about when to use naggy or strict mocks, as they tend to make tests more brittle and harder to maintain. When you refactor your code without changing its externally visible behavior, ideally you should't need to update any tests. If your code interacts with a naggy mock, however, you may start to get spammed with warnings as the result of your change. Worse, if your code interacts with a strict mock, your tests may start to fail and you'll be forced to fix them. Our general recommendation is to use nice mocks (not yet the default) most of the time, use naggy mocks (the current default) when developing or debugging tests, and use strict mocks only as the last resort.
...@@ -1029,9 +1030,10 @@ a value that satisfies matcher `m`. ...@@ -1029,9 +1030,10 @@ a value that satisfies matcher `m`.
For example: For example:
> | `Field(&Foo::number, Ge(3))` | Matches `x` where `x.number >= 3`. | | Expression | Description |
|:-----------------------------|:-----------------------------------| |:-----------------------------|:-----------------------------------|
> | `Property(&Foo::name, StartsWith("John "))` | Matches `x` where `x.name()` starts with `"John "`. | | `Field(&Foo::number, Ge(3))` | Matches `x` where `x.number >= 3`. |
| `Property(&Foo::name, StartsWith("John "))` | Matches `x` where `x.name()` starts with `"John "`. |
Note that in `Property(&Foo::baz, ...)`, method `baz()` must take no Note that in `Property(&Foo::baz, ...)`, method `baz()` must take no
argument and be declared as `const`. argument and be declared as `const`.
...@@ -1680,7 +1682,7 @@ This also works when the argument is an output iterator: ...@@ -1680,7 +1682,7 @@ This also works when the argument is an output iterator:
``` ```
using ::testing::_; using ::testing::_;
using ::testing::SeArrayArgument; using ::testing::SetArrayArgument;
class MockRolodex : public Rolodex { class MockRolodex : public Rolodex {
public: public:
...@@ -1919,9 +1921,9 @@ using ::testing::_; ...@@ -1919,9 +1921,9 @@ using ::testing::_;
// second argument DoThis() receives. // second argument DoThis() receives.
``` ```
Arghh, you need to refer to a mock function argument but C++ has no Arghh, you need to refer to a mock function argument but your version
lambda (yet), so you have to define your own action. :-( Or do you of C++ has no lambdas, so you have to define your own action. :-(
really? Or do you really?
Well, Google Mock has an action to solve _exactly_ this problem: Well, Google Mock has an action to solve _exactly_ this problem:
...@@ -2365,7 +2367,7 @@ Now there’s one topic we haven’t covered: how do you set expectations on `Sh ...@@ -2365,7 +2367,7 @@ Now there’s one topic we haven’t covered: how do you set expectations on `Sh
// When one calls ShareBuzz() on the MockBuzzer like this, the call is // When one calls ShareBuzz() on the MockBuzzer like this, the call is
// forwarded to DoShareBuzz(), which is mocked. Therefore this statement // forwarded to DoShareBuzz(), which is mocked. Therefore this statement
// will trigger the above EXPECT_CALL. // will trigger the above EXPECT_CALL.
mock_buzzer_.ShareBuzz(MakeUnique&lt;Buzz&gt;(AccessLevel::kInternal), mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal),
::base::Now()); ::base::Now());
``` ```
...@@ -2404,7 +2406,7 @@ Now, the mock `DoShareBuzz()` method is free to save the buzz argument for later ...@@ -2404,7 +2406,7 @@ Now, the mock `DoShareBuzz()` method is free to save the buzz argument for later
``` ```
std::unique_ptr<Buzz> intercepted_buzz; std::unique_ptr<Buzz> intercepted_buzz;
EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _)) EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _))
.WillOnce(Invoke([&amp;intercepted_buzz](Buzz* buzz, Time timestamp) { .WillOnce(Invoke([&intercepted_buzz](Buzz* buzz, Time timestamp) {
// Save buzz in intercepted_buzz for analysis later. // Save buzz in intercepted_buzz for analysis later.
intercepted_buzz.reset(buzz); intercepted_buzz.reset(buzz);
return false; return false;
...@@ -2482,12 +2484,12 @@ MockFoo::~MockFoo() {} ...@@ -2482,12 +2484,12 @@ MockFoo::~MockFoo() {}
## Forcing a Verification ## ## Forcing a Verification ##
When it's being destoyed, your friendly mock object will automatically When it's being destroyed, your friendly mock object will automatically
verify that all expectations on it have been satisfied, and will verify that all expectations on it have been satisfied, and will
generate [Google Test](../../googletest/) failures generate [Google Test](../../googletest/) failures
if not. This is convenient as it leaves you with one less thing to if not. This is convenient as it leaves you with one less thing to
worry about. That is, unless you are not sure if your mock object will worry about. That is, unless you are not sure if your mock object will
be destoyed. be destroyed.
How could it be that your mock object won't eventually be destroyed? How could it be that your mock object won't eventually be destroyed?
Well, it might be created on the heap and owned by the code you are Well, it might be created on the heap and owned by the code you are
...@@ -3347,6 +3349,7 @@ For example, when using an `ACTION` as a stub action for mock function: ...@@ -3347,6 +3349,7 @@ For example, when using an `ACTION` as a stub action for mock function:
int DoSomething(bool flag, int* ptr); int DoSomething(bool flag, int* ptr);
``` ```
we have: we have:
| **Pre-defined Symbol** | **Is Bound To** | | **Pre-defined Symbol** | **Is Bound To** |
|:-----------------------|:----------------| |:-----------------------|:----------------|
| `arg0` | the value of `flag` | | `arg0` | the value of `flag` |
...@@ -3508,6 +3511,7 @@ is asked to infer the type of `x`? ...@@ -3508,6 +3511,7 @@ is asked to infer the type of `x`?
If you are writing a function that returns an `ACTION` object, you'll If you are writing a function that returns an `ACTION` object, you'll
need to know its type. The type depends on the macro used to define need to know its type. The type depends on the macro used to define
the action and the parameter types. The rule is relatively simple: the action and the parameter types. The rule is relatively simple:
| **Given Definition** | **Expression** | **Has Type** | | **Given Definition** | **Expression** | **Has Type** |
|:---------------------|:---------------|:-------------| |:---------------------|:---------------|:-------------|
| `ACTION(Foo)` | `Foo()` | `FooAction` | | `ACTION(Foo)` | `Foo()` | `FooAction` |
...@@ -3515,7 +3519,7 @@ the action and the parameter types. The rule is relatively simple: ...@@ -3515,7 +3519,7 @@ the action and the parameter types. The rule is relatively simple:
| `ACTION_P(Bar, param)` | `Bar(int_value)` | `BarActionP<int>` | | `ACTION_P(Bar, param)` | `Bar(int_value)` | `BarActionP<int>` |
| `ACTION_TEMPLATE(Bar, HAS_m_TEMPLATE_PARAMS(...), AND_1_VALUE_PARAMS(p1))` | `Bar<t1, ..., t_m>(int_value)` | `FooActionP<t1, ..., t_m, int>` | | `ACTION_TEMPLATE(Bar, HAS_m_TEMPLATE_PARAMS(...), AND_1_VALUE_PARAMS(p1))` | `Bar<t1, ..., t_m>(int_value)` | `FooActionP<t1, ..., t_m, int>` |
| `ACTION_P2(Baz, p1, p2)` | `Baz(bool_value, int_value)` | `BazActionP2<bool, int>` | | `ACTION_P2(Baz, p1, p2)` | `Baz(bool_value, int_value)` | `BazActionP2<bool, int>` |
| `ACTION_TEMPLATE(Baz, HAS_m_TEMPLATE_PARAMS(...), AND_2_VALUE_PARAMS(p1, p2))` | `Baz<t1, ..., t_m>(bool_value, int_value)` | `FooActionP2<t1, ..., t_m, bool, int>` | | `ACTION_TEMPLATE(Baz, HAS_m_TEMPLATE_PARAMS(...), AND_2_VALUE_PARAMS(p1, p2))`| `Baz<t1, ..., t_m>(bool_value, int_value)` | `FooActionP2<t1, ..., t_m, bool, int>` |
| ... | ... | ... | | ... | ... | ... |
Note that we have to pick different suffixes (`Action`, `ActionP`, Note that we have to pick different suffixes (`Action`, `ActionP`,
......
...@@ -91,7 +91,7 @@ instructions for how to sign and return it. ...@@ -91,7 +91,7 @@ instructions for how to sign and return it.
To keep the source consistent, readable, diffable and easy to merge, To keep the source consistent, readable, diffable and easy to merge,
we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected
to conform to the style outlined [here](https://github.com/google/styleguide/blob/gh-pages/cppguide.xml). to conform to the style outlined [here](https://google.github.io/styleguide/cppguide.html).
## Submitting Patches ## ## Submitting Patches ##
......
This page lists all documentation wiki pages for Google Mock **(the SVN trunk version)** This page lists all documentation markdown files for Google Mock **(the
- **if you use a released version of Google Mock, please read the documentation for that specific version instead.** current git version)**
-- **if you use a former version of Google Mock, please read the
documentation for that specific version instead (e.g. by checking out
the respective git branch/tag).**
* [ForDummies](ForDummies.md) -- start here if you are new to Google Mock. * [ForDummies](ForDummies.md) -- start here if you are new to Google Mock.
* [CheatSheet](CheatSheet.md) -- a quick reference. * [CheatSheet](CheatSheet.md) -- a quick reference.
...@@ -9,4 +12,4 @@ This page lists all documentation wiki pages for Google Mock **(the SVN trunk ve ...@@ -9,4 +12,4 @@ This page lists all documentation wiki pages for Google Mock **(the SVN trunk ve
To contribute code to Google Mock, read: To contribute code to Google Mock, read:
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch. * [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
* [Pump Manual](../googletest/docs/PumpManual.md) -- how we generate some of Google Mock's source files. * [Pump Manual](../../googletest/docs/PumpManual.md) -- how we generate some of Google Mock's source files.
...@@ -23,8 +23,8 @@ Using Google Mock involves three basic steps: ...@@ -23,8 +23,8 @@ Using Google Mock involves three basic steps:
# Why Google Mock? # # Why Google Mock? #
While mock objects help you remove unnecessary dependencies in tests and make them fast and reliable, using mocks manually in C++ is _hard_: While mock objects help you remove unnecessary dependencies in tests and make them fast and reliable, using mocks manually in C++ is _hard_:
* Someone has to implement the mocks. The job is usually tedious and error-prone. No wonder people go great distance to avoid it. * Someone has to implement the mocks. The job is usually tedious and error-prone. No wonder people go great distances to avoid it.
* The quality of those manually written mocks is a bit, uh, unpredictable. You may see some really polished ones, but you may also see some that were hacked up in a hurry and have all sorts of ad hoc restrictions. * The quality of those manually written mocks is a bit, uh, unpredictable. You may see some really polished ones, but you may also see some that were hacked up in a hurry and have all sorts of ad-hoc restrictions.
* The knowledge you gained from using one mock doesn't transfer to the next. * The knowledge you gained from using one mock doesn't transfer to the next.
In contrast, Java and Python programmers have some fine mock frameworks, which automate the creation of mocks. As a result, mocking is a proven effective technique and widely adopted practice in those communities. Having the right tool absolutely makes the difference. In contrast, Java and Python programmers have some fine mock frameworks, which automate the creation of mocks. As a result, mocking is a proven effective technique and widely adopted practice in those communities. Having the right tool absolutely makes the difference.
...@@ -365,7 +365,7 @@ By creating an object of type `InSequence`, all expectations in its scope are pu ...@@ -365,7 +365,7 @@ By creating an object of type `InSequence`, all expectations in its scope are pu
In this example, we test that `Foo()` calls the three expected functions in the order as written. If a call is made out-of-order, it will be an error. In this example, we test that `Foo()` calls the three expected functions in the order as written. If a call is made out-of-order, it will be an error.
(What if you care about the relative order of some of the calls, but not all of them? Can you specify an arbitrary partial order? The answer is ... yes! If you are impatient, the details can be found in the [CookBook](CookBook#Expecting_Partially_Ordered_Calls.md).) (What if you care about the relative order of some of the calls, but not all of them? Can you specify an arbitrary partial order? The answer is ... yes! If you are impatient, the details can be found in the [CookBook](CookBook.md#expecting-partially-ordered-calls).)
## All Expectations Are Sticky (Unless Said Otherwise) ## ## All Expectations Are Sticky (Unless Said Otherwise) ##
Now let's do a quick quiz to see how well you can use this mock stuff already. How would you test that the turtle is asked to go to the origin _exactly twice_ (you want to ignore any other instructions it receives)? Now let's do a quick quiz to see how well you can use this mock stuff already. How would you test that the turtle is asked to go to the origin _exactly twice_ (you want to ignore any other instructions it receives)?
......
This diff is collapsed.
This diff is collapsed.
This page lists all documentation wiki pages for Google Mock **version 1.5.0** -- **if you use a different version of Google Mock, please read the documentation for that specific version instead.**
* [ForDummies](V1_5_ForDummies.md) -- start here if you are new to Google Mock.
* [CheatSheet](V1_5_CheatSheet.md) -- a quick reference.
* [CookBook](V1_5_CookBook.md) -- recipes for doing various tasks using Google Mock.
* [FrequentlyAskedQuestions](V1_5_FrequentlyAskedQuestions.md) -- check here before asking a question on the mailing list.
To contribute code to Google Mock, read:
* DevGuide -- read this _before_ writing your first patch.
* [Pump Manual](http://code.google.com/p/googletest/wiki/PumpManual) -- how we generate some of Google Mock's source files.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment