mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-07 12:01:16 +00:00
Update googletest to 1.13
Fix issue with CMake 4.0
This commit is contained in:

committed by
Jesse Beder

parent
c9371de783
commit
2f86d13775
@@ -1 +1 @@
|
||||
test/gtest-1.11.0
|
||||
test/googletest-1.13.0
|
||||
|
@@ -8,7 +8,7 @@ EXAMPLE_PATH =
|
||||
|
||||
# One or more directories and files to exclude from documentation generation.
|
||||
# Use relative paths with respect to the repository root directory.
|
||||
EXCLUDE = test/gtest-1.8.0/
|
||||
EXCLUDE = test/googletest-1.13.0/
|
||||
|
||||
# One or more wildcard patterns to exclude files and directories from document
|
||||
# generation.
|
||||
|
@@ -11,9 +11,9 @@ if(YAML_USE_SYSTEM_GTEST)
|
||||
endif()
|
||||
else()
|
||||
add_subdirectory(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/googletest-1.13.0"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/prefix")
|
||||
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.11.0/googletest/include")
|
||||
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/googletest-1.13.0/googletest/include")
|
||||
endif()
|
||||
|
||||
set(test-new-api-pattern "new-api/*.cpp")
|
||||
|
53
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/00-bug_report.yml
vendored
Normal file
53
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/00-bug_report.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
name: Bug Report
|
||||
description: Let us know that something does not work as expected.
|
||||
title: "[Bug]: Please title this bug report"
|
||||
body:
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Describe the issue
|
||||
description: What happened, and what did you expect to happen?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce the problem
|
||||
description: It is important that we are able to reproduce the problem that you are experiencing. Please provide all code and relevant steps to reproduce the problem, including your `BUILD`/`CMakeLists.txt` file and build commands. Links to a GitHub branch or [godbolt.org](https://godbolt.org/) that demonstrate the problem are also helpful.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: version
|
||||
attributes:
|
||||
label: What version of GoogleTest are you using?
|
||||
description: Please include the output of `git rev-parse HEAD` or the GoogleTest release version number that you are using.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: os
|
||||
attributes:
|
||||
label: What operating system and version are you using?
|
||||
description: If you are using a Linux distribution please include the name and version of the distribution as well.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: compiler
|
||||
attributes:
|
||||
label: What compiler and version are you using?
|
||||
description: Please include the output of `gcc -v` or `clang -v`, or the equivalent for your compiler.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: buildsystem
|
||||
attributes:
|
||||
label: What build system are you using?
|
||||
description: Please include the output of `bazel --version` or `cmake --version`, or the equivalent for your build system.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here.
|
||||
validations:
|
||||
required: false
|
33
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/10-feature_request.yml
vendored
Normal file
33
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/10-feature_request.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: Feature request
|
||||
description: Propose a new feature.
|
||||
title: "[FR]: Please title this feature request"
|
||||
labels: "enhancement"
|
||||
body:
|
||||
- type: textarea
|
||||
id: version
|
||||
attributes:
|
||||
label: Does the feature exist in the most recent commit?
|
||||
description: We recommend using the latest commit from GitHub in your projects.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: why
|
||||
attributes:
|
||||
label: Why do we need this feature?
|
||||
description: Ideally, explain why a combination of existing features cannot be used instead.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: proposal
|
||||
attributes:
|
||||
label: Describe the proposal.
|
||||
description: Include a detailed description of the feature, with usage examples.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: platform
|
||||
attributes:
|
||||
label: Is the feature specific to an operating system, compiler, or build system version?
|
||||
description: If it is, please specify which versions.
|
||||
validations:
|
||||
required: true
|
5
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
test/googletest-1.13.0/.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Get Help
|
||||
url: https://github.com/google/googletest/discussions
|
||||
about: Please ask and answer questions here.
|
43
test/googletest-1.13.0/.github/workflows/gtest-ci.yml
vendored
Normal file
43
test/googletest-1.13.0/.github/workflows/gtest-ci.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
BAZEL_CXXOPTS: -std=c++14
|
||||
|
||||
jobs:
|
||||
Linux:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Tests
|
||||
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...
|
||||
|
||||
macOS:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Tests
|
||||
run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ...
|
||||
|
||||
|
||||
Windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Tests
|
||||
run: bazel test --cxxopt=/std:c++14 --features=external_include_paths --test_output=errors ...
|
@@ -30,19 +30,32 @@
|
||||
#
|
||||
# Bazel Build for Google C++ Testing Framework(Google Test)
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
exports_files(["LICENSE"])
|
||||
|
||||
config_setting(
|
||||
name = "qnx",
|
||||
constraint_values = ["@platforms//os:qnx"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "windows",
|
||||
constraint_values = ["@platforms//os:windows"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "freebsd",
|
||||
constraint_values = ["@platforms//os:freebsd"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "openbsd",
|
||||
constraint_values = ["@platforms//os:openbsd"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "msvc_compiler",
|
||||
flag_values = {
|
||||
@@ -86,6 +99,7 @@ cc_library(
|
||||
"googlemock/include/gmock/*.h",
|
||||
]),
|
||||
copts = select({
|
||||
":qnx": [],
|
||||
":windows": [],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
@@ -104,7 +118,16 @@ cc_library(
|
||||
"googletest/include",
|
||||
],
|
||||
linkopts = select({
|
||||
":qnx": ["-lregex"],
|
||||
":windows": [],
|
||||
":freebsd": [
|
||||
"-lm",
|
||||
"-pthread",
|
||||
],
|
||||
":openbsd": [
|
||||
"-lm",
|
||||
"-pthread",
|
||||
],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
||||
deps = select({
|
||||
@@ -112,10 +135,15 @@ cc_library(
|
||||
"@com_google_absl//absl/debugging:failure_signal_handler",
|
||||
"@com_google_absl//absl/debugging:stacktrace",
|
||||
"@com_google_absl//absl/debugging:symbolize",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
"@com_google_absl//absl/flags:parse",
|
||||
"@com_google_absl//absl/flags:reflection",
|
||||
"@com_google_absl//absl/flags:usage",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:any",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
"@com_googlesource_code_re2//:re2",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
@@ -1,19 +1,25 @@
|
||||
# Note: CMake support is community-based. The maintainers do not use CMake
|
||||
# internally.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
if (POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
endif (POLICY CMP0048)
|
||||
|
||||
project(googletest-distribution)
|
||||
set(GOOGLETEST_VERSION 1.11.0)
|
||||
if (POLICY CMP0069)
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
endif (POLICY CMP0069)
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER "3.0.2")
|
||||
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
if (POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
endif (POLICY CMP0077)
|
||||
|
||||
project(googletest-distribution)
|
||||
set(GOOGLETEST_VERSION 1.13.0)
|
||||
|
||||
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
enable_testing()
|
||||
@@ -24,6 +30,7 @@ include(GNUInstallDirs)
|
||||
#Note that googlemock target already builds googletest
|
||||
option(BUILD_GMOCK "Builds the googlemock subproject" ON)
|
||||
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON)
|
||||
option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF)
|
||||
|
||||
if(BUILD_GMOCK)
|
||||
add_subdirectory( googlemock )
|
@@ -21,8 +21,8 @@ accept your pull requests.
|
||||
|
||||
## Are you a Googler?
|
||||
|
||||
If you are a Googler, please make an attempt to submit an internal change rather
|
||||
than a GitHub Pull Request. If you are not able to submit an internal change a
|
||||
If you are a Googler, please make an attempt to submit an internal contribution
|
||||
rather than a GitHub Pull Request. If you are not able to submit internally, a
|
||||
PR is acceptable as an alternative.
|
||||
|
||||
## Contributing A Patch
|
||||
@@ -36,7 +36,8 @@ PR is acceptable as an alternative.
|
||||
This ensures that work isn't being duplicated and communicating your plan
|
||||
early also generally leads to better patches.
|
||||
4. If your proposed change is accepted, and you haven't already done so, sign a
|
||||
Contributor License Agreement (see details above).
|
||||
Contributor License Agreement
|
||||
([see details above](#contributor-license-agreements)).
|
||||
5. Fork the desired repo, develop and test your code changes.
|
||||
6. Ensure that your code adheres to the existing style in the sample to which
|
||||
you are contributing.
|
||||
@@ -79,8 +80,8 @@ 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://google.github.io/styleguide/cppguide.html). Use
|
||||
[.clang-format](https://github.com/google/googletest/blob/master/.clang-format)
|
||||
to check your formatting.
|
||||
[.clang-format](https://github.com/google/googletest/blob/main/.clang-format) to
|
||||
check your formatting.
|
||||
|
||||
## Requirements for Contributors
|
||||
|
@@ -34,6 +34,7 @@ Manuel Klimek <klimek@google.com>
|
||||
Mario Tanev <radix@google.com>
|
||||
Mark Paskin
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Martijn Vels <mvels@google.com>
|
||||
Matthew Simmons <simmonmt@acm.org>
|
||||
Mika Raento <mikie@iki.fi>
|
||||
Mike Bland <mbland@google.com>
|
||||
@@ -55,6 +56,7 @@ Russ Rufer <russ@pentad.com>
|
||||
Sean Mcafee <eefacm@gmail.com>
|
||||
Sigurður Ásgeirsson <siggi@google.com>
|
||||
Sverre Sundsdal <sundsdal@gmail.com>
|
||||
Szymon Sobik <sobik.szymon@gmail.com>
|
||||
Takeshi Yoshino <tyoshino@google.com>
|
||||
Tracy Bialik <tracy@pentad.com>
|
||||
Vadim Berman <vadimb@google.com>
|
@@ -6,7 +6,8 @@
|
||||
|
||||
GoogleTest now follows the
|
||||
[Abseil Live at Head philosophy](https://abseil.io/about/philosophy#upgrade-support).
|
||||
We recommend using the latest commit in the `master` branch in your projects.
|
||||
We recommend
|
||||
[updating to the latest commit in the `main` branch as often as possible](https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-live-at-head-and-how-do-i-do-it).
|
||||
|
||||
#### Documentation Updates
|
||||
|
||||
@@ -14,11 +15,14 @@ Our documentation is now live on GitHub Pages at
|
||||
https://google.github.io/googletest/. We recommend browsing the documentation on
|
||||
GitHub Pages rather than directly in the repository.
|
||||
|
||||
#### Release 1.10.x
|
||||
#### Release 1.12.1
|
||||
|
||||
[Release 1.10.x](https://github.com/google/googletest/releases/tag/release-1.10.0)
|
||||
[Release 1.12.1](https://github.com/google/googletest/releases/tag/release-1.12.1)
|
||||
is now available.
|
||||
|
||||
The 1.12.x branch will be the last to support C++11. Future releases will
|
||||
require at least C++14.
|
||||
|
||||
#### Coming Soon
|
||||
|
||||
* We are planning to take a dependency on
|
||||
@@ -55,39 +59,12 @@ More information about building GoogleTest can be found at
|
||||
|
||||
## Supported Platforms
|
||||
|
||||
GoogleTest requires a codebase and compiler compliant with the C++11 standard or
|
||||
newer.
|
||||
|
||||
The GoogleTest code is officially supported on the following platforms.
|
||||
Operating systems or tools not listed below are community-supported. For
|
||||
community-supported platforms, patches that do not complicate the code may be
|
||||
considered.
|
||||
|
||||
If you notice any problems on your platform, please file an issue on the
|
||||
[GoogleTest GitHub Issue Tracker](https://github.com/google/googletest/issues).
|
||||
Pull requests containing fixes are welcome!
|
||||
|
||||
### Operating Systems
|
||||
|
||||
* Linux
|
||||
* macOS
|
||||
* Windows
|
||||
|
||||
### Compilers
|
||||
|
||||
* gcc 5.0+
|
||||
* clang 5.0+
|
||||
* MSVC 2015+
|
||||
|
||||
**macOS users:** Xcode 9.3+ provides clang 5.0+.
|
||||
|
||||
### Build Systems
|
||||
|
||||
* [Bazel](https://bazel.build/)
|
||||
* [CMake](https://cmake.org/)
|
||||
|
||||
**Note:** Bazel is the build system used by the team internally and in tests.
|
||||
CMake is supported on a best-effort basis and by the community.
|
||||
GoogleTest follows Google's
|
||||
[Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support).
|
||||
See
|
||||
[this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md)
|
||||
for a list of currently supported versions compilers, platforms, and build
|
||||
tools.
|
||||
|
||||
## Who Is Using GoogleTest?
|
||||
|
||||
@@ -109,8 +86,8 @@ Windows and Linux platforms.
|
||||
|
||||
[GoogleTest UI](https://github.com/ospector/gtest-gbar) is a test runner that
|
||||
runs 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
|
||||
Test UI is written in C#.
|
||||
displays a list of test failures. Clicking on one shows failure text. GoogleTest
|
||||
UI is written in C#.
|
||||
|
||||
[GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event
|
||||
listener for GoogleTest that implements the
|
||||
@@ -121,11 +98,11 @@ result output. If your test runner understands TAP, you may find it useful.
|
||||
runs tests from your binary in parallel to provide significant speed-up.
|
||||
|
||||
[GoogleTest Adapter](https://marketplace.visualstudio.com/items?itemName=DavidSchuldenfrei.gtest-adapter)
|
||||
is a VS Code extension allowing to view GoogleTest in a tree view, and run/debug
|
||||
is a VS Code extension allowing to view GoogleTest in a tree view and run/debug
|
||||
your tests.
|
||||
|
||||
[C++ TestMate](https://github.com/matepek/vscode-catch2-test-adapter) is a VS
|
||||
Code extension allowing to view GoogleTest in a tree view, and run/debug your
|
||||
Code extension allowing to view GoogleTest in a tree view and run/debug your
|
||||
tests.
|
||||
|
||||
[Cornichon](https://pypi.org/project/cornichon/) is a small Gherkin DSL parser
|
||||
@@ -134,7 +111,7 @@ that generates stub code for GoogleTest.
|
||||
## Contributing Changes
|
||||
|
||||
Please read
|
||||
[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/master/CONTRIBUTING.md)
|
||||
[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/main/CONTRIBUTING.md)
|
||||
for details on how to contribute to this project.
|
||||
|
||||
Happy testing!
|
40
test/googletest-1.13.0/WORKSPACE
Normal file
40
test/googletest-1.13.0/WORKSPACE
Normal file
@@ -0,0 +1,40 @@
|
||||
workspace(name = "com_google_googletest")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "com_google_absl", # 2023-01-10T21:08:25Z
|
||||
sha256 = "f9a4e749f42c386a32a90fddf0e2913ed408d10c42f7f33ccf4c59ac4f0d1d05",
|
||||
strip_prefix = "abseil-cpp-52835439ca90d86b27bf8cd1708296e95604d724",
|
||||
urls = ["https://github.com/abseil/abseil-cpp/archive/52835439ca90d86b27bf8cd1708296e95604d724.zip"],
|
||||
)
|
||||
|
||||
# Note this must use a commit from the `abseil` branch of the RE2 project.
|
||||
# https://github.com/google/re2/tree/abseil
|
||||
http_archive(
|
||||
name = "com_googlesource_code_re2", # 2022-12-21T14:29:10Z
|
||||
sha256 = "b9ce3a51beebb38534d11d40f8928d40509b9e18a735f6a4a97ad3d014c87cb5",
|
||||
strip_prefix = "re2-d0b1f8f2ecc2ea74956c7608b6f915175314ff0e",
|
||||
urls = ["https://github.com/google/re2/archive/d0b1f8f2ecc2ea74956c7608b6f915175314ff0e.zip"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "rules_python", # 2023-01-10T22:00:51Z
|
||||
sha256 = "5de54486a60ad8948dabe49605bb1c08053e04001a431ab3e96745b4d97a4419",
|
||||
strip_prefix = "rules_python-70cce26432187a60b4e950118791385e6fb3c26f",
|
||||
urls = ["https://github.com/bazelbuild/rules_python/archive/70cce26432187a60b4e950118791385e6fb3c26f.zip"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "bazel_skylib", # 2022-11-16T18:29:32Z
|
||||
sha256 = "a22290c26d29d3ecca286466f7f295ac6cbe32c0a9da3a91176a90e0725e3649",
|
||||
strip_prefix = "bazel-skylib-5bfcb1a684550626ce138fe0fe8f5f702b3764c3",
|
||||
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/5bfcb1a684550626ce138fe0fe8f5f702b3764c3.zip"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "platforms", # 2022-11-09T19:18:22Z
|
||||
sha256 = "b4a3b45dc4202e2b3e34e3bc49d2b5b37295fc23ea58d88fb9e01f3642ad9b55",
|
||||
strip_prefix = "platforms-3fbc687756043fb58a407c2ea8c944bc2fe1d922",
|
||||
urls = ["https://github.com/bazelbuild/platforms/archive/3fbc687756043fb58a407c2ea8c944bc2fe1d922.zip"],
|
||||
)
|
@@ -31,15 +31,15 @@
|
||||
|
||||
set -euox pipefail
|
||||
|
||||
readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20210525"
|
||||
readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20201015"
|
||||
readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220217"
|
||||
readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20220621"
|
||||
|
||||
if [[ -z ${GTEST_ROOT:-} ]]; then
|
||||
GTEST_ROOT="$(realpath $(dirname ${0})/..)"
|
||||
fi
|
||||
|
||||
if [[ -z ${STD:-} ]]; then
|
||||
STD="c++11 c++14 c++17 c++20"
|
||||
STD="c++14 c++17 c++20"
|
||||
fi
|
||||
|
||||
# Test the CMake build
|
||||
@@ -55,7 +55,7 @@ for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do
|
||||
${LINUX_LATEST_CONTAINER} \
|
||||
/bin/bash -c "
|
||||
cmake /src \
|
||||
-DCMAKE_CXX_STANDARD=11 \
|
||||
-DCMAKE_CXX_STANDARD=14 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
@@ -72,11 +72,15 @@ time docker run \
|
||||
--workdir="/src" \
|
||||
--rm \
|
||||
--env="CC=/usr/local/bin/gcc" \
|
||||
--env="BAZEL_CXXOPTS=-std=c++14" \
|
||||
${LINUX_GCC_FLOOR_CONTAINER} \
|
||||
/usr/local/bin/bazel test ... \
|
||||
--copt="-Wall" \
|
||||
--copt="-Werror" \
|
||||
--copt="-Wuninitialized" \
|
||||
--copt="-Wno-error=pragmas" \
|
||||
--distdir="/bazel-distdir" \
|
||||
--features=external_include_paths \
|
||||
--keep_going \
|
||||
--show_timestamps \
|
||||
--test_output=errors
|
||||
@@ -94,8 +98,10 @@ for std in ${STD}; do
|
||||
/usr/local/bin/bazel test ... \
|
||||
--copt="-Wall" \
|
||||
--copt="-Werror" \
|
||||
--copt="-Wuninitialized" \
|
||||
--define="absl=${absl}" \
|
||||
--distdir="/bazel-distdir" \
|
||||
--features=external_include_paths \
|
||||
--keep_going \
|
||||
--show_timestamps \
|
||||
--test_output=errors
|
||||
@@ -116,8 +122,10 @@ for std in ${STD}; do
|
||||
--copt="--gcc-toolchain=/usr/local" \
|
||||
--copt="-Wall" \
|
||||
--copt="-Werror" \
|
||||
--copt="-Wuninitialized" \
|
||||
--define="absl=${absl}" \
|
||||
--distdir="/bazel-distdir" \
|
||||
--features=external_include_paths \
|
||||
--keep_going \
|
||||
--linkopt="--gcc-toolchain=/usr/local" \
|
||||
--show_timestamps \
|
@@ -40,7 +40,7 @@ for cmake_off_on in OFF ON; do
|
||||
BUILD_DIR=$(mktemp -d build_dir.XXXXXXXX)
|
||||
cd ${BUILD_DIR}
|
||||
time cmake ${GTEST_ROOT} \
|
||||
-DCMAKE_CXX_STANDARD=11 \
|
||||
-DCMAKE_CXX_STANDARD=14 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
@@ -53,7 +53,7 @@ done
|
||||
# Test the Bazel build
|
||||
|
||||
# If we are running on Kokoro, check for a versioned Bazel binary.
|
||||
KOKORO_GFILE_BAZEL_BIN="bazel-3.7.0-darwin-x86_64"
|
||||
KOKORO_GFILE_BAZEL_BIN="bazel-5.1.1-darwin-x86_64"
|
||||
if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then
|
||||
BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}"
|
||||
chmod +x ${BAZEL_BIN}
|
||||
@@ -66,7 +66,9 @@ for absl in 0 1; do
|
||||
${BAZEL_BIN} test ... \
|
||||
--copt="-Wall" \
|
||||
--copt="-Werror" \
|
||||
--cxxopt="-std=c++14" \
|
||||
--define="absl=${absl}" \
|
||||
--features=external_include_paths \
|
||||
--keep_going \
|
||||
--show_timestamps \
|
||||
--test_output=errors
|
56
test/googletest-1.13.0/ci/windows-presubmit.bat
Normal file
56
test/googletest-1.13.0/ci/windows-presubmit.bat
Normal file
@@ -0,0 +1,56 @@
|
||||
SETLOCAL ENABLEDELAYEDEXPANSION
|
||||
|
||||
SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe
|
||||
|
||||
SET PATH=C:\Python37;%PATH%
|
||||
SET BAZEL_PYTHON=C:\python37\python.exe
|
||||
SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe
|
||||
SET CMAKE_BIN="C:\Program Files\CMake\bin\cmake.exe"
|
||||
SET CTEST_BIN="C:\Program Files\CMake\bin\ctest.exe"
|
||||
SET CTEST_OUTPUT_ON_FAILURE=1
|
||||
|
||||
IF EXIST git\googletest (
|
||||
CD git\googletest
|
||||
) ELSE IF EXIST github\googletest (
|
||||
CD github\googletest
|
||||
)
|
||||
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: CMake Visual Studio 15 2017 Win64
|
||||
MKDIR cmake_msvc2017
|
||||
CD cmake_msvc2017
|
||||
|
||||
%CMAKE_BIN% .. ^
|
||||
-G "Visual Studio 15 2017 Win64" ^
|
||||
-DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^
|
||||
-DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^
|
||||
-DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^
|
||||
-Dgtest_build_samples=ON ^
|
||||
-Dgtest_build_tests=ON ^
|
||||
-Dgmock_build_tests=ON
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
%CMAKE_BIN% --build . --target ALL_BUILD --config Debug -- -maxcpucount
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
%CTEST_BIN% -C Debug --timeout 600
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
CD ..
|
||||
RMDIR /S /Q cmake_msvc2017
|
||||
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: Bazel Visual Studio 15 2017 Win64
|
||||
|
||||
SET BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC
|
||||
%BAZEL_EXE% test ... ^
|
||||
--compilation_mode=dbg ^
|
||||
--copt=/std:c++14 ^
|
||||
--copt=/WX ^
|
||||
--features=external_include_paths ^
|
||||
--keep_going ^
|
||||
--test_output=errors ^
|
||||
--test_tag_filters=-no_test_msvc2017
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
@@ -48,7 +48,7 @@
|
||||
<div class="footer">
|
||||
GoogleTest ·
|
||||
<a href="https://github.com/google/googletest">GitHub Repository</a> ·
|
||||
<a href="https://github.com/google/googletest/blob/master/LICENSE">License</a> ·
|
||||
<a href="https://github.com/google/googletest/blob/main/LICENSE">License</a> ·
|
||||
<a href="https://policies.google.com/privacy">Privacy Policy</a>
|
||||
</div>
|
||||
</div>
|
@@ -157,8 +157,11 @@ that can be used in the predicate assertion macro
|
||||
example:
|
||||
|
||||
```c++
|
||||
EXPECT_PRED_FORMAT2(testing::FloatLE, val1, val2);
|
||||
EXPECT_PRED_FORMAT2(testing::DoubleLE, val1, val2);
|
||||
using ::testing::FloatLE;
|
||||
using ::testing::DoubleLE;
|
||||
...
|
||||
EXPECT_PRED_FORMAT2(FloatLE, val1, val2);
|
||||
EXPECT_PRED_FORMAT2(DoubleLE, val1, val2);
|
||||
```
|
||||
|
||||
The above code verifies that `val1` is less than, or approximately equal to,
|
||||
@@ -202,10 +205,9 @@ You can call the function
|
||||
|
||||
to assert that types `T1` and `T2` are the same. The function does nothing if
|
||||
the assertion is satisfied. If the types are different, the function call will
|
||||
fail to compile, the compiler error message will say that
|
||||
`T1 and T2 are not the same type` and most likely (depending on the compiler)
|
||||
show you the actual values of `T1` and `T2`. This is mainly useful inside
|
||||
template code.
|
||||
fail to compile, the compiler error message will say that `T1 and T2 are not the
|
||||
same type` and most likely (depending on the compiler) show you the actual
|
||||
values of `T1` and `T2`. This is mainly useful inside template code.
|
||||
|
||||
**Caveat**: When used inside a member function of a class template or a function
|
||||
template, `StaticAssertTypeEq<T1, T2>()` is effective only if the function is
|
||||
@@ -383,10 +385,10 @@ EXPECT_TRUE(IsCorrectBarIntVector(bar_ints))
|
||||
## Death Tests
|
||||
|
||||
In many applications, there are assertions that can cause application failure if
|
||||
a condition is not met. These sanity checks, which ensure that the program is in
|
||||
a known good state, are there to fail at the earliest possible time after some
|
||||
program state is corrupted. If the assertion checks the wrong condition, then
|
||||
the program may proceed in an erroneous state, which could lead to memory
|
||||
a condition is not met. These consistency checks, which ensure that the program
|
||||
is in a known good state, are there to fail at the earliest possible time after
|
||||
some program state is corrupted. If the assertion checks the wrong condition,
|
||||
then the program may proceed in an erroneous state, which could lead to memory
|
||||
corruption, security holes, or worse. Hence it is vitally important to test that
|
||||
such assertion statements work as expected.
|
||||
|
||||
@@ -480,10 +482,12 @@ TEST_F(FooDeathTest, DoesThat) {
|
||||
|
||||
### Regular Expression Syntax
|
||||
|
||||
On POSIX systems (e.g. Linux, Cygwin, and Mac), googletest uses the
|
||||
When built with Bazel and using Abseil, googletest uses the
|
||||
[RE2](https://github.com/google/re2/wiki/Syntax) syntax. Otherwise, for POSIX
|
||||
systems (Linux, Cygwin, Mac), googletest uses the
|
||||
[POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04)
|
||||
syntax. To learn about this syntax, you may want to read this
|
||||
[Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_Extended_Regular_Expressions).
|
||||
syntax. To learn about POSIX syntax, you may want to read this
|
||||
[Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_extended).
|
||||
|
||||
On Windows, googletest uses its own simple regular expression implementation. It
|
||||
lacks many features. For example, we don't support union (`"x|y"`), grouping
|
||||
@@ -558,7 +562,7 @@ The automated testing framework does not set the style flag. You can choose a
|
||||
particular style of death tests by setting the flag programmatically:
|
||||
|
||||
```c++
|
||||
testing::FLAGS_gtest_death_test_style="threadsafe"
|
||||
GTEST_FLAG_SET(death_test_style, "threadsafe")
|
||||
```
|
||||
|
||||
You can do this in `main()` to set the style for all death tests in the binary,
|
||||
@@ -568,12 +572,12 @@ restored afterwards, so you need not do that yourself. For example:
|
||||
```c++
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
testing::FLAGS_gtest_death_test_style = "fast";
|
||||
GTEST_FLAG_SET(death_test_style, "fast");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
TEST(MyDeathTest, TestOne) {
|
||||
testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
GTEST_FLAG_SET(death_test_style, "threadsafe");
|
||||
// This test is run in the "threadsafe" style:
|
||||
ASSERT_DEATH(ThisShouldDie(), "");
|
||||
}
|
||||
@@ -610,15 +614,14 @@ Despite the improved thread safety afforded by the "threadsafe" style of death
|
||||
test, thread problems such as deadlock are still possible in the presence of
|
||||
handlers registered with `pthread_atfork(3)`.
|
||||
|
||||
|
||||
## Using Assertions in Sub-routines
|
||||
|
||||
{: .callout .note}
|
||||
Note: If you want to put a series of test assertions in a subroutine to check
|
||||
for a complex condition, consider using
|
||||
[a custom GMock matcher](gmock_cook_book.md#NewMatchers)
|
||||
instead. This lets you provide a more readable error message in case of failure
|
||||
and avoid all of the issues described below.
|
||||
[a custom GMock matcher](gmock_cook_book.md#NewMatchers) instead. This lets you
|
||||
provide a more readable error message in case of failure and avoid all of the
|
||||
issues described below.
|
||||
|
||||
### Adding Traces to Assertions
|
||||
|
||||
@@ -631,6 +634,7 @@ the `SCOPED_TRACE` macro or the `ScopedTrace` utility:
|
||||
```c++
|
||||
SCOPED_TRACE(message);
|
||||
```
|
||||
|
||||
```c++
|
||||
ScopedTrace trace("file_path", line_number, message);
|
||||
```
|
||||
@@ -837,7 +841,7 @@ will output XML like this:
|
||||
|
||||
```xml
|
||||
...
|
||||
<testcase name="MinAndMaxWidgets" status="run" time="0.006" classname="WidgetUsageTest" MaximumWidgets="12" MinimumWidgets="9" />
|
||||
<testcase name="MinAndMaxWidgets" file="test.cpp" line="1" status="run" time="0.006" classname="WidgetUsageTest" MaximumWidgets="12" MinimumWidgets="9" />
|
||||
...
|
||||
```
|
||||
|
||||
@@ -888,6 +892,12 @@ preceding or following another. Also, the tests must either not modify the state
|
||||
of any shared resource, or, if they do modify the state, they must restore the
|
||||
state to its original value before passing control to the next test.
|
||||
|
||||
Note that `SetUpTestSuite()` may be called multiple times for a test fixture
|
||||
class that has derived classes, so you should not expect code in the function
|
||||
body to be run only once. Also, derived classes still have access to shared
|
||||
resources defined as static members, so careful consideration is needed when
|
||||
managing shared resources to avoid memory leaks.
|
||||
|
||||
Here's an example of per-test-suite set-up and tear-down:
|
||||
|
||||
```c++
|
||||
@@ -897,7 +907,10 @@ class FooTest : public testing::Test {
|
||||
// Called before the first test in this test suite.
|
||||
// Can be omitted if not needed.
|
||||
static void SetUpTestSuite() {
|
||||
shared_resource_ = new ...;
|
||||
// Avoid reallocating static objects if called in subclasses of FooTest.
|
||||
if (shared_resource_ == nullptr) {
|
||||
shared_resource_ = new ...;
|
||||
}
|
||||
}
|
||||
|
||||
// Per-test-suite tear-down.
|
||||
@@ -1082,6 +1095,11 @@ instantiation of the test suite. The next argument is the name of the test
|
||||
pattern, and the last is the
|
||||
[parameter generator](reference/testing.md#param-generators).
|
||||
|
||||
The parameter generator expression is not evaluated until GoogleTest is
|
||||
initialized (via `InitGoogleTest()`). Any prior initialization done in the
|
||||
`main` function will be accessible from the parameter generator, for example,
|
||||
the results of flag parsing.
|
||||
|
||||
You can instantiate a test pattern more than once, so to distinguish different
|
||||
instances of the pattern, the instantiation name is added as a prefix to the
|
||||
actual test suite name. Remember to pick unique prefixes for different
|
||||
@@ -1129,8 +1147,8 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest);
|
||||
|
||||
You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples.
|
||||
|
||||
[sample7_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample7_unittest.cc "Parameterized Test example"
|
||||
[sample8_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters"
|
||||
[sample7_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample7_unittest.cc "Parameterized Test example"
|
||||
[sample8_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters"
|
||||
|
||||
### Creating Value-Parameterized Abstract Tests
|
||||
|
||||
@@ -1281,7 +1299,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||
|
||||
You can see [sample6_unittest.cc] for a complete example.
|
||||
|
||||
[sample6_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc "Typed Test example"
|
||||
[sample6_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample6_unittest.cc "Typed Test example"
|
||||
|
||||
## Type-Parameterized Tests
|
||||
|
||||
@@ -1302,6 +1320,7 @@ First, define a fixture class template, as we did with typed tests:
|
||||
```c++
|
||||
template <typename T>
|
||||
class FooTest : public testing::Test {
|
||||
void DoSomethingInteresting();
|
||||
...
|
||||
};
|
||||
```
|
||||
@@ -1319,6 +1338,9 @@ this as many times as you want:
|
||||
TYPED_TEST_P(FooTest, DoesBlah) {
|
||||
// Inside a test, refer to TypeParam to get the type parameter.
|
||||
TypeParam n = 0;
|
||||
|
||||
// You will need to use `this` explicitly to refer to fixture members.
|
||||
this->DoSomethingInteresting()
|
||||
...
|
||||
}
|
||||
|
||||
@@ -1481,8 +1503,8 @@ In frameworks that report a failure by throwing an exception, you could catch
|
||||
the exception and assert on it. But googletest doesn't use exceptions, so how do
|
||||
we test that a piece of code generates an expected failure?
|
||||
|
||||
`"gtest/gtest-spi.h"` contains some constructs to do this. After #including this header,
|
||||
you can use
|
||||
`"gtest/gtest-spi.h"` contains some constructs to do this.
|
||||
After #including this header, you can use
|
||||
|
||||
```c++
|
||||
EXPECT_FATAL_FAILURE(statement, substring);
|
||||
@@ -1586,12 +1608,14 @@ void RegisterMyTests(const std::vector<int>& values) {
|
||||
}
|
||||
...
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
std::vector<int> values_to_test = LoadValuesFromConfig();
|
||||
RegisterMyTests(values_to_test);
|
||||
...
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
```
|
||||
|
||||
## Getting the Current Test's Name
|
||||
|
||||
Sometimes a function may need to know the name of the currently running test.
|
||||
@@ -1714,7 +1738,7 @@ You can do so by adding one line:
|
||||
Now, sit back and enjoy a completely different output from your tests. For more
|
||||
details, see [sample9_unittest.cc].
|
||||
|
||||
[sample9_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample9_unittest.cc "Event listener example"
|
||||
[sample9_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample9_unittest.cc "Event listener example"
|
||||
|
||||
You may append more than one listener to the list. When an `On*Start()` or
|
||||
`OnTestPartResult()` event is fired, the listeners will receive it in the order
|
||||
@@ -1741,7 +1765,7 @@ by the former.
|
||||
|
||||
See [sample10_unittest.cc] for an example of a failure-raising listener.
|
||||
|
||||
[sample10_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample10_unittest.cc "Failure-raising listener example"
|
||||
[sample10_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample10_unittest.cc "Failure-raising listener example"
|
||||
|
||||
## Running Test Programs: Advanced Options
|
||||
|
||||
@@ -1816,8 +1840,7 @@ By default, a googletest program runs all tests the user has defined. In some
|
||||
cases (e.g. iterative test development & execution) it may be desirable stop
|
||||
test execution upon first failure (trading improved latency for completeness).
|
||||
If `GTEST_FAIL_FAST` environment variable or `--gtest_fail_fast` flag is set,
|
||||
the test runner will stop execution as soon as the first test failure is
|
||||
found.
|
||||
the test runner will stop execution as soon as the first test failure is found.
|
||||
|
||||
#### Temporarily Disabling Tests
|
||||
|
||||
@@ -1890,8 +1913,12 @@ Repeat the tests whose name matches the filter 1000 times.
|
||||
|
||||
If your test program contains
|
||||
[global set-up/tear-down](#global-set-up-and-tear-down) code, it will be
|
||||
repeated in each iteration as well, as the flakiness may be in it. You can also
|
||||
specify the repeat count by setting the `GTEST_REPEAT` environment variable.
|
||||
repeated in each iteration as well, as the flakiness may be in it. To avoid
|
||||
repeating global set-up/tear-down, specify
|
||||
`--gtest_recreate_environments_when_repeating=false`{.nowrap}.
|
||||
|
||||
You can also specify the repeat count by setting the `GTEST_REPEAT` environment
|
||||
variable.
|
||||
|
||||
### Shuffling the Tests
|
||||
|
||||
@@ -1911,6 +1938,58 @@ time.
|
||||
If you combine this with `--gtest_repeat=N`, googletest will pick a different
|
||||
random seed and re-shuffle the tests in each iteration.
|
||||
|
||||
### Distributing Test Functions to Multiple Machines
|
||||
|
||||
If you have more than one machine you can use to run a test program, you might
|
||||
want to run the test functions in parallel and get the result faster. We call
|
||||
this technique *sharding*, where each machine is called a *shard*.
|
||||
|
||||
GoogleTest is compatible with test sharding. To take advantage of this feature,
|
||||
your test runner (not part of GoogleTest) needs to do the following:
|
||||
|
||||
1. Allocate a number of machines (shards) to run the tests.
|
||||
1. On each shard, set the `GTEST_TOTAL_SHARDS` environment variable to the total
|
||||
number of shards. It must be the same for all shards.
|
||||
1. On each shard, set the `GTEST_SHARD_INDEX` environment variable to the index
|
||||
of the shard. Different shards must be assigned different indices, which
|
||||
must be in the range `[0, GTEST_TOTAL_SHARDS - 1]`.
|
||||
1. Run the same test program on all shards. When GoogleTest sees the above two
|
||||
environment variables, it will select a subset of the test functions to run.
|
||||
Across all shards, each test function in the program will be run exactly
|
||||
once.
|
||||
1. Wait for all shards to finish, then collect and report the results.
|
||||
|
||||
Your project may have tests that were written without GoogleTest and thus don't
|
||||
understand this protocol. In order for your test runner to figure out which test
|
||||
supports sharding, it can set the environment variable `GTEST_SHARD_STATUS_FILE`
|
||||
to a non-existent file path. If a test program supports sharding, it will create
|
||||
this file to acknowledge that fact; otherwise it will not create it. The actual
|
||||
contents of the file are not important at this time, although we may put some
|
||||
useful information in it in the future.
|
||||
|
||||
Here's an example to make it clear. Suppose you have a test program `foo_test`
|
||||
that contains the following 5 test functions:
|
||||
|
||||
```
|
||||
TEST(A, V)
|
||||
TEST(A, W)
|
||||
TEST(B, X)
|
||||
TEST(B, Y)
|
||||
TEST(B, Z)
|
||||
```
|
||||
|
||||
Suppose you have 3 machines at your disposal. To run the test functions in
|
||||
parallel, you would set `GTEST_TOTAL_SHARDS` to 3 on all machines, and set
|
||||
`GTEST_SHARD_INDEX` to 0, 1, and 2 on the machines respectively. Then you would
|
||||
run the same `foo_test` on each machine.
|
||||
|
||||
GoogleTest reserves the right to change how the work is distributed across the
|
||||
shards, but here's one possible scenario:
|
||||
|
||||
* Machine #0 runs `A.V` and `B.X`.
|
||||
* Machine #1 runs `A.W` and `B.Y`.
|
||||
* Machine #2 runs `B.Z`.
|
||||
|
||||
### Controlling Test Output
|
||||
|
||||
#### Colored Terminal Output
|
||||
@@ -1965,8 +2044,6 @@ text because, for example, you don't have an UTF-8 compatible output medium, run
|
||||
the test program with `--gtest_print_utf8=0` or set the `GTEST_PRINT_UTF8`
|
||||
environment variable to `0`.
|
||||
|
||||
|
||||
|
||||
#### Generating an XML Report
|
||||
|
||||
googletest can emit a detailed XML report to a file in addition to its normal
|
||||
@@ -2020,15 +2097,15 @@ could generate this report:
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="3" failures="1" errors="0" time="0.035" timestamp="2011-10-31T18:52:42" name="AllTests">
|
||||
<testsuite name="MathTest" tests="2" failures="1" errors="0" time="0.015">
|
||||
<testcase name="Addition" status="run" time="0.007" classname="">
|
||||
<testcase name="Addition" file="test.cpp" line="1" status="run" time="0.007" classname="">
|
||||
<failure message="Value of: add(1, 1)
 Actual: 3
Expected: 2" type="">...</failure>
|
||||
<failure message="Value of: add(1, -1)
 Actual: 1
Expected: 0" type="">...</failure>
|
||||
</testcase>
|
||||
<testcase name="Subtraction" status="run" time="0.005" classname="">
|
||||
<testcase name="Subtraction" file="test.cpp" line="2" status="run" time="0.005" classname="">
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="LogicTest" tests="1" failures="0" errors="0" time="0.005">
|
||||
<testcase name="NonContradiction" status="run" time="0.005" classname="">
|
||||
<testcase name="NonContradiction" file="test.cpp" line="3" status="run" time="0.005" classname="">
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
@@ -2046,6 +2123,9 @@ Things to note:
|
||||
* The `timestamp` attribute records the local date and time of the test
|
||||
execution.
|
||||
|
||||
* The `file` and `line` attributes record the source file location, where the
|
||||
test was defined.
|
||||
|
||||
* Each `<failure>` element corresponds to a single failed googletest
|
||||
assertion.
|
||||
|
||||
@@ -2085,6 +2165,8 @@ The report format conforms to the following JSON Schema:
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"file": { "type": "string" },
|
||||
"line": { "type": "integer" },
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["RUN", "NOTRUN"]
|
||||
@@ -2162,6 +2244,8 @@ message TestCase {
|
||||
|
||||
message TestInfo {
|
||||
string name = 1;
|
||||
string file = 6;
|
||||
int32 line = 7;
|
||||
enum Status {
|
||||
RUN = 0;
|
||||
NOTRUN = 1;
|
||||
@@ -2205,6 +2289,8 @@ could generate this report:
|
||||
"testsuite": [
|
||||
{
|
||||
"name": "Addition",
|
||||
"file": "test.cpp",
|
||||
"line": 1,
|
||||
"status": "RUN",
|
||||
"time": "0.007s",
|
||||
"classname": "",
|
||||
@@ -2221,6 +2307,8 @@ could generate this report:
|
||||
},
|
||||
{
|
||||
"name": "Subtraction",
|
||||
"file": "test.cpp",
|
||||
"line": 2,
|
||||
"status": "RUN",
|
||||
"time": "0.005s",
|
||||
"classname": ""
|
||||
@@ -2236,6 +2324,8 @@ could generate this report:
|
||||
"testsuite": [
|
||||
{
|
||||
"name": "NonContradiction",
|
||||
"file": "test.cpp",
|
||||
"line": 3,
|
||||
"status": "RUN",
|
||||
"time": "0.005s",
|
||||
"classname": ""
|
||||
@@ -2253,12 +2343,11 @@ IMPORTANT: The exact format of the JSON document is subject to change.
|
||||
|
||||
#### Detecting Test Premature Exit
|
||||
|
||||
Google Test implements the _premature-exit-file_ protocol for test runners
|
||||
to catch any kind of unexpected exits of test programs. Upon start,
|
||||
Google Test creates the file which will be automatically deleted after
|
||||
all work has been finished. Then, the test runner can check if this file
|
||||
exists. In case the file remains undeleted, the inspected test has exited
|
||||
prematurely.
|
||||
Google Test implements the _premature-exit-file_ protocol for test runners to
|
||||
catch any kind of unexpected exits of test programs. Upon start, Google Test
|
||||
creates the file which will be automatically deleted after all work has been
|
||||
finished. Then, the test runner can check if this file exists. In case the file
|
||||
remains undeleted, the inspected test has exited prematurely.
|
||||
|
||||
This feature is enabled only if the `TEST_PREMATURE_EXIT_FILE` environment
|
||||
variable has been set.
|
@@ -1,9 +1,9 @@
|
||||
# Googletest FAQ
|
||||
# GoogleTest FAQ
|
||||
|
||||
## Why should test suite names and test names not contain underscore?
|
||||
|
||||
{: .callout .note}
|
||||
Note: Googletest reserves underscore (`_`) for special purpose keywords, such as
|
||||
Note: GoogleTest reserves underscore (`_`) for special purpose keywords, such as
|
||||
[the `DISABLED_` prefix](advanced.md#temporarily-disabling-tests), in addition
|
||||
to the following rationale.
|
||||
|
||||
@@ -50,15 +50,15 @@ Now, the two `TEST`s will both generate the same class
|
||||
|
||||
So for simplicity, we just ask the users to avoid `_` in `TestSuiteName` and
|
||||
`TestName`. The rule is more constraining than necessary, but it's simple and
|
||||
easy to remember. It also gives googletest some wiggle room in case its
|
||||
easy to remember. It also gives GoogleTest some wiggle room in case its
|
||||
implementation needs to change in the future.
|
||||
|
||||
If you violate the rule, there may not be immediate consequences, but your test
|
||||
may (just may) break with a new compiler (or a new version of the compiler you
|
||||
are using) or with a new version of googletest. Therefore it's best to follow
|
||||
are using) or with a new version of GoogleTest. Therefore it's best to follow
|
||||
the rule.
|
||||
|
||||
## Why does googletest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`?
|
||||
## Why does GoogleTest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`?
|
||||
|
||||
First of all, you can use `nullptr` with each of these macros, e.g.
|
||||
`EXPECT_EQ(ptr, nullptr)`, `EXPECT_NE(ptr, nullptr)`, `ASSERT_EQ(ptr, nullptr)`,
|
||||
@@ -68,7 +68,7 @@ because `nullptr` does not have the type problems that `NULL` does.
|
||||
Due to some peculiarity of C++, it requires some non-trivial template meta
|
||||
programming tricks to support using `NULL` as an argument of the `EXPECT_XX()`
|
||||
and `ASSERT_XX()` macros. Therefore we only do it where it's most needed
|
||||
(otherwise we make the implementation of googletest harder to maintain and more
|
||||
(otherwise we make the implementation of GoogleTest harder to maintain and more
|
||||
error-prone than necessary).
|
||||
|
||||
Historically, the `EXPECT_EQ()` macro took the *expected* value as its first
|
||||
@@ -162,7 +162,7 @@ methods, the parent process will think the calls have never occurred. Therefore,
|
||||
you may want to move your `EXPECT_CALL` statements inside the `EXPECT_DEATH`
|
||||
macro.
|
||||
|
||||
## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a googletest bug?
|
||||
## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a GoogleTest bug?
|
||||
|
||||
Actually, the bug is in `htonl()`.
|
||||
|
||||
@@ -199,7 +199,7 @@ const int Foo::kBar; // No initializer here.
|
||||
```
|
||||
|
||||
Otherwise your code is **invalid C++**, and may break in unexpected ways. In
|
||||
particular, using it in googletest comparison assertions (`EXPECT_EQ`, etc) will
|
||||
particular, using it in GoogleTest comparison assertions (`EXPECT_EQ`, etc) will
|
||||
generate an "undefined reference" linker error. The fact that "it used to work"
|
||||
doesn't mean it's valid. It just means that you were lucky. :-)
|
||||
|
||||
@@ -225,7 +225,7 @@ cases may want to use the same or slightly different fixtures. For example, you
|
||||
may want to make sure that all of a GUI library's test suites don't leak
|
||||
important system resources like fonts and brushes.
|
||||
|
||||
In googletest, you share a fixture among test suites by putting the shared logic
|
||||
In GoogleTest, you share a fixture among test suites by putting the shared logic
|
||||
in a base test fixture, then deriving from that base a separate fixture for each
|
||||
test suite that wants to use this common logic. You then use `TEST_F()` to write
|
||||
tests using each derived fixture.
|
||||
@@ -264,10 +264,10 @@ TEST_F(FooTest, Baz) { ... }
|
||||
```
|
||||
|
||||
If necessary, you can continue to derive test fixtures from a derived fixture.
|
||||
googletest has no limit on how deep the hierarchy can be.
|
||||
GoogleTest has no limit on how deep the hierarchy can be.
|
||||
|
||||
For a complete example using derived test fixtures, see
|
||||
[sample5_unittest.cc](https://github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc).
|
||||
[sample5_unittest.cc](https://github.com/google/googletest/blob/main/googletest/samples/sample5_unittest.cc).
|
||||
|
||||
## My compiler complains "void value not ignored as it ought to be." What does this mean?
|
||||
|
||||
@@ -278,7 +278,7 @@ disabled by our build system. Please see more details
|
||||
|
||||
## My death test hangs (or seg-faults). How do I fix it?
|
||||
|
||||
In googletest, death tests are run in a child process and the way they work is
|
||||
In GoogleTest, death tests are run in a child process and the way they work is
|
||||
delicate. To write death tests you really need to understand how they work—see
|
||||
the details at [Death Assertions](reference/assertions.md#death) in the
|
||||
Assertions Reference.
|
||||
@@ -305,8 +305,8 @@ bullet - sorry!
|
||||
|
||||
## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? {#CtorVsSetUp}
|
||||
|
||||
The first thing to remember is that googletest does **not** reuse the same test
|
||||
fixture object across multiple tests. For each `TEST_F`, googletest will create
|
||||
The first thing to remember is that GoogleTest does **not** reuse the same test
|
||||
fixture object across multiple tests. For each `TEST_F`, GoogleTest will create
|
||||
a **fresh** test fixture object, immediately call `SetUp()`, run the test body,
|
||||
call `TearDown()`, and then delete the test fixture object.
|
||||
|
||||
@@ -328,7 +328,7 @@ You may still want to use `SetUp()/TearDown()` in the following cases:
|
||||
|
||||
* C++ does not allow virtual function calls in constructors and destructors.
|
||||
You can call a method declared as virtual, but it will not use dynamic
|
||||
dispatch, it will use the definition from the class the constructor of which
|
||||
dispatch. It will use the definition from the class the constructor of which
|
||||
is currently executing. This is because calling a virtual method before the
|
||||
derived class constructor has a chance to run is very dangerous - the
|
||||
virtual method might operate on uninitialized data. Therefore, if you need
|
||||
@@ -345,11 +345,11 @@ You may still want to use `SetUp()/TearDown()` in the following cases:
|
||||
that many standard libraries (like STL) may throw when exceptions are
|
||||
enabled in the compiler. Therefore you should prefer `TearDown()` if you
|
||||
want to write portable tests that work with or without exceptions.
|
||||
* The googletest team is considering making the assertion macros throw on
|
||||
* The GoogleTest team is considering making the assertion macros throw on
|
||||
platforms where exceptions are enabled (e.g. Windows, Mac OS, and Linux
|
||||
client-side), which will eliminate the need for the user to propagate
|
||||
failures from a subroutine to its caller. Therefore, you shouldn't use
|
||||
googletest assertions in a destructor if your code could run on such a
|
||||
GoogleTest assertions in a destructor if your code could run on such a
|
||||
platform.
|
||||
|
||||
## The compiler complains "no matching function to call" when I use ASSERT_PRED*. How do I fix it?
|
||||
@@ -375,7 +375,7 @@ they write
|
||||
This is **wrong and dangerous**. The testing services needs to see the return
|
||||
value of `RUN_ALL_TESTS()` in order to determine if a test has passed. If your
|
||||
`main()` function ignores it, your test will be considered successful even if it
|
||||
has a googletest assertion failure. Very bad.
|
||||
has a GoogleTest assertion failure. Very bad.
|
||||
|
||||
We have decided to fix this (thanks to Michael Chastain for the idea). Now, your
|
||||
code will no longer be able to ignore `RUN_ALL_TESTS()` when compiled with
|
||||
@@ -410,7 +410,6 @@ C++ is case-sensitive. Did you spell it as `Setup()`?
|
||||
Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and
|
||||
wonder why it's never called.
|
||||
|
||||
|
||||
## I have several test suites which share the same test fixture logic, do I have to define a new test fixture class for each of them? This seems pretty tedious.
|
||||
|
||||
You don't have to. Instead of
|
||||
@@ -441,14 +440,14 @@ TEST_F(BarTest, Abc) { ... }
|
||||
TEST_F(BarTest, Def) { ... }
|
||||
```
|
||||
|
||||
## googletest output is buried in a whole bunch of LOG messages. What do I do?
|
||||
## GoogleTest output is buried in a whole bunch of LOG messages. What do I do?
|
||||
|
||||
The googletest output is meant to be a concise and human-friendly report. If
|
||||
your test generates textual output itself, it will mix with the googletest
|
||||
The GoogleTest output is meant to be a concise and human-friendly report. If
|
||||
your test generates textual output itself, it will mix with the GoogleTest
|
||||
output, making it hard to read. However, there is an easy solution to this
|
||||
problem.
|
||||
|
||||
Since `LOG` messages go to stderr, we decided to let googletest output go to
|
||||
Since `LOG` messages go to stderr, we decided to let GoogleTest output go to
|
||||
stdout. This way, you can easily separate the two using redirection. For
|
||||
example:
|
||||
|
||||
@@ -521,7 +520,7 @@ TEST(MyDeathTest, CompoundStatement) {
|
||||
|
||||
## I have a fixture class `FooTest`, but `TEST_F(FooTest, Bar)` gives me error ``"no matching function for call to `FooTest::FooTest()'"``. Why?
|
||||
|
||||
Googletest needs to be able to create objects of your test fixture class, so it
|
||||
GoogleTest needs to be able to create objects of your test fixture class, so it
|
||||
must have a default constructor. Normally the compiler will define one for you.
|
||||
However, there are cases where you have to define your own:
|
||||
|
||||
@@ -546,11 +545,11 @@ The new NPTL thread library doesn't suffer from this problem, as it doesn't
|
||||
create a manager thread. However, if you don't control which machine your test
|
||||
runs on, you shouldn't depend on this.
|
||||
|
||||
## Why does googletest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH?
|
||||
## Why does GoogleTest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH?
|
||||
|
||||
googletest does not interleave tests from different test suites. That is, it
|
||||
GoogleTest does not interleave tests from different test suites. That is, it
|
||||
runs all tests in one test suite first, and then runs all tests in the next test
|
||||
suite, and so on. googletest does this because it needs to set up a test suite
|
||||
suite, and so on. GoogleTest does this because it needs to set up a test suite
|
||||
before the first test in it is run, and tear it down afterwards. Splitting up
|
||||
the test case would require multiple set-up and tear-down processes, which is
|
||||
inefficient and makes the semantics unclean.
|
||||
@@ -589,11 +588,11 @@ TEST_F(FooDeathTest, Uvw) { ... EXPECT_DEATH(...) ... }
|
||||
TEST_F(FooDeathTest, Xyz) { ... ASSERT_DEATH(...) ... }
|
||||
```
|
||||
|
||||
## googletest prints the LOG messages in a death test's child process only when the test fails. How can I see the LOG messages when the death test succeeds?
|
||||
## GoogleTest prints the LOG messages in a death test's child process only when the test fails. How can I see the LOG messages when the death test succeeds?
|
||||
|
||||
Printing the LOG messages generated by the statement inside `EXPECT_DEATH()`
|
||||
makes it harder to search for real problems in the parent's log. Therefore,
|
||||
googletest only prints them when the death test has failed.
|
||||
GoogleTest only prints them when the death test has failed.
|
||||
|
||||
If you really need to see such LOG messages, a workaround is to temporarily
|
||||
break the death test (e.g. by changing the regex pattern it is expected to
|
||||
@@ -612,7 +611,7 @@ needs to be defined in the *same* name space. See
|
||||
|
||||
## How do I suppress the memory leak messages on Windows?
|
||||
|
||||
Since the statically initialized googletest singleton requires allocations on
|
||||
Since the statically initialized GoogleTest singleton requires allocations on
|
||||
the heap, the Visual C++ memory leak detector will report memory leaks at the
|
||||
end of the program run. The easiest way to avoid this is to use the
|
||||
`_CrtMemCheckpoint` and `_CrtMemDumpAllObjectsSince` calls to not report any
|
||||
@@ -626,7 +625,7 @@ things accordingly, you are leaking test-only logic into production code and
|
||||
there is no easy way to ensure that the test-only code paths aren't run by
|
||||
mistake in production. Such cleverness also leads to
|
||||
[Heisenbugs](https://en.wikipedia.org/wiki/Heisenbug). Therefore we strongly
|
||||
advise against the practice, and googletest doesn't provide a way to do it.
|
||||
advise against the practice, and GoogleTest doesn't provide a way to do it.
|
||||
|
||||
In general, the recommended way to cause the code to behave differently under
|
||||
test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject
|
||||
@@ -673,7 +672,7 @@ TEST(CoolTest, DoSomething) {
|
||||
```
|
||||
|
||||
However, the following code is **not allowed** and will produce a runtime error
|
||||
from googletest because the test methods are using different test fixture
|
||||
from GoogleTest because the test methods are using different test fixture
|
||||
classes with the same test suite name.
|
||||
|
||||
```c++
|
@@ -8,7 +8,7 @@ Given
|
||||
|
||||
```cpp
|
||||
class Foo {
|
||||
...
|
||||
public:
|
||||
virtual ~Foo();
|
||||
virtual int GetSize() const = 0;
|
||||
virtual string Describe(const char* name) = 0;
|
||||
@@ -23,7 +23,7 @@ class Foo {
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
class MockFoo : public Foo {
|
||||
...
|
||||
public:
|
||||
MOCK_METHOD(int, GetSize, (), (const, override));
|
||||
MOCK_METHOD(string, Describe, (const char* name), (override));
|
||||
MOCK_METHOD(string, Describe, (int type), (override));
|
||||
@@ -58,7 +58,7 @@ To mock
|
||||
```cpp
|
||||
template <typename Elem>
|
||||
class StackInterface {
|
||||
...
|
||||
public:
|
||||
virtual ~StackInterface();
|
||||
virtual int GetSize() const = 0;
|
||||
virtual void Push(const Elem& x) = 0;
|
||||
@@ -71,7 +71,7 @@ class StackInterface {
|
||||
```cpp
|
||||
template <typename Elem>
|
||||
class MockStack : public StackInterface<Elem> {
|
||||
...
|
||||
public:
|
||||
MOCK_METHOD(int, GetSize, (), (const, override));
|
||||
MOCK_METHOD(void, Push, (const Elem& x), (override));
|
||||
};
|
||||
@@ -140,7 +140,7 @@ To customize the default action for functions with return type `T`, use
|
||||
// Sets the default action for return type std::unique_ptr<Buzz> to
|
||||
// creating a new Buzz every time.
|
||||
DefaultValue<std::unique_ptr<Buzz>>::SetFactory(
|
||||
[] { return MakeUnique<Buzz>(AccessLevel::kInternal); });
|
||||
[] { return std::make_unique<Buzz>(AccessLevel::kInternal); });
|
||||
|
||||
// When this fires, the default action of MakeBuzz() will run, which
|
||||
// will return a new Buzz object.
|
||||
@@ -230,7 +230,7 @@ class MockFunction<R(A1, ..., An)> {
|
||||
};
|
||||
```
|
||||
|
||||
See this [recipe](gmock_cook_book.md#using-check-points) for one application of
|
||||
See this [recipe](gmock_cook_book.md#UsingCheckPoints) for one application of
|
||||
it.
|
||||
|
||||
## Flags
|
@@ -392,8 +392,7 @@ Old macros and their new equivalents:
|
||||
If a mock method has no `EXPECT_CALL` spec but is called, we say that it's an
|
||||
"uninteresting call", and the default action (which can be specified using
|
||||
`ON_CALL()`) of the method will be taken. Currently, an uninteresting call will
|
||||
also by default cause gMock to print a warning. (In the future, we might remove
|
||||
this warning by default.)
|
||||
also by default cause gMock to print a warning.
|
||||
|
||||
However, sometimes you may want to ignore these uninteresting calls, and
|
||||
sometimes you may want to treat them as errors. gMock lets you make the decision
|
||||
@@ -905,7 +904,7 @@ using ::testing::Contains;
|
||||
using ::testing::Property;
|
||||
|
||||
inline constexpr auto HasFoo = [](const auto& f) {
|
||||
return Property(&MyClass::foo, Contains(f));
|
||||
return Property("foo", &MyClass::foo, Contains(f));
|
||||
};
|
||||
...
|
||||
EXPECT_THAT(x, HasFoo("blah"));
|
||||
@@ -1084,7 +1083,7 @@ using ::testing::Lt;
|
||||
```
|
||||
|
||||
says that `Blah` will be called with arguments `x`, `y`, and `z` where `x < y <
|
||||
z`. Note that in this example, it wasn't necessary specify the positional
|
||||
z`. Note that in this example, it wasn't necessary to specify the positional
|
||||
matchers.
|
||||
|
||||
As a convenience and example, gMock provides some matchers for 2-tuples,
|
||||
@@ -1159,7 +1158,7 @@ int IsEven(int n) { return (n % 2) == 0 ? 1 : 0; }
|
||||
```
|
||||
|
||||
Note that the predicate function / functor doesn't have to return `bool`. It
|
||||
works as long as the return value can be used as the condition in in statement
|
||||
works as long as the return value can be used as the condition in the statement
|
||||
`if (condition) ...`.
|
||||
|
||||
### Matching Arguments that Are Not Copyable
|
||||
@@ -1300,23 +1299,27 @@ What if you have a pointer to pointer? You guessed it - you can use nested
|
||||
`Pointee(Pointee(Lt(3)))` matches a pointer that points to a pointer that points
|
||||
to a number less than 3 (what a mouthful...).
|
||||
|
||||
### Testing a Certain Property of an Object
|
||||
### Defining a Custom Matcher Class {#CustomMatcherClass}
|
||||
|
||||
Sometimes you want to specify that an object argument has a certain property,
|
||||
but there is no existing matcher that does this. If you want good error
|
||||
messages, you should [define a matcher](#NewMatchers). If you want to do it
|
||||
quick and dirty, you could get away with writing an ordinary function.
|
||||
Most matchers can be simply defined using [the MATCHER* macros](#NewMatchers),
|
||||
which are terse and flexible, and produce good error messages. However, these
|
||||
macros are not very explicit about the interfaces they create and are not always
|
||||
suitable, especially for matchers that will be widely reused.
|
||||
|
||||
Let's say you have a mock function that takes an object of type `Foo`, which has
|
||||
an `int bar()` method and an `int baz()` method, and you want to constrain that
|
||||
the argument's `bar()` value plus its `baz()` value is a given number. Here's
|
||||
how you can define a matcher to do it:
|
||||
For more advanced cases, you may need to define your own matcher class. A custom
|
||||
matcher allows you to test a specific invariant property of that object. Let's
|
||||
take a look at how to do so.
|
||||
|
||||
Imagine you have a mock function that takes an object of type `Foo`, which has
|
||||
an `int bar()` method and an `int baz()` method. You want to constrain that the
|
||||
argument's `bar()` value plus its `baz()` value is a given number. (This is an
|
||||
invariant.) Here's how we can write and use a matcher class to do so:
|
||||
|
||||
```cpp
|
||||
using ::testing::Matcher;
|
||||
|
||||
class BarPlusBazEqMatcher {
|
||||
public:
|
||||
using is_gtest_matcher = void;
|
||||
|
||||
explicit BarPlusBazEqMatcher(int expected_sum)
|
||||
: expected_sum_(expected_sum) {}
|
||||
|
||||
@@ -1325,23 +1328,24 @@ class BarPlusBazEqMatcher {
|
||||
return (foo.bar() + foo.baz()) == expected_sum_;
|
||||
}
|
||||
|
||||
void DescribeTo(std::ostream& os) const {
|
||||
os << "bar() + baz() equals " << expected_sum_;
|
||||
void DescribeTo(std::ostream* os) const {
|
||||
*os << "bar() + baz() equals " << expected_sum_;
|
||||
}
|
||||
|
||||
void DescribeNegationTo(std::ostream& os) const {
|
||||
os << "bar() + baz() does not equal " << expected_sum_;
|
||||
void DescribeNegationTo(std::ostream* os) const {
|
||||
*os << "bar() + baz() does not equal " << expected_sum_;
|
||||
}
|
||||
private:
|
||||
const int expected_sum_;
|
||||
};
|
||||
|
||||
Matcher<const Foo&> BarPlusBazEq(int expected_sum) {
|
||||
::testing::Matcher<const Foo&> BarPlusBazEq(int expected_sum) {
|
||||
return BarPlusBazEqMatcher(expected_sum);
|
||||
}
|
||||
|
||||
...
|
||||
EXPECT_CALL(..., DoThis(BarPlusBazEq(5)))...;
|
||||
Foo foo;
|
||||
EXPECT_THAT(foo, BarPlusBazEq(5))...;
|
||||
```
|
||||
|
||||
### Matching Containers
|
||||
@@ -1420,11 +1424,12 @@ Use `Pair` when comparing maps or other associative containers.
|
||||
{% raw %}
|
||||
|
||||
```cpp
|
||||
using testing::ElementsAre;
|
||||
using testing::Pair;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
using ::testing::Pair;
|
||||
...
|
||||
std::map<string, int> m = {{"a", 1}, {"b", 2}, {"c", 3}};
|
||||
EXPECT_THAT(m, ElementsAre(Pair("a", 1), Pair("b", 2), Pair("c", 3)));
|
||||
absl::flat_hash_map<string, int> m = {{"a", 1}, {"b", 2}, {"c", 3}};
|
||||
EXPECT_THAT(m, UnorderedElementsAre(
|
||||
Pair("a", 1), Pair("b", 2), Pair("c", 3)));
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
@@ -1441,8 +1446,8 @@ using testing::Pair;
|
||||
* If the container is passed by pointer instead of by reference, just write
|
||||
`Pointee(ElementsAre*(...))`.
|
||||
* The order of elements *matters* for `ElementsAre*()`. If you are using it
|
||||
with containers whose element order are undefined (e.g. `hash_map`) you
|
||||
should use `WhenSorted` around `ElementsAre`.
|
||||
with containers whose element order are undefined (such as a
|
||||
`std::unordered_map`) you should use `UnorderedElementsAre`.
|
||||
|
||||
### Sharing Matchers
|
||||
|
||||
@@ -1452,7 +1457,7 @@ the pointer is copied. When the last matcher that references the implementation
|
||||
object dies, the implementation object will be deleted.
|
||||
|
||||
Therefore, if you have some complex matcher that you want to use again and
|
||||
again, there is no need to build it everytime. Just assign it to a matcher
|
||||
again, there is no need to build it every time. Just assign it to a matcher
|
||||
variable and use that variable repeatedly! For example,
|
||||
|
||||
```cpp
|
||||
@@ -1754,7 +1759,7 @@ specifies the following DAG (where `s1` is `A -> B`, and `s2` is `A -> C -> D`):
|
||||
|
|
||||
A ---|
|
||||
|
|
||||
+---> C ---> D
|
||||
+---> C ---> D
|
||||
```
|
||||
|
||||
This means that A must occur before B and C, and C must occur before D. There's
|
||||
@@ -1899,7 +1904,7 @@ using testing::ReturnPointee;
|
||||
### Combining Actions
|
||||
|
||||
Want to do more than one thing when a function is called? That's fine. `DoAll()`
|
||||
allow you to do sequence of actions every time. Only the return value of the
|
||||
allows you to do a sequence of actions every time. Only the return value of the
|
||||
last action in the sequence will be used.
|
||||
|
||||
```cpp
|
||||
@@ -1980,6 +1985,7 @@ If the mock method also needs to return a value as well, you can chain
|
||||
|
||||
```cpp
|
||||
using ::testing::_;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
|
||||
@@ -2033,10 +2039,7 @@ class MockRolodex : public Rolodex {
|
||||
}
|
||||
...
|
||||
MockRolodex rolodex;
|
||||
vector<string> names;
|
||||
names.push_back("George");
|
||||
names.push_back("John");
|
||||
names.push_back("Thomas");
|
||||
vector<string> names = {"George", "John", "Thomas"};
|
||||
EXPECT_CALL(rolodex, GetNames(_))
|
||||
.WillOnce(SetArrayArgument<0>(names.begin(), names.end()));
|
||||
```
|
||||
@@ -2604,7 +2607,7 @@ efficient. When the last action that references the implementation object dies,
|
||||
the implementation object will be deleted.
|
||||
|
||||
If you have some complex action that you want to use again and again, you may
|
||||
not have to build it from scratch everytime. If the action doesn't have an
|
||||
not have to build it from scratch every time. If the action doesn't have an
|
||||
internal state (i.e. if it always does the same thing no matter how many times
|
||||
it has been called), you can assign it to an action variable and use that
|
||||
variable repeatedly. For example:
|
||||
@@ -2781,7 +2784,7 @@ If you just need to return a pre-defined move-only value, you can use the
|
||||
// When this fires, the unique_ptr<> specified by ByMove(...) will
|
||||
// be returned.
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("world"))
|
||||
.WillOnce(Return(ByMove(MakeUnique<Buzz>(AccessLevel::kInternal))));
|
||||
.WillOnce(Return(ByMove(std::make_unique<Buzz>(AccessLevel::kInternal))));
|
||||
|
||||
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("world"));
|
||||
```
|
||||
@@ -2802,7 +2805,7 @@ pretty much anything you want:
|
||||
```cpp
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("x"))
|
||||
.WillRepeatedly([](StringPiece text) {
|
||||
return MakeUnique<Buzz>(AccessLevel::kInternal);
|
||||
return std::make_unique<Buzz>(AccessLevel::kInternal);
|
||||
});
|
||||
|
||||
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x"));
|
||||
@@ -2821,7 +2824,7 @@ can always use `Return`, or a [lambda or functor](#FunctionsAsActions):
|
||||
using ::testing::Unused;
|
||||
|
||||
EXPECT_CALL(mock_buzzer_, ShareBuzz(NotNull(), _)).WillOnce(Return(true));
|
||||
EXPECT_TRUE(mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal)),
|
||||
EXPECT_TRUE(mock_buzzer_.ShareBuzz(std::make_unique<Buzz>(AccessLevel::kInternal)),
|
||||
0);
|
||||
|
||||
EXPECT_CALL(mock_buzzer_, ShareBuzz(_, _)).WillOnce(
|
||||
@@ -2865,7 +2868,7 @@ method:
|
||||
// When one calls ShareBuzz() on the MockBuzzer like this, the call is
|
||||
// forwarded to DoShareBuzz(), which is mocked. Therefore this statement
|
||||
// will trigger the above EXPECT_CALL.
|
||||
mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal), 0);
|
||||
mock_buzzer_.ShareBuzz(std::make_unique<Buzz>(AccessLevel::kInternal), 0);
|
||||
```
|
||||
|
||||
### Making the Compilation Faster
|
||||
@@ -3809,22 +3812,19 @@ Cardinality EvenNumber() {
|
||||
.Times(EvenNumber());
|
||||
```
|
||||
|
||||
### Writing New Actions Quickly {#QuickNewActions}
|
||||
### Writing New Actions {#QuickNewActions}
|
||||
|
||||
If the built-in actions don't work for you, you can easily define your own one.
|
||||
Just define a functor class with a (possibly templated) call operator, matching
|
||||
the signature of your action.
|
||||
All you need is a call operator with a signature compatible with the mocked
|
||||
function. So you can use a lambda:
|
||||
|
||||
```cpp
|
||||
struct Increment {
|
||||
template <typename T>
|
||||
T operator()(T* arg) {
|
||||
return ++(*arg);
|
||||
}
|
||||
}
|
||||
```
|
||||
MockFunction<int(int)> mock;
|
||||
EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; });
|
||||
EXPECT_EQ(14, mock.AsStdFunction()(2));
|
||||
```
|
||||
|
||||
The same approach works with stateful functors (or any callable, really):
|
||||
Or a struct with a call operator (even a templated one):
|
||||
|
||||
```
|
||||
struct MultiplyBy {
|
||||
@@ -3832,12 +3832,54 @@ struct MultiplyBy {
|
||||
T operator()(T arg) { return arg * multiplier; }
|
||||
|
||||
int multiplier;
|
||||
}
|
||||
};
|
||||
|
||||
// Then use:
|
||||
// EXPECT_CALL(...).WillOnce(MultiplyBy{7});
|
||||
```
|
||||
|
||||
It's also fine for the callable to take no arguments, ignoring the arguments
|
||||
supplied to the mock function:
|
||||
|
||||
```
|
||||
MockFunction<int(int)> mock;
|
||||
EXPECT_CALL(mock, Call).WillOnce([] { return 17; });
|
||||
EXPECT_EQ(17, mock.AsStdFunction()(0));
|
||||
```
|
||||
|
||||
When used with `WillOnce`, the callable can assume it will be called at most
|
||||
once and is allowed to be a move-only type:
|
||||
|
||||
```
|
||||
// An action that contains move-only types and has an &&-qualified operator,
|
||||
// demanding in the type system that it be called at most once. This can be
|
||||
// used with WillOnce, but the compiler will reject it if handed to
|
||||
// WillRepeatedly.
|
||||
struct MoveOnlyAction {
|
||||
std::unique_ptr<int> move_only_state;
|
||||
std::unique_ptr<int> operator()() && { return std::move(move_only_state); }
|
||||
};
|
||||
|
||||
MockFunction<std::unique_ptr<int>()> mock;
|
||||
EXPECT_CALL(mock, Call).WillOnce(MoveOnlyAction{std::make_unique<int>(17)});
|
||||
EXPECT_THAT(mock.AsStdFunction()(), Pointee(Eq(17)));
|
||||
```
|
||||
|
||||
More generally, to use with a mock function whose signature is `R(Args...)` the
|
||||
object can be anything convertible to `OnceAction<R(Args...)>` or
|
||||
`Action<R(Args...)`>. The difference between the two is that `OnceAction` has
|
||||
weaker requirements (`Action` requires a copy-constructible input that can be
|
||||
called repeatedly whereas `OnceAction` requires only move-constructible and
|
||||
supports `&&`-qualified call operators), but can be used only with `WillOnce`.
|
||||
`OnceAction` is typically relevant only when supporting move-only types or
|
||||
actions that want a type-system guarantee that they will be called at most once.
|
||||
|
||||
Typically the `OnceAction` and `Action` templates need not be referenced
|
||||
directly in your actions: a struct or class with a call operator is sufficient,
|
||||
as in the examples above. But fancier polymorphic actions that need to know the
|
||||
specific return type of the mock function can define templated conversion
|
||||
operators to make that possible. See `gmock-actions.h` for examples.
|
||||
|
||||
#### Legacy macro-based Actions
|
||||
|
||||
Before C++11, the functor-based actions were not supported; the old way of
|
||||
@@ -4191,7 +4233,7 @@ This implementation class does *not* need to inherit from any particular class.
|
||||
What matters is that it must have a `Perform()` method template. This method
|
||||
template takes the mock function's arguments as a tuple in a **single**
|
||||
argument, and returns the result of the action. It can be either `const` or not,
|
||||
but must be invokable with exactly one template argument, which is the result
|
||||
but must be invocable with exactly one template argument, which is the result
|
||||
type. In other words, you must be able to call `Perform<R>(args)` where `R` is
|
||||
the mock function's return type and `args` is its arguments in a tuple.
|
||||
|
@@ -369,8 +369,8 @@ Usually, if your action is for a particular function type, defining it using
|
||||
different types (e.g. if you are defining `Return(*value*)`),
|
||||
`MakePolymorphicAction()` is easiest. Sometimes you want precise control on what
|
||||
types of functions the action can be used in, and implementing `ActionInterface`
|
||||
is the way to go here. See the implementation of `Return()` in
|
||||
`testing/base/public/gmock-actions.h` for an example.
|
||||
is the way to go here. See the implementation of `Return()` in `gmock-actions.h`
|
||||
for an example.
|
||||
|
||||
### I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting return type specified". What does it mean?
|
||||
|
@@ -190,10 +190,10 @@ Some people put it in a `_test.cc`. This is fine when the interface being mocked
|
||||
`Foo` changes it, your test could break. (You can't really expect `Foo`'s
|
||||
maintainer to fix every test that uses `Foo`, can you?)
|
||||
|
||||
So, the rule of thumb is: if you need to mock `Foo` and it's owned by others,
|
||||
define the mock class in `Foo`'s package (better, in a `testing` sub-package
|
||||
such that you can clearly separate production code and testing utilities), put
|
||||
it in a `.h` and a `cc_library`. Then everyone can reference them from their
|
||||
Generally, you should not mock classes you don't own. If you must mock such a
|
||||
class owned by others, define the mock class in `Foo`'s Bazel package (usually
|
||||
the same directory or a `testing` sub-directory), and put it in a `.h` and a
|
||||
`cc_library` with `testonly=True`. Then everyone can reference them from their
|
||||
tests. If `Foo` ever changes, there is only one copy of `MockFoo` to change, and
|
||||
only tests that depend on the changed methods need to be fixed.
|
||||
|
||||
@@ -480,8 +480,8 @@ the *default* action for the function every time (unless, of course, you have a
|
||||
`WillRepeatedly()`.).
|
||||
|
||||
What can we do inside `WillOnce()` besides `Return()`? You can return a
|
||||
reference using `ReturnRef(*variable*)`, or invoke a pre-defined function, among
|
||||
[others](gmock_cook_book.md#using-actions).
|
||||
reference using `ReturnRef(`*`variable`*`)`, or invoke a pre-defined function,
|
||||
among [others](gmock_cook_book.md#using-actions).
|
||||
|
||||
**Important note:** The `EXPECT_CALL()` statement evaluates the action clause
|
||||
only once, even though the action may be performed many times. Therefore you
|
@@ -105,7 +105,7 @@ includedir=/usr/include
|
||||
|
||||
Name: gtest
|
||||
Description: GoogleTest (without main() function)
|
||||
Version: 1.10.0
|
||||
Version: 1.11.0
|
||||
URL: https://github.com/google/googletest
|
||||
Libs: -L${libdir} -lgtest -lpthread
|
||||
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread
|
@@ -162,9 +162,9 @@ TEST(TestSuiteName, TestName) {
|
||||
|
||||
`TEST()` arguments go from general to specific. The *first* argument is the name
|
||||
of the test suite, and the *second* argument is the test's name within the test
|
||||
suite. Both names must be valid C++ identifiers, and they should not contain
|
||||
any underscores (`_`). A test's *full name* consists of its containing test suite and
|
||||
its individual name. Tests from different test suites can have the same
|
||||
suite. Both names must be valid C++ identifiers, and they should not contain any
|
||||
underscores (`_`). A test's *full name* consists of its containing test suite
|
||||
and its individual name. Tests from different test suites can have the same
|
||||
individual name.
|
||||
|
||||
For example, let's take a simple integer function:
|
||||
@@ -245,8 +245,8 @@ Also, you must first define a test fixture class before using it in a
|
||||
declaration`".
|
||||
|
||||
For each test defined with `TEST_F()`, googletest will create a *fresh* test
|
||||
fixture at runtime, immediately initialize it via `SetUp()`, run the test,
|
||||
clean up by calling `TearDown()`, and then delete the test fixture. Note that
|
||||
fixture at runtime, immediately initialize it via `SetUp()`, run the test, clean
|
||||
up by calling `TearDown()`, and then delete the test fixture. Note that
|
||||
different tests in the same test suite have different test fixture objects, and
|
||||
googletest always deletes a test fixture before it creates the next one.
|
||||
googletest does **not** reuse the same test fixture for multiple tests. Any
|
||||
@@ -274,6 +274,7 @@ First, define a fixture class. By convention, you should give it the name
|
||||
class QueueTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// q0_ remains empty
|
||||
q1_.Enqueue(1);
|
||||
q2_.Enqueue(2);
|
||||
q2_.Enqueue(3);
|
||||
@@ -342,8 +343,8 @@ your defined tests in order to run them.
|
||||
|
||||
After defining your tests, you can run them with `RUN_ALL_TESTS()`, which
|
||||
returns `0` if all the tests are successful, or `1` otherwise. Note that
|
||||
`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from
|
||||
different test suites, or even different source files.
|
||||
`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from different
|
||||
test suites, or even different source files.
|
||||
|
||||
When invoked, the `RUN_ALL_TESTS()` macro:
|
||||
|
||||
@@ -456,8 +457,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
The `::testing::InitGoogleTest()` function parses the command line for
|
||||
googletest flags, and removes all recognized flags. This allows the user to
|
||||
control a test program's behavior via various flags, which we'll cover in
|
||||
the [AdvancedGuide](advanced.md). You **must** call this function before calling
|
||||
control a test program's behavior via various flags, which we'll cover in the
|
||||
[AdvancedGuide](advanced.md). You **must** call this function before calling
|
||||
`RUN_ALL_TESTS()`, or the flags won't be properly initialized.
|
||||
|
||||
On Windows, `InitGoogleTest()` also works with wide strings, so it can be used
|
@@ -9,7 +9,7 @@ we recommend this tutorial as a starting point.
|
||||
To complete this tutorial, you'll need:
|
||||
|
||||
* A compatible operating system (e.g. Linux, macOS, Windows).
|
||||
* A compatible C++ compiler that supports at least C++11.
|
||||
* A compatible C++ compiler that supports at least C++14.
|
||||
* [Bazel](https://bazel.build/), the preferred build system used by the
|
||||
GoogleTest team.
|
||||
|
||||
@@ -17,16 +17,15 @@ See [Supported Platforms](platforms.md) for more information about platforms
|
||||
compatible with GoogleTest.
|
||||
|
||||
If you don't already have Bazel installed, see the
|
||||
[Bazel installation guide](https://docs.bazel.build/versions/master/install.html).
|
||||
[Bazel installation guide](https://bazel.build/install).
|
||||
|
||||
{: .callout .note}
|
||||
Note: The terminal commands in this tutorial show a Unix shell prompt, but the
|
||||
commands work on the Windows command line as well.
|
||||
{: .callout .note} Note: The terminal commands in this tutorial show a Unix
|
||||
shell prompt, but the commands work on the Windows command line as well.
|
||||
|
||||
## Set up a Bazel workspace
|
||||
|
||||
A
|
||||
[Bazel workspace](https://docs.bazel.build/versions/master/build-ref.html#workspace)
|
||||
[Bazel workspace](https://docs.bazel.build/versions/main/build-ref.html#workspace)
|
||||
is a directory on your filesystem that you use to manage source files for the
|
||||
software you want to build. Each workspace directory has a text file named
|
||||
`WORKSPACE` which may be empty, or may contain references to external
|
||||
@@ -40,9 +39,9 @@ $ mkdir my_workspace && cd my_workspace
|
||||
|
||||
Next, you’ll create the `WORKSPACE` file to specify dependencies. A common and
|
||||
recommended way to depend on GoogleTest is to use a
|
||||
[Bazel external dependency](https://docs.bazel.build/versions/master/external.html)
|
||||
[Bazel external dependency](https://docs.bazel.build/versions/main/external.html)
|
||||
via the
|
||||
[`http_archive` rule](https://docs.bazel.build/versions/master/repo/http.html#http_archive).
|
||||
[`http_archive` rule](https://docs.bazel.build/versions/main/repo/http.html#http_archive).
|
||||
To do this, in the root directory of your workspace (`my_workspace/`), create a
|
||||
file named `WORKSPACE` with the following contents:
|
||||
|
||||
@@ -51,28 +50,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "com_google_googletest",
|
||||
urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"],
|
||||
strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5",
|
||||
urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"],
|
||||
strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015",
|
||||
)
|
||||
```
|
||||
|
||||
The above configuration declares a dependency on GoogleTest which is downloaded
|
||||
as a ZIP archive from GitHub. In the above example,
|
||||
`609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is the Git commit hash of the
|
||||
`5ab508a01f9eb089207ee87fd547d290da39d015` is the Git commit hash of the
|
||||
GoogleTest version to use; we recommend updating the hash often to point to the
|
||||
latest version.
|
||||
|
||||
Bazel also needs a dependency on the
|
||||
[`rules_cc` repository](https://github.com/bazelbuild/rules_cc) to build C++
|
||||
code, so add the following to the `WORKSPACE` file:
|
||||
|
||||
```
|
||||
http_archive(
|
||||
name = "rules_cc",
|
||||
urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"],
|
||||
strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556",
|
||||
)
|
||||
```
|
||||
latest version. Use a recent hash on the `main` branch.
|
||||
|
||||
Now you're ready to build C++ code that uses GoogleTest.
|
||||
|
||||
@@ -104,8 +91,6 @@ To build the code, create a file named `BUILD` in the same directory with the
|
||||
following contents:
|
||||
|
||||
```
|
||||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||
|
||||
cc_test(
|
||||
name = "hello_test",
|
||||
size = "small",
|
||||
@@ -118,7 +103,7 @@ This `cc_test` rule declares the C++ test binary you want to build, and links to
|
||||
GoogleTest (`//:gtest_main`) using the prefix you specified in the `WORKSPACE`
|
||||
file (`@com_google_googletest`). For more information about Bazel `BUILD` files,
|
||||
see the
|
||||
[Bazel C++ Tutorial](https://docs.bazel.build/versions/master/tutorial/cpp.html).
|
||||
[Bazel C++ Tutorial](https://docs.bazel.build/versions/main/tutorial/cpp.html).
|
||||
|
||||
Now you can build and run your test:
|
||||
|
@@ -10,7 +10,7 @@ this tutorial as a starting point. If your project uses Bazel, see the
|
||||
To complete this tutorial, you'll need:
|
||||
|
||||
* A compatible operating system (e.g. Linux, macOS, Windows).
|
||||
* A compatible C++ compiler that supports at least C++11.
|
||||
* A compatible C++ compiler that supports at least C++14.
|
||||
* [CMake](https://cmake.org/) and a compatible build tool for building the
|
||||
project.
|
||||
* Compatible build tools include
|
||||
@@ -52,13 +52,13 @@ To do this, in your project directory (`my_project`), create a file named
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(my_project)
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
# GoogleTest requires at least C++14
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
|
||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
@@ -66,7 +66,7 @@ FetchContent_MakeAvailable(googletest)
|
||||
```
|
||||
|
||||
The above configuration declares a dependency on GoogleTest which is downloaded
|
||||
from GitHub. In the above example, `609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is
|
||||
from GitHub. In the above example, `03597a01ee50ed33e9dfd640b249b4be3799d395` is
|
||||
the Git commit hash of the GoogleTest version to use; we recommend updating the
|
||||
hash often to point to the latest version.
|
||||
|
||||
@@ -108,7 +108,7 @@ add_executable(
|
||||
)
|
||||
target_link_libraries(
|
||||
hello_test
|
||||
gtest_main
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
@@ -6,7 +6,7 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace.
|
||||
|
||||
## Returning a Value
|
||||
|
||||
| | |
|
||||
| Action | Description |
|
||||
| :-------------------------------- | :-------------------------------------------- |
|
||||
| `Return()` | Return from a `void` mock function. |
|
||||
| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. |
|
||||
@@ -20,7 +20,7 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace.
|
||||
|
||||
## Side Effects
|
||||
|
||||
| | |
|
||||
| Action | Description |
|
||||
| :--------------------------------- | :-------------------------------------- |
|
||||
| `Assign(&variable, value)` | Assign `value` to variable. |
|
||||
| `DeleteArg<N>()` | Delete the `N`-th (0-based) argument, which must be a pointer. |
|
||||
@@ -38,9 +38,9 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace.
|
||||
In the following, by "callable" we mean a free function, `std::function`,
|
||||
functor, or lambda.
|
||||
|
||||
| | |
|
||||
| Action | Description |
|
||||
| :---------------------------------- | :------------------------------------- |
|
||||
| `f` | Invoke f with the arguments passed to the mock function, where f is a callable. |
|
||||
| `f` | Invoke `f` with the arguments passed to the mock function, where `f` is a callable. |
|
||||
| `Invoke(f)` | Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor. |
|
||||
| `Invoke(object_pointer, &class::method)` | Invoke the method on the object with the arguments passed to the mock function. |
|
||||
| `InvokeWithoutArgs(f)` | Invoke `f`, which can be a global/static function or a functor. `f` must take no arguments. |
|
||||
@@ -86,7 +86,7 @@ value, and `foo` by reference.
|
||||
|
||||
## Default Action
|
||||
|
||||
| Matcher | Description |
|
||||
| Action | Description |
|
||||
| :------------ | :----------------------------------------------------- |
|
||||
| `DoDefault()` | Do the default action (specified by `ON_CALL()` or the built-in one). |
|
||||
|
||||
@@ -96,7 +96,7 @@ composite action - trying to do so will result in a run-time error.
|
||||
|
||||
## Composite Actions
|
||||
|
||||
| | |
|
||||
| Action | Description |
|
||||
| :----------------------------- | :------------------------------------------ |
|
||||
| `DoAll(a1, a2, ..., an)` | Do all actions `a1` to `an` and return the result of `an` in each invocation. The first `n - 1` sub-actions must return void and will receive a readonly view of the arguments. |
|
||||
| `IgnoreResult(a)` | Perform action `a` and ignore its result. `a` must not return void. |
|
||||
@@ -106,7 +106,7 @@ composite action - trying to do so will result in a run-time error.
|
||||
|
||||
## Defining Actions
|
||||
|
||||
| | |
|
||||
| Macro | Description |
|
||||
| :--------------------------------- | :-------------------------------------- |
|
||||
| `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. |
|
||||
| `ACTION_P(Plus, n) { return arg0 + n; }` | Defines an action `Plus(n)` to return the sum of the mock function's argument #0 and `n`. |
|
@@ -8,9 +8,13 @@ A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
|
||||
| `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. |
|
||||
| `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. |
|
||||
|
||||
{: .callout .note}
|
||||
**Note:** Although equality matching via `EXPECT_THAT(actual_value,
|
||||
expected_value)` is supported, prefer to make the comparison explicit via
|
||||
{: .callout .warning}
|
||||
**WARNING:** Equality matching via `EXPECT_THAT(actual_value, expected_value)`
|
||||
is supported, however note that implicit conversions can cause surprising
|
||||
results. For example, `EXPECT_THAT(some_bool, "some string")` will compile and
|
||||
may pass unintentionally.
|
||||
|
||||
**BEST PRACTICE:** Prefer to make the comparison explicit via
|
||||
`EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value,
|
||||
expected_value)`.
|
||||
|
||||
@@ -88,16 +92,17 @@ The `argument` can be either a C string or a C++ string object:
|
||||
|
||||
| Matcher | Description |
|
||||
| :---------------------- | :------------------------------------------------- |
|
||||
| `ContainsRegex(string)` | `argument` matches the given regular expression. |
|
||||
| `EndsWith(suffix)` | `argument` ends with string `suffix`. |
|
||||
| `HasSubstr(string)` | `argument` contains `string` as a sub-string. |
|
||||
| `IsEmpty()` | `argument` is an empty string. |
|
||||
| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. |
|
||||
| `StartsWith(prefix)` | `argument` starts with string `prefix`. |
|
||||
| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. |
|
||||
| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. |
|
||||
| `StrEq(string)` | `argument` is equal to `string`. |
|
||||
| `StrNe(string)` | `argument` is not equal to `string`. |
|
||||
| `ContainsRegex(string)` | `argument` matches the given regular expression. |
|
||||
| `EndsWith(suffix)` | `argument` ends with string `suffix`. |
|
||||
| `HasSubstr(string)` | `argument` contains `string` as a sub-string. |
|
||||
| `IsEmpty()` | `argument` is an empty string. |
|
||||
| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. |
|
||||
| `StartsWith(prefix)` | `argument` starts with string `prefix`. |
|
||||
| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. |
|
||||
| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. |
|
||||
| `StrEq(string)` | `argument` is equal to `string`. |
|
||||
| `StrNe(string)` | `argument` is not equal to `string`. |
|
||||
| `WhenBase64Unescaped(m)` | `argument` is a base-64 escaped string whose unescaped string matches `m`. |
|
||||
|
||||
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
|
||||
use the regular expression syntax defined
|
||||
@@ -116,6 +121,7 @@ messages, you can use:
|
||||
| `BeginEndDistanceIs(m)` | `argument` is a container whose `begin()` and `end()` iterators are separated by a number of increments matching `m`. E.g. `BeginEndDistanceIs(2)` or `BeginEndDistanceIs(Lt(2))`. For containers that define a `size()` method, `SizeIs(m)` may be more efficient. |
|
||||
| `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. |
|
||||
| `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. |
|
||||
| `Contains(e).Times(n)` | `argument` contains elements that match `e`, which can be either a value or a matcher, and the number of matches is `n`, which can be either a value or a matcher. Unlike the plain `Contains` and `Each` this allows to check for arbitrary occurrences including testing for absence with `Contains(e).Times(0)`. |
|
||||
| `Each(e)` | `argument` is a container where *every* element matches `e`, which can be either a value or a matcher. |
|
||||
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. |
|
||||
| `ElementsAreArray({e0, e1, ..., en})`, `ElementsAreArray(a_container)`, `ElementsAreArray(begin, end)`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. |
|
||||
@@ -146,7 +152,6 @@ messages, you can use:
|
||||
one might write:
|
||||
|
||||
```cpp
|
||||
using ::std::get;
|
||||
MATCHER(FooEq, "") {
|
||||
return std::get<0>(arg).Equals(std::get<1>(arg));
|
||||
}
|
||||
@@ -193,6 +198,7 @@ messages, you can use:
|
||||
| Matcher | Description |
|
||||
| :--------------- | :------------------------------------------------ |
|
||||
| `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. |
|
||||
| `ResultOf(result_description, f, m)` | The same as the two-parameter version, but provides a better error message.
|
||||
|
||||
## Pointer Matchers
|
||||
|
||||
@@ -237,6 +243,7 @@ You can make a matcher from one or more other matchers:
|
||||
| `AnyOf(m1, m2, ..., mn)` | `argument` matches at least one of the matchers `m1` to `mn`. |
|
||||
| `AnyOfArray({m0, m1, ..., mn})`, `AnyOfArray(a_container)`, `AnyOfArray(begin, end)`, `AnyOfArray(array)`, or `AnyOfArray(array, count)` | The same as `AnyOf()` except that the matchers come from an initializer list, STL-style container, iterator range, or C-style array. |
|
||||
| `Not(m)` | `argument` doesn't match matcher `m`. |
|
||||
| `Conditional(cond, m1, m2)` | Matches matcher `m1` if `cond` evaluates to true, else matches `m2`.|
|
||||
|
||||
## Adapters for Matchers
|
||||
|
||||
@@ -259,7 +266,7 @@ which must be a permanent callback.
|
||||
|
||||
## Defining Matchers
|
||||
|
||||
| Matcher | Description |
|
||||
| Macro | Description |
|
||||
| :----------------------------------- | :------------------------------------ |
|
||||
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |
|
||||
| `MATCHER_P(IsDivisibleBy, n, "") { *result_listener << "where the remainder is " << (arg % n); return (arg % n) == 0; }` | Defines a matcher `IsDivisibleBy(n)` to match a number divisible by `n`. |
|
@@ -248,7 +248,9 @@ EXPECT_CALL(my_mock, GetNumber())
|
||||
.WillOnce(Return(3));
|
||||
```
|
||||
|
||||
The `WillOnce` clause can be used any number of times on an expectation.
|
||||
The `WillOnce` clause can be used any number of times on an expectation. Unlike
|
||||
`WillRepeatedly`, the action fed to each `WillOnce` call will be called at most
|
||||
once, so may be a move-only type and/or have an `&&`-qualified call operator.
|
||||
|
||||
#### WillRepeatedly {#EXPECT_CALL.WillRepeatedly}
|
||||
|
@@ -109,7 +109,7 @@ namespace:
|
||||
| `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. |
|
||||
| `Bool()` | Yields sequence `{false, true}`. |
|
||||
| `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. |
|
||||
|
||||
| `ConvertGenerator<T>(g)` | Yields values generated by generator `g`, `static_cast` to `T`. |
|
||||
The optional last argument *`name_generator`* is a function or functor that
|
||||
generates custom test name suffixes based on the test parameters. The function
|
||||
must accept an argument of type
|
||||
@@ -518,8 +518,8 @@ Logs a property for the current test, test suite, or entire invocation of the
|
||||
test program. Only the last value for a given key is logged.
|
||||
|
||||
The key must be a valid XML attribute name, and cannot conflict with the ones
|
||||
already used by GoogleTest (`name`, `status`, `time`, `classname`, `type_param`,
|
||||
and `value_param`).
|
||||
already used by GoogleTest (`name`, `file`, `line`, `status`, `time`,
|
||||
`classname`, `type_param`, and `value_param`).
|
||||
|
||||
`RecordProperty` is `public static` so it can be called from utility functions
|
||||
that are not members of the test fixture.
|
@@ -1,7 +1,7 @@
|
||||
# Googletest Samples
|
||||
|
||||
If you're like us, you'd like to look at
|
||||
[googletest samples.](https://github.com/google/googletest/tree/master/googletest/samples)
|
||||
[googletest samples.](https://github.com/google/googletest/blob/main/googletest/samples)
|
||||
The sample directory has a number of well-commented samples showing how to use a
|
||||
variety of googletest features.
|
||||
|
@@ -36,13 +36,9 @@ endif()
|
||||
# as ${gmock_SOURCE_DIR} and to the root binary directory as
|
||||
# ${gmock_BINARY_DIR}.
|
||||
# Language "C" is required for find_package(Threads).
|
||||
if (CMAKE_VERSION VERSION_LESS 3.0)
|
||||
project(gmock CXX C)
|
||||
else()
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
|
||||
endif()
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
|
||||
|
||||
if (COMMAND set_up_hermetic_build)
|
||||
set_up_hermetic_build()
|
||||
@@ -109,11 +105,12 @@ endif()
|
||||
# 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).
|
||||
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
|
||||
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
|
||||
target_include_directories(gmock SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
target_include_directories(gmock_main SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
endif()
|
||||
|
||||
@@ -154,7 +151,10 @@ if (gmock_build_tests)
|
||||
cxx_test(gmock_ex_test gmock_main)
|
||||
cxx_test(gmock-function-mocker_test gmock_main)
|
||||
cxx_test(gmock-internal-utils_test gmock_main)
|
||||
cxx_test(gmock-matchers_test gmock_main)
|
||||
cxx_test(gmock-matchers-arithmetic_test gmock_main)
|
||||
cxx_test(gmock-matchers-comparisons_test gmock_main)
|
||||
cxx_test(gmock-matchers-containers_test gmock_main)
|
||||
cxx_test(gmock-matchers-misc_test gmock_main)
|
||||
cxx_test(gmock-more-actions_test gmock_main)
|
||||
cxx_test(gmock-nice-strict_test gmock_main)
|
||||
cxx_test(gmock-port_test gmock_main)
|
@@ -35,10 +35,6 @@ Details and examples can be found here:
|
||||
* [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html)
|
||||
* [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html)
|
||||
|
||||
Please note that code under scripts/generator/ is from the
|
||||
[cppclean project](http://code.google.com/p/cppclean/) and under the Apache
|
||||
License, which is different from GoogleMock's license.
|
||||
|
||||
GoogleMock is a part of
|
||||
[GoogleTest C++ testing framework](http://github.com/google/googletest/) and a
|
||||
subject to the same requirements.
|
File diff suppressed because it is too large
Load Diff
@@ -27,21 +27,23 @@
|
||||
// (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 cardinalities. More
|
||||
// cardinalities can be defined by the user implementing the
|
||||
// CardinalityInterface interface if necessary.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <memory>
|
||||
#include <ostream> // NOLINT
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -116,7 +118,7 @@ class GTEST_API_ Cardinality {
|
||||
// cardinality, i.e. exceed the maximum number of allowed calls.
|
||||
bool IsOverSaturatedByCallCount(int call_count) const {
|
||||
return impl_->IsSaturatedByCallCount(call_count) &&
|
||||
!impl_->IsSatisfiedByCallCount(call_count);
|
||||
!impl_->IsSatisfiedByCallCount(call_count);
|
||||
}
|
||||
|
||||
// Describes self to an ostream
|
@@ -31,10 +31,11 @@
|
||||
//
|
||||
// This file implements MOCK_METHOD.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_
|
||||
|
||||
#include <type_traits> // IWYU pragma: keep
|
||||
#include <utility> // IWYU pragma: keep
|
||||
@@ -64,6 +65,39 @@ struct ThisRefAdjuster {
|
||||
}
|
||||
};
|
||||
|
||||
constexpr bool PrefixOf(const char* a, const char* b) {
|
||||
return *a == 0 || (*a == *b && internal::PrefixOf(a + 1, b + 1));
|
||||
}
|
||||
|
||||
template <int N, int M>
|
||||
constexpr bool StartsWith(const char (&prefix)[N], const char (&str)[M]) {
|
||||
return N <= M && internal::PrefixOf(prefix, str);
|
||||
}
|
||||
|
||||
template <int N, int M>
|
||||
constexpr bool EndsWith(const char (&suffix)[N], const char (&str)[M]) {
|
||||
return N <= M && internal::PrefixOf(suffix, str + M - N);
|
||||
}
|
||||
|
||||
template <int N, int M>
|
||||
constexpr bool Equals(const char (&a)[N], const char (&b)[M]) {
|
||||
return N == M && internal::PrefixOf(a, b);
|
||||
}
|
||||
|
||||
template <int N>
|
||||
constexpr bool ValidateSpec(const char (&spec)[N]) {
|
||||
return internal::Equals("const", spec) ||
|
||||
internal::Equals("override", spec) ||
|
||||
internal::Equals("final", spec) ||
|
||||
internal::Equals("noexcept", spec) ||
|
||||
(internal::StartsWith("noexcept(", spec) &&
|
||||
internal::EndsWith(")", spec)) ||
|
||||
internal::Equals("ref(&)", spec) ||
|
||||
internal::Equals("ref(&&)", spec) ||
|
||||
(internal::StartsWith("Calltype(", spec) &&
|
||||
internal::EndsWith(")", spec));
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The style guide prohibits "using" statements in a namespace scope
|
||||
@@ -74,8 +108,11 @@ struct ThisRefAdjuster {
|
||||
using internal::FunctionMocker;
|
||||
} // namespace testing
|
||||
|
||||
#define MOCK_METHOD(...) \
|
||||
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
|
||||
#define MOCK_METHOD(...) \
|
||||
GMOCK_INTERNAL_WARNING_PUSH() \
|
||||
GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \
|
||||
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) \
|
||||
GMOCK_INTERNAL_WARNING_POP()
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \
|
||||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
|
||||
@@ -86,17 +123,18 @@ using internal::FunctionMocker;
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \
|
||||
GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ())
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
|
||||
GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
|
||||
GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
|
||||
GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
|
||||
GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
|
||||
GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \
|
||||
GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
|
||||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
|
||||
GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
|
||||
GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
|
||||
GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
|
||||
GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
|
||||
GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
|
||||
GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \
|
||||
GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Spec), \
|
||||
GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \
|
||||
(GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)))
|
||||
|
||||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \
|
||||
@@ -166,11 +204,11 @@ using internal::FunctionMocker;
|
||||
GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \
|
||||
} \
|
||||
mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \
|
||||
GMOCK_MOCKER_(_N, _Constness, _MethodName)
|
||||
GMOCK_MOCKER_(_N, _Constness, _MethodName)
|
||||
|
||||
#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__
|
||||
|
||||
// Five Valid modifiers.
|
||||
// Valid modifiers.
|
||||
#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple))
|
||||
|
||||
@@ -189,6 +227,14 @@ using internal::FunctionMocker;
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \
|
||||
_elem, )
|
||||
|
||||
#define GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Tuple) \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE, ~, _Tuple)
|
||||
|
||||
#define GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE(_i, _, _elem) \
|
||||
GMOCK_PP_IF( \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem)), \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), )
|
||||
|
||||
#define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple)
|
||||
|
||||
@@ -196,19 +242,25 @@ using internal::FunctionMocker;
|
||||
GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), )
|
||||
|
||||
#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \
|
||||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple)
|
||||
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
|
||||
static_assert( \
|
||||
(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \
|
||||
GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \
|
||||
GMOCK_PP_STRINGIZE( \
|
||||
#ifdef GMOCK_INTERNAL_STRICT_SPEC_ASSERT
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
|
||||
static_assert( \
|
||||
::testing::internal::ValidateSpec(GMOCK_PP_STRINGIZE(_elem)), \
|
||||
"Token \'" GMOCK_PP_STRINGIZE( \
|
||||
_elem) "\' cannot be recognized as a valid specification " \
|
||||
"modifier. Is a ',' missing?");
|
||||
#else
|
||||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
|
||||
static_assert( \
|
||||
(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \
|
||||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem))) == 1, \
|
||||
GMOCK_PP_STRINGIZE( \
|
||||
_elem) " cannot be recognized as a valid specification modifier.");
|
||||
#endif // GMOCK_INTERNAL_STRICT_SPEC_ASSERT
|
||||
|
||||
// Modifiers implementation.
|
||||
#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \
|
||||
@@ -238,26 +290,12 @@ using internal::FunctionMocker;
|
||||
|
||||
#define GMOCK_INTERNAL_UNPACK_ref(x) x
|
||||
|
||||
#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \
|
||||
GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \
|
||||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \
|
||||
(_elem)
|
||||
#define GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem) \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CALLTYPE_I_, _elem)
|
||||
|
||||
// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and
|
||||
// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows
|
||||
// maybe they can be simplified somehow.
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \
|
||||
GMOCK_INTERNAL_IS_CALLTYPE_I( \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg)
|
||||
#define GMOCK_INTERNAL_DETECT_CALLTYPE_I_Calltype ,
|
||||
|
||||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \
|
||||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \
|
||||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg))
|
||||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \
|
||||
GMOCK_PP_IDENTITY _arg
|
||||
|
||||
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
|
||||
#define GMOCK_INTERNAL_UNPACK_Calltype(...) __VA_ARGS__
|
||||
|
||||
// Note: The use of `identity_t` here allows _Ret to represent return types that
|
||||
// would normally need to be specified in a different way. For example, a method
|
||||
@@ -476,4 +514,4 @@ using internal::FunctionMocker;
|
||||
#define GMOCK_MOCKER_(arity, constness, Method) \
|
||||
GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
|
||||
|
||||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_
|
||||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,662 @@
|
||||
// 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 variadic actions.
|
||||
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
// Include any custom callback actions added by the local installation.
|
||||
#include "gmock/internal/custom/gmock-generated-actions.h"
|
||||
|
||||
// Sometimes you want to give an action explicit template parameters
|
||||
// that cannot be inferred from its value parameters. ACTION() and
|
||||
// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
|
||||
// and can be viewed as an extension to ACTION() and ACTION_P*().
|
||||
//
|
||||
// The syntax:
|
||||
//
|
||||
// ACTION_TEMPLATE(ActionName,
|
||||
// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
|
||||
// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
|
||||
//
|
||||
// defines an action template that takes m explicit template
|
||||
// parameters and n value parameters. name_i is the name of the i-th
|
||||
// template parameter, and kind_i specifies whether it's a typename,
|
||||
// an integral constant, or a template. p_i is the name of the i-th
|
||||
// value parameter.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // DuplicateArg<k, T>(output) converts the k-th argument of the mock
|
||||
// // function to type T and copies it to *output.
|
||||
// ACTION_TEMPLATE(DuplicateArg,
|
||||
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
|
||||
// AND_1_VALUE_PARAMS(output)) {
|
||||
// *output = T(::std::get<k>(args));
|
||||
// }
|
||||
// ...
|
||||
// int n;
|
||||
// EXPECT_CALL(mock, Foo(_, _))
|
||||
// .WillOnce(DuplicateArg<1, unsigned char>(&n));
|
||||
//
|
||||
// To create an instance of an action template, write:
|
||||
//
|
||||
// ActionName<t1, ..., t_m>(v1, ..., v_n)
|
||||
//
|
||||
// where the ts are the template arguments and the vs are the value
|
||||
// arguments. The value argument types are inferred by the compiler.
|
||||
// If you want to explicitly specify the value argument types, you can
|
||||
// provide additional template arguments:
|
||||
//
|
||||
// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
|
||||
//
|
||||
// where u_i is the desired type of v_i.
|
||||
//
|
||||
// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
|
||||
// number of value parameters, but not on the number of template
|
||||
// parameters. Without the restriction, the meaning of the following
|
||||
// is unclear:
|
||||
//
|
||||
// OverloadedAction<int, bool>(x);
|
||||
//
|
||||
// Are we using a single-template-parameter action where 'bool' refers
|
||||
// to the type of x, or are we using a two-template-parameter action
|
||||
// where the compiler is asked to infer the type of x?
|
||||
//
|
||||
// Implementation notes:
|
||||
//
|
||||
// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
|
||||
// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
|
||||
// implementing ACTION_TEMPLATE. The main trick we use is to create
|
||||
// new macro invocations when expanding a macro. For example, we have
|
||||
//
|
||||
// #define ACTION_TEMPLATE(name, template_params, value_params)
|
||||
// ... GMOCK_INTERNAL_DECL_##template_params ...
|
||||
//
|
||||
// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
|
||||
// to expand to
|
||||
//
|
||||
// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
|
||||
//
|
||||
// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
|
||||
// preprocessor will continue to expand it to
|
||||
//
|
||||
// ... typename T ...
|
||||
//
|
||||
// This technique conforms to the C++ standard and is portable. It
|
||||
// allows us to implement action templates using O(N) code, where N is
|
||||
// the maximum number of template/value parameters supported. Without
|
||||
// using it, we'd have to devote O(N^2) amount of code to implement all
|
||||
// combinations of m and n.
|
||||
|
||||
// Declares the template parameters.
|
||||
#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
|
||||
#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \
|
||||
kind0 name0, kind1 name1
|
||||
#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2) \
|
||||
kind0 name0, kind1 name1, kind2 name2
|
||||
#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2, kind3, name3) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3
|
||||
#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4
|
||||
#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2, kind3, name3, \
|
||||
kind4, name4, kind5, name5) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
|
||||
#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
|
||||
kind5 name5, kind6 name6
|
||||
#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
|
||||
kind5 name5, kind6 name6, kind7 name7
|
||||
#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7, kind8, name8) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
|
||||
kind5 name5, kind6 name6, kind7 name7, kind8 name8
|
||||
#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \
|
||||
kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
|
||||
kind5 name5, kind6 name6, kind7 name7, kind8 name8, kind9 name9
|
||||
|
||||
// Lists the template parameters.
|
||||
#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
|
||||
#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \
|
||||
name0, name1
|
||||
#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2) \
|
||||
name0, name1, name2
|
||||
#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2, kind3, name3) \
|
||||
name0, name1, name2, name3
|
||||
#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \
|
||||
name0, name1, name2, name3, name4
|
||||
#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
|
||||
kind2, name2, kind3, name3, \
|
||||
kind4, name4, kind5, name5) \
|
||||
name0, name1, name2, name3, name4, name5
|
||||
#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6) \
|
||||
name0, name1, name2, name3, name4, name5, name6
|
||||
#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7) \
|
||||
name0, name1, name2, name3, name4, name5, name6, name7
|
||||
#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7, kind8, name8) \
|
||||
name0, name1, name2, name3, name4, name5, name6, name7, name8
|
||||
#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS( \
|
||||
kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
|
||||
kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \
|
||||
name0, name1, name2, name3, name4, name5, name6, name7, name8, name9
|
||||
|
||||
// Declares the types of value parameters.
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) \
|
||||
, typename p0##_type, typename p1##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
typename p6##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
typename p6##_type, typename p7##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7, p8) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
typename p6##_type, typename p7##_type, typename p8##_type
|
||||
#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7, p8, p9) \
|
||||
, typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
typename p6##_type, typename p7##_type, typename p8##_type, \
|
||||
typename p9##_type
|
||||
|
||||
// Initializes the value parameters.
|
||||
#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS() ()
|
||||
#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0) \
|
||||
(p0##_type gmock_p0) : p0(::std::move(gmock_p0))
|
||||
#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1) \
|
||||
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1))
|
||||
#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2))
|
||||
#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3))
|
||||
#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4))
|
||||
#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5))
|
||||
#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6))
|
||||
#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7))
|
||||
#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
|
||||
p8) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7)), \
|
||||
p8(::std::move(gmock_p8))
|
||||
#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9) \
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) \
|
||||
: p0(::std::move(gmock_p0)), \
|
||||
p1(::std::move(gmock_p1)), \
|
||||
p2(::std::move(gmock_p2)), \
|
||||
p3(::std::move(gmock_p3)), \
|
||||
p4(::std::move(gmock_p4)), \
|
||||
p5(::std::move(gmock_p5)), \
|
||||
p6(::std::move(gmock_p6)), \
|
||||
p7(::std::move(gmock_p7)), \
|
||||
p8(::std::move(gmock_p8)), \
|
||||
p9(::std::move(gmock_p9))
|
||||
|
||||
// Defines the copy constructor
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_0_VALUE_PARAMS() \
|
||||
{} // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_1_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_2_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_3_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_4_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_5_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_6_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_7_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_8_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_9_VALUE_PARAMS(...) = default;
|
||||
#define GMOCK_INTERNAL_DEFN_COPY_AND_10_VALUE_PARAMS(...) = default;
|
||||
|
||||
// Declares the fields for storing the value parameters.
|
||||
#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4; \
|
||||
p5##_type p5;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4; \
|
||||
p5##_type p5; \
|
||||
p6##_type p6;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4; \
|
||||
p5##_type p5; \
|
||||
p6##_type p6; \
|
||||
p7##_type p7;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
|
||||
p8) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4; \
|
||||
p5##_type p5; \
|
||||
p6##_type p6; \
|
||||
p7##_type p7; \
|
||||
p8##_type p8;
|
||||
#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9) \
|
||||
p0##_type p0; \
|
||||
p1##_type p1; \
|
||||
p2##_type p2; \
|
||||
p3##_type p3; \
|
||||
p4##_type p4; \
|
||||
p5##_type p5; \
|
||||
p6##_type p6; \
|
||||
p7##_type p7; \
|
||||
p8##_type p8; \
|
||||
p9##_type p9;
|
||||
|
||||
// Lists the value parameters.
|
||||
#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
|
||||
#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
|
||||
#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
|
||||
#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
|
||||
#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
p0, p1, p2, p3, p4
|
||||
#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
p0, p1, p2, p3, p4, p5
|
||||
#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
|
||||
p0, p1, p2, p3, p4, p5, p6
|
||||
#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
|
||||
p0, p1, p2, p3, p4, p5, p6, p7
|
||||
#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
|
||||
p8) \
|
||||
p0, p1, p2, p3, p4, p5, p6, p7, p8
|
||||
#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9) \
|
||||
p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
|
||||
|
||||
// Lists the value parameter types.
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) \
|
||||
, p0##_type, p1##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \
|
||||
, p0##_type, p1##_type, p2##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
|
||||
p6##_type, p7##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7, p8) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
|
||||
p6##_type, p7##_type, p8##_type
|
||||
#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
|
||||
p6, p7, p8, p9) \
|
||||
, p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
|
||||
p6##_type, p7##_type, p8##_type, p9##_type
|
||||
|
||||
// Declares the value parameters.
|
||||
#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
|
||||
#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) \
|
||||
p0##_type p0, p1##_type p1
|
||||
#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2
|
||||
#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3
|
||||
#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
|
||||
#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
|
||||
p5##_type p5
|
||||
#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
|
||||
p5##_type p5, p6##_type p6
|
||||
#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
|
||||
p5##_type p5, p6##_type p6, p7##_type p7
|
||||
#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
|
||||
p8) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
|
||||
p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
|
||||
#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9) \
|
||||
p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
|
||||
p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, p9##_type p9
|
||||
|
||||
// The suffix of the class template implementing the action template.
|
||||
#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
|
||||
#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
|
||||
#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
|
||||
#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
|
||||
#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
|
||||
#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
|
||||
#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
|
||||
#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
|
||||
#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7) \
|
||||
P8
|
||||
#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8) \
|
||||
P9
|
||||
#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9) \
|
||||
P10
|
||||
|
||||
// The name of the class template implementing the action template.
|
||||
#define GMOCK_ACTION_CLASS_(name, value_params) \
|
||||
GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
|
||||
|
||||
#define ACTION_TEMPLATE(name, template_params, value_params) \
|
||||
template <GMOCK_INTERNAL_DECL_##template_params \
|
||||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \
|
||||
class GMOCK_ACTION_CLASS_(name, value_params) { \
|
||||
public: \
|
||||
explicit GMOCK_ACTION_CLASS_(name, value_params)( \
|
||||
GMOCK_INTERNAL_DECL_##value_params) \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \
|
||||
= default; \
|
||||
, \
|
||||
: impl_(std::make_shared<gmock_Impl>( \
|
||||
GMOCK_INTERNAL_LIST_##value_params)){}) \
|
||||
GMOCK_ACTION_CLASS_(name, value_params)(const GMOCK_ACTION_CLASS_( \
|
||||
name, value_params) &) noexcept GMOCK_INTERNAL_DEFN_COPY_ \
|
||||
##value_params GMOCK_ACTION_CLASS_(name, value_params)( \
|
||||
GMOCK_ACTION_CLASS_(name, value_params) &&) noexcept \
|
||||
GMOCK_INTERNAL_DEFN_COPY_##value_params template <typename F> \
|
||||
operator ::testing::Action<F>() const { \
|
||||
return GMOCK_PP_IF( \
|
||||
GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \
|
||||
(::testing::internal::MakeAction<F, gmock_Impl>()), \
|
||||
(::testing::internal::MakeAction<F>(impl_))); \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
class gmock_Impl { \
|
||||
public: \
|
||||
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {} \
|
||||
template <typename function_type, typename return_type, \
|
||||
typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
|
||||
return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
|
||||
GMOCK_INTERNAL_DEFN_##value_params \
|
||||
}; \
|
||||
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), , \
|
||||
std::shared_ptr<const gmock_Impl> impl_;) \
|
||||
}; \
|
||||
template <GMOCK_INTERNAL_DECL_##template_params \
|
||||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \
|
||||
GMOCK_ACTION_CLASS_( \
|
||||
name, value_params)<GMOCK_INTERNAL_LIST_##template_params \
|
||||
GMOCK_INTERNAL_LIST_TYPE_##value_params> \
|
||||
name(GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \
|
||||
template <GMOCK_INTERNAL_DECL_##template_params \
|
||||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \
|
||||
inline GMOCK_ACTION_CLASS_( \
|
||||
name, value_params)<GMOCK_INTERNAL_LIST_##template_params \
|
||||
GMOCK_INTERNAL_LIST_TYPE_##value_params> \
|
||||
name(GMOCK_INTERNAL_DECL_##value_params) { \
|
||||
return GMOCK_ACTION_CLASS_( \
|
||||
name, value_params)<GMOCK_INTERNAL_LIST_##template_params \
|
||||
GMOCK_INTERNAL_LIST_TYPE_##value_params>( \
|
||||
GMOCK_INTERNAL_LIST_##value_params); \
|
||||
} \
|
||||
template <GMOCK_INTERNAL_DECL_##template_params \
|
||||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \
|
||||
template <typename function_type, typename return_type, typename args_type, \
|
||||
GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \
|
||||
return_type GMOCK_ACTION_CLASS_( \
|
||||
name, value_params)<GMOCK_INTERNAL_LIST_##template_params \
|
||||
GMOCK_INTERNAL_LIST_TYPE_##value_params>:: \
|
||||
gmock_Impl::gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) \
|
||||
const
|
||||
|
||||
namespace testing {
|
||||
|
||||
// The ACTION*() macros trigger warning C4100 (unreferenced formal
|
||||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
// is expanded and macro expansion cannot contain #pragma. Therefore
|
||||
// we suppress them here.
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#endif
|
||||
|
||||
namespace internal {
|
||||
|
||||
// internal::InvokeArgument - a helper for InvokeArgument action.
|
||||
// The basic overloads are provided here for generic functors.
|
||||
// Overloads for other custom-callables are provided in the
|
||||
// internal/custom/gmock-generated-actions.h header.
|
||||
template <typename F, typename... Args>
|
||||
auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
|
||||
return f(args...);
|
||||
}
|
||||
|
||||
template <std::size_t index, typename... Params>
|
||||
struct InvokeArgumentAction {
|
||||
template <typename... Args,
|
||||
typename = typename std::enable_if<(index < sizeof...(Args))>::type>
|
||||
auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument(
|
||||
std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)),
|
||||
std::declval<const Params&>()...)) {
|
||||
internal::FlatTuple<Args&&...> args_tuple(FlatTupleConstructTag{},
|
||||
std::forward<Args>(args)...);
|
||||
return params.Apply([&](const Params&... unpacked_params) {
|
||||
auto&& callable = args_tuple.template Get<index>();
|
||||
return internal::InvokeArgument(
|
||||
std::forward<decltype(callable)>(callable), unpacked_params...);
|
||||
});
|
||||
}
|
||||
|
||||
internal::FlatTuple<Params...> params;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
|
||||
// (0-based) argument, which must be a k-ary callable, of the mock
|
||||
// function, with arguments a1, a2, ..., a_k.
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// 1. The arguments are passed by value by default. If you need to
|
||||
// pass an argument by reference, wrap it inside std::ref(). For
|
||||
// example,
|
||||
//
|
||||
// InvokeArgument<1>(5, string("Hello"), std::ref(foo))
|
||||
//
|
||||
// passes 5 and string("Hello") by value, and passes foo by
|
||||
// reference.
|
||||
//
|
||||
// 2. If the callable takes an argument by reference but std::ref() is
|
||||
// not used, it will receive the reference to a copy of the value,
|
||||
// instead of the original value. For example, when the 0-th
|
||||
// argument of the mock function takes a const string&, the action
|
||||
//
|
||||
// InvokeArgument<0>(string("Hello"))
|
||||
//
|
||||
// makes a copy of the temporary string("Hello") object and passes a
|
||||
// reference of the copy, instead of the original temporary object,
|
||||
// to the callable. This makes it easy for a user to define an
|
||||
// InvokeArgument action from temporary values and have it performed
|
||||
// later.
|
||||
template <std::size_t index, typename... Params>
|
||||
internal::InvokeArgumentAction<index, typename std::decay<Params>::type...>
|
||||
InvokeArgument(Params&&... params) {
|
||||
return {internal::FlatTuple<typename std::decay<Params>::type...>(
|
||||
internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
|
@@ -27,7 +27,6 @@
|
||||
// (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 matchers that depend on gmock-matchers.h.
|
||||
@@ -35,11 +34,15 @@
|
||||
// Note that tests are implemented in gmock-matchers_test.cc rather than
|
||||
// gmock-more-matchers-test.cc.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
namespace testing {
|
||||
@@ -47,23 +50,51 @@ namespace testing {
|
||||
// Silence C4100 (unreferenced formal
|
||||
// parameter) for MSVC
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#if (_MSC_VER == 1900)
|
||||
// and silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Defines a matcher that matches an empty container. The container must
|
||||
// support both size() and empty(), which all STL-like containers provide.
|
||||
MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
|
||||
if (arg.empty()) {
|
||||
return true;
|
||||
namespace internal {
|
||||
|
||||
// Implements the polymorphic IsEmpty matcher, which
|
||||
// can be used as a Matcher<T> as long as T is either a container that defines
|
||||
// empty() and size() (e.g. std::vector or std::string), or a C-style string.
|
||||
class IsEmptyMatcher {
|
||||
public:
|
||||
// Matches anything that defines empty() and size().
|
||||
template <typename MatcheeContainerType>
|
||||
bool MatchAndExplain(const MatcheeContainerType& c,
|
||||
MatchResultListener* listener) const {
|
||||
if (c.empty()) {
|
||||
return true;
|
||||
}
|
||||
*listener << "whose size is " << c.size();
|
||||
return false;
|
||||
}
|
||||
*result_listener << "whose size is " << arg.size();
|
||||
return false;
|
||||
|
||||
// Matches C-style strings.
|
||||
bool MatchAndExplain(const char* s, MatchResultListener* listener) const {
|
||||
return MatchAndExplain(std::string(s), listener);
|
||||
}
|
||||
|
||||
// Describes what this matcher matches.
|
||||
void DescribeTo(std::ostream* os) const { *os << "is empty"; }
|
||||
|
||||
void DescribeNegationTo(std::ostream* os) const { *os << "isn't empty"; }
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Creates a polymorphic matcher that matches an empty container or C-style
|
||||
// string. The container must support both size() and empty(), which all
|
||||
// STL-like containers provide.
|
||||
inline PolymorphicMatcher<internal::IsEmptyMatcher> IsEmpty() {
|
||||
return MakePolymorphicMatcher(internal::IsEmptyMatcher());
|
||||
}
|
||||
|
||||
// Define a matcher that matches a value that evaluates in boolean
|
||||
@@ -83,10 +114,9 @@ MATCHER(IsFalse, negation ? "is true" : "is false") {
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Implements class templates NiceMock, NaggyMock, and StrictMock.
|
||||
//
|
||||
// Given a mock class MockFoo that is created using Google Mock,
|
||||
@@ -58,11 +57,13 @@
|
||||
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
|
||||
// supported.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#include "gmock/gmock-spec-builders.h"
|
||||
@@ -109,25 +110,37 @@ constexpr bool HasStrictnessModifier() {
|
||||
template <typename Base>
|
||||
class NiceMockImpl {
|
||||
public:
|
||||
NiceMockImpl() { ::testing::Mock::AllowUninterestingCalls(this); }
|
||||
NiceMockImpl() {
|
||||
::testing::Mock::AllowUninterestingCalls(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
|
||||
~NiceMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
|
||||
~NiceMockImpl() {
|
||||
::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Base>
|
||||
class NaggyMockImpl {
|
||||
public:
|
||||
NaggyMockImpl() { ::testing::Mock::WarnUninterestingCalls(this); }
|
||||
NaggyMockImpl() {
|
||||
::testing::Mock::WarnUninterestingCalls(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
|
||||
~NaggyMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
|
||||
~NaggyMockImpl() {
|
||||
::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Base>
|
||||
class StrictMockImpl {
|
||||
public:
|
||||
StrictMockImpl() { ::testing::Mock::FailUninterestingCalls(this); }
|
||||
StrictMockImpl() {
|
||||
::testing::Mock::FailUninterestingCalls(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
|
||||
~StrictMockImpl() { ::testing::Mock::UnregisterCallReaction(this); }
|
||||
~StrictMockImpl() {
|
||||
::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
@@ -169,7 +182,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
|
||||
NiceMock(const NiceMock&) = delete;
|
||||
NiceMock& operator=(const NiceMock&) = delete;
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
@@ -210,7 +224,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
|
||||
NaggyMock(const NaggyMock&) = delete;
|
||||
NaggyMock& operator=(const NaggyMock&) = delete;
|
||||
};
|
||||
|
||||
template <class MockClass>
|
||||
@@ -251,7 +266,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock
|
||||
}
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
|
||||
StrictMock(const StrictMock&) = delete;
|
||||
StrictMock& operator=(const StrictMock&) = delete;
|
||||
};
|
||||
|
||||
#undef GTEST_INTERNAL_EMPTY_BASE_CLASS
|
File diff suppressed because it is too large
Load Diff
@@ -27,13 +27,10 @@
|
||||
// (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 is the main header file a user should include.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_
|
||||
|
||||
@@ -64,14 +61,15 @@
|
||||
#include "gmock/gmock-more-matchers.h"
|
||||
#include "gmock/gmock-nice-strict.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
namespace testing {
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
// Declares Google Mock flags that we want a user to use programmatically.
|
||||
GMOCK_DECLARE_bool_(catch_leaked_mocks);
|
||||
GMOCK_DECLARE_string_(verbose);
|
||||
GMOCK_DECLARE_int32_(default_mock_behavior);
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Initializes Google Mock. This must be called before running the
|
||||
// tests. In particular, it parses the command line for the flags
|
||||
// that Google Mock recognizes. Whenever a Google Mock flag is seen,
|
@@ -14,3 +14,5 @@ The following macros can be defined:
|
||||
* `GMOCK_DEFINE_bool_(name, default_val, doc)`
|
||||
* `GMOCK_DEFINE_int32_(name, default_val, doc)`
|
||||
* `GMOCK_DEFINE_string_(name, default_val, doc)`
|
||||
* `GMOCK_FLAG_GET(flag_name)`
|
||||
* `GMOCK_FLAG_SET(flag_name, value)`
|
@@ -1,4 +1,5 @@
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
|
@@ -26,10 +26,11 @@
|
||||
// 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.
|
||||
//
|
||||
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
|
@@ -26,12 +26,13 @@
|
||||
// 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.
|
||||
//
|
||||
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
|
@@ -27,22 +27,25 @@
|
||||
// (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 defines some utilities useful for implementing Google
|
||||
// Mock. They are subject to change without notice, so please DO NOT
|
||||
// USE THEM IN USER CODE.
|
||||
|
||||
// GOOGLETEST_CM0002 DO NOT DELETE
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ostream> // NOLINT
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -56,14 +59,15 @@ namespace internal {
|
||||
// Silence MSVC C4100 (unreferenced formal parameter) and
|
||||
// C4805('==': unsafe mix of type 'const int' and type 'const bool')
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
# pragma warning(disable:4805)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#pragma warning(disable : 4805)
|
||||
#endif
|
||||
|
||||
// Joins a vector of strings as if they are fields of a tuple; returns
|
||||
// the joined string.
|
||||
GTEST_API_ std::string JoinAsTuple(const Strings& fields);
|
||||
GTEST_API_ std::string JoinAsKeyValueTuple(
|
||||
const std::vector<const char*>& names, const Strings& values);
|
||||
|
||||
// Converts an identifier name to a space-separated list of lower-case
|
||||
// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
|
||||
@@ -78,9 +82,36 @@ template <typename Pointer>
|
||||
inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
||||
return p.get();
|
||||
}
|
||||
// This overload version is for std::reference_wrapper, which does not work with
|
||||
// the overload above, as it does not have an `element_type`.
|
||||
template <typename Element>
|
||||
inline const Element* GetRawPointer(const std::reference_wrapper<Element>& r) {
|
||||
return &r.get();
|
||||
}
|
||||
|
||||
// This overloaded version is for the raw pointer case.
|
||||
template <typename Element>
|
||||
inline Element* GetRawPointer(Element* p) { return p; }
|
||||
inline Element* GetRawPointer(Element* p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
// Default definitions for all compilers.
|
||||
// NOTE: If you implement support for other compilers, make sure to avoid
|
||||
// unexpected overlaps.
|
||||
// (e.g., Clang also processes #pragma GCC, and clang-cl also handles _MSC_VER.)
|
||||
#define GMOCK_INTERNAL_WARNING_PUSH()
|
||||
#define GMOCK_INTERNAL_WARNING_CLANG(Level, Name)
|
||||
#define GMOCK_INTERNAL_WARNING_POP()
|
||||
|
||||
#if defined(__clang__)
|
||||
#undef GMOCK_INTERNAL_WARNING_PUSH
|
||||
#define GMOCK_INTERNAL_WARNING_PUSH() _Pragma("clang diagnostic push")
|
||||
#undef GMOCK_INTERNAL_WARNING_CLANG
|
||||
#define GMOCK_INTERNAL_WARNING_CLANG(Level, Warning) \
|
||||
_Pragma(GMOCK_PP_INTERNAL_STRINGIZE(clang diagnostic Level Warning))
|
||||
#undef GMOCK_INTERNAL_WARNING_POP
|
||||
#define GMOCK_INTERNAL_WARNING_POP() _Pragma("clang diagnostic pop")
|
||||
#endif
|
||||
|
||||
// MSVC treats wchar_t as a native type usually, but treats it as the
|
||||
// same as unsigned short when the compiler option /Zc:wchar_t- is
|
||||
@@ -89,7 +120,7 @@ inline Element* GetRawPointer(Element* p) { return p; }
|
||||
#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
// wchar_t is a typedef.
|
||||
#else
|
||||
# define GMOCK_WCHAR_T_IS_NATIVE_ 1
|
||||
#define GMOCK_WCHAR_T_IS_NATIVE_ 1
|
||||
#endif
|
||||
|
||||
// In what follows, we use the term "kind" to indicate whether a type
|
||||
@@ -97,18 +128,20 @@ inline Element* GetRawPointer(Element* p) { return p; }
|
||||
// or none of them. This categorization is useful for determining
|
||||
// when a matcher argument type can be safely converted to another
|
||||
// type in the implementation of SafeMatcherCast.
|
||||
enum TypeKind {
|
||||
kBool, kInteger, kFloatingPoint, kOther
|
||||
};
|
||||
enum TypeKind { kBool, kInteger, kFloatingPoint, kOther };
|
||||
|
||||
// KindOf<T>::value is the kind of type T.
|
||||
template <typename T> struct KindOf {
|
||||
template <typename T>
|
||||
struct KindOf {
|
||||
enum { value = kOther }; // The default kind.
|
||||
};
|
||||
|
||||
// This macro declares that the kind of 'type' is 'kind'.
|
||||
#define GMOCK_DECLARE_KIND_(type, kind) \
|
||||
template <> struct KindOf<type> { enum { value = kind }; }
|
||||
template <> \
|
||||
struct KindOf<type> { \
|
||||
enum { value = kind }; \
|
||||
}
|
||||
|
||||
GMOCK_DECLARE_KIND_(bool, kBool);
|
||||
|
||||
@@ -116,13 +149,13 @@ GMOCK_DECLARE_KIND_(bool, kBool);
|
||||
GMOCK_DECLARE_KIND_(char, kInteger);
|
||||
GMOCK_DECLARE_KIND_(signed char, kInteger);
|
||||
GMOCK_DECLARE_KIND_(unsigned char, kInteger);
|
||||
GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(int, kInteger);
|
||||
GMOCK_DECLARE_KIND_(unsigned int, kInteger);
|
||||
GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT
|
||||
GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT
|
||||
|
||||
#if GMOCK_WCHAR_T_IS_NATIVE_
|
||||
@@ -137,7 +170,7 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
|
||||
#undef GMOCK_DECLARE_KIND_
|
||||
|
||||
// Evaluates to the kind of 'type'.
|
||||
#define GMOCK_KIND_OF_(type) \
|
||||
#define GMOCK_KIND_OF_(type) \
|
||||
static_cast< ::testing::internal::TypeKind>( \
|
||||
::testing::internal::KindOf<type>::value)
|
||||
|
||||
@@ -193,9 +226,7 @@ using LosslessArithmeticConvertible =
|
||||
class FailureReporterInterface {
|
||||
public:
|
||||
// The type of a failure (either non-fatal or fatal).
|
||||
enum FailureType {
|
||||
kNonfatal, kFatal
|
||||
};
|
||||
enum FailureType { kNonfatal, kFatal };
|
||||
|
||||
virtual ~FailureReporterInterface() {}
|
||||
|
||||
@@ -215,8 +246,8 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter();
|
||||
inline void Assert(bool condition, const char* file, int line,
|
||||
const std::string& msg) {
|
||||
if (!condition) {
|
||||
GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
|
||||
file, line, msg);
|
||||
GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file,
|
||||
line, msg);
|
||||
}
|
||||
}
|
||||
inline void Assert(bool condition, const char* file, int line) {
|
||||
@@ -237,10 +268,7 @@ inline void Expect(bool condition, const char* file, int line) {
|
||||
}
|
||||
|
||||
// Severity level of a log.
|
||||
enum LogSeverity {
|
||||
kInfo = 0,
|
||||
kWarning = 1
|
||||
};
|
||||
enum LogSeverity { kInfo = 0, kWarning = 1 };
|
||||
|
||||
// Valid values for the --gmock_verbose flag.
|
||||
|
||||
@@ -280,13 +308,6 @@ class WithoutMatchers {
|
||||
// Internal use only: access the singleton instance of WithoutMatchers.
|
||||
GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
||||
|
||||
// Disable MSVC warnings for infinite recursion, since in this case the
|
||||
// the recursion is unreachable.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4717)
|
||||
#endif
|
||||
|
||||
// Invalid<T>() is usable as an expression of type T, but will terminate
|
||||
// the program with an assertion failure if actually run. This is useful
|
||||
// when a value of type T is needed for compilation, but the statement
|
||||
@@ -295,15 +316,14 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
||||
template <typename T>
|
||||
inline T Invalid() {
|
||||
Assert(false, "", -1, "Internal error: attempt to return invalid value");
|
||||
// This statement is unreachable, and would never terminate even if it
|
||||
// could be reached. It is provided only to placate compiler warnings
|
||||
// about missing return statements.
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
__builtin_unreachable();
|
||||
#elif defined(_MSC_VER)
|
||||
__assume(0);
|
||||
#else
|
||||
return Invalid<T>();
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Given a raw type (i.e. having no top-level reference or const
|
||||
// modifier) RawContainer that's either an STL-style container or a
|
||||
@@ -381,7 +401,8 @@ class StlContainerView< ::std::tuple<ElementPointer, Size> > {
|
||||
|
||||
// The following specialization prevents the user from instantiating
|
||||
// StlContainer with a reference type.
|
||||
template <typename T> class StlContainerView<T&>;
|
||||
template <typename T>
|
||||
class StlContainerView<T&>;
|
||||
|
||||
// A type transform to remove constness from the first part of a pair.
|
||||
// Pairs like that are used as the value_type of associative containers,
|
||||
@@ -402,17 +423,18 @@ struct RemoveConstFromKey<std::pair<const K, V> > {
|
||||
GTEST_API_ void IllegalDoDefault(const char* file, int line);
|
||||
|
||||
template <typename F, typename Tuple, size_t... Idx>
|
||||
auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype(
|
||||
std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) {
|
||||
auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>)
|
||||
-> decltype(std::forward<F>(f)(
|
||||
std::get<Idx>(std::forward<Tuple>(args))...)) {
|
||||
return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
|
||||
}
|
||||
|
||||
// Apply the function to a tuple of arguments.
|
||||
template <typename F, typename Tuple>
|
||||
auto Apply(F&& f, Tuple&& args) -> decltype(
|
||||
ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
|
||||
MakeIndexSequence<std::tuple_size<
|
||||
typename std::remove_reference<Tuple>::type>::value>())) {
|
||||
auto Apply(F&& f, Tuple&& args) -> decltype(ApplyImpl(
|
||||
std::forward<F>(f), std::forward<Tuple>(args),
|
||||
MakeIndexSequence<std::tuple_size<
|
||||
typename std::remove_reference<Tuple>::type>::value>())) {
|
||||
return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
|
||||
MakeIndexSequence<std::tuple_size<
|
||||
typename std::remove_reference<Tuple>::type>::value>());
|
||||
@@ -449,8 +471,17 @@ struct Function<R(Args...)> {
|
||||
template <typename R, typename... Args>
|
||||
constexpr size_t Function<R(Args...)>::ArgumentCount;
|
||||
|
||||
// Workaround for MSVC error C2039: 'type': is not a member of 'std'
|
||||
// when std::tuple_element is used.
|
||||
// See: https://github.com/google/googletest/issues/3931
|
||||
// Can be replaced with std::tuple_element_t in C++14.
|
||||
template <size_t I, typename T>
|
||||
using TupleElement = typename std::tuple_element<I, T>::type;
|
||||
|
||||
bool Base64Unescape(const std::string& encoded, std::string* decoded);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace internal
|
@@ -0,0 +1,139 @@
|
||||
// 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.
|
||||
|
||||
// Low-level types and utilities for porting Google Mock to various
|
||||
// platforms. All macros ending with _ and symbols defined in an
|
||||
// internal namespace are subject to change without notice. Code
|
||||
// outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't
|
||||
// end with _ are part of Google Mock's public API and can be used by
|
||||
// code outside Google Mock.
|
||||
|
||||
// IWYU pragma: private, include "gmock/gmock.h"
|
||||
// IWYU pragma: friend gmock/.*
|
||||
|
||||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
|
||||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
// Most of the utilities needed for porting Google Mock are also
|
||||
// required for Google Test and are defined in gtest-port.h.
|
||||
//
|
||||
// Note to maintainers: to reduce code duplication, prefer adding
|
||||
// portability utilities to Google Test's gtest-port.h instead of
|
||||
// here, as Google Mock depends on Google Test. Only add a utility
|
||||
// here if it's truly specific to Google Mock.
|
||||
|
||||
#include "gmock/internal/custom/gmock-port.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#include "absl/flags/declare.h"
|
||||
#include "absl/flags/flag.h"
|
||||
#endif
|
||||
|
||||
// For MS Visual C++, check the compiler version. At least VS 2015 is
|
||||
// required to compile Google Mock.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
|
||||
#endif
|
||||
|
||||
// Macro for referencing flags. This is public as we want the user to
|
||||
// use this syntax to reference Google Mock flags.
|
||||
#define GMOCK_FLAG_NAME_(name) gmock_##name
|
||||
#define GMOCK_FLAG(name) FLAGS_gmock_##name
|
||||
|
||||
// Pick a command line flags implementation.
|
||||
#if GTEST_HAS_ABSL
|
||||
|
||||
// Macros for defining flags.
|
||||
#define GMOCK_DEFINE_bool_(name, default_val, doc) \
|
||||
ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)
|
||||
#define GMOCK_DEFINE_int32_(name, default_val, doc) \
|
||||
ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)
|
||||
#define GMOCK_DEFINE_string_(name, default_val, doc) \
|
||||
ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)
|
||||
|
||||
// Macros for declaring flags.
|
||||
#define GMOCK_DECLARE_bool_(name) \
|
||||
ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))
|
||||
#define GMOCK_DECLARE_int32_(name) \
|
||||
ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))
|
||||
#define GMOCK_DECLARE_string_(name) \
|
||||
ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))
|
||||
|
||||
#define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))
|
||||
#define GMOCK_FLAG_SET(name, value) \
|
||||
(void)(::absl::SetFlag(&GMOCK_FLAG(name), value))
|
||||
|
||||
#else // GTEST_HAS_ABSL
|
||||
|
||||
// Macros for defining flags.
|
||||
#define GMOCK_DEFINE_bool_(name, default_val, doc) \
|
||||
namespace testing { \
|
||||
GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
#define GMOCK_DEFINE_int32_(name, default_val, doc) \
|
||||
namespace testing { \
|
||||
GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
#define GMOCK_DEFINE_string_(name, default_val, doc) \
|
||||
namespace testing { \
|
||||
GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
|
||||
// Macros for declaring flags.
|
||||
#define GMOCK_DECLARE_bool_(name) \
|
||||
namespace testing { \
|
||||
GTEST_API_ extern bool GMOCK_FLAG(name); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
#define GMOCK_DECLARE_int32_(name) \
|
||||
namespace testing { \
|
||||
GTEST_API_ extern int32_t GMOCK_FLAG(name); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
#define GMOCK_DECLARE_string_(name) \
|
||||
namespace testing { \
|
||||
GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
|
||||
} \
|
||||
static_assert(true, "no-op to require trailing semicolon")
|
||||
|
||||
#define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)
|
||||
#define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)
|
||||
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
|
@@ -27,7 +27,6 @@
|
||||
// (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 cardinalities.
|
||||
@@ -35,9 +34,11 @@
|
||||
#include "gmock/gmock-cardinalities.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -49,8 +50,7 @@ namespace {
|
||||
class BetweenCardinalityImpl : public CardinalityInterface {
|
||||
public:
|
||||
BetweenCardinalityImpl(int min, int max)
|
||||
: min_(min >= 0 ? min : 0),
|
||||
max_(max >= min_ ? max : min_) {
|
||||
: min_(min >= 0 ? min : 0), max_(max >= min_ ? max : min_) {
|
||||
std::stringstream ss;
|
||||
if (min < 0) {
|
||||
ss << "The invocation lower bound must be >= 0, "
|
||||
@@ -62,8 +62,7 @@ class BetweenCardinalityImpl : public CardinalityInterface {
|
||||
internal::Expect(false, __FILE__, __LINE__, ss.str());
|
||||
} else if (min > max) {
|
||||
ss << "The invocation upper bound (" << max
|
||||
<< ") must be >= the invocation lower bound (" << min
|
||||
<< ").";
|
||||
<< ") must be >= the invocation lower bound (" << min << ").";
|
||||
internal::Expect(false, __FILE__, __LINE__, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -87,7 +86,8 @@ class BetweenCardinalityImpl : public CardinalityInterface {
|
||||
const int min_;
|
||||
const int max_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl);
|
||||
BetweenCardinalityImpl(const BetweenCardinalityImpl&) = delete;
|
||||
BetweenCardinalityImpl& operator=(const BetweenCardinalityImpl&) = delete;
|
||||
};
|
||||
|
||||
// Formats "n times" in a human-friendly way.
|
@@ -27,7 +27,6 @@
|
||||
// (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 defines some utilities useful for implementing Google
|
||||
@@ -37,8 +36,15 @@
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <ostream> // NOLINT
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -48,21 +54,22 @@ namespace internal {
|
||||
|
||||
// Joins a vector of strings as if they are fields of a tuple; returns
|
||||
// the joined string.
|
||||
GTEST_API_ std::string JoinAsTuple(const Strings& fields) {
|
||||
switch (fields.size()) {
|
||||
case 0:
|
||||
return "";
|
||||
case 1:
|
||||
return fields[0];
|
||||
default:
|
||||
std::string result = "(" + fields[0];
|
||||
for (size_t i = 1; i < fields.size(); i++) {
|
||||
result += ", ";
|
||||
result += fields[i];
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
GTEST_API_ std::string JoinAsKeyValueTuple(
|
||||
const std::vector<const char*>& names, const Strings& values) {
|
||||
GTEST_CHECK_(names.size() == values.size());
|
||||
if (values.empty()) {
|
||||
return "";
|
||||
}
|
||||
const auto build_one = [&](const size_t i) {
|
||||
return std::string(names[i]) + ": " + values[i];
|
||||
};
|
||||
std::string result = "(" + build_one(0);
|
||||
for (size_t i = 1; i < values.size(); i++) {
|
||||
result += ", ";
|
||||
result += build_one(i);
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
}
|
||||
|
||||
// Converts an identifier name to a space-separated list of lower-case
|
||||
@@ -76,12 +83,11 @@ GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) {
|
||||
// We don't care about the current locale as the input is
|
||||
// guaranteed to be a valid C++ identifier name.
|
||||
const bool starts_new_word = IsUpper(*p) ||
|
||||
(!IsAlpha(prev_char) && IsLower(*p)) ||
|
||||
(!IsDigit(prev_char) && IsDigit(*p));
|
||||
(!IsAlpha(prev_char) && IsLower(*p)) ||
|
||||
(!IsDigit(prev_char) && IsDigit(*p));
|
||||
|
||||
if (IsAlNum(*p)) {
|
||||
if (starts_new_word && result != "")
|
||||
result += ' ';
|
||||
if (starts_new_word && result != "") result += ' ';
|
||||
result += ToLower(*p);
|
||||
}
|
||||
}
|
||||
@@ -95,12 +101,9 @@ class GoogleTestFailureReporter : public FailureReporterInterface {
|
||||
public:
|
||||
void ReportFailure(FailureType type, const char* file, int line,
|
||||
const std::string& message) override {
|
||||
AssertHelper(type == kFatal ?
|
||||
TestPartResult::kFatalFailure :
|
||||
TestPartResult::kNonFatalFailure,
|
||||
file,
|
||||
line,
|
||||
message.c_str()) = Message();
|
||||
AssertHelper(type == kFatal ? TestPartResult::kFatalFailure
|
||||
: TestPartResult::kNonFatalFailure,
|
||||
file, line, message.c_str()) = Message();
|
||||
if (type == kFatal) {
|
||||
posix::Abort();
|
||||
}
|
||||
@@ -126,10 +129,10 @@ static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex);
|
||||
// Returns true if and only if a log with the given severity is visible
|
||||
// according to the --gmock_verbose flag.
|
||||
GTEST_API_ bool LogIsVisible(LogSeverity severity) {
|
||||
if (GMOCK_FLAG(verbose) == kInfoVerbosity) {
|
||||
if (GMOCK_FLAG_GET(verbose) == kInfoVerbosity) {
|
||||
// Always show the log if --gmock_verbose=info.
|
||||
return true;
|
||||
} else if (GMOCK_FLAG(verbose) == kErrorVerbosity) {
|
||||
} else if (GMOCK_FLAG_GET(verbose) == kErrorVerbosity) {
|
||||
// Always hide it if --gmock_verbose=error.
|
||||
return false;
|
||||
} else {
|
||||
@@ -148,8 +151,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
|
||||
// conservative.
|
||||
GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
||||
int stack_frames_to_skip) {
|
||||
if (!LogIsVisible(severity))
|
||||
return;
|
||||
if (!LogIsVisible(severity)) return;
|
||||
|
||||
// Ensures that logs from different threads don't interleave.
|
||||
MutexLock l(&g_log_mutex);
|
||||
@@ -178,8 +180,8 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << "Stack trace:\n"
|
||||
<< ::testing::internal::GetCurrentOsStackTraceExceptTop(
|
||||
::testing::UnitTest::GetInstance(), actual_to_skip);
|
||||
<< ::testing::internal::GetCurrentOsStackTraceExceptTop(
|
||||
actual_to_skip);
|
||||
}
|
||||
std::cout << ::std::flush;
|
||||
}
|
||||
@@ -196,5 +198,54 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) {
|
||||
"the variable in various places.");
|
||||
}
|
||||
|
||||
constexpr char UnBase64Impl(char c, const char* const base64, char carry) {
|
||||
return *base64 == 0 ? static_cast<char>(65)
|
||||
: *base64 == c
|
||||
? carry
|
||||
: UnBase64Impl(c, base64 + 1, static_cast<char>(carry + 1));
|
||||
}
|
||||
|
||||
template <size_t... I>
|
||||
constexpr std::array<char, 256> UnBase64Impl(IndexSequence<I...>,
|
||||
const char* const base64) {
|
||||
return {{UnBase64Impl(static_cast<char>(I), base64, 0)...}};
|
||||
}
|
||||
|
||||
constexpr std::array<char, 256> UnBase64(const char* const base64) {
|
||||
return UnBase64Impl(MakeIndexSequence<256>{}, base64);
|
||||
}
|
||||
|
||||
static constexpr char kBase64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static constexpr std::array<char, 256> kUnBase64 = UnBase64(kBase64);
|
||||
|
||||
bool Base64Unescape(const std::string& encoded, std::string* decoded) {
|
||||
decoded->clear();
|
||||
size_t encoded_len = encoded.size();
|
||||
decoded->reserve(3 * (encoded_len / 4) + (encoded_len % 4));
|
||||
int bit_pos = 0;
|
||||
char dst = 0;
|
||||
for (int src : encoded) {
|
||||
if (std::isspace(src) || src == '=') {
|
||||
continue;
|
||||
}
|
||||
char src_bin = kUnBase64[static_cast<size_t>(src)];
|
||||
if (src_bin >= 64) {
|
||||
decoded->clear();
|
||||
return false;
|
||||
}
|
||||
if (bit_pos == 0) {
|
||||
dst |= static_cast<char>(src_bin << 2);
|
||||
bit_pos = 6;
|
||||
} else {
|
||||
dst |= static_cast<char>(src_bin >> (bit_pos - 2));
|
||||
decoded->push_back(dst);
|
||||
dst = static_cast<char>(src_bin << (10 - bit_pos));
|
||||
bit_pos = (bit_pos + 6) % 8;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
@@ -27,7 +27,6 @@
|
||||
// (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 Matcher<const string&>, Matcher<string>, and
|
||||
@@ -36,9 +35,11 @@
|
||||
#include "gmock/gmock-matchers.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@@ -48,11 +49,13 @@ namespace internal {
|
||||
// 'negation' is false; otherwise returns the description of the
|
||||
// negation of the matcher. 'param_values' contains a list of strings
|
||||
// that are the print-out of the matcher's parameters.
|
||||
GTEST_API_ std::string FormatMatcherDescription(bool negation,
|
||||
const char* matcher_name,
|
||||
const Strings& param_values) {
|
||||
GTEST_API_ std::string FormatMatcherDescription(
|
||||
bool negation, const char* matcher_name,
|
||||
const std::vector<const char*>& param_names, const Strings& param_values) {
|
||||
std::string result = ConvertIdentifierNameToWords(matcher_name);
|
||||
if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
|
||||
if (param_values.size() >= 1) {
|
||||
result += " " + JoinAsKeyValueTuple(param_names, param_values);
|
||||
}
|
||||
return negation ? "not (" + result + ")" : result;
|
||||
}
|
||||
|
||||
@@ -367,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
|
||||
bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
|
||||
const ::std::vector<std::string>& element_printouts,
|
||||
const MatchMatrix& matrix, MatchResultListener* listener) const {
|
||||
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
|
||||
if (matrix.LhsSize() != matrix.RhsSize()) {
|
||||
// The element count doesn't match. If the container is empty,
|
||||
// there's no need to explain anything as Google Mock already
|
||||
// prints the empty container. Otherwise we just need to show
|
||||
// how many elements there actually are.
|
||||
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
|
||||
*listener << "which has " << Elements(matrix.LhsSize());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
::std::vector<char> element_matched(matrix.LhsSize(), 0);
|
||||
::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
|
@@ -27,7 +27,6 @@
|
||||
// (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 the spec builder syntax (ON_CALL and
|
||||
@@ -42,6 +41,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
@@ -49,15 +49,18 @@
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
|
||||
# include <unistd.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#endif
|
||||
#if GTEST_OS_QURT
|
||||
#include <qurt_event.h>
|
||||
#endif
|
||||
|
||||
// Silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 15
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4800)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4800)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -195,11 +198,12 @@ void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const
|
||||
|
||||
// Describes the state of the expectation (e.g. is it satisfied?
|
||||
// is it active?).
|
||||
*os << " - " << (IsOverSaturated() ? "over-saturated" :
|
||||
IsSaturated() ? "saturated" :
|
||||
IsSatisfied() ? "satisfied" : "unsatisfied")
|
||||
<< " and "
|
||||
<< (is_retired() ? "retired" : "active");
|
||||
*os << " - "
|
||||
<< (IsOverSaturated() ? "over-saturated"
|
||||
: IsSaturated() ? "saturated"
|
||||
: IsSatisfied() ? "satisfied"
|
||||
: "unsatisfied")
|
||||
<< " and " << (is_retired() ? "retired" : "active");
|
||||
}
|
||||
|
||||
// Checks the action count (i.e. the number of WillOnce() and
|
||||
@@ -242,13 +246,12 @@ void ExpectationBase::CheckActionCountIfNotDone() const
|
||||
|
||||
::std::stringstream ss;
|
||||
DescribeLocationTo(&ss);
|
||||
ss << "Too " << (too_many ? "many" : "few")
|
||||
<< " actions specified in " << source_text() << "...\n"
|
||||
ss << "Too " << (too_many ? "many" : "few") << " actions specified in "
|
||||
<< source_text() << "...\n"
|
||||
<< "Expected to be ";
|
||||
cardinality().DescribeTo(&ss);
|
||||
ss << ", but has " << (too_many ? "" : "only ")
|
||||
<< action_count << " WillOnce()"
|
||||
<< (action_count == 1 ? "" : "s");
|
||||
ss << ", but has " << (too_many ? "" : "only ") << action_count
|
||||
<< " WillOnce()" << (action_count == 1 ? "" : "s");
|
||||
if (repeated_action_specified_) {
|
||||
ss << " and a WillRepeatedly()";
|
||||
}
|
||||
@@ -264,10 +267,10 @@ void ExpectationBase::UntypedTimes(const Cardinality& a_cardinality) {
|
||||
".Times() cannot appear "
|
||||
"more than once in an EXPECT_CALL().");
|
||||
} else {
|
||||
ExpectSpecProperty(last_clause_ < kTimes,
|
||||
".Times() cannot appear after "
|
||||
".InSequence(), .WillOnce(), .WillRepeatedly(), "
|
||||
"or .RetiresOnSaturation().");
|
||||
ExpectSpecProperty(
|
||||
last_clause_ < kTimes,
|
||||
".Times() may only appear *before* .InSequence(), .WillOnce(), "
|
||||
".WillRepeatedly(), or .RetiresOnSaturation(), not after.");
|
||||
}
|
||||
last_clause_ = kTimes;
|
||||
|
||||
@@ -283,7 +286,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
|
||||
void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
|
||||
// Include a stack trace only if --gmock_verbose=info is specified.
|
||||
const int stack_frames_to_skip =
|
||||
GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1;
|
||||
GMOCK_FLAG_GET(verbose) == kInfoVerbosity ? 3 : -1;
|
||||
switch (reaction) {
|
||||
case kAllow:
|
||||
Log(kInfo, msg, stack_frames_to_skip);
|
||||
@@ -295,7 +298,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
|
||||
"call should not happen. Do not suppress it by blindly adding "
|
||||
"an EXPECT_CALL() if you don't mean to enforce the call. "
|
||||
"See "
|
||||
"https://github.com/google/googletest/blob/master/docs/"
|
||||
"https://github.com/google/googletest/blob/main/docs/"
|
||||
"gmock_cook_book.md#"
|
||||
"knowing-when-to-expect for details.\n",
|
||||
stack_frames_to_skip);
|
||||
@@ -370,143 +373,12 @@ const char* UntypedFunctionMockerBase::Name() const
|
||||
return name;
|
||||
}
|
||||
|
||||
// Calculates the result of invoking this mock function with the given
|
||||
// arguments, prints it, and returns it. The caller is responsible
|
||||
// for deleting the result.
|
||||
UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
|
||||
void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
// See the definition of untyped_expectations_ for why access to it
|
||||
// is unprotected here.
|
||||
if (untyped_expectations_.size() == 0) {
|
||||
// No expectation is set on this mock method - we have an
|
||||
// uninteresting call.
|
||||
|
||||
// We must get Google Mock's reaction on uninteresting calls
|
||||
// made on this mock object BEFORE performing the action,
|
||||
// because the action may DELETE the mock object and make the
|
||||
// following expression meaningless.
|
||||
const CallReaction reaction =
|
||||
Mock::GetReactionOnUninterestingCalls(MockObject());
|
||||
|
||||
// True if and only if we need to print this call's arguments and return
|
||||
// value. This definition must be kept in sync with
|
||||
// the behavior of ReportUninterestingCall().
|
||||
const bool need_to_report_uninteresting_call =
|
||||
// If the user allows this uninteresting call, we print it
|
||||
// only when they want informational messages.
|
||||
reaction == kAllow ? LogIsVisible(kInfo) :
|
||||
// If the user wants this to be a warning, we print
|
||||
// it only when they want to see warnings.
|
||||
reaction == kWarn
|
||||
? LogIsVisible(kWarning)
|
||||
:
|
||||
// Otherwise, the user wants this to be an error, and we
|
||||
// should always print detailed information in the error.
|
||||
true;
|
||||
|
||||
if (!need_to_report_uninteresting_call) {
|
||||
// Perform the action without printing the call information.
|
||||
return this->UntypedPerformDefaultAction(
|
||||
untyped_args, "Function call: " + std::string(Name()));
|
||||
}
|
||||
|
||||
// Warns about the uninteresting call.
|
||||
::std::stringstream ss;
|
||||
this->UntypedDescribeUninterestingCall(untyped_args, &ss);
|
||||
|
||||
// Calculates the function result.
|
||||
UntypedActionResultHolderBase* const result =
|
||||
this->UntypedPerformDefaultAction(untyped_args, ss.str());
|
||||
|
||||
// Prints the function result.
|
||||
if (result != nullptr) result->PrintAsActionResult(&ss);
|
||||
|
||||
ReportUninterestingCall(reaction, ss.str());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_excessive = false;
|
||||
::std::stringstream ss;
|
||||
::std::stringstream why;
|
||||
::std::stringstream loc;
|
||||
const void* untyped_action = nullptr;
|
||||
|
||||
// The UntypedFindMatchingExpectation() function acquires and
|
||||
// releases g_gmock_mutex.
|
||||
|
||||
const ExpectationBase* const untyped_expectation =
|
||||
this->UntypedFindMatchingExpectation(untyped_args, &untyped_action,
|
||||
&is_excessive, &ss, &why);
|
||||
const bool found = untyped_expectation != nullptr;
|
||||
|
||||
// True if and only if we need to print the call's arguments
|
||||
// and return value.
|
||||
// This definition must be kept in sync with the uses of Expect()
|
||||
// and Log() in this function.
|
||||
const bool need_to_report_call =
|
||||
!found || is_excessive || LogIsVisible(kInfo);
|
||||
if (!need_to_report_call) {
|
||||
// Perform the action without printing the call information.
|
||||
return untyped_action == nullptr
|
||||
? this->UntypedPerformDefaultAction(untyped_args, "")
|
||||
: this->UntypedPerformAction(untyped_action, untyped_args);
|
||||
}
|
||||
|
||||
ss << " Function call: " << Name();
|
||||
this->UntypedPrintArgs(untyped_args, &ss);
|
||||
|
||||
// In case the action deletes a piece of the expectation, we
|
||||
// generate the message beforehand.
|
||||
if (found && !is_excessive) {
|
||||
untyped_expectation->DescribeLocationTo(&loc);
|
||||
}
|
||||
|
||||
UntypedActionResultHolderBase* result = nullptr;
|
||||
|
||||
auto perform_action = [&] {
|
||||
return untyped_action == nullptr
|
||||
? this->UntypedPerformDefaultAction(untyped_args, ss.str())
|
||||
: this->UntypedPerformAction(untyped_action, untyped_args);
|
||||
};
|
||||
auto handle_failures = [&] {
|
||||
ss << "\n" << why.str();
|
||||
|
||||
if (!found) {
|
||||
// No expectation matches this call - reports a failure.
|
||||
Expect(false, nullptr, -1, ss.str());
|
||||
} else if (is_excessive) {
|
||||
// We had an upper-bound violation and the failure message is in ss.
|
||||
Expect(false, untyped_expectation->file(), untyped_expectation->line(),
|
||||
ss.str());
|
||||
} else {
|
||||
// We had an expected call and the matching expectation is
|
||||
// described in ss.
|
||||
Log(kInfo, loc.str() + ss.str(), 2);
|
||||
}
|
||||
};
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
try {
|
||||
result = perform_action();
|
||||
} catch (...) {
|
||||
handle_failures();
|
||||
throw;
|
||||
}
|
||||
#else
|
||||
result = perform_action();
|
||||
#endif
|
||||
|
||||
if (result != nullptr) result->PrintAsActionResult(&ss);
|
||||
handle_failures();
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns an Expectation object that references and co-owns exp,
|
||||
// which must be an expectation on this mock function.
|
||||
Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
|
||||
// See the definition of untyped_expectations_ for why access to it
|
||||
// is unprotected here.
|
||||
for (UntypedExpectations::const_iterator it =
|
||||
untyped_expectations_.begin();
|
||||
for (UntypedExpectations::const_iterator it = untyped_expectations_.begin();
|
||||
it != untyped_expectations_.end(); ++it) {
|
||||
if (it->get() == exp) {
|
||||
return Expectation(*it);
|
||||
@@ -526,8 +398,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
bool expectations_met = true;
|
||||
for (UntypedExpectations::const_iterator it =
|
||||
untyped_expectations_.begin();
|
||||
for (UntypedExpectations::const_iterator it = untyped_expectations_.begin();
|
||||
it != untyped_expectations_.end(); ++it) {
|
||||
ExpectationBase* const untyped_expectation = it->get();
|
||||
if (untyped_expectation->IsOverSaturated()) {
|
||||
@@ -538,15 +409,22 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
||||
} else if (!untyped_expectation->IsSatisfied()) {
|
||||
expectations_met = false;
|
||||
::std::stringstream ss;
|
||||
ss << "Actual function call count doesn't match "
|
||||
<< untyped_expectation->source_text() << "...\n";
|
||||
|
||||
const ::std::string& expectation_name =
|
||||
untyped_expectation->GetDescription();
|
||||
ss << "Actual function ";
|
||||
if (!expectation_name.empty()) {
|
||||
ss << "\"" << expectation_name << "\" ";
|
||||
}
|
||||
ss << "call count doesn't match " << untyped_expectation->source_text()
|
||||
<< "...\n";
|
||||
// No need to show the source file location of the expectation
|
||||
// in the description, as the Expect() call that follows already
|
||||
// takes care of it.
|
||||
untyped_expectation->MaybeDescribeExtraMatcherTo(&ss);
|
||||
untyped_expectation->DescribeCallCountTo(&ss);
|
||||
Expect(false, untyped_expectation->file(),
|
||||
untyped_expectation->line(), ss.str());
|
||||
Expect(false, untyped_expectation->file(), untyped_expectation->line(),
|
||||
ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +445,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
||||
return expectations_met;
|
||||
}
|
||||
|
||||
CallReaction intToCallReaction(int mock_behavior) {
|
||||
static CallReaction intToCallReaction(int mock_behavior) {
|
||||
if (mock_behavior >= kAllow && mock_behavior <= kFail) {
|
||||
return static_cast<internal::CallReaction>(mock_behavior);
|
||||
}
|
||||
@@ -613,8 +491,7 @@ class MockObjectRegistry {
|
||||
// object alive. Therefore we report any living object as test
|
||||
// failure, unless the user explicitly asked us to ignore it.
|
||||
~MockObjectRegistry() {
|
||||
if (!GMOCK_FLAG(catch_leaked_mocks))
|
||||
return;
|
||||
if (!GMOCK_FLAG_GET(catch_leaked_mocks)) return;
|
||||
|
||||
int leaked_count = 0;
|
||||
for (StateMap::const_iterator it = states_.begin(); it != states_.end();
|
||||
@@ -634,7 +511,7 @@ class MockObjectRegistry {
|
||||
<< state.first_used_test << ")";
|
||||
}
|
||||
std::cout << " should be deleted but never is. Its address is @"
|
||||
<< it->first << ".";
|
||||
<< it->first << ".";
|
||||
leaked_count++;
|
||||
}
|
||||
if (leaked_count > 0) {
|
||||
@@ -652,8 +529,12 @@ class MockObjectRegistry {
|
||||
// RUN_ALL_TESTS() has already returned when this destructor is
|
||||
// called. Therefore we cannot use the normal Google Test
|
||||
// failure reporting mechanism.
|
||||
#if GTEST_OS_QURT
|
||||
qurt_exception_raise_fatal();
|
||||
#else
|
||||
_exit(1); // We cannot call exit() as it is not reentrant and
|
||||
// may already have been called.
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,57 +549,63 @@ MockObjectRegistry g_mock_object_registry;
|
||||
|
||||
// Maps a mock object to the reaction Google Mock should have when an
|
||||
// uninteresting method is called. Protected by g_gmock_mutex.
|
||||
std::map<const void*, internal::CallReaction> g_uninteresting_call_reaction;
|
||||
std::unordered_map<uintptr_t, internal::CallReaction>&
|
||||
UninterestingCallReactionMap() {
|
||||
static auto* map = new std::unordered_map<uintptr_t, internal::CallReaction>;
|
||||
return *map;
|
||||
}
|
||||
|
||||
// Sets the reaction Google Mock should have when an uninteresting
|
||||
// method of the given mock object is called.
|
||||
void SetReactionOnUninterestingCalls(const void* mock_obj,
|
||||
void SetReactionOnUninterestingCalls(uintptr_t mock_obj,
|
||||
internal::CallReaction reaction)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||
g_uninteresting_call_reaction[mock_obj] = reaction;
|
||||
UninterestingCallReactionMap()[mock_obj] = reaction;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Tells Google Mock to allow uninteresting calls on the given mock
|
||||
// object.
|
||||
void Mock::AllowUninterestingCalls(const void* mock_obj)
|
||||
void Mock::AllowUninterestingCalls(uintptr_t mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
SetReactionOnUninterestingCalls(mock_obj, internal::kAllow);
|
||||
}
|
||||
|
||||
// Tells Google Mock to warn the user about uninteresting calls on the
|
||||
// given mock object.
|
||||
void Mock::WarnUninterestingCalls(const void* mock_obj)
|
||||
void Mock::WarnUninterestingCalls(uintptr_t mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
SetReactionOnUninterestingCalls(mock_obj, internal::kWarn);
|
||||
}
|
||||
|
||||
// Tells Google Mock to fail uninteresting calls on the given mock
|
||||
// object.
|
||||
void Mock::FailUninterestingCalls(const void* mock_obj)
|
||||
void Mock::FailUninterestingCalls(uintptr_t mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
SetReactionOnUninterestingCalls(mock_obj, internal::kFail);
|
||||
}
|
||||
|
||||
// Tells Google Mock the given mock object is being destroyed and its
|
||||
// entry in the call-reaction table should be removed.
|
||||
void Mock::UnregisterCallReaction(const void* mock_obj)
|
||||
void Mock::UnregisterCallReaction(uintptr_t mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||
g_uninteresting_call_reaction.erase(mock_obj);
|
||||
UninterestingCallReactionMap().erase(static_cast<uintptr_t>(mock_obj));
|
||||
}
|
||||
|
||||
// Returns the reaction Google Mock will have on uninteresting calls
|
||||
// made on the given mock object.
|
||||
internal::CallReaction Mock::GetReactionOnUninterestingCalls(
|
||||
const void* mock_obj)
|
||||
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
const void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
|
||||
internal::intToCallReaction(GMOCK_FLAG(default_mock_behavior)) :
|
||||
g_uninteresting_call_reaction[mock_obj];
|
||||
return (UninterestingCallReactionMap().count(
|
||||
reinterpret_cast<uintptr_t>(mock_obj)) == 0)
|
||||
? internal::intToCallReaction(
|
||||
GMOCK_FLAG_GET(default_mock_behavior))
|
||||
: UninterestingCallReactionMap()[reinterpret_cast<uintptr_t>(
|
||||
mock_obj)];
|
||||
}
|
||||
|
||||
// Tells Google Mock to ignore mock_obj when checking for leaked mock
|
||||
@@ -873,8 +760,8 @@ Expectation::~Expectation() {}
|
||||
void Sequence::AddExpectation(const Expectation& expectation) const {
|
||||
if (*last_expectation_ != expectation) {
|
||||
if (last_expectation_->expectation_base() != nullptr) {
|
||||
expectation.expectation_base()->immediate_prerequisites_
|
||||
+= *last_expectation_;
|
||||
expectation.expectation_base()->immediate_prerequisites_ +=
|
||||
*last_expectation_;
|
||||
}
|
||||
*last_expectation_ = expectation;
|
||||
}
|
||||
@@ -903,6 +790,6 @@ InSequence::~InSequence() {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
@@ -27,17 +27,15 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
namespace testing {
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
|
||||
"true if and only if Google Mock should report leaked "
|
||||
"mock objects as failures.");
|
||||
|
||||
GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
|
||||
GMOCK_DEFINE_string_(verbose, testing::internal::kWarningVerbosity,
|
||||
"Controls how verbose Google Mock's output is."
|
||||
" Valid values:\n"
|
||||
" info - prints all messages.\n"
|
||||
@@ -51,6 +49,7 @@ GMOCK_DEFINE_int32_(default_mock_behavior, 1,
|
||||
" 1 - by default, mocks act as NaggyMocks.\n"
|
||||
" 2 - by default, mocks act as StrictMocks.");
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Parses a string as a command line flag. The string should have the
|
||||
@@ -59,18 +58,18 @@ namespace internal {
|
||||
//
|
||||
// Returns the value of the flag, or NULL if the parsing failed.
|
||||
static const char* ParseGoogleMockFlagValue(const char* str,
|
||||
const char* flag,
|
||||
const char* flag_name,
|
||||
bool def_optional) {
|
||||
// str and flag must not be NULL.
|
||||
if (str == nullptr || flag == nullptr) return nullptr;
|
||||
if (str == nullptr || flag_name == nullptr) return nullptr;
|
||||
|
||||
// The flag must start with "--gmock_".
|
||||
const std::string flag_str = std::string("--gmock_") + flag;
|
||||
const size_t flag_len = flag_str.length();
|
||||
if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr;
|
||||
const std::string flag_name_str = std::string("--gmock_") + flag_name;
|
||||
const size_t flag_name_len = flag_name_str.length();
|
||||
if (strncmp(str, flag_name_str.c_str(), flag_name_len) != 0) return nullptr;
|
||||
|
||||
// Skips the flag name.
|
||||
const char* flag_end = str + flag_len;
|
||||
const char* flag_end = str + flag_name_len;
|
||||
|
||||
// When def_optional is true, it's OK to not have a "=value" part.
|
||||
if (def_optional && (flag_end[0] == '\0')) {
|
||||
@@ -91,10 +90,10 @@ static const char* ParseGoogleMockFlagValue(const char* str,
|
||||
//
|
||||
// On success, stores the value of the flag in *value, and returns
|
||||
// true. On failure, returns false without changing *value.
|
||||
static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
|
||||
bool* value) {
|
||||
static bool ParseGoogleMockFlag(const char* str, const char* flag_name,
|
||||
bool* value) {
|
||||
// Gets the value of the flag as a string.
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, true);
|
||||
|
||||
// Aborts if the parsing failed.
|
||||
if (value_str == nullptr) return false;
|
||||
@@ -110,10 +109,10 @@ static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
|
||||
// On success, stores the value of the flag in *value, and returns
|
||||
// true. On failure, returns false without changing *value.
|
||||
template <typename String>
|
||||
static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
|
||||
String* value) {
|
||||
static bool ParseGoogleMockFlag(const char* str, const char* flag_name,
|
||||
String* value) {
|
||||
// Gets the value of the flag as a string.
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag, false);
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, false);
|
||||
|
||||
// Aborts if the parsing failed.
|
||||
if (value_str == nullptr) return false;
|
||||
@@ -123,17 +122,17 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ParseGoogleMockIntFlag(const char* str, const char* flag,
|
||||
int32_t* value) {
|
||||
static bool ParseGoogleMockFlag(const char* str, const char* flag_name,
|
||||
int32_t* value) {
|
||||
// Gets the value of the flag as a string.
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
|
||||
const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, true);
|
||||
|
||||
// Aborts if the parsing failed.
|
||||
if (value_str == nullptr) return false;
|
||||
|
||||
// Sets *value to the value of the flag.
|
||||
return ParseInt32(Message() << "The value of flag --" << flag,
|
||||
value_str, value);
|
||||
return ParseInt32(Message() << "The value of flag --" << flag_name, value_str,
|
||||
value);
|
||||
}
|
||||
|
||||
// The internal implementation of InitGoogleMock().
|
||||
@@ -152,11 +151,22 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
|
||||
const char* const arg = arg_string.c_str();
|
||||
|
||||
// Do we see a Google Mock flag?
|
||||
if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
|
||||
&GMOCK_FLAG(catch_leaked_mocks)) ||
|
||||
ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose)) ||
|
||||
ParseGoogleMockIntFlag(arg, "default_mock_behavior",
|
||||
&GMOCK_FLAG(default_mock_behavior))) {
|
||||
bool found_gmock_flag = false;
|
||||
|
||||
#define GMOCK_INTERNAL_PARSE_FLAG(flag_name) \
|
||||
if (!found_gmock_flag) { \
|
||||
auto value = GMOCK_FLAG_GET(flag_name); \
|
||||
if (ParseGoogleMockFlag(arg, #flag_name, &value)) { \
|
||||
GMOCK_FLAG_SET(flag_name, value); \
|
||||
found_gmock_flag = true; \
|
||||
} \
|
||||
}
|
||||
|
||||
GMOCK_INTERNAL_PARSE_FLAG(catch_leaked_mocks)
|
||||
GMOCK_INTERNAL_PARSE_FLAG(verbose)
|
||||
GMOCK_INTERNAL_PARSE_FLAG(default_mock_behavior)
|
||||
|
||||
if (found_gmock_flag) {
|
||||
// Yes. Shift the remainder of the argv list left by one. Note
|
||||
// that argv has (*argc + 1) elements, the last one always being
|
||||
// NULL. The following loop moves the trailing NULL element as
|
@@ -27,8 +27,8 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -56,7 +56,7 @@ void loop() { RUN_ALL_TESTS(); }
|
||||
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
|
||||
// // NOLINT
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
# include <tchar.h> // NOLINT
|
||||
#include <tchar.h> // NOLINT
|
||||
|
||||
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
|
||||
#else
|
@@ -30,7 +30,6 @@
|
||||
#
|
||||
# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
|
||||
load("@rules_python//python:defs.bzl", "py_library", "py_test")
|
||||
|
||||
licenses(["notice"])
|
||||
@@ -39,8 +38,9 @@ licenses(["notice"])
|
||||
cc_test(
|
||||
name = "gmock_all_test",
|
||||
size = "small",
|
||||
srcs = glob(include = ["gmock-*.cc"]),
|
||||
srcs = glob(include = ["gmock-*.cc"]) + ["gmock-matchers_test.h"],
|
||||
linkopts = select({
|
||||
"//:qnx": [],
|
||||
"//:windows": [],
|
||||
"//conditions:default": ["-pthread"],
|
||||
}),
|
File diff suppressed because it is too large
Load Diff
@@ -27,14 +27,13 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests the built-in cardinalities.
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -55,13 +54,12 @@ class MockFoo {
|
||||
MOCK_METHOD0(Bar, int()); // NOLINT
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
MockFoo(const MockFoo&) = delete;
|
||||
MockFoo& operator=(const MockFoo&) = delete;
|
||||
};
|
||||
|
||||
// Tests that Cardinality objects can be default constructed.
|
||||
TEST(CardinalityTest, IsDefaultConstructable) {
|
||||
Cardinality c;
|
||||
}
|
||||
TEST(CardinalityTest, IsDefaultConstructable) { Cardinality c; }
|
||||
|
||||
// Tests that Cardinality objects are copyable.
|
||||
TEST(CardinalityTest, IsCopyable) {
|
||||
@@ -119,8 +117,7 @@ TEST(AnyNumber, Works) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called any number of times",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called any number of times", ss.str());
|
||||
}
|
||||
|
||||
TEST(AnyNumberTest, HasCorrectBounds) {
|
||||
@@ -132,9 +129,11 @@ TEST(AnyNumberTest, HasCorrectBounds) {
|
||||
// Tests AtLeast(n).
|
||||
|
||||
TEST(AtLeastTest, OnNegativeNumber) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
AtLeast(-1);
|
||||
}, "The invocation lower bound must be >= 0");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
AtLeast(-1);
|
||||
},
|
||||
"The invocation lower bound must be >= 0");
|
||||
}
|
||||
|
||||
TEST(AtLeastTest, OnZero) {
|
||||
@@ -147,8 +146,7 @@ TEST(AtLeastTest, OnZero) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "any number of times",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "any number of times", ss.str());
|
||||
}
|
||||
|
||||
TEST(AtLeastTest, OnPositiveNumber) {
|
||||
@@ -164,18 +162,15 @@ TEST(AtLeastTest, OnPositiveNumber) {
|
||||
|
||||
stringstream ss1;
|
||||
AtLeast(1).DescribeTo(&ss1);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least once",
|
||||
ss1.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least once", ss1.str());
|
||||
|
||||
stringstream ss2;
|
||||
c.DescribeTo(&ss2);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least twice",
|
||||
ss2.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least twice", ss2.str());
|
||||
|
||||
stringstream ss3;
|
||||
AtLeast(3).DescribeTo(&ss3);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least 3 times",
|
||||
ss3.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "at least 3 times", ss3.str());
|
||||
}
|
||||
|
||||
TEST(AtLeastTest, HasCorrectBounds) {
|
||||
@@ -187,9 +182,11 @@ TEST(AtLeastTest, HasCorrectBounds) {
|
||||
// Tests AtMost(n).
|
||||
|
||||
TEST(AtMostTest, OnNegativeNumber) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
AtMost(-1);
|
||||
}, "The invocation upper bound must be >= 0");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
AtMost(-1);
|
||||
},
|
||||
"The invocation upper bound must be >= 0");
|
||||
}
|
||||
|
||||
TEST(AtMostTest, OnZero) {
|
||||
@@ -202,8 +199,7 @@ TEST(AtMostTest, OnZero) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called", ss.str());
|
||||
}
|
||||
|
||||
TEST(AtMostTest, OnPositiveNumber) {
|
||||
@@ -219,18 +215,15 @@ TEST(AtMostTest, OnPositiveNumber) {
|
||||
|
||||
stringstream ss1;
|
||||
AtMost(1).DescribeTo(&ss1);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most once",
|
||||
ss1.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most once", ss1.str());
|
||||
|
||||
stringstream ss2;
|
||||
c.DescribeTo(&ss2);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most twice",
|
||||
ss2.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most twice", ss2.str());
|
||||
|
||||
stringstream ss3;
|
||||
AtMost(3).DescribeTo(&ss3);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most 3 times",
|
||||
ss3.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most 3 times", ss3.str());
|
||||
}
|
||||
|
||||
TEST(AtMostTest, HasCorrectBounds) {
|
||||
@@ -242,22 +235,28 @@ TEST(AtMostTest, HasCorrectBounds) {
|
||||
// Tests Between(m, n).
|
||||
|
||||
TEST(BetweenTest, OnNegativeStart) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Between(-1, 2);
|
||||
}, "The invocation lower bound must be >= 0, but is actually -1");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Between(-1, 2);
|
||||
},
|
||||
"The invocation lower bound must be >= 0, but is actually -1");
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnNegativeEnd) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Between(1, -2);
|
||||
}, "The invocation upper bound must be >= 0, but is actually -2");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Between(1, -2);
|
||||
},
|
||||
"The invocation upper bound must be >= 0, but is actually -2");
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnStartBiggerThanEnd) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Between(2, 1);
|
||||
}, "The invocation upper bound (1) must be >= "
|
||||
"the invocation lower bound (2)");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Between(2, 1);
|
||||
},
|
||||
"The invocation upper bound (1) must be >= "
|
||||
"the invocation lower bound (2)");
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnZeroStartAndZeroEnd) {
|
||||
@@ -271,8 +270,7 @@ TEST(BetweenTest, OnZeroStartAndZeroEnd) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called", ss.str());
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
|
||||
@@ -289,8 +287,7 @@ TEST(BetweenTest, OnZeroStartAndNonZeroEnd) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most twice",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called at most twice", ss.str());
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnSameStartAndEnd) {
|
||||
@@ -307,8 +304,7 @@ TEST(BetweenTest, OnSameStartAndEnd) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called 3 times",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called 3 times", ss.str());
|
||||
}
|
||||
|
||||
TEST(BetweenTest, OnDifferentStartAndEnd) {
|
||||
@@ -328,8 +324,7 @@ TEST(BetweenTest, OnDifferentStartAndEnd) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called between 3 and 5 times",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called between 3 and 5 times", ss.str());
|
||||
}
|
||||
|
||||
TEST(BetweenTest, HasCorrectBounds) {
|
||||
@@ -341,9 +336,11 @@ TEST(BetweenTest, HasCorrectBounds) {
|
||||
// Tests Exactly(n).
|
||||
|
||||
TEST(ExactlyTest, OnNegativeNumber) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Exactly(-1);
|
||||
}, "The invocation lower bound must be >= 0");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Exactly(-1);
|
||||
},
|
||||
"The invocation lower bound must be >= 0");
|
||||
}
|
||||
|
||||
TEST(ExactlyTest, OnZero) {
|
||||
@@ -356,8 +353,7 @@ TEST(ExactlyTest, OnZero) {
|
||||
|
||||
stringstream ss;
|
||||
c.DescribeTo(&ss);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called",
|
||||
ss.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "never called", ss.str());
|
||||
}
|
||||
|
||||
TEST(ExactlyTest, OnPositiveNumber) {
|
||||
@@ -370,18 +366,15 @@ TEST(ExactlyTest, OnPositiveNumber) {
|
||||
|
||||
stringstream ss1;
|
||||
Exactly(1).DescribeTo(&ss1);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called once",
|
||||
ss1.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called once", ss1.str());
|
||||
|
||||
stringstream ss2;
|
||||
c.DescribeTo(&ss2);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called twice",
|
||||
ss2.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called twice", ss2.str());
|
||||
|
||||
stringstream ss3;
|
||||
Exactly(3).DescribeTo(&ss3);
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called 3 times",
|
||||
ss3.str());
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "called 3 times", ss3.str());
|
||||
}
|
||||
|
||||
TEST(ExactlyTest, HasCorrectBounds) {
|
@@ -27,6 +27,11 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Silence C4503 (decorated name length exceeded) for MSVC.
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4503)
|
||||
#endif
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
@@ -37,7 +42,7 @@
|
||||
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
|
||||
// we are getting compiler errors if we use basetyps.h, hence including
|
||||
// objbase.h for definition of STDMETHOD.
|
||||
# include <objbase.h>
|
||||
#include <objbase.h>
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include <functional>
|
||||
@@ -65,7 +70,7 @@ using testing::Return;
|
||||
using testing::ReturnRef;
|
||||
using testing::TypedEq;
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class TemplatedCopyable {
|
||||
public:
|
||||
TemplatedCopyable() {}
|
||||
@@ -82,7 +87,7 @@ class FooInterface {
|
||||
|
||||
virtual int Nullary() = 0;
|
||||
virtual bool Unary(int x) = 0;
|
||||
virtual long Binary(short x, int y) = 0; // NOLINT
|
||||
virtual long Binary(short x, int y) = 0; // NOLINT
|
||||
virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
|
||||
float g, double h, unsigned i, char* j,
|
||||
const std::string& k) = 0;
|
||||
@@ -133,8 +138,8 @@ class FooInterface {
|
||||
// signature. This was fixed in Visual Studio 2008. However, the compiler
|
||||
// still emits a warning that alerts about this change in behavior.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4373)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4373)
|
||||
#endif
|
||||
class MockFoo : public FooInterface {
|
||||
public:
|
||||
@@ -203,7 +208,8 @@ class MockFoo : public FooInterface {
|
||||
MOCK_METHOD(int, RefQualifiedOverloaded, (), (ref(&&), override));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
MockFoo(const MockFoo&) = delete;
|
||||
MockFoo& operator=(const MockFoo&) = delete;
|
||||
};
|
||||
|
||||
class LegacyMockFoo : public FooInterface {
|
||||
@@ -275,11 +281,12 @@ class LegacyMockFoo : public FooInterface {
|
||||
int RefQualifiedOverloaded() && override { return 0; }
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockFoo);
|
||||
LegacyMockFoo(const LegacyMockFoo&) = delete;
|
||||
LegacyMockFoo& operator=(const LegacyMockFoo&) = delete;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
@@ -493,7 +500,8 @@ class MockB {
|
||||
MOCK_METHOD(void, DoB, ());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
|
||||
MockB(const MockB&) = delete;
|
||||
MockB& operator=(const MockB&) = delete;
|
||||
};
|
||||
|
||||
class LegacyMockB {
|
||||
@@ -503,7 +511,8 @@ class LegacyMockB {
|
||||
MOCK_METHOD0(DoB, void());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockB);
|
||||
LegacyMockB(const LegacyMockB&) = delete;
|
||||
LegacyMockB& operator=(const LegacyMockB&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -558,7 +567,8 @@ class MockStack : public StackInterface<T> {
|
||||
MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (int), (const));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
|
||||
MockStack(const MockStack&) = delete;
|
||||
MockStack& operator=(const MockStack&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -576,7 +586,8 @@ class LegacyMockStack : public StackInterface<T> {
|
||||
MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStack);
|
||||
LegacyMockStack(const LegacyMockStack&) = delete;
|
||||
LegacyMockStack& operator=(const LegacyMockStack&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -595,10 +606,8 @@ TYPED_TEST(TemplateMockTest, Works) {
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(mock, Push(_));
|
||||
int n = 5;
|
||||
EXPECT_CALL(mock, GetTop())
|
||||
.WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop())
|
||||
.Times(AnyNumber());
|
||||
EXPECT_CALL(mock, GetTop()).WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop()).Times(AnyNumber());
|
||||
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
mock.Push(5);
|
||||
@@ -612,10 +621,8 @@ TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
|
||||
TypeParam mock;
|
||||
|
||||
const std::map<int, int> a_map;
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma())
|
||||
.WillOnce(Return(a_map));
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma(1))
|
||||
.WillOnce(Return(a_map));
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma()).WillOnce(Return(a_map));
|
||||
EXPECT_CALL(mock, ReturnTypeWithComma(1)).WillOnce(Return(a_map));
|
||||
|
||||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
|
||||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
|
||||
@@ -650,7 +657,8 @@ class MockStackWithCallType : public StackInterfaceWithCallType<T> {
|
||||
(Calltype(STDMETHODCALLTYPE), override, const));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
|
||||
MockStackWithCallType(const MockStackWithCallType&) = delete;
|
||||
MockStackWithCallType& operator=(const MockStackWithCallType&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -664,7 +672,9 @@ class LegacyMockStackWithCallType : public StackInterfaceWithCallType<T> {
|
||||
MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStackWithCallType);
|
||||
LegacyMockStackWithCallType(const LegacyMockStackWithCallType&) = delete;
|
||||
LegacyMockStackWithCallType& operator=(const LegacyMockStackWithCallType&) =
|
||||
delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -685,10 +695,8 @@ TYPED_TEST(TemplateMockTestWithCallType, Works) {
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(mock, Push(_));
|
||||
int n = 5;
|
||||
EXPECT_CALL(mock, GetTop())
|
||||
.WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop())
|
||||
.Times(AnyNumber());
|
||||
EXPECT_CALL(mock, GetTop()).WillOnce(ReturnRef(n));
|
||||
EXPECT_CALL(mock, Pop()).Times(AnyNumber());
|
||||
|
||||
EXPECT_EQ(0, mock.GetSize());
|
||||
mock.Push(5);
|
||||
@@ -716,7 +724,9 @@ class MockOverloadedOnArgNumber {
|
||||
MY_MOCK_METHODS1_;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
|
||||
MockOverloadedOnArgNumber(const MockOverloadedOnArgNumber&) = delete;
|
||||
MockOverloadedOnArgNumber& operator=(const MockOverloadedOnArgNumber&) =
|
||||
delete;
|
||||
};
|
||||
|
||||
class LegacyMockOverloadedOnArgNumber {
|
||||
@@ -726,7 +736,10 @@ class LegacyMockOverloadedOnArgNumber {
|
||||
LEGACY_MY_MOCK_METHODS1_;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockOverloadedOnArgNumber);
|
||||
LegacyMockOverloadedOnArgNumber(const LegacyMockOverloadedOnArgNumber&) =
|
||||
delete;
|
||||
LegacyMockOverloadedOnArgNumber& operator=(
|
||||
const LegacyMockOverloadedOnArgNumber&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -747,9 +760,9 @@ TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
|
||||
EXPECT_TRUE(mock.Overloaded(true, 1));
|
||||
}
|
||||
|
||||
#define MY_MOCK_METHODS2_ \
|
||||
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
|
||||
MOCK_METHOD1(Overloaded, int(int n))
|
||||
#define MY_MOCK_METHODS2_ \
|
||||
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
|
||||
MOCK_METHOD1(Overloaded, int(int n))
|
||||
|
||||
class MockOverloadedOnConstness {
|
||||
public:
|
||||
@@ -758,7 +771,9 @@ class MockOverloadedOnConstness {
|
||||
MY_MOCK_METHODS2_;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness);
|
||||
MockOverloadedOnConstness(const MockOverloadedOnConstness&) = delete;
|
||||
MockOverloadedOnConstness& operator=(const MockOverloadedOnConstness&) =
|
||||
delete;
|
||||
};
|
||||
|
||||
TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
|
||||
@@ -779,9 +794,7 @@ TEST(MockMethodMockFunctionTest, WorksForVoidNullary) {
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForNonVoidNullary) {
|
||||
MockFunction<int()> foo;
|
||||
EXPECT_CALL(foo, Call())
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
EXPECT_CALL(foo, Call()).WillOnce(Return(1)).WillOnce(Return(2));
|
||||
EXPECT_EQ(1, foo.Call());
|
||||
EXPECT_EQ(2, foo.Call());
|
||||
}
|
||||
@@ -794,19 +807,17 @@ TEST(MockMethodMockFunctionTest, WorksForVoidUnary) {
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksForNonVoidBinary) {
|
||||
MockFunction<int(bool, int)> foo;
|
||||
EXPECT_CALL(foo, Call(false, 42))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
EXPECT_CALL(foo, Call(true, Ge(100)))
|
||||
.WillOnce(Return(3));
|
||||
EXPECT_CALL(foo, Call(false, 42)).WillOnce(Return(1)).WillOnce(Return(2));
|
||||
EXPECT_CALL(foo, Call(true, Ge(100))).WillOnce(Return(3));
|
||||
EXPECT_EQ(1, foo.Call(false, 42));
|
||||
EXPECT_EQ(2, foo.Call(false, 42));
|
||||
EXPECT_EQ(3, foo.Call(true, 120));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
|
||||
MockFunction<int(bool a0, char a1, int a2, int a3, int a4,
|
||||
int a5, int a6, char a7, int a8, bool a9)> foo;
|
||||
MockFunction<int(bool a0, char a1, int a2, int a3, int a4, int a5, int a6,
|
||||
char a7, int a8, bool a9)>
|
||||
foo;
|
||||
EXPECT_CALL(foo, Call(_, 'a', _, _, _, _, _, _, _, _))
|
||||
.WillOnce(Return(1))
|
||||
.WillOnce(Return(2));
|
||||
@@ -816,9 +827,7 @@ TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
|
||||
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunction) {
|
||||
MockFunction<int(int)> foo;
|
||||
auto call = [](const std::function<int(int)> &f, int i) {
|
||||
return f(i);
|
||||
};
|
||||
auto call = [](const std::function<int(int)>& f, int i) { return f(i); };
|
||||
EXPECT_CALL(foo, Call(1)).WillOnce(Return(-1));
|
||||
EXPECT_CALL(foo, Call(2)).WillOnce(Return(-2));
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), 1));
|
||||
@@ -836,10 +845,8 @@ TEST(MockMethodMockFunctionTest, AsStdFunctionReturnsReference) {
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) {
|
||||
MockFunction<int(int &)> foo;
|
||||
auto call = [](const std::function<int(int& )> &f, int &i) {
|
||||
return f(i);
|
||||
};
|
||||
MockFunction<int(int&)> foo;
|
||||
auto call = [](const std::function<int(int&)>& f, int& i) { return f(i); };
|
||||
int i = 42;
|
||||
EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1));
|
||||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
|
||||
@@ -888,8 +895,7 @@ TYPED_TEST(
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
struct AlternateCallable {
|
||||
};
|
||||
struct AlternateCallable {};
|
||||
|
||||
TYPED_TEST(MockMethodMockFunctionSignatureTest,
|
||||
IsMockFunctionTemplateArgumentDeducedForAlternateCallable) {
|
||||
@@ -898,16 +904,14 @@ TYPED_TEST(MockMethodMockFunctionSignatureTest,
|
||||
EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo));
|
||||
}
|
||||
|
||||
TYPED_TEST(
|
||||
MockMethodMockFunctionSignatureTest,
|
||||
IsMockFunctionCallMethodSignatureTheSameForAlternateCallable) {
|
||||
TYPED_TEST(MockMethodMockFunctionSignatureTest,
|
||||
IsMockFunctionCallMethodSignatureTheSameForAlternateCallable) {
|
||||
using ForRawSignature = decltype(&MockFunction<TypeParam>::Call);
|
||||
using ForStdFunction =
|
||||
decltype(&MockFunction<std::function<TypeParam>>::Call);
|
||||
EXPECT_TRUE((std::is_same<ForRawSignature, ForStdFunction>::value));
|
||||
}
|
||||
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD(void, func, ());
|
||||
};
|
||||
@@ -925,22 +929,21 @@ struct MockMethodSizes4 {
|
||||
};
|
||||
|
||||
struct LegacyMockMethodSizes0 {
|
||||
MOCK_METHOD0(func, void());
|
||||
MOCK_METHOD0(func, void());
|
||||
};
|
||||
struct LegacyMockMethodSizes1 {
|
||||
MOCK_METHOD1(func, void(int));
|
||||
MOCK_METHOD1(func, void(int));
|
||||
};
|
||||
struct LegacyMockMethodSizes2 {
|
||||
MOCK_METHOD2(func, void(int, int));
|
||||
MOCK_METHOD2(func, void(int, int));
|
||||
};
|
||||
struct LegacyMockMethodSizes3 {
|
||||
MOCK_METHOD3(func, void(int, int, int));
|
||||
MOCK_METHOD3(func, void(int, int, int));
|
||||
};
|
||||
struct LegacyMockMethodSizes4 {
|
||||
MOCK_METHOD4(func, void(int, int, int, int));
|
||||
MOCK_METHOD4(func, void(int, int, int, int));
|
||||
};
|
||||
|
||||
|
||||
TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) {
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
|
||||
@@ -955,6 +958,21 @@ TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) {
|
||||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(MockMethodSizes0));
|
||||
}
|
||||
|
||||
TEST(MockMethodMockFunctionTest, EnsureNoUnusedMemberFunction) {
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic error "-Wunused-member-function"
|
||||
#endif
|
||||
// https://github.com/google/googletest/issues/4052
|
||||
struct Foo {
|
||||
MOCK_METHOD(void, foo, ());
|
||||
};
|
||||
EXPECT_CALL(Foo(), foo()).Times(0);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
||||
void hasTwoParams(int, int);
|
||||
void MaybeThrows();
|
||||
void DoesntThrow() noexcept;
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests the internal utilities.
|
||||
@@ -58,7 +57,7 @@
|
||||
#undef GTEST_IMPLEMENTATION_
|
||||
|
||||
#if GTEST_OS_CYGWIN
|
||||
# include <sys/types.h> // For ssize_t. NOLINT
|
||||
#include <sys/types.h> // For ssize_t. NOLINT
|
||||
#endif
|
||||
|
||||
namespace proto2 {
|
||||
@@ -70,24 +69,23 @@ namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(JoinAsTupleTest, JoinsEmptyTuple) {
|
||||
EXPECT_EQ("", JoinAsTuple(Strings()));
|
||||
TEST(JoinAsKeyValueTupleTest, JoinsEmptyTuple) {
|
||||
EXPECT_EQ("", JoinAsKeyValueTuple({}, Strings()));
|
||||
}
|
||||
|
||||
TEST(JoinAsTupleTest, JoinsOneTuple) {
|
||||
const char* fields[] = {"1"};
|
||||
EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1)));
|
||||
TEST(JoinAsKeyValueTupleTest, JoinsOneTuple) {
|
||||
EXPECT_EQ("(a: 1)", JoinAsKeyValueTuple({"a"}, {"1"}));
|
||||
}
|
||||
|
||||
TEST(JoinAsTupleTest, JoinsTwoTuple) {
|
||||
const char* fields[] = {"1", "a"};
|
||||
EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2)));
|
||||
TEST(JoinAsKeyValueTupleTest, JoinsTwoTuple) {
|
||||
EXPECT_EQ("(a: 1, b: 2)", JoinAsKeyValueTuple({"a", "b"}, {"1", "2"}));
|
||||
}
|
||||
|
||||
TEST(JoinAsTupleTest, JoinsTenTuple) {
|
||||
const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
|
||||
EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
|
||||
JoinAsTuple(Strings(fields, fields + 10)));
|
||||
TEST(JoinAsKeyValueTupleTest, JoinsTenTuple) {
|
||||
EXPECT_EQ(
|
||||
"(a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10)",
|
||||
JoinAsKeyValueTuple({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
|
||||
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));
|
||||
}
|
||||
|
||||
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
|
||||
@@ -140,6 +138,12 @@ TEST(GetRawPointerTest, WorksForRawPointers) {
|
||||
EXPECT_EQ(&n, GetRawPointer(&n));
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForStdReferenceWrapper) {
|
||||
int n = 1;
|
||||
EXPECT_EQ(&n, GetRawPointer(std::ref(n)));
|
||||
EXPECT_EQ(&n, GetRawPointer(std::cref(n)));
|
||||
}
|
||||
|
||||
// Tests KindOf<T>.
|
||||
|
||||
class Base {};
|
||||
@@ -150,19 +154,19 @@ TEST(KindOfTest, Bool) {
|
||||
}
|
||||
|
||||
TEST(KindOfTest, Integer) {
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
|
||||
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
|
||||
// ssize_t is not defined on Windows and possibly some other OSes.
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT
|
||||
@@ -170,15 +174,15 @@ TEST(KindOfTest, Integer) {
|
||||
}
|
||||
|
||||
TEST(KindOfTest, FloatingPoint) {
|
||||
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT
|
||||
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT
|
||||
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT
|
||||
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT
|
||||
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT
|
||||
}
|
||||
|
||||
TEST(KindOfTest, Other) {
|
||||
EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT
|
||||
EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT
|
||||
EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT
|
||||
EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT
|
||||
EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT
|
||||
}
|
||||
|
||||
// Tests LosslessArithmeticConvertible<T, U>.
|
||||
@@ -209,26 +213,26 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
|
||||
|
||||
// Unsigned => larger unsigned is fine.
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<
|
||||
unsigned short, uint64_t>::value)); // NOLINT
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned short,
|
||||
uint64_t>::value)); // NOLINT
|
||||
|
||||
// Signed => unsigned is not fine.
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
short, uint64_t>::value)); // NOLINT
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
signed char, unsigned int>::value)); // NOLINT
|
||||
EXPECT_FALSE(
|
||||
(LosslessArithmeticConvertible<short, uint64_t>::value)); // NOLINT
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<signed char,
|
||||
unsigned int>::value)); // NOLINT
|
||||
|
||||
// Same size and same signedness: fine too.
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<
|
||||
unsigned char, unsigned char>::value));
|
||||
EXPECT_TRUE(
|
||||
(LosslessArithmeticConvertible<unsigned char, unsigned char>::value));
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<
|
||||
unsigned long, unsigned long>::value)); // NOLINT
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned long,
|
||||
unsigned long>::value)); // NOLINT
|
||||
|
||||
// Same size, different signedness: not fine.
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
unsigned char, signed char>::value));
|
||||
EXPECT_FALSE(
|
||||
(LosslessArithmeticConvertible<unsigned char, signed char>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::value));
|
||||
|
||||
@@ -243,8 +247,8 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
|
||||
// the format of the latter is implementation-defined.
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
short, long double>::value)); // NOLINT
|
||||
EXPECT_FALSE(
|
||||
(LosslessArithmeticConvertible<short, long double>::value)); // NOLINT
|
||||
}
|
||||
|
||||
TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
|
||||
@@ -272,7 +276,7 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (sizeof(double) == sizeof(long double)) { // NOLINT
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
// In some implementations (e.g. MSVC), double and long double
|
||||
// have the same size.
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
|
||||
@@ -291,7 +295,7 @@ TEST(TupleMatchesTest, WorksForSize0) {
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize1) {
|
||||
std::tuple<Matcher<int> > matchers(Eq(1));
|
||||
std::tuple<Matcher<int>> matchers(Eq(1));
|
||||
std::tuple<int> values1(1), values2(2);
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
@@ -299,7 +303,7 @@ TEST(TupleMatchesTest, WorksForSize1) {
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize2) {
|
||||
std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
||||
std::tuple<Matcher<int>, Matcher<char>> matchers(Eq(1), Eq('a'));
|
||||
std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
|
||||
values4(2, 'b');
|
||||
|
||||
@@ -312,7 +316,7 @@ TEST(TupleMatchesTest, WorksForSize2) {
|
||||
TEST(TupleMatchesTest, WorksForSize5) {
|
||||
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
|
||||
Matcher<long>, // NOLINT
|
||||
Matcher<std::string> >
|
||||
Matcher<std::string>>
|
||||
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
|
||||
std::tuple<int, char, bool, long, std::string> // NOLINT
|
||||
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
|
||||
@@ -331,13 +335,10 @@ TEST(AssertTest, SucceedsOnTrue) {
|
||||
|
||||
// Tests that Assert(false, ...) generates a fatal failure.
|
||||
TEST(AssertTest, FailsFatallyOnFalse) {
|
||||
EXPECT_DEATH_IF_SUPPORTED({
|
||||
Assert(false, __FILE__, __LINE__, "This should fail.");
|
||||
}, "");
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
{ Assert(false, __FILE__, __LINE__, "This should fail."); }, "");
|
||||
|
||||
EXPECT_DEATH_IF_SUPPORTED({
|
||||
Assert(false, __FILE__, __LINE__);
|
||||
}, "");
|
||||
EXPECT_DEATH_IF_SUPPORTED({ Assert(false, __FILE__, __LINE__); }, "");
|
||||
}
|
||||
|
||||
// Tests that Expect(true, ...) succeeds.
|
||||
@@ -348,40 +349,44 @@ TEST(ExpectTest, SucceedsOnTrue) {
|
||||
|
||||
// Tests that Expect(false, ...) generates a non-fatal failure.
|
||||
TEST(ExpectTest, FailsNonfatallyOnFalse) {
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Expect(false, __FILE__, __LINE__, "This should fail.");
|
||||
}, "This should fail");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Expect(false, __FILE__, __LINE__, "This should fail.");
|
||||
},
|
||||
"This should fail");
|
||||
|
||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||
Expect(false, __FILE__, __LINE__);
|
||||
}, "Expectation failed");
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
{ // NOLINT
|
||||
Expect(false, __FILE__, __LINE__);
|
||||
},
|
||||
"Expectation failed");
|
||||
}
|
||||
|
||||
// Tests LogIsVisible().
|
||||
|
||||
class LogIsVisibleTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override { original_verbose_ = GMOCK_FLAG(verbose); }
|
||||
void SetUp() override { original_verbose_ = GMOCK_FLAG_GET(verbose); }
|
||||
|
||||
void TearDown() override { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
void TearDown() override { GMOCK_FLAG_SET(verbose, original_verbose_); }
|
||||
|
||||
std::string original_verbose_;
|
||||
};
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
|
||||
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kInfoVerbosity);
|
||||
EXPECT_TRUE(LogIsVisible(kInfo));
|
||||
EXPECT_TRUE(LogIsVisible(kWarning));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
|
||||
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kErrorVerbosity);
|
||||
EXPECT_FALSE(LogIsVisible(kInfo));
|
||||
EXPECT_FALSE(LogIsVisible(kWarning));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
||||
GMOCK_FLAG(verbose) = kWarningVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kWarningVerbosity);
|
||||
EXPECT_FALSE(LogIsVisible(kInfo));
|
||||
EXPECT_TRUE(LogIsVisible(kWarning));
|
||||
}
|
||||
@@ -394,31 +399,31 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
||||
// and log severity.
|
||||
void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
|
||||
bool should_print) {
|
||||
const std::string old_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = verbosity;
|
||||
const std::string old_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, verbosity);
|
||||
CaptureStdout();
|
||||
Log(severity, "Test log.\n", 0);
|
||||
if (should_print) {
|
||||
EXPECT_THAT(GetCapturedStdout().c_str(),
|
||||
ContainsRegex(
|
||||
severity == kWarning ?
|
||||
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
|
||||
"^\nTest log\\.\nStack trace:\n"));
|
||||
EXPECT_THAT(
|
||||
GetCapturedStdout().c_str(),
|
||||
ContainsRegex(severity == kWarning
|
||||
? "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n"
|
||||
: "^\nTest log\\.\nStack trace:\n"));
|
||||
} else {
|
||||
EXPECT_STREQ("", GetCapturedStdout().c_str());
|
||||
}
|
||||
GMOCK_FLAG(verbose) = old_flag;
|
||||
GMOCK_FLAG_SET(verbose, old_flag);
|
||||
}
|
||||
|
||||
// Tests that when the stack_frames_to_skip parameter is negative,
|
||||
// Log() doesn't include the stack trace in the output.
|
||||
TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, kInfoVerbosity);
|
||||
CaptureStdout();
|
||||
Log(kInfo, "Test log.\n", -1);
|
||||
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
|
||||
@@ -440,7 +445,8 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
|
||||
const std::string log = GetCapturedStdout();
|
||||
|
||||
std::string expected_trace =
|
||||
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
|
||||
(testing::Message() << GTEST_FLAG_GET(stack_trace_depth) << "::")
|
||||
.GetString();
|
||||
std::string expected_message =
|
||||
"\nGMOCK WARNING:\n"
|
||||
"Test log.\n"
|
||||
@@ -449,13 +455,13 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
|
||||
EXPECT_THAT(log, HasSubstr(expected_message));
|
||||
int skip_count = atoi(log.substr(expected_message.size()).c_str());
|
||||
|
||||
# if defined(NDEBUG)
|
||||
#if defined(NDEBUG)
|
||||
// In opt mode, no stack frame should be skipped.
|
||||
const int expected_skip_count = 0;
|
||||
# else
|
||||
#else
|
||||
// In dbg mode, the stack frames should be skipped.
|
||||
const int expected_skip_count = 100;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Note that each inner implementation layer will +1 the number to remove
|
||||
// itself from the trace. This means that the value is a little higher than
|
||||
@@ -497,12 +503,12 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
|
||||
|
||||
// Verifies that Log() behaves correctly for the given verbosity level
|
||||
// and log severity.
|
||||
std::string GrabOutput(void(*logger)(), const char* verbosity) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = verbosity;
|
||||
std::string GrabOutput(void (*logger)(), const char* verbosity) {
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, verbosity);
|
||||
CaptureStdout();
|
||||
logger();
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
return GetCapturedStdout();
|
||||
}
|
||||
|
||||
@@ -532,7 +538,7 @@ TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
|
||||
|
||||
// Verifies that EXPECT_CALL doesn't log
|
||||
// if the --gmock_verbose flag is set to "error".
|
||||
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
|
||||
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
|
||||
EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
|
||||
}
|
||||
|
||||
@@ -576,9 +582,9 @@ TEST(OnCallTest, LogsAnythingArgument) {
|
||||
|
||||
TEST(StlContainerViewTest, WorksForStlContainer) {
|
||||
StaticAssertTypeEq<std::vector<int>,
|
||||
StlContainerView<std::vector<int> >::type>();
|
||||
StlContainerView<std::vector<int>>::type>();
|
||||
StaticAssertTypeEq<const std::vector<double>&,
|
||||
StlContainerView<std::vector<double> >::const_reference>();
|
||||
StlContainerView<std::vector<double>>::const_reference>();
|
||||
|
||||
typedef std::vector<char> Chars;
|
||||
Chars v1;
|
||||
@@ -591,17 +597,16 @@ TEST(StlContainerViewTest, WorksForStlContainer) {
|
||||
}
|
||||
|
||||
TEST(StlContainerViewTest, WorksForStaticNativeArray) {
|
||||
StaticAssertTypeEq<NativeArray<int>,
|
||||
StlContainerView<int[3]>::type>();
|
||||
StaticAssertTypeEq<NativeArray<int>, StlContainerView<int[3]>::type>();
|
||||
StaticAssertTypeEq<NativeArray<double>,
|
||||
StlContainerView<const double[4]>::type>();
|
||||
StlContainerView<const double[4]>::type>();
|
||||
StaticAssertTypeEq<NativeArray<char[3]>,
|
||||
StlContainerView<const char[2][3]>::type>();
|
||||
StlContainerView<const char[2][3]>::type>();
|
||||
|
||||
StaticAssertTypeEq<const NativeArray<int>,
|
||||
StlContainerView<int[2]>::const_reference>();
|
||||
StlContainerView<int[2]>::const_reference>();
|
||||
|
||||
int a1[3] = { 0, 1, 2 };
|
||||
int a1[3] = {0, 1, 2};
|
||||
NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
|
||||
EXPECT_EQ(3U, a2.size());
|
||||
EXPECT_EQ(a1, a2.begin());
|
||||
@@ -619,24 +624,24 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
|
||||
|
||||
TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
|
||||
StaticAssertTypeEq<NativeArray<int>,
|
||||
StlContainerView<std::tuple<const int*, size_t> >::type>();
|
||||
StlContainerView<std::tuple<const int*, size_t>>::type>();
|
||||
StaticAssertTypeEq<
|
||||
NativeArray<double>,
|
||||
StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>();
|
||||
StlContainerView<std::tuple<std::shared_ptr<double>, int>>::type>();
|
||||
|
||||
StaticAssertTypeEq<
|
||||
const NativeArray<int>,
|
||||
StlContainerView<std::tuple<const int*, int> >::const_reference>();
|
||||
StlContainerView<std::tuple<const int*, int>>::const_reference>();
|
||||
|
||||
int a1[3] = { 0, 1, 2 };
|
||||
int a1[3] = {0, 1, 2};
|
||||
const int* const p1 = a1;
|
||||
NativeArray<int> a2 =
|
||||
StlContainerView<std::tuple<const int*, int> >::ConstReference(
|
||||
StlContainerView<std::tuple<const int*, int>>::ConstReference(
|
||||
std::make_tuple(p1, 3));
|
||||
EXPECT_EQ(3U, a2.size());
|
||||
EXPECT_EQ(a1, a2.begin());
|
||||
|
||||
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
|
||||
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t>>::Copy(
|
||||
std::make_tuple(static_cast<int*>(a1), 3));
|
||||
ASSERT_EQ(3U, a3.size());
|
||||
EXPECT_EQ(0, a3.begin()[0]);
|
||||
@@ -715,6 +720,46 @@ TEST(FunctionTest, LongArgumentList) {
|
||||
F::MakeResultIgnoredValue>::value));
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, InvalidString) {
|
||||
std::string unescaped;
|
||||
EXPECT_FALSE(Base64Unescape("(invalid)", &unescaped));
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortString) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQh", &unescaped));
|
||||
EXPECT_EQ("Hello world!", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortStringWithPadding) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ=", &unescaped));
|
||||
EXPECT_EQ("Hello world", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortStringWithoutPadding) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ", &unescaped));
|
||||
EXPECT_EQ("Hello world", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, LongStringWithWhiteSpaces) {
|
||||
std::string escaped =
|
||||
R"(TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
|
||||
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
|
||||
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
|
||||
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
|
||||
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=)";
|
||||
std::string expected =
|
||||
"Man is distinguished, not only by his reason, but by this singular "
|
||||
"passion from other animals, which is a lust of the mind, that by a "
|
||||
"perseverance of delight in the continued and indefatigable generation "
|
||||
"of knowledge, exceeds the short vehemence of any carnal pleasure.";
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape(escaped, &unescaped));
|
||||
EXPECT_EQ(expected, unescaped);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace internal
|
||||
} // namespace testing
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1819
test/googletest-1.13.0/googlemock/test/gmock-matchers-misc_test.cc
Normal file
1819
test/googletest-1.13.0/googlemock/test/gmock-matchers-misc_test.cc
Normal file
File diff suppressed because it is too large
Load Diff
192
test/googletest-1.13.0/googlemock/test/gmock-matchers_test.h
Normal file
192
test/googletest-1.13.0/googlemock/test/gmock-matchers_test.h
Normal file
@@ -0,0 +1,192 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests some commonly used argument matchers.
|
||||
|
||||
#ifndef GOOGLEMOCK_TEST_GMOCK_MATCHERS_TEST_H_
|
||||
#define GOOGLEMOCK_TEST_GMOCK_MATCHERS_TEST_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock-matchers.h"
|
||||
#include "gmock/gmock-more-matchers.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_matchers_test {
|
||||
|
||||
using std::greater;
|
||||
using std::less;
|
||||
using std::list;
|
||||
using std::make_pair;
|
||||
using std::map;
|
||||
using std::multimap;
|
||||
using std::multiset;
|
||||
using std::ostream;
|
||||
using std::pair;
|
||||
using std::set;
|
||||
using std::stringstream;
|
||||
using std::vector;
|
||||
using testing::internal::DummyMatchResultListener;
|
||||
using testing::internal::ElementMatcherPair;
|
||||
using testing::internal::ElementMatcherPairs;
|
||||
using testing::internal::ElementsAreArrayMatcher;
|
||||
using testing::internal::ExplainMatchFailureTupleTo;
|
||||
using testing::internal::FloatingEqMatcher;
|
||||
using testing::internal::FormatMatcherDescription;
|
||||
using testing::internal::IsReadableTypeName;
|
||||
using testing::internal::MatchMatrix;
|
||||
using testing::internal::PredicateFormatterFromMatcher;
|
||||
using testing::internal::RE;
|
||||
using testing::internal::StreamMatchResultListener;
|
||||
using testing::internal::Strings;
|
||||
|
||||
// Helper for testing container-valued matchers in mock method context. It is
|
||||
// important to test matchers in this context, since it requires additional type
|
||||
// deduction beyond what EXPECT_THAT does, thus making it more restrictive.
|
||||
struct ContainerHelper {
|
||||
MOCK_METHOD1(Call, void(std::vector<std::unique_ptr<int>>));
|
||||
};
|
||||
|
||||
// For testing ExplainMatchResultTo().
|
||||
template <typename T>
|
||||
struct GtestGreaterThanMatcher {
|
||||
using is_gtest_matcher = void;
|
||||
|
||||
void DescribeTo(ostream* os) const { *os << "is > " << rhs; }
|
||||
void DescribeNegationTo(ostream* os) const { *os << "is <= " << rhs; }
|
||||
|
||||
bool MatchAndExplain(T lhs, MatchResultListener* listener) const {
|
||||
if (lhs > rhs) {
|
||||
*listener << "which is " << (lhs - rhs) << " more than " << rhs;
|
||||
} else if (lhs == rhs) {
|
||||
*listener << "which is the same as " << rhs;
|
||||
} else {
|
||||
*listener << "which is " << (rhs - lhs) << " less than " << rhs;
|
||||
}
|
||||
|
||||
return lhs > rhs;
|
||||
}
|
||||
|
||||
T rhs;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
GtestGreaterThanMatcher<typename std::decay<T>::type> GtestGreaterThan(
|
||||
T&& rhs) {
|
||||
return {rhs};
|
||||
}
|
||||
|
||||
// As the matcher above, but using the base class with virtual functions.
|
||||
template <typename T>
|
||||
class GreaterThanMatcher : public MatcherInterface<T> {
|
||||
public:
|
||||
explicit GreaterThanMatcher(T rhs) : impl_{rhs} {}
|
||||
|
||||
void DescribeTo(ostream* os) const override { impl_.DescribeTo(os); }
|
||||
void DescribeNegationTo(ostream* os) const override {
|
||||
impl_.DescribeNegationTo(os);
|
||||
}
|
||||
|
||||
bool MatchAndExplain(T lhs, MatchResultListener* listener) const override {
|
||||
return impl_.MatchAndExplain(lhs, listener);
|
||||
}
|
||||
|
||||
private:
|
||||
const GtestGreaterThanMatcher<T> impl_;
|
||||
};
|
||||
|
||||
// Names and instantiates a new instance of GTestMatcherTestP.
|
||||
#define INSTANTIATE_GTEST_MATCHER_TEST_P(TestSuite) \
|
||||
using TestSuite##P = GTestMatcherTestP; \
|
||||
INSTANTIATE_TEST_SUITE_P(MatcherInterface, TestSuite##P, Values(false)); \
|
||||
INSTANTIATE_TEST_SUITE_P(GtestMatcher, TestSuite##P, Values(true))
|
||||
|
||||
class GTestMatcherTestP : public testing::TestWithParam<bool> {
|
||||
public:
|
||||
template <typename T>
|
||||
Matcher<T> GreaterThan(T n) {
|
||||
if (use_gtest_matcher_) {
|
||||
return GtestGreaterThan(n);
|
||||
} else {
|
||||
return MakeMatcher(new GreaterThanMatcher<T>(n));
|
||||
}
|
||||
}
|
||||
const bool use_gtest_matcher_ = GetParam();
|
||||
};
|
||||
|
||||
// Returns the description of the given matcher.
|
||||
template <typename T>
|
||||
std::string Describe(const Matcher<T>& m) {
|
||||
return DescribeMatcher<T>(m);
|
||||
}
|
||||
|
||||
// Returns the description of the negation of the given matcher.
|
||||
template <typename T>
|
||||
std::string DescribeNegation(const Matcher<T>& m) {
|
||||
return DescribeMatcher<T>(m, true);
|
||||
}
|
||||
|
||||
// Returns the reason why x matches, or doesn't match, m.
|
||||
template <typename MatcherType, typename Value>
|
||||
std::string Explain(const MatcherType& m, const Value& x) {
|
||||
StringMatchResultListener listener;
|
||||
ExplainMatchResult(m, x, &listener);
|
||||
return listener.str();
|
||||
}
|
||||
|
||||
} // namespace gmock_matchers_test
|
||||
} // namespace testing
|
||||
|
||||
#endif // GOOGLEMOCK_TEST_GMOCK_MATCHERS_TEST_H_
|
@@ -145,7 +145,7 @@ class Foo {
|
||||
|
||||
std::string Binary(const std::string& str, char c) const { return str + c; }
|
||||
|
||||
int Ternary(int x, bool y, char z) { return value_ + x + y*z; }
|
||||
int Ternary(int x, bool y, char z) { return value_ + x + y * z; }
|
||||
|
||||
int SumOf4(int a, int b, int c, int d) const {
|
||||
return a + b + c + d + value_;
|
||||
@@ -291,8 +291,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) {
|
||||
std::make_tuple(10, 2, 5.6, std::string("hi"));
|
||||
EXPECT_EQ(12, a1.Perform(dummy));
|
||||
|
||||
Action<int(int, int, bool, int*)> a2 =
|
||||
Invoke(SumOfFirst2);
|
||||
Action<int(int, int, bool, int*)> a2 = Invoke(SumOfFirst2);
|
||||
EXPECT_EQ(
|
||||
23, a2.Perform(std::make_tuple(20, 3, true, static_cast<int*>(nullptr))));
|
||||
}
|
||||
@@ -303,8 +302,7 @@ TEST(InvokeTest, MethodWithUnusedParameters) {
|
||||
Action<int(std::string, bool, int, int)> a1 = Invoke(&foo, &Foo::SumOfLast2);
|
||||
EXPECT_EQ(12, a1.Perform(std::make_tuple(CharPtr("hi"), true, 10, 2)));
|
||||
|
||||
Action<int(char, double, int, int)> a2 =
|
||||
Invoke(&foo, &Foo::SumOfLast2);
|
||||
Action<int(char, double, int, int)> a2 = Invoke(&foo, &Foo::SumOfLast2);
|
||||
EXPECT_EQ(23, a2.Perform(std::make_tuple('a', 2.5, 20, 3)));
|
||||
}
|
||||
|
||||
@@ -362,7 +360,8 @@ TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
|
||||
// Tests using Invoke() with a 5-argument method.
|
||||
TEST(InvokeMethodTest, MethodThatTakes5Arguments) {
|
||||
Foo foo;
|
||||
Action<int(int, int, int, int, int)> a = Invoke(&foo, &Foo::SumOf5); // NOLINT
|
||||
Action<int(int, int, int, int, int)> a =
|
||||
Invoke(&foo, &Foo::SumOf5); // NOLINT
|
||||
EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5)));
|
||||
}
|
||||
|
||||
@@ -462,6 +461,12 @@ TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) {
|
||||
EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8)));
|
||||
}
|
||||
|
||||
TEST(ReturnArgActionTest, WorksForNonConstRefArg0) {
|
||||
const Action<std::string&(std::string&)> a = ReturnArg<0>();
|
||||
std::string s = "12345";
|
||||
EXPECT_EQ(&s, &a.Perform(std::forward_as_tuple(s)));
|
||||
}
|
||||
|
||||
TEST(SaveArgActionTest, WorksForSameType) {
|
||||
int result = 0;
|
||||
const Action<void(int n)> a1 = SaveArg<0>(&result);
|
||||
@@ -517,15 +522,12 @@ TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
|
||||
// the bool provided to the constructor to true when destroyed.
|
||||
class DeletionTester {
|
||||
public:
|
||||
explicit DeletionTester(bool* is_deleted)
|
||||
: is_deleted_(is_deleted) {
|
||||
explicit DeletionTester(bool* is_deleted) : is_deleted_(is_deleted) {
|
||||
// Make sure the bit is set to false.
|
||||
*is_deleted_ = false;
|
||||
}
|
||||
|
||||
~DeletionTester() {
|
||||
*is_deleted_ = true;
|
||||
}
|
||||
~DeletionTester() { *is_deleted_ = true; }
|
||||
|
||||
private:
|
||||
bool* is_deleted_;
|
||||
@@ -534,7 +536,7 @@ class DeletionTester {
|
||||
TEST(DeleteArgActionTest, OneArg) {
|
||||
bool is_deleted = false;
|
||||
DeletionTester* t = new DeletionTester(&is_deleted);
|
||||
const Action<void(DeletionTester*)> a1 = DeleteArg<0>(); // NOLINT
|
||||
const Action<void(DeletionTester*)> a1 = DeleteArg<0>(); // NOLINT
|
||||
EXPECT_FALSE(is_deleted);
|
||||
a1.Perform(std::make_tuple(t));
|
||||
EXPECT_TRUE(is_deleted);
|
||||
@@ -543,8 +545,9 @@ TEST(DeleteArgActionTest, OneArg) {
|
||||
TEST(DeleteArgActionTest, TenArgs) {
|
||||
bool is_deleted = false;
|
||||
DeletionTester* t = new DeletionTester(&is_deleted);
|
||||
const Action<void(bool, int, int, const char*, bool,
|
||||
int, int, int, int, DeletionTester*)> a1 = DeleteArg<9>();
|
||||
const Action<void(bool, int, int, const char*, bool, int, int, int, int,
|
||||
DeletionTester*)>
|
||||
a1 = DeleteArg<9>();
|
||||
EXPECT_FALSE(is_deleted);
|
||||
a1.Perform(std::make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t));
|
||||
EXPECT_TRUE(is_deleted);
|
||||
@@ -602,7 +605,7 @@ TEST(ThrowActionTest, Times0) {
|
||||
// pointed to by the N-th (0-based) argument to values in range [first, last).
|
||||
TEST(SetArrayArgumentTest, SetsTheNthArray) {
|
||||
using MyFunction = void(bool, int*, char*);
|
||||
int numbers[] = { 1, 2, 3 };
|
||||
int numbers[] = {1, 2, 3};
|
||||
Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers + 3);
|
||||
|
||||
int n[4] = {};
|
||||
@@ -638,7 +641,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
|
||||
// Tests SetArrayArgument<N>(first, last) where first == last.
|
||||
TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
|
||||
using MyFunction = void(bool, int*);
|
||||
int numbers[] = { 1, 2, 3 };
|
||||
int numbers[] = {1, 2, 3};
|
||||
Action<MyFunction> a = SetArrayArgument<1>(numbers, numbers);
|
||||
|
||||
int n[4] = {};
|
||||
@@ -654,10 +657,10 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
|
||||
// (but not equal) to the argument type.
|
||||
TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) {
|
||||
using MyFunction = void(bool, int*);
|
||||
char chars[] = { 97, 98, 99 };
|
||||
char chars[] = {97, 98, 99};
|
||||
Action<MyFunction> a = SetArrayArgument<1>(chars, chars + 3);
|
||||
|
||||
int codes[4] = { 111, 222, 333, 444 };
|
||||
int codes[4] = {111, 222, 333, 444};
|
||||
int* pcodes = codes;
|
||||
a.Perform(std::make_tuple(true, pcodes));
|
||||
EXPECT_EQ(97, codes[0]);
|
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -44,13 +45,13 @@ class Mock {
|
||||
MOCK_METHOD0(DoThis, void());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
|
||||
Mock(const Mock&) = delete;
|
||||
Mock& operator=(const Mock&) = delete;
|
||||
};
|
||||
|
||||
namespace testing {
|
||||
namespace gmock_nice_strict_test {
|
||||
|
||||
using testing::GMOCK_FLAG(verbose);
|
||||
using testing::HasSubstr;
|
||||
using testing::NaggyMock;
|
||||
using testing::NiceMock;
|
||||
@@ -93,7 +94,8 @@ class MockFoo : public Foo {
|
||||
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
MockFoo(const MockFoo&) = delete;
|
||||
MockFoo& operator=(const MockFoo&) = delete;
|
||||
};
|
||||
|
||||
class MockBar {
|
||||
@@ -103,7 +105,8 @@ class MockBar {
|
||||
MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6,
|
||||
const std::string& a7, const std::string& a8, bool a9, bool a10) {
|
||||
str_ = std::string() + a1 + a2 + a3 + a4 + static_cast<char>(a5) +
|
||||
static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') + (a10 ? 'T' : 'F');
|
||||
static_cast<char>(a6) + a7 + a8 + (a9 ? 'T' : 'F') +
|
||||
(a10 ? 'T' : 'F');
|
||||
}
|
||||
|
||||
virtual ~MockBar() {}
|
||||
@@ -116,10 +119,10 @@ class MockBar {
|
||||
private:
|
||||
std::string str_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
|
||||
MockBar(const MockBar&) = delete;
|
||||
MockBar& operator=(const MockBar&) = delete;
|
||||
};
|
||||
|
||||
|
||||
class MockBaz {
|
||||
public:
|
||||
class MoveOnly {
|
||||
@@ -140,8 +143,8 @@ class MockBaz {
|
||||
|
||||
// Tests that a raw mock generates warnings for uninteresting calls.
|
||||
TEST(RawMockTest, WarningForUninterestingCall) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "warning";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
|
||||
MockFoo raw_foo;
|
||||
|
||||
@@ -151,26 +154,25 @@ TEST(RawMockTest, WarningForUninterestingCall) {
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
// Tests that a raw mock generates warnings for uninteresting calls
|
||||
// that delete the mock object.
|
||||
TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "warning";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
|
||||
MockFoo* const raw_foo = new MockFoo;
|
||||
|
||||
ON_CALL(*raw_foo, DoThis())
|
||||
.WillByDefault(Invoke(raw_foo, &MockFoo::Delete));
|
||||
ON_CALL(*raw_foo, DoThis()).WillByDefault(Invoke(raw_foo, &MockFoo::Delete));
|
||||
|
||||
CaptureStdout();
|
||||
raw_foo->DoThis();
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
// Tests that a raw mock generates informational logs for
|
||||
@@ -178,14 +180,14 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
|
||||
TEST(RawMockTest, InfoForUninterestingCall) {
|
||||
MockFoo raw_foo;
|
||||
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "info";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "info");
|
||||
CaptureStdout();
|
||||
raw_foo.DoThis();
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
@@ -223,14 +225,14 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
|
||||
TEST(NiceMockTest, InfoForUninterestingCall) {
|
||||
NiceMock<MockFoo> nice_foo;
|
||||
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "info";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "info");
|
||||
CaptureStdout();
|
||||
nice_foo.DoThis();
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
@@ -281,8 +283,8 @@ TEST(NiceMockTest, NonDefaultConstructor) {
|
||||
// Tests that NiceMock works with a mock class that has a 10-ary
|
||||
// non-default constructor.
|
||||
TEST(NiceMockTest, NonDefaultConstructor10) {
|
||||
NiceMock<MockBar> nice_bar('a', 'b', "c", "d", 'e', 'f',
|
||||
"g", "h", true, false);
|
||||
NiceMock<MockBar> nice_bar('a', 'b', "c", "d", 'e', 'f', "g", "h", true,
|
||||
false);
|
||||
EXPECT_EQ("abcdefghTF", nice_bar.str());
|
||||
|
||||
nice_bar.This();
|
||||
@@ -326,8 +328,8 @@ TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
|
||||
// Tests that a naggy mock generates warnings for uninteresting calls.
|
||||
TEST(NaggyMockTest, WarningForUninterestingCall) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "warning";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
|
||||
NaggyMock<MockFoo> naggy_foo;
|
||||
|
||||
@@ -337,14 +339,14 @@ TEST(NaggyMockTest, WarningForUninterestingCall) {
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
// Tests that a naggy mock generates a warning for an uninteresting call
|
||||
// that deletes the mock object.
|
||||
TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "warning";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
|
||||
NaggyMock<MockFoo>* const naggy_foo = new NaggyMock<MockFoo>;
|
||||
|
||||
@@ -356,7 +358,7 @@ TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
@@ -391,8 +393,8 @@ TEST(NaggyMockTest, NonDefaultConstructor) {
|
||||
// Tests that NaggyMock works with a mock class that has a 10-ary
|
||||
// non-default constructor.
|
||||
TEST(NaggyMockTest, NonDefaultConstructor10) {
|
||||
NaggyMock<MockBar> naggy_bar('0', '1', "2", "3", '4', '5',
|
||||
"6", "7", true, false);
|
||||
NaggyMock<MockBar> naggy_bar('0', '1', "2", "3", '4', '5', "6", "7", true,
|
||||
false);
|
||||
EXPECT_EQ("01234567TF", naggy_bar.str());
|
||||
|
||||
naggy_bar.This();
|
||||
@@ -419,8 +421,8 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) {
|
||||
}
|
||||
|
||||
TEST(NaggyMockTest, IsNaggyInDestructor) {
|
||||
const std::string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = "warning";
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
CaptureStdout();
|
||||
|
||||
{
|
||||
@@ -431,7 +433,7 @@ TEST(NaggyMockTest, IsNaggyInDestructor) {
|
||||
EXPECT_THAT(GetCapturedStdout(),
|
||||
HasSubstr("Uninteresting mock function call"));
|
||||
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
|
||||
@@ -491,8 +493,8 @@ TEST(StrictMockTest, NonDefaultConstructor) {
|
||||
// Tests that StrictMock works with a mock class that has a 10-ary
|
||||
// non-default constructor.
|
||||
TEST(StrictMockTest, NonDefaultConstructor10) {
|
||||
StrictMock<MockBar> strict_bar('a', 'b', "c", "d", 'e', 'f',
|
||||
"g", "h", true, false);
|
||||
StrictMock<MockBar> strict_bar('a', 'b', "c", "d", 'e', 'f', "g", "h", true,
|
||||
false);
|
||||
EXPECT_EQ("abcdefghTF", strict_bar.str());
|
||||
|
||||
EXPECT_NONFATAL_FAILURE(strict_bar.That(5, true),
|
@@ -27,12 +27,12 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests the internal cross-platform support utilities.
|
||||
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// NOTE: if this file is left without tests for some reason, put a dummy
|
@@ -30,11 +30,10 @@
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests the internal preprocessor macro library.
|
||||
#include "gmock/internal/gmock-pp.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gmock/internal/gmock-pp.h"
|
||||
|
||||
namespace testing {
|
||||
namespace {
|
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,10 @@
|
||||
#include "test/gmock-actions_test.cc"
|
||||
#include "test/gmock-cardinalities_test.cc"
|
||||
#include "test/gmock-internal-utils_test.cc"
|
||||
#include "test/gmock-matchers_test.cc"
|
||||
#include "test/gmock-matchers-arithmetic_test.cc"
|
||||
#include "test/gmock-matchers-comparisons_test.cc"
|
||||
#include "test/gmock-matchers-containers_test.cc"
|
||||
#include "test/gmock-matchers-misc_test.cc"
|
||||
#include "test/gmock-more-actions_test.cc"
|
||||
#include "test/gmock-nice-strict_test.cc"
|
||||
#include "test/gmock-port_test.cc"
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Tests Google Mock's functionality that depends on exceptions.
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
@@ -75,6 +74,5 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // unnamed namespace
|
||||
#endif
|
@@ -31,7 +31,7 @@
|
||||
|
||||
"""Tests that leaked mock objects can be caught be Google Mock."""
|
||||
|
||||
import gmock_test_utils
|
||||
from googlemock.test import gmock_test_utils
|
||||
|
||||
PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_')
|
||||
TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*']
|
@@ -27,7 +27,6 @@
|
||||
// (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 program is for verifying that a leaked mock object can be
|
||||
@@ -52,7 +51,8 @@ class MockFoo : public FooInterface {
|
||||
MOCK_METHOD0(DoThis, void());
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
MockFoo(const MockFoo&) = delete;
|
||||
MockFoo& operator=(const MockFoo&) = delete;
|
||||
};
|
||||
|
||||
TEST(LeakTest, LeakedMockWithExpectCallCausesFailureWhenLeakCheckingIsEnabled) {
|
@@ -27,7 +27,6 @@
|
||||
// (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 is for verifying that various Google Mock constructs do not
|
@@ -27,7 +27,6 @@
|
||||
// (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 is for verifying that various Google Mock constructs do not
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests that:
|
||||
@@ -118,7 +117,7 @@
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#if !GTEST_OS_WINDOWS_MOBILE
|
||||
# include <errno.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
@@ -200,14 +199,14 @@ class Interface {
|
||||
virtual char* StringFromString(char* str) = 0;
|
||||
virtual int IntFromString(char* str) = 0;
|
||||
virtual int& IntRefFromString(char* str) = 0;
|
||||
virtual void VoidFromFunc(void(*func)(char* str)) = 0;
|
||||
virtual void VoidFromFunc(void (*func)(char* str)) = 0;
|
||||
virtual void VoidFromIntRef(int& n) = 0; // NOLINT
|
||||
virtual void VoidFromFloat(float n) = 0;
|
||||
virtual void VoidFromDouble(double n) = 0;
|
||||
virtual void VoidFromVector(const std::vector<int>& v) = 0;
|
||||
};
|
||||
|
||||
class Mock: public Interface {
|
||||
class Mock : public Interface {
|
||||
public:
|
||||
Mock() {}
|
||||
|
||||
@@ -215,14 +214,15 @@ class Mock: public Interface {
|
||||
MOCK_METHOD1(StringFromString, char*(char* str));
|
||||
MOCK_METHOD1(IntFromString, int(char* str));
|
||||
MOCK_METHOD1(IntRefFromString, int&(char* str));
|
||||
MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
|
||||
MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
|
||||
MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT
|
||||
MOCK_METHOD1(VoidFromFloat, void(float n));
|
||||
MOCK_METHOD1(VoidFromDouble, void(double n));
|
||||
MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
|
||||
Mock(const Mock&) = delete;
|
||||
Mock& operator=(const Mock&) = delete;
|
||||
};
|
||||
|
||||
class InvokeHelper {
|
||||
@@ -301,8 +301,8 @@ TEST(LinkTest, TestSetArrayArgument) {
|
||||
char ch = 'x';
|
||||
char ch2 = 'y';
|
||||
|
||||
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2,
|
||||
&ch2 + 1));
|
||||
EXPECT_CALL(mock, VoidFromString(_))
|
||||
.WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
|
||||
mock.VoidFromString(&ch);
|
||||
}
|
||||
|
||||
@@ -339,8 +339,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) {
|
||||
|
||||
EXPECT_CALL(mock, VoidFromString(_))
|
||||
.WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
|
||||
.WillOnce(InvokeWithoutArgs(&test_invoke_helper,
|
||||
&InvokeHelper::VoidFromVoid));
|
||||
.WillOnce(
|
||||
InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
|
||||
mock.VoidFromString(nullptr);
|
||||
mock.VoidFromString(nullptr);
|
||||
}
|
||||
@@ -424,14 +424,14 @@ TEST(LinkTest, TestThrow) {
|
||||
// is expanded and macro expansion cannot contain #pragma. Therefore
|
||||
// we suppress them here.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#endif
|
||||
|
||||
// Tests the linkage of actions created using ACTION macro.
|
||||
namespace {
|
||||
ACTION(Return1) { return 1; }
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(LinkTest, TestActionMacro) {
|
||||
Mock mock;
|
||||
@@ -443,7 +443,7 @@ TEST(LinkTest, TestActionMacro) {
|
||||
// Tests the linkage of actions created using ACTION_P macro.
|
||||
namespace {
|
||||
ACTION_P(ReturnArgument, ret_value) { return ret_value; }
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(LinkTest, TestActionPMacro) {
|
||||
Mock mock;
|
||||
@@ -457,10 +457,10 @@ namespace {
|
||||
ACTION_P2(ReturnEqualsEitherOf, first, second) {
|
||||
return arg0 == first || arg0 == second;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
TEST(LinkTest, TestActionP2Macro) {
|
||||
@@ -492,8 +492,7 @@ TEST(LinkTest, TestMatchersEq) {
|
||||
const char* p = "x";
|
||||
|
||||
ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
|
||||
ON_CALL(mock, VoidFromString(const_cast<char*>("y")))
|
||||
.WillByDefault(Return());
|
||||
ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
|
||||
}
|
||||
|
||||
// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
|
||||
@@ -592,7 +591,7 @@ TEST(LinkTest, TestMatcherElementsAre) {
|
||||
// Tests the linkage of the ElementsAreArray matcher.
|
||||
TEST(LinkTest, TestMatcherElementsAreArray) {
|
||||
Mock mock;
|
||||
char arr[] = { 'a', 'b' };
|
||||
char arr[] = {'a', 'b'};
|
||||
|
||||
ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
|
||||
}
|
@@ -43,7 +43,7 @@ from io import open # pylint: disable=redefined-builtin, g-importing-member
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import gmock_test_utils
|
||||
from googlemock.test import gmock_test_utils
|
||||
|
||||
|
||||
# The flag for generating the golden file
|
||||
@@ -159,15 +159,18 @@ class GMockOutputTest(gmock_test_utils.TestCase):
|
||||
golden_file = open(GOLDEN_PATH, 'rb')
|
||||
golden = golden_file.read().decode('utf-8')
|
||||
golden_file.close()
|
||||
# On Windows the repository might have been checked out with \r\n line
|
||||
# endings, so normalize it here.
|
||||
golden = ToUnixLineEnding(golden)
|
||||
|
||||
# The normalized output should match the golden file.
|
||||
self.assertEquals(golden, output)
|
||||
self.assertEqual(golden, output)
|
||||
|
||||
# The raw output should contain 2 leaked mock object errors for
|
||||
# test GMockOutputTest.CatchesLeakedMocks.
|
||||
self.assertEquals(['GMockOutputTest.CatchesLeakedMocks',
|
||||
'GMockOutputTest.CatchesLeakedMocks'],
|
||||
leaky_tests)
|
||||
self.assertEqual(['GMockOutputTest.CatchesLeakedMocks',
|
||||
'GMockOutputTest.CatchesLeakedMocks'],
|
||||
leaky_tests)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
@@ -27,21 +27,20 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Tests Google Mock's output in various scenarios. This ensures that
|
||||
// Google Mock's messages are readable and useful.
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// Silence C4100 (unreferenced formal parameter)
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4100)
|
||||
#endif
|
||||
|
||||
using testing::_;
|
||||
@@ -63,7 +62,8 @@ class MockFoo {
|
||||
MOCK_METHOD2(Bar3, void(int x, int y));
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
|
||||
MockFoo(const MockFoo&) = delete;
|
||||
MockFoo& operator=(const MockFoo&) = delete;
|
||||
};
|
||||
|
||||
class GMockOutputTest : public testing::Test {
|
||||
@@ -72,27 +72,25 @@ class GMockOutputTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(GMockOutputTest, ExpectedCall) {
|
||||
testing::GMOCK_FLAG(verbose) = "info";
|
||||
GMOCK_FLAG_SET(verbose, "info");
|
||||
|
||||
EXPECT_CALL(foo_, Bar2(0, _));
|
||||
foo_.Bar2(0, 0); // Expected call
|
||||
|
||||
testing::GMOCK_FLAG(verbose) = "warning";
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, ExpectedCallToVoidFunction) {
|
||||
testing::GMOCK_FLAG(verbose) = "info";
|
||||
GMOCK_FLAG_SET(verbose, "info");
|
||||
|
||||
EXPECT_CALL(foo_, Bar3(0, _));
|
||||
foo_.Bar3(0, 0); // Expected call
|
||||
|
||||
testing::GMOCK_FLAG(verbose) = "warning";
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, ExplicitActionsRunOut) {
|
||||
EXPECT_CALL(foo_, Bar2(_, _))
|
||||
.Times(2)
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(foo_, Bar2(_, _)).Times(2).WillOnce(Return(false));
|
||||
foo_.Bar2(2, 2);
|
||||
foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
|
||||
}
|
||||
@@ -134,8 +132,7 @@ TEST_F(GMockOutputTest, UninterestingCallToVoidFunction) {
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, RetiredExpectation) {
|
||||
EXPECT_CALL(foo_, Bar2(_, _))
|
||||
.RetiresOnSaturation();
|
||||
EXPECT_CALL(foo_, Bar2(_, _)).RetiresOnSaturation();
|
||||
EXPECT_CALL(foo_, Bar2(0, 0));
|
||||
|
||||
foo_.Bar2(1, 1);
|
||||
@@ -160,12 +157,9 @@ TEST_F(GMockOutputTest, UnsatisfiedPrerequisite) {
|
||||
TEST_F(GMockOutputTest, UnsatisfiedPrerequisites) {
|
||||
Sequence s1, s2;
|
||||
|
||||
EXPECT_CALL(foo_, Bar(_, 0, _))
|
||||
.InSequence(s1);
|
||||
EXPECT_CALL(foo_, Bar2(0, 0))
|
||||
.InSequence(s2);
|
||||
EXPECT_CALL(foo_, Bar2(1, _))
|
||||
.InSequence(s1, s2);
|
||||
EXPECT_CALL(foo_, Bar(_, 0, _)).InSequence(s1);
|
||||
EXPECT_CALL(foo_, Bar2(0, 0)).InSequence(s2);
|
||||
EXPECT_CALL(foo_, Bar2(1, _)).InSequence(s1, s2);
|
||||
|
||||
foo_.Bar2(1, 0); // Has two immediate unsatisfied pre-requisites
|
||||
foo_.Bar("Hi", 0, 0);
|
||||
@@ -179,8 +173,7 @@ TEST_F(GMockOutputTest, UnsatisfiedWith) {
|
||||
|
||||
TEST_F(GMockOutputTest, UnsatisfiedExpectation) {
|
||||
EXPECT_CALL(foo_, Bar(_, _, _));
|
||||
EXPECT_CALL(foo_, Bar2(0, _))
|
||||
.Times(2);
|
||||
EXPECT_CALL(foo_, Bar2(0, _)).Times(2);
|
||||
|
||||
foo_.Bar2(0, 1);
|
||||
}
|
||||
@@ -194,26 +187,22 @@ TEST_F(GMockOutputTest, MismatchArguments) {
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, MismatchWith) {
|
||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
|
||||
.With(Ge());
|
||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))).With(Ge());
|
||||
|
||||
foo_.Bar2(2, 3); // Mismatch With()
|
||||
foo_.Bar2(2, 1);
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, MismatchArgumentsAndWith) {
|
||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
|
||||
.With(Ge());
|
||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1))).With(Ge());
|
||||
|
||||
foo_.Bar2(1, 3); // Mismatch arguments and mismatch With()
|
||||
foo_.Bar2(2, 1);
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) {
|
||||
ON_CALL(foo_, Bar2(_, _))
|
||||
.WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _))
|
||||
.WillByDefault(Return(false)); // Default action #2
|
||||
ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
|
||||
|
||||
EXPECT_CALL(foo_, Bar2(2, 2));
|
||||
foo_.Bar2(1, 0); // Unexpected call, takes default action #2.
|
||||
@@ -222,10 +211,8 @@ TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) {
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) {
|
||||
ON_CALL(foo_, Bar2(_, _))
|
||||
.WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _))
|
||||
.WillByDefault(Return(false)); // Default action #2
|
||||
ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
|
||||
|
||||
EXPECT_CALL(foo_, Bar2(2, 2));
|
||||
EXPECT_CALL(foo_, Bar2(1, 1));
|
||||
@@ -237,22 +224,17 @@ TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) {
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, UninterestingCallWithDefaultAction) {
|
||||
ON_CALL(foo_, Bar2(_, _))
|
||||
.WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _))
|
||||
.WillByDefault(Return(false)); // Default action #2
|
||||
ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(1, _)).WillByDefault(Return(false)); // Default action #2
|
||||
|
||||
foo_.Bar2(2, 2); // Uninteresting call, takes default action #1.
|
||||
foo_.Bar2(1, 1); // Uninteresting call, takes default action #2.
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, ExplicitActionsRunOutWithDefaultAction) {
|
||||
ON_CALL(foo_, Bar2(_, _))
|
||||
.WillByDefault(Return(true)); // Default action #1
|
||||
ON_CALL(foo_, Bar2(_, _)).WillByDefault(Return(true)); // Default action #1
|
||||
|
||||
EXPECT_CALL(foo_, Bar2(_, _))
|
||||
.Times(2)
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(foo_, Bar2(_, _)).Times(2).WillOnce(Return(false));
|
||||
foo_.Bar2(2, 2);
|
||||
foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
|
||||
}
|
||||
@@ -293,17 +275,17 @@ void TestCatchesLeakedMocksInAdHocTests() {
|
||||
// foo is deliberately leaked.
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
// Ensures that the tests pass no matter what value of
|
||||
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
|
||||
testing::GMOCK_FLAG(catch_leaked_mocks) = true;
|
||||
testing::GMOCK_FLAG(verbose) = "warning";
|
||||
GMOCK_FLAG_SET(catch_leaked_mocks, true);
|
||||
GMOCK_FLAG_SET(verbose, "warning");
|
||||
|
||||
TestCatchesLeakedMocksInAdHocTests();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
@@ -75,14 +75,14 @@ GMOCK WARNING:
|
||||
Uninteresting mock function call - returning default value.
|
||||
Function call: Bar2(0, 1)
|
||||
Returns: false
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
[ OK ] GMockOutputTest.UninterestingCall
|
||||
[ RUN ] GMockOutputTest.UninterestingCallToVoidFunction
|
||||
|
||||
GMOCK WARNING:
|
||||
Uninteresting mock function call - returning directly.
|
||||
Function call: Bar3(0, 1)
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
[ OK ] GMockOutputTest.UninterestingCallToVoidFunction
|
||||
[ RUN ] GMockOutputTest.RetiredExpectation
|
||||
unknown file: Failure
|
||||
@@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at:
|
||||
FILE:#:
|
||||
Function call: Bar2(2, 2)
|
||||
Returns: true
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
|
||||
GMOCK WARNING:
|
||||
Uninteresting mock function call - taking default action specified at:
|
||||
FILE:#:
|
||||
Function call: Bar2(1, 1)
|
||||
Returns: false
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details.
|
||||
[ OK ] GMockOutputTest.UninterestingCallWithDefaultAction
|
||||
[ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
|
||||
|
||||
@@ -291,7 +291,7 @@ Stack trace:
|
||||
[ RUN ] GMockOutputTest.PrintsMatcher
|
||||
FILE:#: Failure
|
||||
Value of: (std::pair<int, bool>(42, true))
|
||||
Expected: is pair (is >= 48, true)
|
||||
Expected: is pair (first: is >= 48, second: true)
|
||||
Actual: (42, true) (of type std::pair<int, bool>)
|
||||
[ FAILED ] GMockOutputTest.PrintsMatcher
|
||||
[ FAILED ] GMockOutputTest.UnexpectedCall
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Tests that Google Mock constructs can be used in a large number of
|
||||
// threads concurrently.
|
||||
|
||||
@@ -49,7 +48,7 @@ const int kRepeat = 50;
|
||||
|
||||
class MockFoo {
|
||||
public:
|
||||
MOCK_METHOD1(Bar, int(int n)); // NOLINT
|
||||
MOCK_METHOD1(Bar, int(int n)); // NOLINT
|
||||
MOCK_METHOD2(Baz, char(const char* s1, const std::string& s2)); // NOLINT
|
||||
};
|
||||
|
||||
@@ -62,21 +61,16 @@ void JoinAndDelete(ThreadWithParam<T>* t) {
|
||||
|
||||
struct Dummy {};
|
||||
|
||||
|
||||
// Tests that different mock objects can be used in their respective
|
||||
// threads. This should generate no Google Test failure.
|
||||
void TestConcurrentMockObjects(Dummy /* dummy */) {
|
||||
// Creates a mock and does some typical operations on it.
|
||||
MockFoo foo;
|
||||
ON_CALL(foo, Bar(_))
|
||||
.WillByDefault(Return(1));
|
||||
ON_CALL(foo, Baz(_, _))
|
||||
.WillByDefault(Return('b'));
|
||||
ON_CALL(foo, Baz(_, "you"))
|
||||
.WillByDefault(Return('a'));
|
||||
ON_CALL(foo, Bar(_)).WillByDefault(Return(1));
|
||||
ON_CALL(foo, Baz(_, _)).WillByDefault(Return('b'));
|
||||
ON_CALL(foo, Baz(_, "you")).WillByDefault(Return('a'));
|
||||
|
||||
EXPECT_CALL(foo, Bar(0))
|
||||
.Times(AtMost(3));
|
||||
EXPECT_CALL(foo, Bar(0)).Times(AtMost(3));
|
||||
EXPECT_CALL(foo, Baz(_, _));
|
||||
EXPECT_CALL(foo, Baz("hi", "you"))
|
||||
.WillOnce(Return('z'))
|
||||
@@ -119,22 +113,19 @@ void Helper1(Helper1Param param) {
|
||||
void TestConcurrentCallsOnSameObject(Dummy /* dummy */) {
|
||||
MockFoo foo;
|
||||
|
||||
ON_CALL(foo, Bar(_))
|
||||
.WillByDefault(Return(1));
|
||||
EXPECT_CALL(foo, Baz(_, "b"))
|
||||
.Times(kRepeat)
|
||||
.WillRepeatedly(Return('a'));
|
||||
ON_CALL(foo, Bar(_)).WillByDefault(Return(1));
|
||||
EXPECT_CALL(foo, Baz(_, "b")).Times(kRepeat).WillRepeatedly(Return('a'));
|
||||
EXPECT_CALL(foo, Baz(_, "c")); // Expected to be unsatisfied.
|
||||
|
||||
// This chunk of code should generate kRepeat failures about
|
||||
// excessive calls, and 2*kRepeat failures about unexpected calls.
|
||||
int count1 = 0;
|
||||
const Helper1Param param = { &foo, &count1 };
|
||||
const Helper1Param param = {&foo, &count1};
|
||||
ThreadWithParam<Helper1Param>* const t =
|
||||
new ThreadWithParam<Helper1Param>(Helper1, param, nullptr);
|
||||
|
||||
int count2 = 0;
|
||||
const Helper1Param param2 = { &foo, &count2 };
|
||||
const Helper1Param param2 = {&foo, &count2};
|
||||
Helper1(param2);
|
||||
JoinAndDelete(t);
|
||||
|
||||
@@ -162,22 +153,18 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
|
||||
{
|
||||
InSequence dummy;
|
||||
EXPECT_CALL(foo, Bar(0));
|
||||
EXPECT_CALL(foo, Bar(1))
|
||||
.InSequence(s1, s2);
|
||||
EXPECT_CALL(foo, Bar(1)).InSequence(s1, s2);
|
||||
}
|
||||
|
||||
EXPECT_CALL(foo, Bar(2))
|
||||
.Times(2*kRepeat)
|
||||
.Times(2 * kRepeat)
|
||||
.InSequence(s1)
|
||||
.RetiresOnSaturation();
|
||||
EXPECT_CALL(foo, Bar(3))
|
||||
.Times(2*kRepeat)
|
||||
.InSequence(s2);
|
||||
EXPECT_CALL(foo, Bar(3)).Times(2 * kRepeat).InSequence(s2);
|
||||
|
||||
{
|
||||
InSequence dummy;
|
||||
EXPECT_CALL(foo, Bar(2))
|
||||
.InSequence(s1, s2);
|
||||
EXPECT_CALL(foo, Bar(2)).InSequence(s1, s2);
|
||||
EXPECT_CALL(foo, Bar(4));
|
||||
}
|
||||
|
||||
@@ -196,12 +183,12 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
|
||||
// Tests using Google Mock constructs in many threads concurrently.
|
||||
TEST(StressTest, CanUseGMockWithThreads) {
|
||||
void (*test_routines[])(Dummy dummy) = {
|
||||
&TestConcurrentMockObjects,
|
||||
&TestConcurrentCallsOnSameObject,
|
||||
&TestPartiallyOrderedExpectationsWithThreads,
|
||||
&TestConcurrentMockObjects,
|
||||
&TestConcurrentCallsOnSameObject,
|
||||
&TestPartiallyOrderedExpectationsWithThreads,
|
||||
};
|
||||
|
||||
const int kRoutines = sizeof(test_routines)/sizeof(test_routines[0]);
|
||||
const int kRoutines = sizeof(test_routines) / sizeof(test_routines[0]);
|
||||
const int kCopiesOfEachRoutine = kMaxTestThreads / kRoutines;
|
||||
const int kTestThreads = kCopiesOfEachRoutine * kRoutines;
|
||||
ThreadWithParam<Dummy>* threads[kTestThreads] = {};
|
||||
@@ -220,7 +207,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
|
||||
// Ensures that the correct number of failures have been reported.
|
||||
const TestInfo* const info = UnitTest::GetInstance()->current_test_info();
|
||||
const TestResult& result = *info->result();
|
||||
const int kExpectedFailures = (3*kRepeat + 1)*kCopiesOfEachRoutine;
|
||||
const int kExpectedFailures = (3 * kRepeat + 1) * kCopiesOfEachRoutine;
|
||||
GTEST_CHECK_(kExpectedFailures == result.total_part_count())
|
||||
<< "Expected " << kExpectedFailures << " failures, but got "
|
||||
<< result.total_part_count();
|
||||
@@ -229,7 +216,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
|
||||
} // namespace
|
||||
} // namespace testing
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
const int exit_code = RUN_ALL_TESTS(); // Expected to fail.
|
@@ -27,7 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests code in gmock.cc.
|
||||
@@ -35,13 +34,12 @@
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/custom/gtest.h"
|
||||
|
||||
#if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
|
||||
|
||||
using testing::GMOCK_FLAG(default_mock_behavior);
|
||||
using testing::GMOCK_FLAG(verbose);
|
||||
using testing::InitGoogleMock;
|
||||
|
||||
// Verifies that calling InitGoogleMock() on argv results in new_argv,
|
||||
@@ -49,7 +47,7 @@ using testing::InitGoogleMock;
|
||||
template <typename Char, int M, int N>
|
||||
void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
|
||||
const ::std::string& expected_gmock_verbose) {
|
||||
const ::std::string old_verbose = GMOCK_FLAG(verbose);
|
||||
const ::std::string old_verbose = GMOCK_FLAG_GET(verbose);
|
||||
|
||||
int argc = M - 1;
|
||||
InitGoogleMock(&argc, const_cast<Char**>(argv));
|
||||
@@ -59,8 +57,8 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
|
||||
EXPECT_STREQ(new_argv[i], argv[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG(verbose).c_str());
|
||||
GMOCK_FLAG(verbose) = old_verbose; // Restores the gmock_verbose flag.
|
||||
EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG_GET(verbose));
|
||||
GMOCK_FLAG_SET(verbose, old_verbose); // Restores the gmock_verbose flag.
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesInvalidCommandLine) {
|
||||
@@ -68,7 +66,7 @@ TEST(InitGoogleMockTest, ParsesInvalidCommandLine) {
|
||||
|
||||
const char* new_argv[] = {nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesEmptyCommandLine) {
|
||||
@@ -76,7 +74,7 @@ TEST(InitGoogleMockTest, ParsesEmptyCommandLine) {
|
||||
|
||||
const char* new_argv[] = {"foo.exe", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesSingleFlag) {
|
||||
@@ -88,16 +86,16 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) {
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesMultipleFlags) {
|
||||
int old_default_behavior = GMOCK_FLAG(default_mock_behavior);
|
||||
int old_default_behavior = GMOCK_FLAG_GET(default_mock_behavior);
|
||||
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info",
|
||||
L"--gmock_default_mock_behavior=2", nullptr};
|
||||
|
||||
const wchar_t* new_argv[] = {L"foo.exe", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, "info");
|
||||
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior));
|
||||
EXPECT_EQ(2, GMOCK_FLAG_GET(default_mock_behavior));
|
||||
EXPECT_NE(2, old_default_behavior);
|
||||
GMOCK_FLAG(default_mock_behavior) = old_default_behavior;
|
||||
GMOCK_FLAG_SET(default_mock_behavior, old_default_behavior);
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||
@@ -105,7 +103,7 @@ TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||
|
||||
const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
|
||||
@@ -122,7 +120,7 @@ TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
|
||||
|
||||
const wchar_t* new_argv[] = {nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) {
|
||||
@@ -130,7 +128,7 @@ TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) {
|
||||
|
||||
const wchar_t* new_argv[] = {L"foo.exe", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
|
||||
@@ -142,16 +140,16 @@ TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
|
||||
}
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesMultipleFlags) {
|
||||
int old_default_behavior = GMOCK_FLAG(default_mock_behavior);
|
||||
int old_default_behavior = GMOCK_FLAG_GET(default_mock_behavior);
|
||||
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info",
|
||||
L"--gmock_default_mock_behavior=2", nullptr};
|
||||
|
||||
const wchar_t* new_argv[] = {L"foo.exe", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, "info");
|
||||
EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior));
|
||||
EXPECT_EQ(2, GMOCK_FLAG_GET(default_mock_behavior));
|
||||
EXPECT_NE(2, old_default_behavior);
|
||||
GMOCK_FLAG(default_mock_behavior) = old_default_behavior;
|
||||
GMOCK_FLAG_SET(default_mock_behavior, old_default_behavior);
|
||||
}
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||
@@ -159,7 +157,7 @@ TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
|
||||
|
||||
const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
|
||||
TestInitGoogleMock(argv, new_argv, GMOCK_FLAG_GET(verbose));
|
||||
}
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
|
||||
@@ -175,7 +173,7 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
|
||||
|
||||
// Makes sure Google Mock flags can be accessed in code.
|
||||
TEST(FlagTest, IsAccessibleInCode) {
|
||||
bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) &&
|
||||
testing::GMOCK_FLAG(verbose) == "";
|
||||
bool dummy =
|
||||
GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose) == "";
|
||||
(void)dummy; // Avoids the "unused local variable" warning.
|
||||
}
|
@@ -30,21 +30,9 @@
|
||||
"""Unit test utilities for Google C++ Mocking Framework."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Determines path to gtest_test_utils and imports it.
|
||||
SCRIPT_DIR = os.path.dirname(__file__) or '.'
|
||||
|
||||
# isdir resolves symbolic links.
|
||||
gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../../googletest/test')
|
||||
if os.path.isdir(gtest_tests_util_dir):
|
||||
GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
|
||||
else:
|
||||
GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../googletest/test')
|
||||
sys.path.append(GTEST_TESTS_UTIL_DIR)
|
||||
|
||||
# pylint: disable=C6204
|
||||
import gtest_test_utils
|
||||
from googletest.test import gtest_test_utils
|
||||
|
||||
|
||||
def GetSourceDir():
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user