Unverified Commit 11f5a274 authored by Gennadiy Civil's avatar Gennadiy Civil Committed by GitHub
Browse files

Merge branch 'master' into cross-testing-patch-1

parents 008e54c1 66bd580b
...@@ -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,8 +37,13 @@ endif() ...@@ -37,8 +37,13 @@ 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)
cmake_minimum_required(VERSION 2.6.2) 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)
if (COMMAND set_up_hermetic_build) if (COMMAND set_up_hermetic_build)
set_up_hermetic_build() set_up_hermetic_build()
...@@ -69,6 +74,8 @@ include_directories("${gmock_SOURCE_DIR}/include" ...@@ -69,6 +74,8 @@ include_directories("${gmock_SOURCE_DIR}/include"
# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple. # <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10 # VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
# VS 2013 12 1800 std::tr1::tuple # VS 2013 12 1800 std::tr1::tuple
# VS 2015 14 1900 std::tuple
# VS 2017 15 >= 1910 std::tuple
if (MSVC AND MSVC_VERSION EQUAL 1700) if (MSVC AND MSVC_VERSION EQUAL 1700)
add_definitions(/D _VARIADIC_MAX=10) add_definitions(/D _VARIADIC_MAX=10)
endif() endif()
...@@ -81,32 +88,55 @@ endif() ...@@ -81,32 +88,55 @@ endif()
# Google Mock libraries. We build them using more strict warnings than what # Google Mock libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that Google Mock can be compiled by # are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings. # a user aggressive about warnings.
cxx_library(gmock if (MSVC)
"${cxx_strict}" cxx_library(gmock
"${gtest_dir}/src/gtest-all.cc" "${cxx_strict}"
src/gmock-all.cc) "${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc)
cxx_library(gmock_main
"${cxx_strict}" cxx_library(gmock_main
"${gtest_dir}/src/gtest-all.cc" "${cxx_strict}"
src/gmock-all.cc "${gtest_dir}/src/gtest-all.cc"
src/gmock_main.cc) src/gmock-all.cc
src/gmock_main.cc)
else()
cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
target_link_libraries(gmock gtest)
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
target_link_libraries(gmock_main gmock)
endif()
# If the CMake version supports it, attach header directory information # If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled # to the targets for when we are part of a parent build (ie being pulled
# in via add_subdirectory() rather than being a standalone build). # in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(gmock INTERFACE "${gmock_SOURCE_DIR}/include") target_include_directories(gmock SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include")
target_include_directories(gmock_main INTERFACE "${gmock_SOURCE_DIR}/include") target_include_directories(gmock_main SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include")
endif() 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()
######################################################################## ########################################################################
# #
...@@ -143,7 +173,7 @@ if (gmock_build_tests) ...@@ -143,7 +173,7 @@ if (gmock_build_tests)
cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
cxx_test(gmock_test gmock_main) cxx_test(gmock_test gmock_main)
if (CMAKE_USE_PTHREADS_INIT) if (DEFINED GTEST_HAS_PTHREAD)
cxx_test(gmock_stress_test gmock) cxx_test(gmock_stress_test gmock)
endif() endif()
...@@ -154,23 +184,33 @@ if (gmock_build_tests) ...@@ -154,23 +184,33 @@ if (gmock_build_tests)
############################################################ ############################################################
# C++ tests built with non-standard compiler flags. # C++ tests built with non-standard compiler flags.
cxx_library(gmock_main_no_exception "${cxx_no_exception}" if (MSVC)
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) cxx_library(gmock_main_no_exception "${cxx_no_exception}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
# Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}" if (MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc) # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
# conflict with our own definitions. Therefore using our own tuple does not
# work on those compilers.
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
endif()
else()
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_exception gmock)
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
target_link_libraries(gmock_main_no_rtti gmock)
cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
target_link_libraries(gmock_main_use_own_tuple gmock)
endif() endif()
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
gmock_main_no_exception test/gmock-more-actions_test.cc) gmock_main_no_exception test/gmock-more-actions_test.cc)
......
...@@ -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.
...@@ -53,18 +53,18 @@ the Apache License, which is different from Google Mock's license. ...@@ -53,18 +53,18 @@ the Apache License, which is different from Google Mock's license.
If you are new to the project, we suggest that you read the user If you are new to the project, we suggest that you read the user
documentation in the following order: documentation in the following order:
* Learn the [basics](../googletest/docs/Primer.md) of * Learn the [basics](../../master/googletest/docs/primer.md) of
Google Test, if you choose to use Google Mock with it (recommended). Google Test, if you choose to use Google Mock with it (recommended).
* Read [Google Mock for Dummies](docs/ForDummies.md). * Read [Google Mock for Dummies](../../master/googlemock/docs/ForDummies.md).
* Read the instructions below on how to build Google Mock. * 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. 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: Once you understand the basics, check out the rest of the docs:
* [CheatSheet](docs/CheatSheet.md) - all the commonly used stuff * [CheatSheet](../../master/googlemock/docs/CheatSheet.md) - all the commonly used stuff
at a glance. at a glance.
* [CookBook](docs/CookBook.md) - recipes for getting things done, * [CookBook](../../master/googlemock/docs/CookBook.md) - recipes for getting things done,
including advanced techniques. including advanced techniques.
If you need help, please check the If you need help, please check the
...@@ -78,8 +78,8 @@ posting a question on the ...@@ -78,8 +78,8 @@ posting a question on the
Google Mock is not a testing framework itself. Instead, it needs a Google Mock is not a testing framework itself. Instead, it needs a
testing framework for writing tests. Google Mock works seamlessly testing framework for writing tests. Google Mock works seamlessly
with [Google Test](http://code.google.com/p/googletest/), but with [Google Test](https://github.com/google/googletest), but
you can also use it with [any C++ testing framework](googlemock/ForDummies.md#Using_Google_Mock_with_Any_Testing_Framework). you can also use it with [any C++ testing framework](../../master/googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework).
### Requirements for End Users ### ### Requirements for End Users ###
...@@ -90,7 +90,7 @@ You must use the bundled version of Google Test when using Google Mock. ...@@ -90,7 +90,7 @@ 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 You can also easily configure Google Mock to work with another testing
framework, although it will still need Google Test. Please read framework, although it will still need Google Test. Please read
["Using_Google_Mock_with_Any_Testing_Framework"]( ["Using_Google_Mock_with_Any_Testing_Framework"](
docs/ForDummies.md#Using_Google_Mock_with_Any_Testing_Framework) ../../master/googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework)
for instructions. for instructions.
Google Mock depends on advanced C++ features and thus requires a more Google Mock depends on advanced C++ features and thus requires a more
...@@ -125,6 +125,47 @@ build Google Mock and its tests, which has further requirements: ...@@ -125,6 +125,47 @@ 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
[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.
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) ####
If you are using a Unix system and plan to use the GNU Autotools build If you are using a Unix system and plan to use the GNU Autotools build
...@@ -292,42 +333,12 @@ may need to tweak your compiler and/or linker flags. Please see the ...@@ -292,42 +333,12 @@ may need to tweak your compiler and/or linker flags. Please see the
If you have custom matchers defined using `MatcherInterface` or If you have custom matchers defined using `MatcherInterface` or
`MakePolymorphicMatcher()`, you'll need to update their definitions to `MakePolymorphicMatcher()`, you'll need to update their definitions to
use the new matcher API ( use the new matcher API (
[monomorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Monomorphic_Matchers), [monomorphic](./docs/CookBook.md#writing-new-monomorphic-matchers),
[polymorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Polymorphic_Matchers)). [polymorphic](./docs/CookBook.md#writing-new-polymorphic-matchers)).
Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected. Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected.
### Developing Google Mock ###
This section discusses how to make your own changes to Google Mock.
#### Testing Google Mock Itself ####
To make sure your changes work as intended and don't break existing
functionality, you'll want to compile and run Google Test's own tests.
For that you'll need Autotools. First, make sure you have followed
the instructions above to configure Google Mock.
Then, create a build output directory and enter it. Next,
${GMOCK_DIR}/configure # try --help for more info
Once you have successfully configured Google Mock, the build steps are
standard for GNU-style OSS packages.
make # Standard makefile following GNU conventions
make check # Builds and runs all tests - all should pass.
Note that when building your project against Google Mock, you are building
against Google Test as well. There is no need to configure Google Test
separately.
#### Contributing a Patch ####
We welcome patches.
Please read the [Developer's Guide](docs/DevGuide.md)
for how you can contribute. In particular, make sure you have signed
the Contributor License Agreement, or we won't be able to accept the
patch.
Happy testing! Happy testing!
[gtest_readme]: ../googletest/README.md "googletest" [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"
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@
m4_include(../googletest/m4/acx_pthread.m4) m4_include(../googletest/m4/acx_pthread.m4)
AC_INIT([Google C++ Mocking Framework], AC_INIT([Google C++ Mocking Framework],
[1.7.0], [1.8.0],
[googlemock@googlegroups.com], [googlemock@googlegroups.com],
[gmock]) [gmock])
...@@ -101,7 +101,7 @@ AC_ARG_VAR([GTEST_VERSION], ...@@ -101,7 +101,7 @@ AC_ARG_VAR([GTEST_VERSION],
[The version of Google Test available.]) [The version of Google Test available.])
HAVE_BUILT_GTEST="no" HAVE_BUILT_GTEST="no"
GTEST_MIN_VERSION="1.7.0" GTEST_MIN_VERSION="1.8.0"
AS_IF([test "x${enable_external_gtest}" = "xyes"], AS_IF([test "x${enable_external_gtest}" = "xyes"],
[# Begin filling in variables as we are able. [# Begin filling in variables as we are able.
...@@ -129,8 +129,8 @@ AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"], ...@@ -129,8 +129,8 @@ AS_IF([test "x${HAVE_BUILT_GTEST}" = "xyes"],
GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags` GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
GTEST_LIBS=`${GTEST_CONFIG} --libs` GTEST_LIBS=`${GTEST_CONFIG} --libs`
GTEST_VERSION=`${GTEST_CONFIG} --version`], GTEST_VERSION=`${GTEST_CONFIG} --version`],
[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'
......
...@@ -65,7 +65,7 @@ can specify it by appending `_WITH_CALLTYPE` to any of the macros ...@@ -65,7 +65,7 @@ can specify it by appending `_WITH_CALLTYPE` to any of the macros
described in the previous two sections and supplying the calling described in the previous two sections and supplying the calling
convention as the first argument to the macro. For example, convention as the first argument to the macro. For example,
``` ```
MOCK_METHOD_1_WITH_CALLTYPE(STDMETHODCALLTYPE, Foo, bool(int n)); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, Foo, bool(int n));
MOCK_CONST_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, Bar, int(double x, double y)); MOCK_CONST_METHOD2_WITH_CALLTYPE(STDMETHODCALLTYPE, Bar, int(double x, double y));
``` ```
where `STDMETHODCALLTYPE` is defined by `<objbase.h>` on Windows. where `STDMETHODCALLTYPE` is defined by `<objbase.h>` on Windows.
...@@ -178,6 +178,8 @@ divided into several categories: ...@@ -178,6 +178,8 @@ divided into several categories:
|`Ne(value)` |`argument != value`| |`Ne(value)` |`argument != value`|
|`IsNull()` |`argument` is a `NULL` pointer (raw or smart).| |`IsNull()` |`argument` is a `NULL` pointer (raw or smart).|
|`NotNull()` |`argument` is a non-null pointer (raw or smart).| |`NotNull()` |`argument` is a non-null pointer (raw or smart).|
|`VariantWith<T>(m)` |`argument` is `variant<>` that holds the alternative of
type T with a value matching `m`.|
|`Ref(variable)` |`argument` is a reference to `variable`.| |`Ref(variable)` |`argument` is a reference to `variable`.|
|`TypedEq<type>(value)`|`argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded.| |`TypedEq<type>(value)`|`argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded.|
...@@ -227,7 +229,7 @@ The `argument` can be either a C string or a C++ string object: ...@@ -227,7 +229,7 @@ The `argument` can be either a C string or a C++ string object:
`ContainsRegex()` and `MatchesRegex()` use the regular expression `ContainsRegex()` and `MatchesRegex()` use the regular expression
syntax defined syntax defined
[here](../../googletest/docs/AdvancedGuide.md#regular-expression-syntax). [here](../../googletest/docs/advanced.md#regular-expression-syntax).
`StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide `StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide
strings as well. strings as well.
...@@ -249,7 +251,7 @@ match them more flexibly, or get more informative messages, you can use: ...@@ -249,7 +251,7 @@ match them more flexibly, or get more informative messages, you can use:
| `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. | | `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. |
| `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under some permutation each element matches an `ei` (for a different `i`), which can be a value or a matcher. 0 to 10 arguments are allowed. | | `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under some permutation each element matches an `ei` (for a different `i`), which can be a value or a matcher. 0 to 10 arguments are allowed. |
| `UnorderedElementsAreArray({ e0, e1, ..., en })`, `UnorderedElementsAreArray(array)`, or `UnorderedElementsAreArray(array, count)` | The same as `UnorderedElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, or C-style array. | | `UnorderedElementsAreArray({ e0, e1, ..., en })`, `UnorderedElementsAreArray(array)`, or `UnorderedElementsAreArray(array, count)` | The same as `UnorderedElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, or C-style array. |
| `WhenSorted(m)` | When `argument` is sorted using the `<` operator, it matches container matcher `m`. E.g. `WhenSorted(UnorderedElementsAre(1, 2, 3))` verifies that `argument` contains elements `1`, `2`, and `3`, ignoring order. | | `WhenSorted(m)` | When `argument` is sorted using the `<` operator, it matches container matcher `m`. E.g. `WhenSorted(ElementsAre(1, 2, 3))` verifies that `argument` contains elements `1`, `2`, and `3`, ignoring order. |
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except that the given comparator instead of `<` is used to sort `argument`. E.g. `WhenSortedBy(std::greater<int>(), ElementsAre(3, 2, 1))`. | | `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except that the given comparator instead of `<` is used to sort `argument`. E.g. `WhenSortedBy(std::greater<int>(), ElementsAre(3, 2, 1))`. |
Notes: Notes:
...@@ -347,7 +349,7 @@ You can make a matcher from one or more other matchers: ...@@ -347,7 +349,7 @@ You can make a matcher from one or more other matchers:
## Matchers as Test Assertions ## ## Matchers as Test Assertions ##
|`ASSERT_THAT(expression, m)`|Generates a [fatal failure](../../googletest/docs/Primer.md#assertions) if the value of `expression` doesn't match matcher `m`.| |`ASSERT_THAT(expression, m)`|Generates a [fatal failure](../../googletest/docs/primer.md#assertions) if the value of `expression` doesn't match matcher `m`.|
|:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------| |:---------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
|`EXPECT_THAT(expression, m)`|Generates a non-fatal failure if the value of `expression` doesn't match matcher `m`. | |`EXPECT_THAT(expression, m)`|Generates a non-fatal failure if the value of `expression` doesn't match matcher `m`. |
......
This diff is collapsed.
If you are interested in understanding the internals of Google Mock,
building from source, or contributing ideas or modifications to the
project, then this document is for you.
# Introduction #
First, let's give you some background of the project.
## Licensing ##
All Google Mock source and pre-built packages are provided under the [New BSD License](http://www.opensource.org/licenses/bsd-license.php).
## The Google Mock Community ##
The Google Mock community exists primarily through the [discussion group](http://groups.google.com/group/googlemock), the
[issue tracker](https://github.com/google/googletest/issues) and, to a lesser extent, the [source control repository](../). You are definitely encouraged to contribute to the
discussion and you can also help us to keep the effectiveness of the
group high by following and promoting the guidelines listed here.
### Please Be Friendly ###
Showing courtesy and respect to others is a vital part of the Google
culture, and we strongly encourage everyone participating in Google
Mock development to join us in accepting nothing less. Of course,
being courteous is not the same as failing to constructively disagree
with each other, but it does mean that we should be respectful of each
other when enumerating the 42 technical reasons that a particular
proposal may not be the best choice. There's never a reason to be
antagonistic or dismissive toward anyone who is sincerely trying to
contribute to a discussion.
Sure, C++ testing is serious business and all that, but it's also
a lot of fun. Let's keep it that way. Let's strive to be one of the
friendliest communities in all of open source.
### Where to Discuss Google Mock ###
As always, discuss Google Mock in the official [Google C++ Mocking Framework discussion group](http://groups.google.com/group/googlemock). You don't have to actually submit
code in order to sign up. Your participation itself is a valuable
contribution.
# Working with the Code #
If you want to get your hands dirty with the code inside Google Mock,
this is the section for you.
## Checking Out the Source from Subversion ##
Checking out the Google Mock source is most useful if you plan to
tweak it yourself. You check out the source for Google Mock using a
[Subversion](http://subversion.tigris.org/) client as you would for any
other project hosted on Google Code. Please see the instruction on
the [source code access page](../) for how to do it.
## Compiling from Source ##
Once you check out the code, you can find instructions on how to
compile it in the [README](../README.md) file.
## Testing ##
A mocking framework is of no good if itself is not thoroughly tested.
Tests should be written for any new code, and changes should be
verified to not break existing tests before they are submitted for
review. To perform the tests, follow the instructions in [README](http://code.google.com/p/googlemock/source/browse/trunk/README) and
verify that there are no failures.
# Contributing Code #
We are excited that Google Mock is now open source, and hope to get
great patches from the community. Before you fire up your favorite IDE
and begin hammering away at that new feature, though, please take the
time to read this section and understand the process. While it seems
rigorous, we want to keep a high standard of quality in the code
base.
## Contributor License Agreements ##
You must sign a Contributor License Agreement (CLA) before we can
accept any code. The CLA protects you and us.
* If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html).
* If you work for a company that wants to allow you to contribute your work to Google Mock, then you'll need to sign a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html).
Follow either of the two links above to access the appropriate CLA and
instructions for how to sign and return it.
## Coding Style ##
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
to conform to the style outlined [here](https://github.com/google/styleguide/blob/gh-pages/cppguide.xml).
## Submitting Patches ##
Please do submit code. Here's what you need to do:
1. Normally you should make your change against the SVN trunk instead of a branch or a tag, as the latter two are for release control and should be treated mostly as read-only.
1. Decide which code you want to submit. A submission should be a set of changes that addresses one issue in the [Google Mock issue tracker](http://code.google.com/p/googlemock/issues/list). Please don't mix more than one logical change per submittal, because it makes the history hard to follow. If you want to make a change that doesn't have a corresponding issue in the issue tracker, please create one.
1. Also, coordinate with team members that are listed on the issue in question. This ensures that work isn't being duplicated and communicating your plan early also generally leads to better patches.
1. Ensure that your code adheres to the [Google Mock source code style](#Coding_Style.md).
1. Ensure that there are unit tests for your code.
1. Sign a Contributor License Agreement.
1. Create a patch file using `svn diff`.
1. We use [Rietveld](http://codereview.appspot.com/) to do web-based code reviews. You can read about the tool [here](https://github.com/rietveld-codereview/rietveld/wiki). When you are ready, upload your patch via Rietveld and notify `googlemock@googlegroups.com` to review it. There are several ways to upload the patch. We recommend using the [upload\_gmock.py](../scripts/upload_gmock.py) script, which you can find in the `scripts/` folder in the SVN trunk.
## Google Mock Committers ##
The current members of the Google Mock engineering team are the only
committers at present. In the great tradition of eating one's own
dogfood, we will be requiring each new Google Mock engineering team
member to earn the right to become a committer by following the
procedures in this document, writing consistently great code, and
demonstrating repeatedly that he or she truly gets the zen of Google
Mock.
# Release Process #
We follow the typical release process for Subversion-based projects:
1. A release branch named `release-X.Y` is created.
1. Bugs are fixed and features are added in trunk; those individual patches are merged into the release branch until it's stable.
1. An individual point release (the `Z` in `X.Y.Z`) is made by creating a tag from the branch.
1. Repeat steps 2 and 3 throughout one release cycle (as determined by features or time).
1. Go back to step 1 to create another release branch and so on.
---
This page is based on the [Making GWT Better](http://code.google.com/webtoolkit/makinggwtbetter.html) guide from the [Google Web Toolkit](http://code.google.com/webtoolkit/) project. Except as otherwise [noted](http://code.google.com/policies.html#restrictions), the content of this page is licensed under the [Creative Commons Attribution 2.5 License](http://creativecommons.org/licenses/by/2.5/).
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.
...@@ -8,5 +11,5 @@ This page lists all documentation wiki pages for Google Mock **(the SVN trunk ve ...@@ -8,5 +11,5 @@ 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. * [CONTRIBUTING](../CONTRIBUTING.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.
...@@ -170,7 +170,7 @@ Admittedly, this test is contrived and doesn't do much. You can easily achieve t ...@@ -170,7 +170,7 @@ Admittedly, this test is contrived and doesn't do much. You can easily achieve t
## Using Google Mock with Any Testing Framework ## ## Using Google Mock with Any Testing Framework ##
If you want to use something other than Google Test (e.g. [CppUnit](http://sourceforge.net/projects/cppunit/) or If you want to use something other than Google Test (e.g. [CppUnit](http://sourceforge.net/projects/cppunit/) or
[CxxTest](http://cxxtest.tigris.org/)) as your testing framework, just change the `main()` function in the previous section to: [CxxTest](https://cxxtest.com/)) as your testing framework, just change the `main()` function in the previous section to:
``` ```
int main(int argc, char** argv) { int main(int argc, char** argv) {
// The following line causes Google Mock to throw an exception on failure, // The following line causes Google Mock to throw an exception on failure,
...@@ -187,7 +187,7 @@ sometimes causes the test program to crash. You'll still be able to ...@@ -187,7 +187,7 @@ sometimes causes the test program to crash. You'll still be able to
notice that the test has failed, but it's not a graceful failure. notice that the test has failed, but it's not a graceful failure.
A better solution is to use Google Test's A better solution is to use Google Test's
[event listener API](../../googletest/docs/AdvancedGuide.md#extending-google-test-by-handling-test-events) [event listener API](../../googletest/docs/advanced.md#extending-google-test-by-handling-test-events)
to report a test failure to your testing framework properly. You'll need to to report a test failure to your testing framework properly. You'll need to
implement the `OnTestPartResult()` method of the event listener interface, but it implement the `OnTestPartResult()` method of the event listener interface, but it
should be straightforward. should be straightforward.
...@@ -217,7 +217,8 @@ The macro can be followed by some optional _clauses_ that provide more informati ...@@ -217,7 +217,8 @@ The macro can be followed by some optional _clauses_ that provide more informati
This syntax is designed to make an expectation read like English. For example, you can probably guess that This syntax is designed to make an expectation read like English. For example, you can probably guess that
``` ```
using ::testing::Return;... using ::testing::Return;
...
EXPECT_CALL(turtle, GetX()) EXPECT_CALL(turtle, GetX())
.Times(5) .Times(5)
.WillOnce(Return(100)) .WillOnce(Return(100))
...@@ -251,7 +252,8 @@ EXPECT_CALL(turtle, Forward(_)); ...@@ -251,7 +252,8 @@ EXPECT_CALL(turtle, Forward(_));
A list of built-in matchers can be found in the [CheatSheet](CheatSheet.md). For example, here's the `Ge` (greater than or equal) matcher: A list of built-in matchers can be found in the [CheatSheet](CheatSheet.md). For example, here's the `Ge` (greater than or equal) matcher:
``` ```
using ::testing::Ge;... using ::testing::Ge;
...
EXPECT_CALL(turtle, Forward(Ge(100))); EXPECT_CALL(turtle, Forward(Ge(100)));
``` ```
...@@ -280,7 +282,8 @@ First, if the return type of a mock function is a built-in type or a pointer, th ...@@ -280,7 +282,8 @@ First, if the return type of a mock function is a built-in type or a pointer, th
Second, if a mock function doesn't have a default action, or the default action doesn't suit you, you can specify the action to be taken each time the expectation matches using a series of `WillOnce()` clauses followed by an optional `WillRepeatedly()`. For example, Second, if a mock function doesn't have a default action, or the default action doesn't suit you, you can specify the action to be taken each time the expectation matches using a series of `WillOnce()` clauses followed by an optional `WillRepeatedly()`. For example,
``` ```
using ::testing::Return;... using ::testing::Return;
...
EXPECT_CALL(turtle, GetX()) EXPECT_CALL(turtle, GetX())
.WillOnce(Return(100)) .WillOnce(Return(100))
.WillOnce(Return(200)) .WillOnce(Return(200))
...@@ -290,7 +293,8 @@ EXPECT_CALL(turtle, GetX()) ...@@ -290,7 +293,8 @@ EXPECT_CALL(turtle, GetX())
This says that `turtle.GetX()` will be called _exactly three times_ (Google Mock inferred this from how many `WillOnce()` clauses we've written, since we didn't explicitly write `Times()`), and will return 100, 200, and 300 respectively. This says that `turtle.GetX()` will be called _exactly three times_ (Google Mock inferred this from how many `WillOnce()` clauses we've written, since we didn't explicitly write `Times()`), and will return 100, 200, and 300 respectively.
``` ```
using ::testing::Return;... using ::testing::Return;
...
EXPECT_CALL(turtle, GetY()) EXPECT_CALL(turtle, GetY())
.WillOnce(Return(100)) .WillOnce(Return(100))
.WillOnce(Return(200)) .WillOnce(Return(200))
...@@ -317,7 +321,8 @@ Instead of returning 100, 101, 102, ..., consecutively, this mock function will ...@@ -317,7 +321,8 @@ Instead of returning 100, 101, 102, ..., consecutively, this mock function will
Time for another quiz! What do you think the following means? Time for another quiz! What do you think the following means?
``` ```
using ::testing::Return;... using ::testing::Return;
...
EXPECT_CALL(turtle, GetY()) EXPECT_CALL(turtle, GetY())
.Times(4) .Times(4)
.WillOnce(Return(100)); .WillOnce(Return(100));
...@@ -331,7 +336,8 @@ So far we've only shown examples where you have a single expectation. More reali ...@@ -331,7 +336,8 @@ So far we've only shown examples where you have a single expectation. More reali
By default, when a mock method is invoked, Google Mock will search the expectations in the **reverse order** they are defined, and stop when an active expectation that matches the arguments is found (you can think of it as "newer rules override older ones."). If the matching expectation cannot take any more calls, you will get an upper-bound-violated failure. Here's an example: By default, when a mock method is invoked, Google Mock will search the expectations in the **reverse order** they are defined, and stop when an active expectation that matches the arguments is found (you can think of it as "newer rules override older ones."). If the matching expectation cannot take any more calls, you will get an upper-bound-violated failure. Here's an example:
``` ```
using ::testing::_;... using ::testing::_;
...
EXPECT_CALL(turtle, Forward(_)); // #1 EXPECT_CALL(turtle, Forward(_)); // #1
EXPECT_CALL(turtle, Forward(10)) // #2 EXPECT_CALL(turtle, Forward(10)) // #2
.Times(2); .Times(2);
...@@ -347,7 +353,8 @@ By default, an expectation can match a call even though an earlier expectation h ...@@ -347,7 +353,8 @@ By default, an expectation can match a call even though an earlier expectation h
Sometimes, you may want all the expected calls to occur in a strict order. To say this in Google Mock is easy: Sometimes, you may want all the expected calls to occur in a strict order. To say this in Google Mock is easy:
``` ```
using ::testing::InSequence;... using ::testing::InSequence;
...
TEST(FooTest, DrawsLineSegment) { TEST(FooTest, DrawsLineSegment) {
... ...
{ {
...@@ -365,7 +372,7 @@ By creating an object of type `InSequence`, all expectations in its scope are pu ...@@ -365,7 +372,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)?
...@@ -373,7 +380,8 @@ Now let's do a quick quiz to see how well you can use this mock stuff already. H ...@@ -373,7 +380,8 @@ Now let's do a quick quiz to see how well you can use this mock stuff already. H
After you've come up with your answer, take a look at ours and compare notes (solve it yourself first - don't cheat!): After you've come up with your answer, take a look at ours and compare notes (solve it yourself first - don't cheat!):
``` ```
using ::testing::_;... using ::testing::_;
...
EXPECT_CALL(turtle, GoTo(_, _)) // #1 EXPECT_CALL(turtle, GoTo(_, _)) // #1
.Times(AnyNumber()); .Times(AnyNumber());
EXPECT_CALL(turtle, GoTo(0, 0)) // #2 EXPECT_CALL(turtle, GoTo(0, 0)) // #2
......
...@@ -240,7 +240,7 @@ You cannot mock a variadic function (i.e. a function taking ellipsis ...@@ -240,7 +240,7 @@ You cannot mock a variadic function (i.e. a function taking ellipsis
The problem is that in general, there is _no way_ for a mock object to The problem is that in general, there is _no way_ for a mock object to
know how many arguments are passed to the variadic method, and what know how many arguments are passed to the variadic method, and what
the arguments' types are. Only the _author of the base class_ knows the arguments' types are. Only the _author of the base class_ knows
the protocol, and we cannot look into his head. the protocol, and we cannot look into their head.
Therefore, to mock such a function, the _user_ must teach the mock Therefore, to mock such a function, the _user_ must teach the mock
object how to figure out the number of arguments and their types. One object how to figure out the number of arguments and their types. One
...@@ -528,7 +528,7 @@ interface, which then can be easily mocked. It's a bit of work ...@@ -528,7 +528,7 @@ interface, which then can be easily mocked. It's a bit of work
initially, but usually pays for itself quickly. initially, but usually pays for itself quickly.
This Google Testing Blog This Google Testing Blog
[post](http://googletesting.blogspot.com/2008/06/defeat-static-cling.html) [post](https://testing.googleblog.com/2008/06/defeat-static-cling.html)
says it excellently. Check it out. says it excellently. Check it out.
## My mock object needs to do complex stuff. It's a lot of pain to specify the actions. Google Mock sucks! ## ## My mock object needs to do complex stuff. It's a lot of pain to specify the actions. Google Mock sucks! ##
...@@ -607,7 +607,6 @@ See this [recipe](CookBook.md#mocking_side_effects) for more details and an exam ...@@ -607,7 +607,6 @@ See this [recipe](CookBook.md#mocking_side_effects) for more details and an exam
If you cannot find the answer to your question in this FAQ, there are If you cannot find the answer to your question in this FAQ, there are
some other resources you can use: some other resources you can use:
1. read other [documentation](Documentation.md),
1. search the mailing list [archive](http://groups.google.com/group/googlemock/topics), 1. search the mailing list [archive](http://groups.google.com/group/googlemock/topics),
1. ask it on [googlemock@googlegroups.com](mailto:googlemock@googlegroups.com) and someone will answer it (to prevent spam, we require you to join the [discussion group](http://groups.google.com/group/googlemock) before you can post.). 1. ask it on [googlemock@googlegroups.com](mailto:googlemock@googlegroups.com) and someone will answer it (to prevent spam, we require you to join the [discussion group](http://groups.google.com/group/googlemock) before you can post.).
......
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.
This diff is collapsed.
This diff is collapsed.
This page lists all documentation wiki pages for Google Mock **1.6**
- **if you use a released version of Google Mock, please read the documentation for that specific version instead.**
* [ForDummies](V1_6_ForDummies.md) -- start here if you are new to Google Mock.
* [CheatSheet](V1_6_CheatSheet.md) -- a quick reference.
* [CookBook](V1_6_CookBook.md) -- recipes for doing various tasks using Google Mock.
* [FrequentlyAskedQuestions](V1_6_FrequentlyAskedQuestions.md) -- check here before asking a question on the mailing list.
To contribute code to Google Mock, read:
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
* [Pump Manual](http://code.google.com/p/googletest/wiki/V1_6_PumpManual) -- how we generate some of Google Mock's source files.
\ No newline at end of file
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