已合并
googletest_1.13.0 升级 #37
AtomGit-Bot创建于 2024年1月11日
googletest_1.13.0 升级 #37
已合并
从refs/pull/37/head合入到master
共 210 个文件变更+18257-15675
| @@ -30,19 +30,32 @@ | |||
| 30 | # | 30 | # |
| 31 | # Bazel Build for Google C++ Testing Framework(Google Test) | 31 | # Bazel Build for Google C++ Testing Framework(Google Test) |
| 32 | 32 | ||
| 33 | -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") | ||
| 34 | - | ||
| 35 | package(default_visibility = ["//visibility:public"]) | 33 | package(default_visibility = ["//visibility:public"]) |
| 36 | 34 | ||
| 37 | licenses(["notice"]) | 35 | licenses(["notice"]) |
| 38 | 36 | ||
| 39 | exports_files(["LICENSE"]) | 37 | exports_files(["LICENSE"]) |
| 40 | 38 | ||
| 39 | +config_setting( | ||
| 40 | + name = "qnx", | ||
| 41 | + constraint_values = ["@platforms//os:qnx"], | ||
| 42 | +) | ||
| 43 | + | ||
| 41 | config_setting( | 44 | config_setting( |
| 42 | name = "windows", | 45 | name = "windows", |
| 43 | constraint_values = ["@platforms//os:windows"], | 46 | constraint_values = ["@platforms//os:windows"], |
| 44 | ) | 47 | ) |
| 45 | 48 | ||
| 49 | +config_setting( | ||
| 50 | + name = "freebsd", | ||
| 51 | + constraint_values = ["@platforms//os:freebsd"], | ||
| 52 | +) | ||
| 53 | + | ||
| 54 | +config_setting( | ||
| 55 | + name = "openbsd", | ||
| 56 | + constraint_values = ["@platforms//os:openbsd"], | ||
| 57 | +) | ||
| 58 | + | ||
| 46 | config_setting( | 59 | config_setting( |
| 47 | name = "msvc_compiler", | 60 | name = "msvc_compiler", |
| 48 | flag_values = { | 61 | flag_values = { |
| @@ -86,6 +99,7 @@ cc_library( | |||
| 86 | "googlemock/include/gmock/*.h", | 99 | "googlemock/include/gmock/*.h", |
| 87 | ]), | 100 | ]), |
| 88 | copts = select({ | 101 | copts = select({ |
| 102 | + ":qnx": [], | ||
| 89 | ":windows": [], | 103 | ":windows": [], |
| 90 | "//conditions:default": ["-pthread"], | 104 | "//conditions:default": ["-pthread"], |
| 91 | }), | 105 | }), |
| @@ -104,7 +118,16 @@ cc_library( | |||
| 104 | "googletest/include", | 118 | "googletest/include", |
| 105 | ], | 119 | ], |
| 106 | linkopts = select({ | 120 | linkopts = select({ |
| 121 | + ":qnx": ["-lregex"], | ||
| 107 | ":windows": [], | 122 | ":windows": [], |
| 123 | + ":freebsd": [ | ||
| 124 | + "-lm", | ||
| 125 | + "-pthread", | ||
| 126 | + ], | ||
| 127 | + ":openbsd": [ | ||
| 128 | + "-lm", | ||
| 129 | + "-pthread", | ||
| 130 | + ], | ||
| 108 | "//conditions:default": ["-pthread"], | 131 | "//conditions:default": ["-pthread"], |
| 109 | }), | 132 | }), |
| 110 | deps = select({ | 133 | deps = select({ |
| @@ -112,10 +135,15 @@ cc_library( | |||
| 112 | "@com_google_absl//absl/debugging:failure_signal_handler", | 135 | "@com_google_absl//absl/debugging:failure_signal_handler", |
| 113 | "@com_google_absl//absl/debugging:stacktrace", | 136 | "@com_google_absl//absl/debugging:stacktrace", |
| 114 | "@com_google_absl//absl/debugging:symbolize", | 137 | "@com_google_absl//absl/debugging:symbolize", |
| 138 | + "@com_google_absl//absl/flags:flag", | ||
| 139 | + "@com_google_absl//absl/flags:parse", | ||
| 140 | + "@com_google_absl//absl/flags:reflection", | ||
| 141 | + "@com_google_absl//absl/flags:usage", | ||
| 115 | "@com_google_absl//absl/strings", | 142 | "@com_google_absl//absl/strings", |
| 116 | "@com_google_absl//absl/types:any", | 143 | "@com_google_absl//absl/types:any", |
| 117 | "@com_google_absl//absl/types:optional", | 144 | "@com_google_absl//absl/types:optional", |
| 118 | "@com_google_absl//absl/types:variant", | 145 | "@com_google_absl//absl/types:variant", |
| 146 | + "@com_googlesource_code_re2//:re2", | ||
| 119 | ], | 147 | ], |
| 120 | "//conditions:default": [], | 148 | "//conditions:default": [], |
| 121 | }), | 149 | }), |
| @@ -17,8 +17,14 @@ config("gtest_private_config_rtti") { | |||
| 17 | 17 | ||
| 18 | config("gtest_config") { | 18 | config("gtest_config") { |
| 19 | include_dirs = [ "googletest/include" ] | 19 | include_dirs = [ "googletest/include" ] |
| 20 | + cflags_cc = [ | ||
| 21 | + "-std=c++17", | ||
| 22 | + "-Wno-float-equal", | ||
| 23 | + "-Wno-sign-compare", | ||
| 24 | + "-Wno-reorder-init-list", | ||
| 25 | + ] | ||
| 20 | if (is_mingw) { | 26 | if (is_mingw) { |
| 21 | - cflags_cc = [ | 27 | + cflags_cc += [ |
| 22 | "-Wno-unused-const-variable", | 28 | "-Wno-unused-const-variable", |
| 23 | "-Wno-unused-private-field", | 29 | "-Wno-unused-private-field", |
| 24 | ] | 30 | ] |
| @@ -52,6 +58,7 @@ sources_files = [ | |||
| 52 | "googletest/include/gtest/internal/gtest-string.h", | 58 | "googletest/include/gtest/internal/gtest-string.h", |
| 53 | "googletest/include/gtest/internal/gtest-type-util.h", | 59 | "googletest/include/gtest/internal/gtest-type-util.h", |
| 54 | "googletest/src/gtest-all.cc", | 60 | "googletest/src/gtest-all.cc", |
| 61 | + "googletest/src/gtest-assertion-result.cc", | ||
| 55 | "googletest/src/gtest-death-test.cc", | 62 | "googletest/src/gtest-death-test.cc", |
| 56 | "googletest/src/gtest-filepath.cc", | 63 | "googletest/src/gtest-filepath.cc", |
| 57 | "googletest/src/gtest-internal-inl.h", | 64 | "googletest/src/gtest-internal-inl.h", |
| @@ -1,19 +1,25 @@ | |||
| 1 | # Note: CMake support is community-based. The maintainers do not use CMake | 1 | # Note: CMake support is community-based. The maintainers do not use CMake |
| 2 | # internally. | 2 | # internally. |
| 3 | 3 | ||
| 4 | -cmake_minimum_required(VERSION 2.8.12) | 4 | +cmake_minimum_required(VERSION 3.5) |
| 5 | 5 | ||
| 6 | if (POLICY CMP0048) | 6 | if (POLICY CMP0048) |
| 7 | cmake_policy(SET CMP0048 NEW) | 7 | cmake_policy(SET CMP0048 NEW) |
| 8 | endif (POLICY CMP0048) | 8 | endif (POLICY CMP0048) |
| 9 | 9 | ||
| 10 | -project(googletest-distribution) | 10 | +if (POLICY CMP0069) |
| 11 | -set(GOOGLETEST_VERSION 1.11.0) | 11 | + cmake_policy(SET CMP0069 NEW) |
| 12 | +endif (POLICY CMP0069) | ||
| 12 | 13 | ||
| 13 | -if (CMAKE_VERSION VERSION_GREATER "3.0.2") | 14 | +if (POLICY CMP0077) |
| 14 | - if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) | 15 | + cmake_policy(SET CMP0077 NEW) |
| 15 | - set(CMAKE_CXX_EXTENSIONS OFF) | 16 | +endif (POLICY CMP0077) |
| 16 | - endif() | 17 | + |
| 18 | +project(googletest-distribution) | ||
| 19 | +set(GOOGLETEST_VERSION 1.13.0) | ||
| 20 | + | ||
| 21 | +if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) | ||
| 22 | + set(CMAKE_CXX_EXTENSIONS OFF) | ||
| 17 | endif() | 23 | endif() |
| 18 | 24 | ||
| 19 | enable_testing() | 25 | enable_testing() |
| @@ -24,6 +30,7 @@ include(GNUInstallDirs) | |||
| 24 | #Note that googlemock target already builds googletest | 30 | #Note that googlemock target already builds googletest |
| 25 | option(BUILD_GMOCK "Builds the googlemock subproject" ON) | 31 | option(BUILD_GMOCK "Builds the googlemock subproject" ON) |
| 26 | option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) | 32 | option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) |
| 33 | +option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) | ||
| 27 | 34 | ||
| 28 | if(BUILD_GMOCK) | 35 | if(BUILD_GMOCK) |
| 29 | add_subdirectory( googlemock ) | 36 | add_subdirectory( googlemock ) |
| @@ -21,8 +21,8 @@ accept your pull requests. | |||
| 21 | 21 | ||
| 22 | ## Are you a Googler? | 22 | ## Are you a Googler? |
| 23 | 23 | ||
| 24 | -If you are a Googler, please make an attempt to submit an internal change rather | 24 | +If you are a Googler, please make an attempt to submit an internal contribution |
| 25 | -than a GitHub Pull Request. If you are not able to submit an internal change a | 25 | +rather than a GitHub Pull Request. If you are not able to submit internally, a |
| 26 | PR is acceptable as an alternative. | 26 | PR is acceptable as an alternative. |
| 27 | 27 | ||
| 28 | ## Contributing A Patch | 28 | ## Contributing A Patch |
| @@ -36,7 +36,8 @@ PR is acceptable as an alternative. | |||
| 36 | This ensures that work isn't being duplicated and communicating your plan | 36 | This ensures that work isn't being duplicated and communicating your plan |
| 37 | early also generally leads to better patches. | 37 | early also generally leads to better patches. |
| 38 | 4. If your proposed change is accepted, and you haven't already done so, sign a | 38 | 4. If your proposed change is accepted, and you haven't already done so, sign a |
| 39 | - Contributor License Agreement (see details above). | 39 | + Contributor License Agreement |
| 40 | + ([see details above](#contributor-license-agreements)). | ||
| 40 | 5. Fork the desired repo, develop and test your code changes. | 41 | 5. Fork the desired repo, develop and test your code changes. |
| 41 | 6. Ensure that your code adheres to the existing style in the sample to which | 42 | 6. Ensure that your code adheres to the existing style in the sample to which |
| 42 | you are contributing. | 43 | you are contributing. |
| @@ -79,8 +80,8 @@ fairly rigid coding style, as defined by the | |||
| 79 | [google-styleguide](https://github.com/google/styleguide) project. All patches | 80 | [google-styleguide](https://github.com/google/styleguide) project. All patches |
| 80 | will be expected to conform to the style outlined | 81 | will be expected to conform to the style outlined |
| 81 | [here](https://google.github.io/styleguide/cppguide.html). Use | 82 | [here](https://google.github.io/styleguide/cppguide.html). Use |
| 82 | -[.clang-format](https://github.com/google/googletest/blob/master/.clang-format) | 83 | +[.clang-format](https://github.com/google/googletest/blob/main/.clang-format) to |
| 83 | -to check your formatting. | 84 | +check your formatting. |
| 84 | 85 | ||
| 85 | ## Requirements for Contributors | 86 | ## Requirements for Contributors |
| 86 | 87 | ||
| @@ -34,6 +34,7 @@ Manuel Klimek <klimek@google.com> | |||
| 34 | Mario Tanev <radix@google.com> | 34 | Mario Tanev <radix@google.com> |
| 35 | Mark Paskin | 35 | Mark Paskin |
| 36 | Markus Heule <markus.heule@gmail.com> | 36 | Markus Heule <markus.heule@gmail.com> |
| 37 | +Martijn Vels <mvels@google.com> | ||
| 37 | Matthew Simmons <simmonmt@acm.org> | 38 | Matthew Simmons <simmonmt@acm.org> |
| 38 | Mika Raento <mikie@iki.fi> | 39 | Mika Raento <mikie@iki.fi> |
| 39 | Mike Bland <mbland@google.com> | 40 | Mike Bland <mbland@google.com> |
| @@ -55,6 +56,7 @@ Russ Rufer <russ@pentad.com> | |||
| 55 | Sean Mcafee <eefacm@gmail.com> | 56 | Sean Mcafee <eefacm@gmail.com> |
| 56 | Sigurður Ásgeirsson <siggi@google.com> | 57 | Sigurður Ásgeirsson <siggi@google.com> |
| 57 | Sverre Sundsdal <sundsdal@gmail.com> | 58 | Sverre Sundsdal <sundsdal@gmail.com> |
| 59 | +Szymon Sobik <sobik.szymon@gmail.com> | ||
| 58 | Takeshi Yoshino <tyoshino@google.com> | 60 | Takeshi Yoshino <tyoshino@google.com> |
| 59 | Tracy Bialik <tracy@pentad.com> | 61 | Tracy Bialik <tracy@pentad.com> |
| 60 | Vadim Berman <vadimb@google.com> | 62 | Vadim Berman <vadimb@google.com> |
| @@ -8,4 +8,4 @@ | |||
| 8 | "Upstream URL": "https://github.com/google/googletest/releases/tag/release-1.11.0", | 8 | "Upstream URL": "https://github.com/google/googletest/releases/tag/release-1.11.0", |
| 9 | "Description": "The 1.11.x is the last release supporting pre-C++11 compilers. The 1.11.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven critical" | 9 | "Description": "The 1.11.x is the last release supporting pre-C++11 compilers. The 1.11.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven critical" |
| 10 | } | 10 | } |
| 11 | -] | 11 | +] |
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | GoogleTest now follows the | 7 | GoogleTest now follows the |
| 8 | [Abseil Live at Head philosophy](https://abseil.io/about/philosophy#upgrade-support). | 8 | [Abseil Live at Head philosophy](https://abseil.io/about/philosophy#upgrade-support). |
| 9 | -We recommend using the latest commit in the `master` branch in your projects. | 9 | +We recommend |
| 10 | +[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). | ||
| 10 | 11 | ||
| 11 | #### Documentation Updates | 12 | #### Documentation Updates |
| 12 | 13 | ||
| @@ -14,11 +15,14 @@ Our documentation is now live on GitHub Pages at | |||
| 14 | https://google.github.io/googletest/. We recommend browsing the documentation on | 15 | https://google.github.io/googletest/. We recommend browsing the documentation on |
| 15 | GitHub Pages rather than directly in the repository. | 16 | GitHub Pages rather than directly in the repository. |
| 16 | 17 | ||
| 17 | -#### Release 1.10.x | 18 | +#### Release 1.12.1 |
| 18 | 19 | ||
| 19 | -[Release 1.10.x](https://github.com/google/googletest/releases/tag/release-1.10.0) | 20 | +[Release 1.12.1](https://github.com/google/googletest/releases/tag/release-1.12.1) |
| 20 | is now available. | 21 | is now available. |
| 21 | 22 | ||
| 23 | +The 1.12.x branch will be the last to support C++11. Future releases will | ||
| 24 | +require at least C++14. | ||
| 25 | + | ||
| 22 | #### Coming Soon | 26 | #### Coming Soon |
| 23 | 27 | ||
| 24 | * We are planning to take a dependency on | 28 | * We are planning to take a dependency on |
| @@ -55,39 +59,12 @@ More information about building GoogleTest can be found at | |||
| 55 | 59 | ||
| 56 | ## Supported Platforms | 60 | ## Supported Platforms |
| 57 | 61 | ||
| 58 | -GoogleTest requires a codebase and compiler compliant with the C++11 standard or | 62 | +GoogleTest follows Google's |
| 59 | -newer. | 63 | +[Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support). |
| 60 | - | 64 | +See |
| 61 | -The GoogleTest code is officially supported on the following platforms. | 65 | +[this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) |
| 62 | -Operating systems or tools not listed below are community-supported. For | 66 | +for a list of currently supported versions compilers, platforms, and build |
| 63 | -community-supported platforms, patches that do not complicate the code may be | 67 | +tools. |
| 64 | -considered. | ||
| 65 | - | ||
| 66 | -If you notice any problems on your platform, please file an issue on the | ||
| 67 | -[GoogleTest GitHub Issue Tracker](https://github.com/google/googletest/issues). | ||
| 68 | -Pull requests containing fixes are welcome! | ||
| 69 | - | ||
| 70 | -### Operating Systems | ||
| 71 | - | ||
| 72 | -* Linux | ||
| 73 | -* macOS | ||
| 74 | -* Windows | ||
| 75 | - | ||
| 76 | -### Compilers | ||
| 77 | - | ||
| 78 | -* gcc 5.0+ | ||
| 79 | -* clang 5.0+ | ||
| 80 | -* MSVC 2015+ | ||
| 81 | - | ||
| 82 | -**macOS users:** Xcode 9.3+ provides clang 5.0+. | ||
| 83 | - | ||
| 84 | -### Build Systems | ||
| 85 | - | ||
| 86 | -* [Bazel](https://bazel.build/) | ||
| 87 | -* [CMake](https://cmake.org/) | ||
| 88 | - | ||
| 89 | -**Note:** Bazel is the build system used by the team internally and in tests. | ||
| 90 | -CMake is supported on a best-effort basis and by the community. | ||
| 91 | 68 | ||
| 92 | ## Who Is Using GoogleTest? | 69 | ## Who Is Using GoogleTest? |
| 93 | 70 | ||
| @@ -109,8 +86,8 @@ Windows and Linux platforms. | |||
| 109 | 86 | ||
| 110 | [GoogleTest UI](https://github.com/ospector/gtest-gbar) is a test runner that | 87 | [GoogleTest UI](https://github.com/ospector/gtest-gbar) is a test runner that |
| 111 | runs your test binary, allows you to track its progress via a progress bar, and | 88 | runs your test binary, allows you to track its progress via a progress bar, and |
| 112 | -displays a list of test failures. Clicking on one shows failure text. Google | 89 | +displays a list of test failures. Clicking on one shows failure text. GoogleTest |
| 113 | -Test UI is written in C#. | 90 | +UI is written in C#. |
| 114 | 91 | ||
| 115 | [GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event | 92 | [GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event |
| 116 | listener for GoogleTest that implements the | 93 | listener for GoogleTest that implements the |
| @@ -121,11 +98,11 @@ result output. If your test runner understands TAP, you may find it useful. | |||
| 121 | runs tests from your binary in parallel to provide significant speed-up. | 98 | runs tests from your binary in parallel to provide significant speed-up. |
| 122 | 99 | ||
| 123 | [GoogleTest Adapter](https://marketplace.visualstudio.com/items?itemName=DavidSchuldenfrei.gtest-adapter) | 100 | [GoogleTest Adapter](https://marketplace.visualstudio.com/items?itemName=DavidSchuldenfrei.gtest-adapter) |
| 124 | -is a VS Code extension allowing to view GoogleTest in a tree view, and run/debug | 101 | +is a VS Code extension allowing to view GoogleTest in a tree view and run/debug |
| 125 | your tests. | 102 | your tests. |
| 126 | 103 | ||
| 127 | [C++ TestMate](https://github.com/matepek/vscode-catch2-test-adapter) is a VS | 104 | [C++ TestMate](https://github.com/matepek/vscode-catch2-test-adapter) is a VS |
| 128 | -Code extension allowing to view GoogleTest in a tree view, and run/debug your | 105 | +Code extension allowing to view GoogleTest in a tree view and run/debug your |
| 129 | tests. | 106 | tests. |
| 130 | 107 | ||
| 131 | [Cornichon](https://pypi.org/project/cornichon/) is a small Gherkin DSL parser | 108 | [Cornichon](https://pypi.org/project/cornichon/) is a small Gherkin DSL parser |
| @@ -134,7 +111,7 @@ that generates stub code for GoogleTest. | |||
| 134 | ## Contributing Changes | 111 | ## Contributing Changes |
| 135 | 112 | ||
| 136 | Please read | 113 | Please read |
| 137 | -[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/master/CONTRIBUTING.md) | 114 | +[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/main/CONTRIBUTING.md) |
| 138 | for details on how to contribute to this project. | 115 | for details on how to contribute to this project. |
| 139 | 116 | ||
| 140 | Happy testing! | 117 | Happy testing! |
| @@ -3,22 +3,38 @@ workspace(name = "com_google_googletest") | |||
| 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 4 | 4 | ||
| 5 | http_archive( | 5 | http_archive( |
| 6 | - name = "com_google_absl", | 6 | + name = "com_google_absl", # 2023-01-10T21:08:25Z |
| 7 | - urls = ["https://github.com/abseil/abseil-cpp/archive/7971fb358ae376e016d2d4fc9327aad95659b25e.zip"], # 2021-05-20T02:59:16Z | 7 | + sha256 = "f9a4e749f42c386a32a90fddf0e2913ed408d10c42f7f33ccf4c59ac4f0d1d05", |
| 8 | - strip_prefix = "abseil-cpp-7971fb358ae376e016d2d4fc9327aad95659b25e", | 8 | + strip_prefix = "abseil-cpp-52835439ca90d86b27bf8cd1708296e95604d724", |
| 9 | - sha256 = "aeba534f7307e36fe084b452299e49b97420667a8d28102cf9a0daeed340b859", | 9 | + urls = ["https://github.com/abseil/abseil-cpp/archive/52835439ca90d86b27bf8cd1708296e95604d724.zip"], |
| 10 | +) | ||
| 11 | + | ||
| 12 | +# Note this must use a commit from the `abseil` branch of the RE2 project. | ||
| 13 | +# https://github.com/google/re2/tree/abseil | ||
| 14 | +http_archive( | ||
| 15 | + name = "com_googlesource_code_re2", # 2022-12-21T14:29:10Z | ||
| 16 | + sha256 = "b9ce3a51beebb38534d11d40f8928d40509b9e18a735f6a4a97ad3d014c87cb5", | ||
| 17 | + strip_prefix = "re2-d0b1f8f2ecc2ea74956c7608b6f915175314ff0e", | ||
| 18 | + urls = ["https://github.com/google/re2/archive/d0b1f8f2ecc2ea74956c7608b6f915175314ff0e.zip"], | ||
| 10 | ) | 19 | ) |
| 11 | 20 | ||
| 12 | http_archive( | 21 | http_archive( |
| 13 | - name = "rules_cc", | 22 | + name = "rules_python", # 2023-01-10T22:00:51Z |
| 14 | - urls = ["https://github.com/bazelbuild/rules_cc/archive/68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9.zip"], # 2021-05-14T14:51:14Z | 23 | + sha256 = "5de54486a60ad8948dabe49605bb1c08053e04001a431ab3e96745b4d97a4419", |
| 15 | - strip_prefix = "rules_cc-68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9", | 24 | + strip_prefix = "rules_python-70cce26432187a60b4e950118791385e6fb3c26f", |
| 16 | - sha256 = "1e19e9a3bc3d4ee91d7fcad00653485ee6c798efbbf9588d40b34cbfbded143d", | 25 | + urls = ["https://github.com/bazelbuild/rules_python/archive/70cce26432187a60b4e950118791385e6fb3c26f.zip"], |
| 17 | ) | 26 | ) |
| 18 | 27 | ||
| 19 | http_archive( | 28 | http_archive( |
| 20 | - name = "rules_python", | 29 | + name = "bazel_skylib", # 2022-11-16T18:29:32Z |
| 21 | - urls = ["https://github.com/bazelbuild/rules_python/archive/ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2.zip"], # 2021-05-17T00:24:16Z | 30 | + sha256 = "a22290c26d29d3ecca286466f7f295ac6cbe32c0a9da3a91176a90e0725e3649", |
| 22 | - strip_prefix = "rules_python-ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2", | 31 | + strip_prefix = "bazel-skylib-5bfcb1a684550626ce138fe0fe8f5f702b3764c3", |
| 23 | - sha256 = "98b3c592faea9636ac8444bfd9de7f3fb4c60590932d6e6ac5946e3f8dbd5ff6", | 32 | + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/5bfcb1a684550626ce138fe0fe8f5f702b3764c3.zip"], |
| 33 | +) | ||
| 34 | + | ||
| 35 | +http_archive( | ||
| 36 | + name = "platforms", # 2022-11-09T19:18:22Z | ||
| 37 | + sha256 = "b4a3b45dc4202e2b3e34e3bc49d2b5b37295fc23ea58d88fb9e01f3642ad9b55", | ||
| 38 | + strip_prefix = "platforms-3fbc687756043fb58a407c2ea8c944bc2fe1d922", | ||
| 39 | + urls = ["https://github.com/bazelbuild/platforms/archive/3fbc687756043fb58a407c2ea8c944bc2fe1d922.zip"], | ||
| 24 | ) | 40 | ) |
| @@ -31,15 +31,15 @@ | |||
| 31 | 31 | ||
| 32 | set -euox pipefail | 32 | set -euox pipefail |
| 33 | 33 | ||
| 34 | -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20210525" | 34 | +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220217" |
| 35 | -readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20201015" | 35 | +readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20220621" |
| 36 | 36 | ||
| 37 | if [[ -z ${GTEST_ROOT:-} ]]; then | 37 | if [[ -z ${GTEST_ROOT:-} ]]; then |
| 38 | GTEST_ROOT="$(realpath $(dirname ${0})/..)" | 38 | GTEST_ROOT="$(realpath $(dirname ${0})/..)" |
| 39 | fi | 39 | fi |
| 40 | 40 | ||
| 41 | if [[ -z ${STD:-} ]]; then | 41 | if [[ -z ${STD:-} ]]; then |
| 42 | - STD="c++11 c++14 c++17 c++20" | 42 | + STD="c++14 c++17 c++20" |
| 43 | fi | 43 | fi |
| 44 | 44 | ||
| 45 | # Test the CMake build | 45 | # Test the CMake build |
| @@ -55,7 +55,7 @@ for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do | |||
| 55 | ${LINUX_LATEST_CONTAINER} \ | 55 | ${LINUX_LATEST_CONTAINER} \ |
| 56 | /bin/bash -c " | 56 | /bin/bash -c " |
| 57 | cmake /src \ | 57 | cmake /src \ |
| 58 | - -DCMAKE_CXX_STANDARD=11 \ | 58 | + -DCMAKE_CXX_STANDARD=14 \ |
| 59 | -Dgtest_build_samples=ON \ | 59 | -Dgtest_build_samples=ON \ |
| 60 | -Dgtest_build_tests=ON \ | 60 | -Dgtest_build_tests=ON \ |
| 61 | -Dgmock_build_tests=ON \ | 61 | -Dgmock_build_tests=ON \ |
| @@ -72,11 +72,15 @@ time docker run \ | |||
| 72 | --workdir="/src" \ | 72 | --workdir="/src" \ |
| 73 | --rm \ | 73 | --rm \ |
| 74 | --env="CC=/usr/local/bin/gcc" \ | 74 | --env="CC=/usr/local/bin/gcc" \ |
| 75 | + --env="BAZEL_CXXOPTS=-std=c++14" \ | ||
| 75 | ${LINUX_GCC_FLOOR_CONTAINER} \ | 76 | ${LINUX_GCC_FLOOR_CONTAINER} \ |
| 76 | /usr/local/bin/bazel test ... \ | 77 | /usr/local/bin/bazel test ... \ |
| 77 | --copt="-Wall" \ | 78 | --copt="-Wall" \ |
| 78 | --copt="-Werror" \ | 79 | --copt="-Werror" \ |
| 80 | + --copt="-Wuninitialized" \ | ||
| 79 | --copt="-Wno-error=pragmas" \ | 81 | --copt="-Wno-error=pragmas" \ |
| 82 | + --distdir="/bazel-distdir" \ | ||
| 83 | + --features=external_include_paths \ | ||
| 80 | --keep_going \ | 84 | --keep_going \ |
| 81 | --show_timestamps \ | 85 | --show_timestamps \ |
| 82 | --test_output=errors | 86 | --test_output=errors |
| @@ -94,8 +98,10 @@ for std in ${STD}; do | |||
| 94 | /usr/local/bin/bazel test ... \ | 98 | /usr/local/bin/bazel test ... \ |
| 95 | --copt="-Wall" \ | 99 | --copt="-Wall" \ |
| 96 | --copt="-Werror" \ | 100 | --copt="-Werror" \ |
| 101 | + --copt="-Wuninitialized" \ | ||
| 97 | --define="absl=${absl}" \ | 102 | --define="absl=${absl}" \ |
| 98 | --distdir="/bazel-distdir" \ | 103 | --distdir="/bazel-distdir" \ |
| 104 | + --features=external_include_paths \ | ||
| 99 | --keep_going \ | 105 | --keep_going \ |
| 100 | --show_timestamps \ | 106 | --show_timestamps \ |
| 101 | --test_output=errors | 107 | --test_output=errors |
| @@ -116,8 +122,10 @@ for std in ${STD}; do | |||
| 116 | --copt="--gcc-toolchain=/usr/local" \ | 122 | --copt="--gcc-toolchain=/usr/local" \ |
| 117 | --copt="-Wall" \ | 123 | --copt="-Wall" \ |
| 118 | --copt="-Werror" \ | 124 | --copt="-Werror" \ |
| 125 | + --copt="-Wuninitialized" \ | ||
| 119 | --define="absl=${absl}" \ | 126 | --define="absl=${absl}" \ |
| 120 | --distdir="/bazel-distdir" \ | 127 | --distdir="/bazel-distdir" \ |
| 128 | + --features=external_include_paths \ | ||
| 121 | --keep_going \ | 129 | --keep_going \ |
| 122 | --linkopt="--gcc-toolchain=/usr/local" \ | 130 | --linkopt="--gcc-toolchain=/usr/local" \ |
| 123 | --show_timestamps \ | 131 | --show_timestamps \ |
| @@ -40,7 +40,7 @@ for cmake_off_on in OFF ON; do | |||
| 40 | BUILD_DIR=$(mktemp -d build_dir.XXXXXXXX) | 40 | BUILD_DIR=$(mktemp -d build_dir.XXXXXXXX) |
| 41 | cd ${BUILD_DIR} | 41 | cd ${BUILD_DIR} |
| 42 | time cmake ${GTEST_ROOT} \ | 42 | time cmake ${GTEST_ROOT} \ |
| 43 | - -DCMAKE_CXX_STANDARD=11 \ | 43 | + -DCMAKE_CXX_STANDARD=14 \ |
| 44 | -Dgtest_build_samples=ON \ | 44 | -Dgtest_build_samples=ON \ |
| 45 | -Dgtest_build_tests=ON \ | 45 | -Dgtest_build_tests=ON \ |
| 46 | -Dgmock_build_tests=ON \ | 46 | -Dgmock_build_tests=ON \ |
| @@ -53,7 +53,7 @@ done | |||
| 53 | # Test the Bazel build | 53 | # Test the Bazel build |
| 54 | 54 | ||
| 55 | # If we are running on Kokoro, check for a versioned Bazel binary. | 55 | # If we are running on Kokoro, check for a versioned Bazel binary. |
| 56 | -KOKORO_GFILE_BAZEL_BIN="bazel-3.7.0-darwin-x86_64" | 56 | +KOKORO_GFILE_BAZEL_BIN="bazel-5.1.1-darwin-x86_64" |
| 57 | if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then | 57 | if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then |
| 58 | BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}" | 58 | BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}" |
| 59 | chmod +x ${BAZEL_BIN} | 59 | chmod +x ${BAZEL_BIN} |
| @@ -66,7 +66,9 @@ for absl in 0 1; do | |||
| 66 | ${BAZEL_BIN} test ... \ | 66 | ${BAZEL_BIN} test ... \ |
| 67 | --copt="-Wall" \ | 67 | --copt="-Wall" \ |
| 68 | --copt="-Werror" \ | 68 | --copt="-Werror" \ |
| 69 | + --cxxopt="-std=c++14" \ | ||
| 69 | --define="absl=${absl}" \ | 70 | --define="absl=${absl}" \ |
| 71 | + --features=external_include_paths \ | ||
| 70 | --keep_going \ | 72 | --keep_going \ |
| 71 | --show_timestamps \ | 73 | --show_timestamps \ |
| 72 | --test_output=errors | 74 | --test_output=errors |
| @@ -0,0 +1,71 @@ | |||
| 1 | +@echo off | ||
| 2 | +@rem Copyright 2024 googletest authors. | ||
| 3 | +@rem | ||
| 4 | +@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | +@rem you may not use this file except in compliance with the License. | ||
| 6 | +@rem You may obtain a copy of the License at | ||
| 7 | +@rem | ||
| 8 | +@rem http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | +@rem | ||
| 10 | +@rem Unless required by applicable law or agreed to in writing, software | ||
| 11 | +@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | +@rem See the License for the specific language governing permissions and | ||
| 14 | +@rem limitations under the License. | ||
| 15 | + | ||
| 16 | +SETLOCAL ENABLEDELAYEDEXPANSION | ||
| 17 | + | ||
| 18 | +SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe | ||
| 19 | + | ||
| 20 | +SET PATH=C:\Python37;%PATH% | ||
| 21 | +SET BAZEL_PYTHON=C:\python37\python.exe | ||
| 22 | +SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe | ||
| 23 | +SET CMAKE_BIN="C:\Program Files\CMake\bin\cmake.exe" | ||
| 24 | +SET CTEST_BIN="C:\Program Files\CMake\bin\ctest.exe" | ||
| 25 | +SET CTEST_OUTPUT_ON_FAILURE=1 | ||
| 26 | + | ||
| 27 | +IF EXIST git\googletest ( | ||
| 28 | + CD git\googletest | ||
| 29 | +) ELSE IF EXIST github\googletest ( | ||
| 30 | + CD github\googletest | ||
| 31 | +) | ||
| 32 | + | ||
| 33 | +IF %errorlevel% neq 0 EXIT /B 1 | ||
| 34 | + | ||
| 35 | +:: ---------------------------------------------------------------------------- | ||
| 36 | +:: CMake Visual Studio 15 2017 Win64 | ||
| 37 | +MKDIR cmake_msvc2017 | ||
| 38 | +CD cmake_msvc2017 | ||
| 39 | + | ||
| 40 | +%CMAKE_BIN% .. ^ | ||
| 41 | + -G "Visual Studio 15 2017 Win64" ^ | ||
| 42 | + -DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^ | ||
| 43 | + -DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^ | ||
| 44 | + -DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^ | ||
| 45 | + -Dgtest_build_samples=ON ^ | ||
| 46 | + -Dgtest_build_tests=ON ^ | ||
| 47 | + -Dgmock_build_tests=ON | ||
| 48 | +IF %errorlevel% neq 0 EXIT /B 1 | ||
| 49 | + | ||
| 50 | +%CMAKE_BIN% --build . --target ALL_BUILD --config Debug -- -maxcpucount | ||
| 51 | +IF %errorlevel% neq 0 EXIT /B 1 | ||
| 52 | + | ||
| 53 | +%CTEST_BIN% -C Debug --timeout 600 | ||
| 54 | +IF %errorlevel% neq 0 EXIT /B 1 | ||
| 55 | + | ||
| 56 | +CD .. | ||
| 57 | +RMDIR /S /Q cmake_msvc2017 | ||
| 58 | + | ||
| 59 | +:: ---------------------------------------------------------------------------- | ||
| 60 | +:: Bazel Visual Studio 15 2017 Win64 | ||
| 61 | + | ||
| 62 | +SET BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC | ||
| 63 | +%BAZEL_EXE% test ... ^ | ||
| 64 | + --compilation_mode=dbg ^ | ||
| 65 | + --copt=/std:c++14 ^ | ||
| 66 | + --copt=/WX ^ | ||
| 67 | + --features=external_include_paths ^ | ||
| 68 | + --keep_going ^ | ||
| 69 | + --test_output=errors ^ | ||
| 70 | + --test_tag_filters=-no_test_msvc2017 | ||
| 71 | +IF %errorlevel% neq 0 EXIT /B 1 | ||
| @@ -48,7 +48,7 @@ | |||
| 48 | <div class="footer"> | 48 | <div class="footer"> |
| 49 | GoogleTest · | 49 | GoogleTest · |
| 50 | <a href="https://github.com/google/googletest">GitHub Repository</a> · | 50 | <a href="https://github.com/google/googletest">GitHub Repository</a> · |
| 51 | - <a href="https://github.com/google/googletest/blob/master/LICENSE">License</a> · | 51 | + <a href="https://github.com/google/googletest/blob/main/LICENSE">License</a> · |
| 52 | <a href="https://policies.google.com/privacy">Privacy Policy</a> | 52 | <a href="https://policies.google.com/privacy">Privacy Policy</a> |
| 53 | </div> | 53 | </div> |
| 54 | </div> | 54 | </div> |
| @@ -157,8 +157,11 @@ that can be used in the predicate assertion macro | |||
| 157 | example: | 157 | example: |
| 158 | 158 | ||
| 159 | ```c++ | 159 | ```c++ |
| 160 | -EXPECT_PRED_FORMAT2(testing::FloatLE, val1, val2); | 160 | +using ::testing::FloatLE; |
| 161 | -EXPECT_PRED_FORMAT2(testing::DoubleLE, val1, val2); | 161 | +using ::testing::DoubleLE; |
| 162 | +... | ||
| 163 | +EXPECT_PRED_FORMAT2(FloatLE, val1, val2); | ||
| 164 | +EXPECT_PRED_FORMAT2(DoubleLE, val1, val2); | ||
| 162 | ``` | 165 | ``` |
| 163 | 166 | ||
| 164 | The above code verifies that `val1` is less than, or approximately equal to, | 167 | The above code verifies that `val1` is less than, or approximately equal to, |
| @@ -202,10 +205,9 @@ You can call the function | |||
| 202 | 205 | ||
| 203 | to assert that types `T1` and `T2` are the same. The function does nothing if | 206 | to assert that types `T1` and `T2` are the same. The function does nothing if |
| 204 | the assertion is satisfied. If the types are different, the function call will | 207 | the assertion is satisfied. If the types are different, the function call will |
| 205 | -fail to compile, the compiler error message will say that | 208 | +fail to compile, the compiler error message will say that `T1 and T2 are not the |
| 206 | -`T1 and T2 are not the same type` and most likely (depending on the compiler) | 209 | +same type` and most likely (depending on the compiler) show you the actual |
| 207 | -show you the actual values of `T1` and `T2`. This is mainly useful inside | 210 | +values of `T1` and `T2`. This is mainly useful inside template code. |
| 208 | -template code. | ||
| 209 | 211 | ||
| 210 | **Caveat**: When used inside a member function of a class template or a function | 212 | **Caveat**: When used inside a member function of a class template or a function |
| 211 | template, `StaticAssertTypeEq<T1, T2>()` is effective only if the function is | 213 | template, `StaticAssertTypeEq<T1, T2>()` is effective only if the function is |
| @@ -383,10 +385,10 @@ EXPECT_TRUE(IsCorrectBarIntVector(bar_ints)) | |||
| 383 | ## Death Tests | 385 | ## Death Tests |
| 384 | 386 | ||
| 385 | In many applications, there are assertions that can cause application failure if | 387 | In many applications, there are assertions that can cause application failure if |
| 386 | -a condition is not met. These sanity checks, which ensure that the program is in | 388 | +a condition is not met. These consistency checks, which ensure that the program |
| 387 | -a known good state, are there to fail at the earliest possible time after some | 389 | +is in a known good state, are there to fail at the earliest possible time after |
| 388 | -program state is corrupted. If the assertion checks the wrong condition, then | 390 | +some program state is corrupted. If the assertion checks the wrong condition, |
| 389 | -the program may proceed in an erroneous state, which could lead to memory | 391 | +then the program may proceed in an erroneous state, which could lead to memory |
| 390 | corruption, security holes, or worse. Hence it is vitally important to test that | 392 | corruption, security holes, or worse. Hence it is vitally important to test that |
| 391 | such assertion statements work as expected. | 393 | such assertion statements work as expected. |
| 392 | 394 | ||
| @@ -480,10 +482,12 @@ TEST_F(FooDeathTest, DoesThat) { | |||
| 480 | 482 | ||
| 481 | ### Regular Expression Syntax | 483 | ### Regular Expression Syntax |
| 482 | 484 | ||
| 483 | -On POSIX systems (e.g. Linux, Cygwin, and Mac), googletest uses the | 485 | +When built with Bazel and using Abseil, googletest uses the |
| 486 | +[RE2](https://github.com/google/re2/wiki/Syntax) syntax. Otherwise, for POSIX | ||
| 487 | +systems (Linux, Cygwin, Mac), googletest uses the | ||
| 484 | [POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04) | 488 | [POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04) |
| 485 | -syntax. To learn about this syntax, you may want to read this | 489 | +syntax. To learn about POSIX syntax, you may want to read this |
| 486 | -[Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_Extended_Regular_Expressions). | 490 | +[Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_extended). |
| 487 | 491 | ||
| 488 | On Windows, googletest uses its own simple regular expression implementation. It | 492 | On Windows, googletest uses its own simple regular expression implementation. It |
| 489 | lacks many features. For example, we don't support union (`"x|y"`), grouping | 493 | 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 | |||
| 558 | particular style of death tests by setting the flag programmatically: | 562 | particular style of death tests by setting the flag programmatically: |
| 559 | 563 | ||
| 560 | ```c++ | 564 | ```c++ |
| 561 | -testing::FLAGS_gtest_death_test_style="threadsafe" | 565 | +GTEST_FLAG_SET(death_test_style, "threadsafe") |
| 562 | ``` | 566 | ``` |
| 563 | 567 | ||
| 564 | You can do this in `main()` to set the style for all death tests in the binary, | 568 | 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: | |||
| 568 | ```c++ | 572 | ```c++ |
| 569 | int main(int argc, char** argv) { | 573 | int main(int argc, char** argv) { |
| 570 | testing::InitGoogleTest(&argc, argv); | 574 | testing::InitGoogleTest(&argc, argv); |
| 571 | - testing::FLAGS_gtest_death_test_style = "fast"; | 575 | + GTEST_FLAG_SET(death_test_style, "fast"); |
| 572 | return RUN_ALL_TESTS(); | 576 | return RUN_ALL_TESTS(); |
| 573 | } | 577 | } |
| 574 | 578 | ||
| 575 | TEST(MyDeathTest, TestOne) { | 579 | TEST(MyDeathTest, TestOne) { |
| 576 | - testing::FLAGS_gtest_death_test_style = "threadsafe"; | 580 | + GTEST_FLAG_SET(death_test_style, "threadsafe"); |
| 577 | // This test is run in the "threadsafe" style: | 581 | // This test is run in the "threadsafe" style: |
| 578 | ASSERT_DEATH(ThisShouldDie(), ""); | 582 | ASSERT_DEATH(ThisShouldDie(), ""); |
| 579 | } | 583 | } |
| @@ -610,15 +614,14 @@ Despite the improved thread safety afforded by the "threadsafe" style of death | |||
| 610 | test, thread problems such as deadlock are still possible in the presence of | 614 | test, thread problems such as deadlock are still possible in the presence of |
| 611 | handlers registered with `pthread_atfork(3)`. | 615 | handlers registered with `pthread_atfork(3)`. |
| 612 | 616 | ||
| 613 | - | ||
| 614 | ## Using Assertions in Sub-routines | 617 | ## Using Assertions in Sub-routines |
| 615 | 618 | ||
| 616 | {: .callout .note} | 619 | {: .callout .note} |
| 617 | Note: If you want to put a series of test assertions in a subroutine to check | 620 | Note: If you want to put a series of test assertions in a subroutine to check |
| 618 | for a complex condition, consider using | 621 | for a complex condition, consider using |
| 619 | -[a custom GMock matcher](gmock_cook_book.md#NewMatchers) | 622 | +[a custom GMock matcher](gmock_cook_book.md#NewMatchers) instead. This lets you |
| 620 | -instead. This lets you provide a more readable error message in case of failure | 623 | +provide a more readable error message in case of failure and avoid all of the |
| 621 | -and avoid all of the issues described below. | 624 | +issues described below. |
| 622 | 625 | ||
| 623 | ### Adding Traces to Assertions | 626 | ### Adding Traces to Assertions |
| 624 | 627 | ||
| @@ -631,6 +634,7 @@ the `SCOPED_TRACE` macro or the `ScopedTrace` utility: | |||
| 631 | ```c++ | 634 | ```c++ |
| 632 | SCOPED_TRACE(message); | 635 | SCOPED_TRACE(message); |
| 633 | ``` | 636 | ``` |
| 637 | + | ||
| 634 | ```c++ | 638 | ```c++ |
| 635 | ScopedTrace trace("file_path", line_number, message); | 639 | ScopedTrace trace("file_path", line_number, message); |
| 636 | ``` | 640 | ``` |
| @@ -837,7 +841,7 @@ will output XML like this: | |||
| 837 | 841 | ||
| 838 | ```xml | 842 | ```xml |
| 839 | ... | 843 | ... |
| 840 | - <testcase name="MinAndMaxWidgets" status="run" time="0.006" classname="WidgetUsageTest" MaximumWidgets="12" MinimumWidgets="9" /> | 844 | + <testcase name="MinAndMaxWidgets" file="test.cpp" line="1" status="run" time="0.006" classname="WidgetUsageTest" MaximumWidgets="12" MinimumWidgets="9" /> |
| 841 | ... | 845 | ... |
| 842 | ``` | 846 | ``` |
| 843 | 847 | ||
| @@ -888,6 +892,12 @@ preceding or following another. Also, the tests must either not modify the state | |||
| 888 | of any shared resource, or, if they do modify the state, they must restore the | 892 | of any shared resource, or, if they do modify the state, they must restore the |
| 889 | state to its original value before passing control to the next test. | 893 | state to its original value before passing control to the next test. |
| 890 | 894 | ||
| 895 | +Note that `SetUpTestSuite()` may be called multiple times for a test fixture | ||
| 896 | +class that has derived classes, so you should not expect code in the function | ||
| 897 | +body to be run only once. Also, derived classes still have access to shared | ||
| 898 | +resources defined as static members, so careful consideration is needed when | ||
| 899 | +managing shared resources to avoid memory leaks. | ||
| 900 | + | ||
| 891 | Here's an example of per-test-suite set-up and tear-down: | 901 | Here's an example of per-test-suite set-up and tear-down: |
| 892 | 902 | ||
| 893 | ```c++ | 903 | ```c++ |
| @@ -897,7 +907,10 @@ class FooTest : public testing::Test { | |||
| 897 | // Called before the first test in this test suite. | 907 | // Called before the first test in this test suite. |
| 898 | // Can be omitted if not needed. | 908 | // Can be omitted if not needed. |
| 899 | static void SetUpTestSuite() { | 909 | static void SetUpTestSuite() { |
| 900 | - shared_resource_ = new ...; | 910 | + // Avoid reallocating static objects if called in subclasses of FooTest. |
| 911 | + if (shared_resource_ == nullptr) { | ||
| 912 | + shared_resource_ = new ...; | ||
| 913 | + } | ||
| 901 | } | 914 | } |
| 902 | 915 | ||
| 903 | // Per-test-suite tear-down. | 916 | // Per-test-suite tear-down. |
| @@ -1082,6 +1095,11 @@ instantiation of the test suite. The next argument is the name of the test | |||
| 1082 | pattern, and the last is the | 1095 | pattern, and the last is the |
| 1083 | [parameter generator](reference/testing.md#param-generators). | 1096 | [parameter generator](reference/testing.md#param-generators). |
| 1084 | 1097 | ||
| 1098 | +The parameter generator expression is not evaluated until GoogleTest is | ||
| 1099 | +initialized (via `InitGoogleTest()`). Any prior initialization done in the | ||
| 1100 | +`main` function will be accessible from the parameter generator, for example, | ||
| 1101 | +the results of flag parsing. | ||
| 1102 | + | ||
| 1085 | You can instantiate a test pattern more than once, so to distinguish different | 1103 | You can instantiate a test pattern more than once, so to distinguish different |
| 1086 | instances of the pattern, the instantiation name is added as a prefix to the | 1104 | instances of the pattern, the instantiation name is added as a prefix to the |
| 1087 | actual test suite name. Remember to pick unique prefixes for different | 1105 | actual test suite name. Remember to pick unique prefixes for different |
| @@ -1129,8 +1147,8 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest); | |||
| 1129 | 1147 | ||
| 1130 | You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples. | 1148 | You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples. |
| 1131 | 1149 | ||
| 1132 | -[sample7_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample7_unittest.cc "Parameterized Test example" | 1150 | +[sample7_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample7_unittest.cc "Parameterized Test example" |
| 1133 | -[sample8_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters" | 1151 | +[sample8_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters" |
| 1134 | 1152 | ||
| 1135 | ### Creating Value-Parameterized Abstract Tests | 1153 | ### Creating Value-Parameterized Abstract Tests |
| 1136 | 1154 | ||
| @@ -1281,7 +1299,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... } | |||
| 1281 | 1299 | ||
| 1282 | You can see [sample6_unittest.cc] for a complete example. | 1300 | You can see [sample6_unittest.cc] for a complete example. |
| 1283 | 1301 | ||
| 1284 | -[sample6_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc "Typed Test example" | 1302 | +[sample6_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample6_unittest.cc "Typed Test example" |
| 1285 | 1303 | ||
| 1286 | ## Type-Parameterized Tests | 1304 | ## Type-Parameterized Tests |
| 1287 | 1305 | ||
| @@ -1302,6 +1320,7 @@ First, define a fixture class template, as we did with typed tests: | |||
| 1302 | ```c++ | 1320 | ```c++ |
| 1303 | template <typename T> | 1321 | template <typename T> |
| 1304 | class FooTest : public testing::Test { | 1322 | class FooTest : public testing::Test { |
| 1323 | + void DoSomethingInteresting(); | ||
| 1305 | ... | 1324 | ... |
| 1306 | }; | 1325 | }; |
| 1307 | ``` | 1326 | ``` |
| @@ -1319,6 +1338,9 @@ this as many times as you want: | |||
| 1319 | TYPED_TEST_P(FooTest, DoesBlah) { | 1338 | TYPED_TEST_P(FooTest, DoesBlah) { |
| 1320 | // Inside a test, refer to TypeParam to get the type parameter. | 1339 | // Inside a test, refer to TypeParam to get the type parameter. |
| 1321 | TypeParam n = 0; | 1340 | TypeParam n = 0; |
| 1341 | + | ||
| 1342 | + // You will need to use `this` explicitly to refer to fixture members. | ||
| 1343 | + this->DoSomethingInteresting() | ||
| 1322 | ... | 1344 | ... |
| 1323 | } | 1345 | } |
| 1324 | 1346 | ||
| @@ -1481,8 +1503,8 @@ In frameworks that report a failure by throwing an exception, you could catch | |||
| 1481 | the exception and assert on it. But googletest doesn't use exceptions, so how do | 1503 | the exception and assert on it. But googletest doesn't use exceptions, so how do |
| 1482 | we test that a piece of code generates an expected failure? | 1504 | we test that a piece of code generates an expected failure? |
| 1483 | 1505 | ||
| 1484 | -`"gtest/gtest-spi.h"` contains some constructs to do this. After #including this header, | 1506 | +`"gtest/gtest-spi.h"` contains some constructs to do this. |
| 1485 | -you can use | 1507 | +After #including this header, you can use |
| 1486 | 1508 | ||
| 1487 | ```c++ | 1509 | ```c++ |
| 1488 | EXPECT_FATAL_FAILURE(statement, substring); | 1510 | EXPECT_FATAL_FAILURE(statement, substring); |
| @@ -1586,12 +1608,14 @@ void RegisterMyTests(const std::vector<int>& values) { | |||
| 1586 | } | 1608 | } |
| 1587 | ... | 1609 | ... |
| 1588 | int main(int argc, char** argv) { | 1610 | int main(int argc, char** argv) { |
| 1611 | + testing::InitGoogleTest(&argc, argv); | ||
| 1589 | std::vector<int> values_to_test = LoadValuesFromConfig(); | 1612 | std::vector<int> values_to_test = LoadValuesFromConfig(); |
| 1590 | RegisterMyTests(values_to_test); | 1613 | RegisterMyTests(values_to_test); |
| 1591 | ... | 1614 | ... |
| 1592 | return RUN_ALL_TESTS(); | 1615 | return RUN_ALL_TESTS(); |
| 1593 | } | 1616 | } |
| 1594 | ``` | 1617 | ``` |
| 1618 | + | ||
| 1595 | ## Getting the Current Test's Name | 1619 | ## Getting the Current Test's Name |
| 1596 | 1620 | ||
| 1597 | Sometimes a function may need to know the name of the currently running test. | 1621 | 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: | |||
| 1714 | Now, sit back and enjoy a completely different output from your tests. For more | 1738 | Now, sit back and enjoy a completely different output from your tests. For more |
| 1715 | details, see [sample9_unittest.cc]. | 1739 | details, see [sample9_unittest.cc]. |
| 1716 | 1740 | ||
| 1717 | -[sample9_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample9_unittest.cc "Event listener example" | 1741 | +[sample9_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample9_unittest.cc "Event listener example" |
| 1718 | 1742 | ||
| 1719 | You may append more than one listener to the list. When an `On*Start()` or | 1743 | You may append more than one listener to the list. When an `On*Start()` or |
| 1720 | `OnTestPartResult()` event is fired, the listeners will receive it in the order | 1744 | `OnTestPartResult()` event is fired, the listeners will receive it in the order |
| @@ -1741,7 +1765,7 @@ by the former. | |||
| 1741 | 1765 | ||
| 1742 | See [sample10_unittest.cc] for an example of a failure-raising listener. | 1766 | See [sample10_unittest.cc] for an example of a failure-raising listener. |
| 1743 | 1767 | ||
| 1744 | -[sample10_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample10_unittest.cc "Failure-raising listener example" | 1768 | +[sample10_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample10_unittest.cc "Failure-raising listener example" |
| 1745 | 1769 | ||
| 1746 | ## Running Test Programs: Advanced Options | 1770 | ## Running Test Programs: Advanced Options |
| 1747 | 1771 | ||
| @@ -1816,8 +1840,7 @@ By default, a googletest program runs all tests the user has defined. In some | |||
| 1816 | cases (e.g. iterative test development & execution) it may be desirable stop | 1840 | cases (e.g. iterative test development & execution) it may be desirable stop |
| 1817 | test execution upon first failure (trading improved latency for completeness). | 1841 | test execution upon first failure (trading improved latency for completeness). |
| 1818 | If `GTEST_FAIL_FAST` environment variable or `--gtest_fail_fast` flag is set, | 1842 | If `GTEST_FAIL_FAST` environment variable or `--gtest_fail_fast` flag is set, |
| 1819 | -the test runner will stop execution as soon as the first test failure is | 1843 | +the test runner will stop execution as soon as the first test failure is found. |
| 1820 | -found. | ||
| 1821 | 1844 | ||
| 1822 | #### Temporarily Disabling Tests | 1845 | #### Temporarily Disabling Tests |
| 1823 | 1846 | ||
| @@ -1890,8 +1913,12 @@ Repeat the tests whose name matches the filter 1000 times. | |||
| 1890 | 1913 | ||
| 1891 | If your test program contains | 1914 | If your test program contains |
| 1892 | [global set-up/tear-down](#global-set-up-and-tear-down) code, it will be | 1915 | [global set-up/tear-down](#global-set-up-and-tear-down) code, it will be |
| 1893 | -repeated in each iteration as well, as the flakiness may be in it. You can also | 1916 | +repeated in each iteration as well, as the flakiness may be in it. To avoid |
| 1894 | -specify the repeat count by setting the `GTEST_REPEAT` environment variable. | 1917 | +repeating global set-up/tear-down, specify |
| 1918 | +`--gtest_recreate_environments_when_repeating=false`{.nowrap}. | ||
| 1919 | + | ||
| 1920 | +You can also specify the repeat count by setting the `GTEST_REPEAT` environment | ||
| 1921 | +variable. | ||
| 1895 | 1922 | ||
| 1896 | ### Shuffling the Tests | 1923 | ### Shuffling the Tests |
| 1897 | 1924 | ||
| @@ -1911,6 +1938,58 @@ time. | |||
| 1911 | If you combine this with `--gtest_repeat=N`, googletest will pick a different | 1938 | If you combine this with `--gtest_repeat=N`, googletest will pick a different |
| 1912 | random seed and re-shuffle the tests in each iteration. | 1939 | random seed and re-shuffle the tests in each iteration. |
| 1913 | 1940 | ||
| 1941 | +### Distributing Test Functions to Multiple Machines | ||
| 1942 | + | ||
| 1943 | +If you have more than one machine you can use to run a test program, you might | ||
| 1944 | +want to run the test functions in parallel and get the result faster. We call | ||
| 1945 | +this technique *sharding*, where each machine is called a *shard*. | ||
| 1946 | + | ||
| 1947 | +GoogleTest is compatible with test sharding. To take advantage of this feature, | ||
| 1948 | +your test runner (not part of GoogleTest) needs to do the following: | ||
| 1949 | + | ||
| 1950 | +1. Allocate a number of machines (shards) to run the tests. | ||
| 1951 | +1. On each shard, set the `GTEST_TOTAL_SHARDS` environment variable to the total | ||
| 1952 | + number of shards. It must be the same for all shards. | ||
| 1953 | +1. On each shard, set the `GTEST_SHARD_INDEX` environment variable to the index | ||
| 1954 | + of the shard. Different shards must be assigned different indices, which | ||
| 1955 | + must be in the range `[0, GTEST_TOTAL_SHARDS - 1]`. | ||
| 1956 | +1. Run the same test program on all shards. When GoogleTest sees the above two | ||
| 1957 | + environment variables, it will select a subset of the test functions to run. | ||
| 1958 | + Across all shards, each test function in the program will be run exactly | ||
| 1959 | + once. | ||
| 1960 | +1. Wait for all shards to finish, then collect and report the results. | ||
| 1961 | + | ||
| 1962 | +Your project may have tests that were written without GoogleTest and thus don't | ||
| 1963 | +understand this protocol. In order for your test runner to figure out which test | ||
| 1964 | +supports sharding, it can set the environment variable `GTEST_SHARD_STATUS_FILE` | ||
| 1965 | +to a non-existent file path. If a test program supports sharding, it will create | ||
| 1966 | +this file to acknowledge that fact; otherwise it will not create it. The actual | ||
| 1967 | +contents of the file are not important at this time, although we may put some | ||
| 1968 | +useful information in it in the future. | ||
| 1969 | + | ||
| 1970 | +Here's an example to make it clear. Suppose you have a test program `foo_test` | ||
| 1971 | +that contains the following 5 test functions: | ||
| 1972 | + | ||
| 1973 | +``` | ||
| 1974 | +TEST(A, V) | ||
| 1975 | +TEST(A, W) | ||
| 1976 | +TEST(B, X) | ||
| 1977 | +TEST(B, Y) | ||
| 1978 | +TEST(B, Z) | ||
| 1979 | +``` | ||
| 1980 | + | ||
| 1981 | +Suppose you have 3 machines at your disposal. To run the test functions in | ||
| 1982 | +parallel, you would set `GTEST_TOTAL_SHARDS` to 3 on all machines, and set | ||
| 1983 | +`GTEST_SHARD_INDEX` to 0, 1, and 2 on the machines respectively. Then you would | ||
| 1984 | +run the same `foo_test` on each machine. | ||
| 1985 | + | ||
| 1986 | +GoogleTest reserves the right to change how the work is distributed across the | ||
| 1987 | +shards, but here's one possible scenario: | ||
| 1988 | + | ||
| 1989 | +* Machine #0 runs `A.V` and `B.X`. | ||
| 1990 | +* Machine #1 runs `A.W` and `B.Y`. | ||
| 1991 | +* Machine #2 runs `B.Z`. | ||
| 1992 | + | ||
| 1914 | ### Controlling Test Output | 1993 | ### Controlling Test Output |
| 1915 | 1994 | ||
| 1916 | #### Colored Terminal Output | 1995 | #### Colored Terminal Output |
| @@ -1965,8 +2044,6 @@ text because, for example, you don't have an UTF-8 compatible output medium, run | |||
| 1965 | the test program with `--gtest_print_utf8=0` or set the `GTEST_PRINT_UTF8` | 2044 | the test program with `--gtest_print_utf8=0` or set the `GTEST_PRINT_UTF8` |
| 1966 | environment variable to `0`. | 2045 | environment variable to `0`. |
| 1967 | 2046 | ||
| 1968 | - | ||
| 1969 | - | ||
| 1970 | #### Generating an XML Report | 2047 | #### Generating an XML Report |
| 1971 | 2048 | ||
| 1972 | googletest can emit a detailed XML report to a file in addition to its normal | 2049 | googletest can emit a detailed XML report to a file in addition to its normal |
| @@ -2020,15 +2097,15 @@ could generate this report: | |||
| 2020 | <?xml version="1.0" encoding="UTF-8"?> | 2097 | <?xml version="1.0" encoding="UTF-8"?> |
| 2021 | <testsuites tests="3" failures="1" errors="0" time="0.035" timestamp="2011-10-31T18:52:42" name="AllTests"> | 2098 | <testsuites tests="3" failures="1" errors="0" time="0.035" timestamp="2011-10-31T18:52:42" name="AllTests"> |
| 2022 | <testsuite name="MathTest" tests="2" failures="1" errors="0" time="0.015"> | 2099 | <testsuite name="MathTest" tests="2" failures="1" errors="0" time="0.015"> |
| 2023 | - <testcase name="Addition" status="run" time="0.007" classname=""> | 2100 | + <testcase name="Addition" file="test.cpp" line="1" status="run" time="0.007" classname=""> |
| 2024 | <failure message="Value of: add(1, 1)
 Actual: 3
Expected: 2" type="">...</failure> | 2101 | <failure message="Value of: add(1, 1)
 Actual: 3
Expected: 2" type="">...</failure> |
| 2025 | <failure message="Value of: add(1, -1)
 Actual: 1
Expected: 0" type="">...</failure> | 2102 | <failure message="Value of: add(1, -1)
 Actual: 1
Expected: 0" type="">...</failure> |
| 2026 | </testcase> | 2103 | </testcase> |
| 2027 | - <testcase name="Subtraction" status="run" time="0.005" classname=""> | 2104 | + <testcase name="Subtraction" file="test.cpp" line="2" status="run" time="0.005" classname=""> |
| 2028 | </testcase> | 2105 | </testcase> |
| 2029 | </testsuite> | 2106 | </testsuite> |
| 2030 | <testsuite name="LogicTest" tests="1" failures="0" errors="0" time="0.005"> | 2107 | <testsuite name="LogicTest" tests="1" failures="0" errors="0" time="0.005"> |
| 2031 | - <testcase name="NonContradiction" status="run" time="0.005" classname=""> | 2108 | + <testcase name="NonContradiction" file="test.cpp" line="3" status="run" time="0.005" classname=""> |
| 2032 | </testcase> | 2109 | </testcase> |
| 2033 | </testsuite> | 2110 | </testsuite> |
| 2034 | </testsuites> | 2111 | </testsuites> |
| @@ -2046,6 +2123,9 @@ Things to note: | |||
| 2046 | * The `timestamp` attribute records the local date and time of the test | 2123 | * The `timestamp` attribute records the local date and time of the test |
| 2047 | execution. | 2124 | execution. |
| 2048 | 2125 | ||
| 2126 | +* The `file` and `line` attributes record the source file location, where the | ||
| 2127 | + test was defined. | ||
| 2128 | + | ||
| 2049 | * Each `<failure>` element corresponds to a single failed googletest | 2129 | * Each `<failure>` element corresponds to a single failed googletest |
| 2050 | assertion. | 2130 | assertion. |
| 2051 | 2131 | ||
| @@ -2085,6 +2165,8 @@ The report format conforms to the following JSON Schema: | |||
| 2085 | "type": "object", | 2165 | "type": "object", |
| 2086 | "properties": { | 2166 | "properties": { |
| 2087 | "name": { "type": "string" }, | 2167 | "name": { "type": "string" }, |
| 2168 | + "file": { "type": "string" }, | ||
| 2169 | + "line": { "type": "integer" }, | ||
| 2088 | "status": { | 2170 | "status": { |
| 2089 | "type": "string", | 2171 | "type": "string", |
| 2090 | "enum": ["RUN", "NOTRUN"] | 2172 | "enum": ["RUN", "NOTRUN"] |
| @@ -2162,6 +2244,8 @@ message TestCase { | |||
| 2162 | 2244 | ||
| 2163 | message TestInfo { | 2245 | message TestInfo { |
| 2164 | string name = 1; | 2246 | string name = 1; |
| 2247 | + string file = 6; | ||
| 2248 | + int32 line = 7; | ||
| 2165 | enum Status { | 2249 | enum Status { |
| 2166 | RUN = 0; | 2250 | RUN = 0; |
| 2167 | NOTRUN = 1; | 2251 | NOTRUN = 1; |
| @@ -2205,6 +2289,8 @@ could generate this report: | |||
| 2205 | "testsuite": [ | 2289 | "testsuite": [ |
| 2206 | { | 2290 | { |
| 2207 | "name": "Addition", | 2291 | "name": "Addition", |
| 2292 | + "file": "test.cpp", | ||
| 2293 | + "line": 1, | ||
| 2208 | "status": "RUN", | 2294 | "status": "RUN", |
| 2209 | "time": "0.007s", | 2295 | "time": "0.007s", |
| 2210 | "classname": "", | 2296 | "classname": "", |
| @@ -2221,6 +2307,8 @@ could generate this report: | |||
| 2221 | }, | 2307 | }, |
| 2222 | { | 2308 | { |
| 2223 | "name": "Subtraction", | 2309 | "name": "Subtraction", |
| 2310 | + "file": "test.cpp", | ||
| 2311 | + "line": 2, | ||
| 2224 | "status": "RUN", | 2312 | "status": "RUN", |
| 2225 | "time": "0.005s", | 2313 | "time": "0.005s", |
| 2226 | "classname": "" | 2314 | "classname": "" |
| @@ -2236,6 +2324,8 @@ could generate this report: | |||
| 2236 | "testsuite": [ | 2324 | "testsuite": [ |
| 2237 | { | 2325 | { |
| 2238 | "name": "NonContradiction", | 2326 | "name": "NonContradiction", |
| 2327 | + "file": "test.cpp", | ||
| 2328 | + "line": 3, | ||
| 2239 | "status": "RUN", | 2329 | "status": "RUN", |
| 2240 | "time": "0.005s", | 2330 | "time": "0.005s", |
| 2241 | "classname": "" | 2331 | "classname": "" |
| @@ -2253,12 +2343,11 @@ IMPORTANT: The exact format of the JSON document is subject to change. | |||
| 2253 | 2343 | ||
| 2254 | #### Detecting Test Premature Exit | 2344 | #### Detecting Test Premature Exit |
| 2255 | 2345 | ||
| 2256 | -Google Test implements the _premature-exit-file_ protocol for test runners | 2346 | +Google Test implements the _premature-exit-file_ protocol for test runners to |
| 2257 | -to catch any kind of unexpected exits of test programs. Upon start, | 2347 | +catch any kind of unexpected exits of test programs. Upon start, Google Test |
| 2258 | -Google Test creates the file which will be automatically deleted after | 2348 | +creates the file which will be automatically deleted after all work has been |
| 2259 | -all work has been finished. Then, the test runner can check if this file | 2349 | +finished. Then, the test runner can check if this file exists. In case the file |
| 2260 | -exists. In case the file remains undeleted, the inspected test has exited | 2350 | +remains undeleted, the inspected test has exited prematurely. |
| 2261 | -prematurely. | ||
| 2262 | 2351 | ||
| 2263 | This feature is enabled only if the `TEST_PREMATURE_EXIT_FILE` environment | 2352 | This feature is enabled only if the `TEST_PREMATURE_EXIT_FILE` environment |
| 2264 | variable has been set. | 2353 | variable has been set. |
| @@ -1,9 +1,9 @@ | |||
| 1 | -# Googletest FAQ | 1 | +# GoogleTest FAQ |
| 2 | 2 | ||
| 3 | ## Why should test suite names and test names not contain underscore? | 3 | ## Why should test suite names and test names not contain underscore? |
| 4 | 4 | ||
| 5 | {: .callout .note} | 5 | {: .callout .note} |
| 6 | -Note: Googletest reserves underscore (`_`) for special purpose keywords, such as | 6 | +Note: GoogleTest reserves underscore (`_`) for special purpose keywords, such as |
| 7 | [the `DISABLED_` prefix](advanced.md#temporarily-disabling-tests), in addition | 7 | [the `DISABLED_` prefix](advanced.md#temporarily-disabling-tests), in addition |
| 8 | to the following rationale. | 8 | to the following rationale. |
| 9 | 9 | ||
| @@ -50,15 +50,15 @@ Now, the two `TEST`s will both generate the same class | |||
| 50 | 50 | ||
| 51 | So for simplicity, we just ask the users to avoid `_` in `TestSuiteName` and | 51 | So for simplicity, we just ask the users to avoid `_` in `TestSuiteName` and |
| 52 | `TestName`. The rule is more constraining than necessary, but it's simple and | 52 | `TestName`. The rule is more constraining than necessary, but it's simple and |
| 53 | -easy to remember. It also gives googletest some wiggle room in case its | 53 | +easy to remember. It also gives GoogleTest some wiggle room in case its |
| 54 | implementation needs to change in the future. | 54 | implementation needs to change in the future. |
| 55 | 55 | ||
| 56 | If you violate the rule, there may not be immediate consequences, but your test | 56 | If you violate the rule, there may not be immediate consequences, but your test |
| 57 | may (just may) break with a new compiler (or a new version of the compiler you | 57 | may (just may) break with a new compiler (or a new version of the compiler you |
| 58 | -are using) or with a new version of googletest. Therefore it's best to follow | 58 | +are using) or with a new version of GoogleTest. Therefore it's best to follow |
| 59 | the rule. | 59 | the rule. |
| 60 | 60 | ||
| 61 | -## Why does googletest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`? | 61 | +## Why does GoogleTest support `EXPECT_EQ(NULL, ptr)` and `ASSERT_EQ(NULL, ptr)` but not `EXPECT_NE(NULL, ptr)` and `ASSERT_NE(NULL, ptr)`? |
| 62 | 62 | ||
| 63 | First of all, you can use `nullptr` with each of these macros, e.g. | 63 | First of all, you can use `nullptr` with each of these macros, e.g. |
| 64 | `EXPECT_EQ(ptr, nullptr)`, `EXPECT_NE(ptr, nullptr)`, `ASSERT_EQ(ptr, nullptr)`, | 64 | `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. | |||
| 68 | Due to some peculiarity of C++, it requires some non-trivial template meta | 68 | Due to some peculiarity of C++, it requires some non-trivial template meta |
| 69 | programming tricks to support using `NULL` as an argument of the `EXPECT_XX()` | 69 | programming tricks to support using `NULL` as an argument of the `EXPECT_XX()` |
| 70 | and `ASSERT_XX()` macros. Therefore we only do it where it's most needed | 70 | and `ASSERT_XX()` macros. Therefore we only do it where it's most needed |
| 71 | -(otherwise we make the implementation of googletest harder to maintain and more | 71 | +(otherwise we make the implementation of GoogleTest harder to maintain and more |
| 72 | error-prone than necessary). | 72 | error-prone than necessary). |
| 73 | 73 | ||
| 74 | Historically, the `EXPECT_EQ()` macro took the *expected* value as its first | 74 | 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, | |||
| 162 | you may want to move your `EXPECT_CALL` statements inside the `EXPECT_DEATH` | 162 | you may want to move your `EXPECT_CALL` statements inside the `EXPECT_DEATH` |
| 163 | macro. | 163 | macro. |
| 164 | 164 | ||
| 165 | -## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a googletest bug? | 165 | +## EXPECT_EQ(htonl(blah), blah_blah) generates weird compiler errors in opt mode. Is this a GoogleTest bug? |
| 166 | 166 | ||
| 167 | Actually, the bug is in `htonl()`. | 167 | Actually, the bug is in `htonl()`. |
| 168 | 168 | ||
| @@ -199,7 +199,7 @@ const int Foo::kBar; // No initializer here. | |||
| 199 | ``` | 199 | ``` |
| 200 | 200 | ||
| 201 | Otherwise your code is **invalid C++**, and may break in unexpected ways. In | 201 | Otherwise your code is **invalid C++**, and may break in unexpected ways. In |
| 202 | -particular, using it in googletest comparison assertions (`EXPECT_EQ`, etc) will | 202 | +particular, using it in GoogleTest comparison assertions (`EXPECT_EQ`, etc) will |
| 203 | generate an "undefined reference" linker error. The fact that "it used to work" | 203 | generate an "undefined reference" linker error. The fact that "it used to work" |
| 204 | doesn't mean it's valid. It just means that you were lucky. :-) | 204 | doesn't mean it's valid. It just means that you were lucky. :-) |
| 205 | 205 | ||
| @@ -225,7 +225,7 @@ cases may want to use the same or slightly different fixtures. For example, you | |||
| 225 | may want to make sure that all of a GUI library's test suites don't leak | 225 | may want to make sure that all of a GUI library's test suites don't leak |
| 226 | important system resources like fonts and brushes. | 226 | important system resources like fonts and brushes. |
| 227 | 227 | ||
| 228 | -In googletest, you share a fixture among test suites by putting the shared logic | 228 | +In GoogleTest, you share a fixture among test suites by putting the shared logic |
| 229 | in a base test fixture, then deriving from that base a separate fixture for each | 229 | in a base test fixture, then deriving from that base a separate fixture for each |
| 230 | test suite that wants to use this common logic. You then use `TEST_F()` to write | 230 | test suite that wants to use this common logic. You then use `TEST_F()` to write |
| 231 | tests using each derived fixture. | 231 | tests using each derived fixture. |
| @@ -264,10 +264,10 @@ TEST_F(FooTest, Baz) { ... } | |||
| 264 | ``` | 264 | ``` |
| 265 | 265 | ||
| 266 | If necessary, you can continue to derive test fixtures from a derived fixture. | 266 | If necessary, you can continue to derive test fixtures from a derived fixture. |
| 267 | -googletest has no limit on how deep the hierarchy can be. | 267 | +GoogleTest has no limit on how deep the hierarchy can be. |
| 268 | 268 | ||
| 269 | For a complete example using derived test fixtures, see | 269 | For a complete example using derived test fixtures, see |
| 270 | -[sample5_unittest.cc](https://github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc). | 270 | +[sample5_unittest.cc](https://github.com/google/googletest/blob/main/googletest/samples/sample5_unittest.cc). |
| 271 | 271 | ||
| 272 | ## My compiler complains "void value not ignored as it ought to be." What does this mean? | 272 | ## My compiler complains "void value not ignored as it ought to be." What does this mean? |
| 273 | 273 | ||
| @@ -278,7 +278,7 @@ disabled by our build system. Please see more details | |||
| 278 | 278 | ||
| 279 | ## My death test hangs (or seg-faults). How do I fix it? | 279 | ## My death test hangs (or seg-faults). How do I fix it? |
| 280 | 280 | ||
| 281 | -In googletest, death tests are run in a child process and the way they work is | 281 | +In GoogleTest, death tests are run in a child process and the way they work is |
| 282 | delicate. To write death tests you really need to understand how they work—see | 282 | delicate. To write death tests you really need to understand how they work—see |
| 283 | the details at [Death Assertions](reference/assertions.md#death) in the | 283 | the details at [Death Assertions](reference/assertions.md#death) in the |
| 284 | Assertions Reference. | 284 | Assertions Reference. |
| @@ -305,8 +305,8 @@ bullet - sorry! | |||
| 305 | 305 | ||
| 306 | ## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? {#CtorVsSetUp} | 306 | ## Should I use the constructor/destructor of the test fixture or SetUp()/TearDown()? {#CtorVsSetUp} |
| 307 | 307 | ||
| 308 | -The first thing to remember is that googletest does **not** reuse the same test | 308 | +The first thing to remember is that GoogleTest does **not** reuse the same test |
| 309 | -fixture object across multiple tests. For each `TEST_F`, googletest will create | 309 | +fixture object across multiple tests. For each `TEST_F`, GoogleTest will create |
| 310 | a **fresh** test fixture object, immediately call `SetUp()`, run the test body, | 310 | a **fresh** test fixture object, immediately call `SetUp()`, run the test body, |
| 311 | call `TearDown()`, and then delete the test fixture object. | 311 | call `TearDown()`, and then delete the test fixture object. |
| 312 | 312 | ||
| @@ -328,7 +328,7 @@ You may still want to use `SetUp()/TearDown()` in the following cases: | |||
| 328 | 328 | ||
| 329 | * C++ does not allow virtual function calls in constructors and destructors. | 329 | * C++ does not allow virtual function calls in constructors and destructors. |
| 330 | You can call a method declared as virtual, but it will not use dynamic | 330 | You can call a method declared as virtual, but it will not use dynamic |
| 331 | - dispatch, it will use the definition from the class the constructor of which | 331 | + dispatch. It will use the definition from the class the constructor of which |
| 332 | is currently executing. This is because calling a virtual method before the | 332 | is currently executing. This is because calling a virtual method before the |
| 333 | derived class constructor has a chance to run is very dangerous - the | 333 | derived class constructor has a chance to run is very dangerous - the |
| 334 | virtual method might operate on uninitialized data. Therefore, if you need | 334 | 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: | |||
| 345 | that many standard libraries (like STL) may throw when exceptions are | 345 | that many standard libraries (like STL) may throw when exceptions are |
| 346 | enabled in the compiler. Therefore you should prefer `TearDown()` if you | 346 | enabled in the compiler. Therefore you should prefer `TearDown()` if you |
| 347 | want to write portable tests that work with or without exceptions. | 347 | want to write portable tests that work with or without exceptions. |
| 348 | -* The googletest team is considering making the assertion macros throw on | 348 | +* The GoogleTest team is considering making the assertion macros throw on |
| 349 | platforms where exceptions are enabled (e.g. Windows, Mac OS, and Linux | 349 | platforms where exceptions are enabled (e.g. Windows, Mac OS, and Linux |
| 350 | client-side), which will eliminate the need for the user to propagate | 350 | client-side), which will eliminate the need for the user to propagate |
| 351 | failures from a subroutine to its caller. Therefore, you shouldn't use | 351 | failures from a subroutine to its caller. Therefore, you shouldn't use |
| 352 | - googletest assertions in a destructor if your code could run on such a | 352 | + GoogleTest assertions in a destructor if your code could run on such a |
| 353 | platform. | 353 | platform. |
| 354 | 354 | ||
| 355 | ## The compiler complains "no matching function to call" when I use ASSERT_PRED*. How do I fix it? | 355 | ## The compiler complains "no matching function to call" when I use ASSERT_PRED*. How do I fix it? |
| @@ -375,7 +375,7 @@ they write | |||
| 375 | This is **wrong and dangerous**. The testing services needs to see the return | 375 | This is **wrong and dangerous**. The testing services needs to see the return |
| 376 | value of `RUN_ALL_TESTS()` in order to determine if a test has passed. If your | 376 | value of `RUN_ALL_TESTS()` in order to determine if a test has passed. If your |
| 377 | `main()` function ignores it, your test will be considered successful even if it | 377 | `main()` function ignores it, your test will be considered successful even if it |
| 378 | -has a googletest assertion failure. Very bad. | 378 | +has a GoogleTest assertion failure. Very bad. |
| 379 | 379 | ||
| 380 | We have decided to fix this (thanks to Michael Chastain for the idea). Now, your | 380 | We have decided to fix this (thanks to Michael Chastain for the idea). Now, your |
| 381 | code will no longer be able to ignore `RUN_ALL_TESTS()` when compiled with | 381 | 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()`? | |||
| 410 | Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and | 410 | Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and |
| 411 | wonder why it's never called. | 411 | wonder why it's never called. |
| 412 | 412 | ||
| 413 | - | ||
| 414 | ## 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. | 413 | ## 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. |
| 415 | 414 | ||
| 416 | You don't have to. Instead of | 415 | You don't have to. Instead of |
| @@ -441,14 +440,14 @@ TEST_F(BarTest, Abc) { ... } | |||
| 441 | TEST_F(BarTest, Def) { ... } | 440 | TEST_F(BarTest, Def) { ... } |
| 442 | ``` | 441 | ``` |
| 443 | 442 | ||
| 444 | -## googletest output is buried in a whole bunch of LOG messages. What do I do? | 443 | +## GoogleTest output is buried in a whole bunch of LOG messages. What do I do? |
| 445 | 444 | ||
| 446 | -The googletest output is meant to be a concise and human-friendly report. If | 445 | +The GoogleTest output is meant to be a concise and human-friendly report. If |
| 447 | -your test generates textual output itself, it will mix with the googletest | 446 | +your test generates textual output itself, it will mix with the GoogleTest |
| 448 | output, making it hard to read. However, there is an easy solution to this | 447 | output, making it hard to read. However, there is an easy solution to this |
| 449 | problem. | 448 | problem. |
| 450 | 449 | ||
| 451 | -Since `LOG` messages go to stderr, we decided to let googletest output go to | 450 | +Since `LOG` messages go to stderr, we decided to let GoogleTest output go to |
| 452 | stdout. This way, you can easily separate the two using redirection. For | 451 | stdout. This way, you can easily separate the two using redirection. For |
| 453 | example: | 452 | example: |
| 454 | 453 | ||
| @@ -521,7 +520,7 @@ TEST(MyDeathTest, CompoundStatement) { | |||
| 521 | 520 | ||
| 522 | ## I have a fixture class `FooTest`, but `TEST_F(FooTest, Bar)` gives me error ``"no matching function for call to `FooTest::FooTest()'"``. Why? | 521 | ## I have a fixture class `FooTest`, but `TEST_F(FooTest, Bar)` gives me error ``"no matching function for call to `FooTest::FooTest()'"``. Why? |
| 523 | 522 | ||
| 524 | -Googletest needs to be able to create objects of your test fixture class, so it | 523 | +GoogleTest needs to be able to create objects of your test fixture class, so it |
| 525 | must have a default constructor. Normally the compiler will define one for you. | 524 | must have a default constructor. Normally the compiler will define one for you. |
| 526 | However, there are cases where you have to define your own: | 525 | However, there are cases where you have to define your own: |
| 527 | 526 | ||
| @@ -546,11 +545,11 @@ The new NPTL thread library doesn't suffer from this problem, as it doesn't | |||
| 546 | create a manager thread. However, if you don't control which machine your test | 545 | create a manager thread. However, if you don't control which machine your test |
| 547 | runs on, you shouldn't depend on this. | 546 | runs on, you shouldn't depend on this. |
| 548 | 547 | ||
| 549 | -## Why does googletest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH? | 548 | +## Why does GoogleTest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH? |
| 550 | 549 | ||
| 551 | -googletest does not interleave tests from different test suites. That is, it | 550 | +GoogleTest does not interleave tests from different test suites. That is, it |
| 552 | runs all tests in one test suite first, and then runs all tests in the next test | 551 | runs all tests in one test suite first, and then runs all tests in the next test |
| 553 | -suite, and so on. googletest does this because it needs to set up a test suite | 552 | +suite, and so on. GoogleTest does this because it needs to set up a test suite |
| 554 | before the first test in it is run, and tear it down afterwards. Splitting up | 553 | before the first test in it is run, and tear it down afterwards. Splitting up |
| 555 | the test case would require multiple set-up and tear-down processes, which is | 554 | the test case would require multiple set-up and tear-down processes, which is |
| 556 | inefficient and makes the semantics unclean. | 555 | inefficient and makes the semantics unclean. |
| @@ -589,11 +588,11 @@ TEST_F(FooDeathTest, Uvw) { ... EXPECT_DEATH(...) ... } | |||
| 589 | TEST_F(FooDeathTest, Xyz) { ... ASSERT_DEATH(...) ... } | 588 | TEST_F(FooDeathTest, Xyz) { ... ASSERT_DEATH(...) ... } |
| 590 | ``` | 589 | ``` |
| 591 | 590 | ||
| 592 | -## 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? | 591 | +## 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? |
| 593 | 592 | ||
| 594 | Printing the LOG messages generated by the statement inside `EXPECT_DEATH()` | 593 | Printing the LOG messages generated by the statement inside `EXPECT_DEATH()` |
| 595 | makes it harder to search for real problems in the parent's log. Therefore, | 594 | makes it harder to search for real problems in the parent's log. Therefore, |
| 596 | -googletest only prints them when the death test has failed. | 595 | +GoogleTest only prints them when the death test has failed. |
| 597 | 596 | ||
| 598 | If you really need to see such LOG messages, a workaround is to temporarily | 597 | If you really need to see such LOG messages, a workaround is to temporarily |
| 599 | break the death test (e.g. by changing the regex pattern it is expected to | 598 | 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 | |||
| 612 | 611 | ||
| 613 | ## How do I suppress the memory leak messages on Windows? | 612 | ## How do I suppress the memory leak messages on Windows? |
| 614 | 613 | ||
| 615 | -Since the statically initialized googletest singleton requires allocations on | 614 | +Since the statically initialized GoogleTest singleton requires allocations on |
| 616 | the heap, the Visual C++ memory leak detector will report memory leaks at the | 615 | the heap, the Visual C++ memory leak detector will report memory leaks at the |
| 617 | end of the program run. The easiest way to avoid this is to use the | 616 | end of the program run. The easiest way to avoid this is to use the |
| 618 | `_CrtMemCheckpoint` and `_CrtMemDumpAllObjectsSince` calls to not report any | 617 | `_CrtMemCheckpoint` and `_CrtMemDumpAllObjectsSince` calls to not report any |
| @@ -626,7 +625,7 @@ things accordingly, you are leaking test-only logic into production code and | |||
| 626 | there is no easy way to ensure that the test-only code paths aren't run by | 625 | there is no easy way to ensure that the test-only code paths aren't run by |
| 627 | mistake in production. Such cleverness also leads to | 626 | mistake in production. Such cleverness also leads to |
| 628 | [Heisenbugs](https://en.wikipedia.org/wiki/Heisenbug). Therefore we strongly | 627 | [Heisenbugs](https://en.wikipedia.org/wiki/Heisenbug). Therefore we strongly |
| 629 | -advise against the practice, and googletest doesn't provide a way to do it. | 628 | +advise against the practice, and GoogleTest doesn't provide a way to do it. |
| 630 | 629 | ||
| 631 | In general, the recommended way to cause the code to behave differently under | 630 | In general, the recommended way to cause the code to behave differently under |
| 632 | test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject | 631 | test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject |
| @@ -673,7 +672,7 @@ TEST(CoolTest, DoSomething) { | |||
| 673 | ``` | 672 | ``` |
| 674 | 673 | ||
| 675 | However, the following code is **not allowed** and will produce a runtime error | 674 | However, the following code is **not allowed** and will produce a runtime error |
| 676 | -from googletest because the test methods are using different test fixture | 675 | +from GoogleTest because the test methods are using different test fixture |
| 677 | classes with the same test suite name. | 676 | classes with the same test suite name. |
| 678 | 677 | ||
| 679 | ```c++ | 678 | ```c++ |
| @@ -8,7 +8,7 @@ Given | |||
| 8 | 8 | ||
| 9 | ```cpp | 9 | ```cpp |
| 10 | class Foo { | 10 | class Foo { |
| 11 | - ... | 11 | + public: |
| 12 | virtual ~Foo(); | 12 | virtual ~Foo(); |
| 13 | virtual int GetSize() const = 0; | 13 | virtual int GetSize() const = 0; |
| 14 | virtual string Describe(const char* name) = 0; | 14 | virtual string Describe(const char* name) = 0; |
| @@ -23,7 +23,7 @@ class Foo { | |||
| 23 | #include "gmock/gmock.h" | 23 | #include "gmock/gmock.h" |
| 24 | 24 | ||
| 25 | class MockFoo : public Foo { | 25 | class MockFoo : public Foo { |
| 26 | - ... | 26 | + public: |
| 27 | MOCK_METHOD(int, GetSize, (), (const, override)); | 27 | MOCK_METHOD(int, GetSize, (), (const, override)); |
| 28 | MOCK_METHOD(string, Describe, (const char* name), (override)); | 28 | MOCK_METHOD(string, Describe, (const char* name), (override)); |
| 29 | MOCK_METHOD(string, Describe, (int type), (override)); | 29 | MOCK_METHOD(string, Describe, (int type), (override)); |
| @@ -58,7 +58,7 @@ To mock | |||
| 58 | ```cpp | 58 | ```cpp |
| 59 | template <typename Elem> | 59 | template <typename Elem> |
| 60 | class StackInterface { | 60 | class StackInterface { |
| 61 | - ... | 61 | + public: |
| 62 | virtual ~StackInterface(); | 62 | virtual ~StackInterface(); |
| 63 | virtual int GetSize() const = 0; | 63 | virtual int GetSize() const = 0; |
| 64 | virtual void Push(const Elem& x) = 0; | 64 | virtual void Push(const Elem& x) = 0; |
| @@ -71,7 +71,7 @@ class StackInterface { | |||
| 71 | ```cpp | 71 | ```cpp |
| 72 | template <typename Elem> | 72 | template <typename Elem> |
| 73 | class MockStack : public StackInterface<Elem> { | 73 | class MockStack : public StackInterface<Elem> { |
| 74 | - ... | 74 | + public: |
| 75 | MOCK_METHOD(int, GetSize, (), (const, override)); | 75 | MOCK_METHOD(int, GetSize, (), (const, override)); |
| 76 | MOCK_METHOD(void, Push, (const Elem& x), (override)); | 76 | MOCK_METHOD(void, Push, (const Elem& x), (override)); |
| 77 | }; | 77 | }; |
| @@ -140,7 +140,7 @@ To customize the default action for functions with return type `T`, use | |||
| 140 | // Sets the default action for return type std::unique_ptr<Buzz> to | 140 | // Sets the default action for return type std::unique_ptr<Buzz> to |
| 141 | // creating a new Buzz every time. | 141 | // creating a new Buzz every time. |
| 142 | DefaultValue<std::unique_ptr<Buzz>>::SetFactory( | 142 | DefaultValue<std::unique_ptr<Buzz>>::SetFactory( |
| 143 | - [] { return MakeUnique<Buzz>(AccessLevel::kInternal); }); | 143 | + [] { return std::make_unique<Buzz>(AccessLevel::kInternal); }); |
| 144 | 144 | ||
| 145 | // When this fires, the default action of MakeBuzz() will run, which | 145 | // When this fires, the default action of MakeBuzz() will run, which |
| 146 | // will return a new Buzz object. | 146 | // will return a new Buzz object. |
| @@ -230,7 +230,7 @@ class MockFunction<R(A1, ..., An)> { | |||
| 230 | }; | 230 | }; |
| 231 | ``` | 231 | ``` |
| 232 | 232 | ||
| 233 | -See this [recipe](gmock_cook_book.md#using-check-points) for one application of | 233 | +See this [recipe](gmock_cook_book.md#UsingCheckPoints) for one application of |
| 234 | it. | 234 | it. |
| 235 | 235 | ||
| 236 | ## Flags | 236 | ## Flags |
| @@ -392,8 +392,7 @@ Old macros and their new equivalents: | |||
| 392 | If a mock method has no `EXPECT_CALL` spec but is called, we say that it's an | 392 | If a mock method has no `EXPECT_CALL` spec but is called, we say that it's an |
| 393 | "uninteresting call", and the default action (which can be specified using | 393 | "uninteresting call", and the default action (which can be specified using |
| 394 | `ON_CALL()`) of the method will be taken. Currently, an uninteresting call will | 394 | `ON_CALL()`) of the method will be taken. Currently, an uninteresting call will |
| 395 | -also by default cause gMock to print a warning. (In the future, we might remove | 395 | +also by default cause gMock to print a warning. |
| 396 | -this warning by default.) | ||
| 397 | 396 | ||
| 398 | However, sometimes you may want to ignore these uninteresting calls, and | 397 | However, sometimes you may want to ignore these uninteresting calls, and |
| 399 | sometimes you may want to treat them as errors. gMock lets you make the decision | 398 | sometimes you may want to treat them as errors. gMock lets you make the decision |
| @@ -905,7 +904,7 @@ using ::testing::Contains; | |||
| 905 | using ::testing::Property; | 904 | using ::testing::Property; |
| 906 | 905 | ||
| 907 | inline constexpr auto HasFoo = [](const auto& f) { | 906 | inline constexpr auto HasFoo = [](const auto& f) { |
| 908 | - return Property(&MyClass::foo, Contains(f)); | 907 | + return Property("foo", &MyClass::foo, Contains(f)); |
| 909 | }; | 908 | }; |
| 910 | ... | 909 | ... |
| 911 | EXPECT_THAT(x, HasFoo("blah")); | 910 | EXPECT_THAT(x, HasFoo("blah")); |
| @@ -1084,7 +1083,7 @@ using ::testing::Lt; | |||
| 1084 | ``` | 1083 | ``` |
| 1085 | 1084 | ||
| 1086 | says that `Blah` will be called with arguments `x`, `y`, and `z` where `x < y < | 1085 | says that `Blah` will be called with arguments `x`, `y`, and `z` where `x < y < |
| 1087 | -z`. Note that in this example, it wasn't necessary specify the positional | 1086 | +z`. Note that in this example, it wasn't necessary to specify the positional |
| 1088 | matchers. | 1087 | matchers. |
| 1089 | 1088 | ||
| 1090 | As a convenience and example, gMock provides some matchers for 2-tuples, | 1089 | 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; } | |||
| 1159 | ``` | 1158 | ``` |
| 1160 | 1159 | ||
| 1161 | Note that the predicate function / functor doesn't have to return `bool`. It | 1160 | Note that the predicate function / functor doesn't have to return `bool`. It |
| 1162 | -works as long as the return value can be used as the condition in in statement | 1161 | +works as long as the return value can be used as the condition in the statement |
| 1163 | `if (condition) ...`. | 1162 | `if (condition) ...`. |
| 1164 | 1163 | ||
| 1165 | ### Matching Arguments that Are Not Copyable | 1164 | ### 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 | |||
| 1300 | `Pointee(Pointee(Lt(3)))` matches a pointer that points to a pointer that points | 1299 | `Pointee(Pointee(Lt(3)))` matches a pointer that points to a pointer that points |
| 1301 | to a number less than 3 (what a mouthful...). | 1300 | to a number less than 3 (what a mouthful...). |
| 1302 | 1301 | ||
| 1303 | -### Testing a Certain Property of an Object | 1302 | +### Defining a Custom Matcher Class {#CustomMatcherClass} |
| 1304 | 1303 | ||
| 1305 | -Sometimes you want to specify that an object argument has a certain property, | 1304 | +Most matchers can be simply defined using [the MATCHER* macros](#NewMatchers), |
| 1306 | -but there is no existing matcher that does this. If you want good error | 1305 | +which are terse and flexible, and produce good error messages. However, these |
| 1307 | -messages, you should [define a matcher](#NewMatchers). If you want to do it | 1306 | +macros are not very explicit about the interfaces they create and are not always |
| 1308 | -quick and dirty, you could get away with writing an ordinary function. | 1307 | +suitable, especially for matchers that will be widely reused. |
| 1309 | 1308 | ||
| 1310 | -Let's say you have a mock function that takes an object of type `Foo`, which has | 1309 | +For more advanced cases, you may need to define your own matcher class. A custom |
| 1311 | -an `int bar()` method and an `int baz()` method, and you want to constrain that | 1310 | +matcher allows you to test a specific invariant property of that object. Let's |
| 1312 | -the argument's `bar()` value plus its `baz()` value is a given number. Here's | 1311 | +take a look at how to do so. |
| 1313 | -how you can define a matcher to do it: | 1312 | + |
| 1313 | +Imagine you have a mock function that takes an object of type `Foo`, which has | ||
| 1314 | +an `int bar()` method and an `int baz()` method. You want to constrain that the | ||
| 1315 | +argument's `bar()` value plus its `baz()` value is a given number. (This is an | ||
| 1316 | +invariant.) Here's how we can write and use a matcher class to do so: | ||
| 1314 | 1317 | ||
| 1315 | ```cpp | 1318 | ```cpp |
| 1316 | -using ::testing::Matcher; | ||
| 1317 | - | ||
| 1318 | class BarPlusBazEqMatcher { | 1319 | class BarPlusBazEqMatcher { |
| 1319 | public: | 1320 | public: |
| 1321 | + using is_gtest_matcher = void; | ||
| 1322 | + | ||
| 1320 | explicit BarPlusBazEqMatcher(int expected_sum) | 1323 | explicit BarPlusBazEqMatcher(int expected_sum) |
| 1321 | : expected_sum_(expected_sum) {} | 1324 | : expected_sum_(expected_sum) {} |
| 1322 | 1325 | ||
| @@ -1325,23 +1328,24 @@ class BarPlusBazEqMatcher { | |||
| 1325 | return (foo.bar() + foo.baz()) == expected_sum_; | 1328 | return (foo.bar() + foo.baz()) == expected_sum_; |
| 1326 | } | 1329 | } |
| 1327 | 1330 | ||
| 1328 | - void DescribeTo(std::ostream& os) const { | 1331 | + void DescribeTo(std::ostream* os) const { |
| 1329 | - os << "bar() + baz() equals " << expected_sum_; | 1332 | + *os << "bar() + baz() equals " << expected_sum_; |
| 1330 | } | 1333 | } |
| 1331 | 1334 | ||
| 1332 | - void DescribeNegationTo(std::ostream& os) const { | 1335 | + void DescribeNegationTo(std::ostream* os) const { |
| 1333 | - os << "bar() + baz() does not equal " << expected_sum_; | 1336 | + *os << "bar() + baz() does not equal " << expected_sum_; |
| 1334 | } | 1337 | } |
| 1335 | private: | 1338 | private: |
| 1336 | const int expected_sum_; | 1339 | const int expected_sum_; |
| 1337 | }; | 1340 | }; |
| 1338 | 1341 | ||
| 1339 | -Matcher<const Foo&> BarPlusBazEq(int expected_sum) { | 1342 | +::testing::Matcher<const Foo&> BarPlusBazEq(int expected_sum) { |
| 1340 | return BarPlusBazEqMatcher(expected_sum); | 1343 | return BarPlusBazEqMatcher(expected_sum); |
| 1341 | } | 1344 | } |
| 1342 | 1345 | ||
| 1343 | ... | 1346 | ... |
| 1344 | - EXPECT_CALL(..., DoThis(BarPlusBazEq(5)))...; | 1347 | + Foo foo; |
| 1348 | + EXPECT_THAT(foo, BarPlusBazEq(5))...; | ||
| 1345 | ``` | 1349 | ``` |
| 1346 | 1350 | ||
| 1347 | ### Matching Containers | 1351 | ### Matching Containers |
| @@ -1420,11 +1424,12 @@ Use `Pair` when comparing maps or other associative containers. | |||
| 1420 | {% raw %} | 1424 | {% raw %} |
| 1421 | 1425 | ||
| 1422 | ```cpp | 1426 | ```cpp |
| 1423 | -using testing::ElementsAre; | 1427 | +using ::testing::UnorderedElementsAre; |
| 1424 | -using testing::Pair; | 1428 | +using ::testing::Pair; |
| 1425 | ... | 1429 | ... |
| 1426 | - std::map<string, int> m = {{"a", 1}, {"b", 2}, {"c", 3}}; | 1430 | + absl::flat_hash_map<string, int> m = {{"a", 1}, {"b", 2}, {"c", 3}}; |
| 1427 | - EXPECT_THAT(m, ElementsAre(Pair("a", 1), Pair("b", 2), Pair("c", 3))); | 1431 | + EXPECT_THAT(m, UnorderedElementsAre( |
| 1432 | + Pair("a", 1), Pair("b", 2), Pair("c", 3))); | ||
| 1428 | ``` | 1433 | ``` |
| 1429 | 1434 | ||
| 1430 | {% endraw %} | 1435 | {% endraw %} |
| @@ -1441,8 +1446,8 @@ using testing::Pair; | |||
| 1441 | * If the container is passed by pointer instead of by reference, just write | 1446 | * If the container is passed by pointer instead of by reference, just write |
| 1442 | `Pointee(ElementsAre*(...))`. | 1447 | `Pointee(ElementsAre*(...))`. |
| 1443 | * The order of elements *matters* for `ElementsAre*()`. If you are using it | 1448 | * The order of elements *matters* for `ElementsAre*()`. If you are using it |
| 1444 | - with containers whose element order are undefined (e.g. `hash_map`) you | 1449 | + with containers whose element order are undefined (such as a |
| 1445 | - should use `WhenSorted` around `ElementsAre`. | 1450 | + `std::unordered_map`) you should use `UnorderedElementsAre`. |
| 1446 | 1451 | ||
| 1447 | ### Sharing Matchers | 1452 | ### Sharing Matchers |
| 1448 | 1453 | ||
| @@ -1452,7 +1457,7 @@ the pointer is copied. When the last matcher that references the implementation | |||
| 1452 | object dies, the implementation object will be deleted. | 1457 | object dies, the implementation object will be deleted. |
| 1453 | 1458 | ||
| 1454 | Therefore, if you have some complex matcher that you want to use again and | 1459 | Therefore, if you have some complex matcher that you want to use again and |
| 1455 | -again, there is no need to build it everytime. Just assign it to a matcher | 1460 | +again, there is no need to build it every time. Just assign it to a matcher |
| 1456 | variable and use that variable repeatedly! For example, | 1461 | variable and use that variable repeatedly! For example, |
| 1457 | 1462 | ||
| 1458 | ```cpp | 1463 | ```cpp |
| @@ -1754,7 +1759,7 @@ specifies the following DAG (where `s1` is `A -> B`, and `s2` is `A -> C -> D`): | |||
| 1754 | | | 1759 | | |
| 1755 | A ---| | 1760 | A ---| |
| 1756 | | | 1761 | | |
| 1757 | - +---> C ---> D | 1762 | + +---> C ---> D |
| 1758 | ``` | 1763 | ``` |
| 1759 | 1764 | ||
| 1760 | This means that A must occur before B and C, and C must occur before D. There's | 1765 | 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; | |||
| 1899 | ### Combining Actions | 1904 | ### Combining Actions |
| 1900 | 1905 | ||
| 1901 | Want to do more than one thing when a function is called? That's fine. `DoAll()` | 1906 | Want to do more than one thing when a function is called? That's fine. `DoAll()` |
| 1902 | -allow you to do sequence of actions every time. Only the return value of the | 1907 | +allows you to do a sequence of actions every time. Only the return value of the |
| 1903 | last action in the sequence will be used. | 1908 | last action in the sequence will be used. |
| 1904 | 1909 | ||
| 1905 | ```cpp | 1910 | ```cpp |
| @@ -1980,6 +1985,7 @@ If the mock method also needs to return a value as well, you can chain | |||
| 1980 | 1985 | ||
| 1981 | ```cpp | 1986 | ```cpp |
| 1982 | using ::testing::_; | 1987 | using ::testing::_; |
| 1988 | +using ::testing::DoAll; | ||
| 1983 | using ::testing::Return; | 1989 | using ::testing::Return; |
| 1984 | using ::testing::SetArgPointee; | 1990 | using ::testing::SetArgPointee; |
| 1985 | 1991 | ||
| @@ -2033,10 +2039,7 @@ class MockRolodex : public Rolodex { | |||
| 2033 | } | 2039 | } |
| 2034 | ... | 2040 | ... |
| 2035 | MockRolodex rolodex; | 2041 | MockRolodex rolodex; |
| 2036 | - vector<string> names; | 2042 | + vector<string> names = {"George", "John", "Thomas"}; |
| 2037 | - names.push_back("George"); | ||
| 2038 | - names.push_back("John"); | ||
| 2039 | - names.push_back("Thomas"); | ||
| 2040 | EXPECT_CALL(rolodex, GetNames(_)) | 2043 | EXPECT_CALL(rolodex, GetNames(_)) |
| 2041 | .WillOnce(SetArrayArgument<0>(names.begin(), names.end())); | 2044 | .WillOnce(SetArrayArgument<0>(names.begin(), names.end())); |
| 2042 | ``` | 2045 | ``` |
| @@ -2604,7 +2607,7 @@ efficient. When the last action that references the implementation object dies, | |||
| 2604 | the implementation object will be deleted. | 2607 | the implementation object will be deleted. |
| 2605 | 2608 | ||
| 2606 | If you have some complex action that you want to use again and again, you may | 2609 | If you have some complex action that you want to use again and again, you may |
| 2607 | -not have to build it from scratch everytime. If the action doesn't have an | 2610 | +not have to build it from scratch every time. If the action doesn't have an |
| 2608 | internal state (i.e. if it always does the same thing no matter how many times | 2611 | internal state (i.e. if it always does the same thing no matter how many times |
| 2609 | it has been called), you can assign it to an action variable and use that | 2612 | it has been called), you can assign it to an action variable and use that |
| 2610 | variable repeatedly. For example: | 2613 | variable repeatedly. For example: |
| @@ -2781,7 +2784,7 @@ If you just need to return a pre-defined move-only value, you can use the | |||
| 2781 | // When this fires, the unique_ptr<> specified by ByMove(...) will | 2784 | // When this fires, the unique_ptr<> specified by ByMove(...) will |
| 2782 | // be returned. | 2785 | // be returned. |
| 2783 | EXPECT_CALL(mock_buzzer_, MakeBuzz("world")) | 2786 | EXPECT_CALL(mock_buzzer_, MakeBuzz("world")) |
| 2784 | - .WillOnce(Return(ByMove(MakeUnique<Buzz>(AccessLevel::kInternal)))); | 2787 | + .WillOnce(Return(ByMove(std::make_unique<Buzz>(AccessLevel::kInternal)))); |
| 2785 | 2788 | ||
| 2786 | EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("world")); | 2789 | EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("world")); |
| 2787 | ``` | 2790 | ``` |
| @@ -2802,7 +2805,7 @@ pretty much anything you want: | |||
| 2802 | ```cpp | 2805 | ```cpp |
| 2803 | EXPECT_CALL(mock_buzzer_, MakeBuzz("x")) | 2806 | EXPECT_CALL(mock_buzzer_, MakeBuzz("x")) |
| 2804 | .WillRepeatedly([](StringPiece text) { | 2807 | .WillRepeatedly([](StringPiece text) { |
| 2805 | - return MakeUnique<Buzz>(AccessLevel::kInternal); | 2808 | + return std::make_unique<Buzz>(AccessLevel::kInternal); |
| 2806 | }); | 2809 | }); |
| 2807 | 2810 | ||
| 2808 | EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x")); | 2811 | EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x")); |
| @@ -2821,7 +2824,7 @@ can always use `Return`, or a [lambda or functor](#FunctionsAsActions): | |||
| 2821 | using ::testing::Unused; | 2824 | using ::testing::Unused; |
| 2822 | 2825 | ||
| 2823 | EXPECT_CALL(mock_buzzer_, ShareBuzz(NotNull(), _)).WillOnce(Return(true)); | 2826 | EXPECT_CALL(mock_buzzer_, ShareBuzz(NotNull(), _)).WillOnce(Return(true)); |
| 2824 | - EXPECT_TRUE(mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal)), | 2827 | + EXPECT_TRUE(mock_buzzer_.ShareBuzz(std::make_unique<Buzz>(AccessLevel::kInternal)), |
| 2825 | 0); | 2828 | 0); |
| 2826 | 2829 | ||
| 2827 | EXPECT_CALL(mock_buzzer_, ShareBuzz(_, _)).WillOnce( | 2830 | EXPECT_CALL(mock_buzzer_, ShareBuzz(_, _)).WillOnce( |
| @@ -2865,7 +2868,7 @@ method: | |||
| 2865 | // When one calls ShareBuzz() on the MockBuzzer like this, the call is | 2868 | // When one calls ShareBuzz() on the MockBuzzer like this, the call is |
| 2866 | // forwarded to DoShareBuzz(), which is mocked. Therefore this statement | 2869 | // forwarded to DoShareBuzz(), which is mocked. Therefore this statement |
| 2867 | // will trigger the above EXPECT_CALL. | 2870 | // will trigger the above EXPECT_CALL. |
| 2868 | - mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal), 0); | 2871 | + mock_buzzer_.ShareBuzz(std::make_unique<Buzz>(AccessLevel::kInternal), 0); |
| 2869 | ``` | 2872 | ``` |
| 2870 | 2873 | ||
| 2871 | ### Making the Compilation Faster | 2874 | ### Making the Compilation Faster |
| @@ -3809,22 +3812,19 @@ Cardinality EvenNumber() { | |||
| 3809 | .Times(EvenNumber()); | 3812 | .Times(EvenNumber()); |
| 3810 | ``` | 3813 | ``` |
| 3811 | 3814 | ||
| 3812 | -### Writing New Actions Quickly {#QuickNewActions} | 3815 | +### Writing New Actions {#QuickNewActions} |
| 3813 | 3816 | ||
| 3814 | If the built-in actions don't work for you, you can easily define your own one. | 3817 | If the built-in actions don't work for you, you can easily define your own one. |
| 3815 | -Just define a functor class with a (possibly templated) call operator, matching | 3818 | +All you need is a call operator with a signature compatible with the mocked |
| 3816 | -the signature of your action. | 3819 | +function. So you can use a lambda: |
| 3817 | 3820 | ||
| 3818 | -```cpp | 3821 | +``` |
| 3819 | -struct Increment { | 3822 | +MockFunction<int(int)> mock; |
| 3820 | - template <typename T> | 3823 | +EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; }); |
| 3821 | - T operator()(T* arg) { | 3824 | +EXPECT_EQ(14, mock.AsStdFunction()(2)); |
| 3822 | - return ++(*arg); | ||
| 3823 | - } | ||
| 3824 | -} | ||
| 3825 | ``` | 3825 | ``` |
| 3826 | 3826 | ||
| 3827 | -The same approach works with stateful functors (or any callable, really): | 3827 | +Or a struct with a call operator (even a templated one): |
| 3828 | 3828 | ||
| 3829 | ``` | 3829 | ``` |
| 3830 | struct MultiplyBy { | 3830 | struct MultiplyBy { |
| @@ -3832,12 +3832,54 @@ struct MultiplyBy { | |||
| 3832 | T operator()(T arg) { return arg * multiplier; } | 3832 | T operator()(T arg) { return arg * multiplier; } |
| 3833 | 3833 | ||
| 3834 | int multiplier; | 3834 | int multiplier; |
| 3835 | -} | 3835 | +}; |
| 3836 | 3836 | ||
| 3837 | // Then use: | 3837 | // Then use: |
| 3838 | // EXPECT_CALL(...).WillOnce(MultiplyBy{7}); | 3838 | // EXPECT_CALL(...).WillOnce(MultiplyBy{7}); |
| 3839 | ``` | 3839 | ``` |
| 3840 | 3840 | ||
| 3841 | +It's also fine for the callable to take no arguments, ignoring the arguments | ||
| 3842 | +supplied to the mock function: | ||
| 3843 | + | ||
| 3844 | +``` | ||
| 3845 | +MockFunction<int(int)> mock; | ||
| 3846 | +EXPECT_CALL(mock, Call).WillOnce([] { return 17; }); | ||
| 3847 | +EXPECT_EQ(17, mock.AsStdFunction()(0)); | ||
| 3848 | +``` | ||
| 3849 | + | ||
| 3850 | +When used with `WillOnce`, the callable can assume it will be called at most | ||
| 3851 | +once and is allowed to be a move-only type: | ||
| 3852 | + | ||
| 3853 | +``` | ||
| 3854 | +// An action that contains move-only types and has an &&-qualified operator, | ||
| 3855 | +// demanding in the type system that it be called at most once. This can be | ||
| 3856 | +// used with WillOnce, but the compiler will reject it if handed to | ||
| 3857 | +// WillRepeatedly. | ||
| 3858 | +struct MoveOnlyAction { | ||
| 3859 | + std::unique_ptr<int> move_only_state; | ||
| 3860 | + std::unique_ptr<int> operator()() && { return std::move(move_only_state); } | ||
| 3861 | +}; | ||
| 3862 | + | ||
| 3863 | +MockFunction<std::unique_ptr<int>()> mock; | ||
| 3864 | +EXPECT_CALL(mock, Call).WillOnce(MoveOnlyAction{std::make_unique<int>(17)}); | ||
| 3865 | +EXPECT_THAT(mock.AsStdFunction()(), Pointee(Eq(17))); | ||
| 3866 | +``` | ||
| 3867 | + | ||
| 3868 | +More generally, to use with a mock function whose signature is `R(Args...)` the | ||
| 3869 | +object can be anything convertible to `OnceAction<R(Args...)>` or | ||
| 3870 | +`Action<R(Args...)`>. The difference between the two is that `OnceAction` has | ||
| 3871 | +weaker requirements (`Action` requires a copy-constructible input that can be | ||
| 3872 | +called repeatedly whereas `OnceAction` requires only move-constructible and | ||
| 3873 | +supports `&&`-qualified call operators), but can be used only with `WillOnce`. | ||
| 3874 | +`OnceAction` is typically relevant only when supporting move-only types or | ||
| 3875 | +actions that want a type-system guarantee that they will be called at most once. | ||
| 3876 | + | ||
| 3877 | +Typically the `OnceAction` and `Action` templates need not be referenced | ||
| 3878 | +directly in your actions: a struct or class with a call operator is sufficient, | ||
| 3879 | +as in the examples above. But fancier polymorphic actions that need to know the | ||
| 3880 | +specific return type of the mock function can define templated conversion | ||
| 3881 | +operators to make that possible. See `gmock-actions.h` for examples. | ||
| 3882 | + | ||
| 3841 | #### Legacy macro-based Actions | 3883 | #### Legacy macro-based Actions |
| 3842 | 3884 | ||
| 3843 | Before C++11, the functor-based actions were not supported; the old way of | 3885 | 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. | |||
| 4191 | What matters is that it must have a `Perform()` method template. This method | 4233 | What matters is that it must have a `Perform()` method template. This method |
| 4192 | template takes the mock function's arguments as a tuple in a **single** | 4234 | template takes the mock function's arguments as a tuple in a **single** |
| 4193 | argument, and returns the result of the action. It can be either `const` or not, | 4235 | argument, and returns the result of the action. It can be either `const` or not, |
| 4194 | -but must be invokable with exactly one template argument, which is the result | 4236 | +but must be invocable with exactly one template argument, which is the result |
| 4195 | type. In other words, you must be able to call `Perform<R>(args)` where `R` is | 4237 | type. In other words, you must be able to call `Perform<R>(args)` where `R` is |
| 4196 | the mock function's return type and `args` is its arguments in a tuple. | 4238 | the mock function's return type and `args` is its arguments in a tuple. |
| 4197 | 4239 | ||
| @@ -369,8 +369,8 @@ Usually, if your action is for a particular function type, defining it using | |||
| 369 | different types (e.g. if you are defining `Return(*value*)`), | 369 | different types (e.g. if you are defining `Return(*value*)`), |
| 370 | `MakePolymorphicAction()` is easiest. Sometimes you want precise control on what | 370 | `MakePolymorphicAction()` is easiest. Sometimes you want precise control on what |
| 371 | types of functions the action can be used in, and implementing `ActionInterface` | 371 | types of functions the action can be used in, and implementing `ActionInterface` |
| 372 | -is the way to go here. See the implementation of `Return()` in | 372 | +is the way to go here. See the implementation of `Return()` in `gmock-actions.h` |
| 373 | -`testing/base/public/gmock-actions.h` for an example. | 373 | +for an example. |
| 374 | 374 | ||
| 375 | ### I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting return type specified". What does it mean? | 375 | ### I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting return type specified". What does it mean? |
| 376 | 376 | ||
| @@ -190,10 +190,10 @@ Some people put it in a `_test.cc`. This is fine when the interface being mocked | |||
| 190 | `Foo` changes it, your test could break. (You can't really expect `Foo`'s | 190 | `Foo` changes it, your test could break. (You can't really expect `Foo`'s |
| 191 | maintainer to fix every test that uses `Foo`, can you?) | 191 | maintainer to fix every test that uses `Foo`, can you?) |
| 192 | 192 | ||
| 193 | -So, the rule of thumb is: if you need to mock `Foo` and it's owned by others, | 193 | +Generally, you should not mock classes you don't own. If you must mock such a |
| 194 | -define the mock class in `Foo`'s package (better, in a `testing` sub-package | 194 | +class owned by others, define the mock class in `Foo`'s Bazel package (usually |
| 195 | -such that you can clearly separate production code and testing utilities), put | 195 | +the same directory or a `testing` sub-directory), and put it in a `.h` and a |
| 196 | -it in a `.h` and a `cc_library`. Then everyone can reference them from their | 196 | +`cc_library` with `testonly=True`. Then everyone can reference them from their |
| 197 | tests. If `Foo` ever changes, there is only one copy of `MockFoo` to change, and | 197 | tests. If `Foo` ever changes, there is only one copy of `MockFoo` to change, and |
| 198 | only tests that depend on the changed methods need to be fixed. | 198 | only tests that depend on the changed methods need to be fixed. |
| 199 | 199 | ||
| @@ -480,8 +480,8 @@ the *default* action for the function every time (unless, of course, you have a | |||
| 480 | `WillRepeatedly()`.). | 480 | `WillRepeatedly()`.). |
| 481 | 481 | ||
| 482 | What can we do inside `WillOnce()` besides `Return()`? You can return a | 482 | What can we do inside `WillOnce()` besides `Return()`? You can return a |
| 483 | -reference using `ReturnRef(*variable*)`, or invoke a pre-defined function, among | 483 | +reference using `ReturnRef(`*`variable`*`)`, or invoke a pre-defined function, |
| 484 | -[others](gmock_cook_book.md#using-actions). | 484 | +among [others](gmock_cook_book.md#using-actions). |
| 485 | 485 | ||
| 486 | **Important note:** The `EXPECT_CALL()` statement evaluates the action clause | 486 | **Important note:** The `EXPECT_CALL()` statement evaluates the action clause |
| 487 | only once, even though the action may be performed many times. Therefore you | 487 | only once, even though the action may be performed many times. Therefore you |
| @@ -105,7 +105,7 @@ includedir=/usr/include | |||
| 105 | 105 | ||
| 106 | Name: gtest | 106 | Name: gtest |
| 107 | Description: GoogleTest (without main() function) | 107 | Description: GoogleTest (without main() function) |
| 108 | -Version: 1.10.0 | 108 | +Version: 1.11.0 |
| 109 | URL: https://github.com/google/googletest | 109 | URL: https://github.com/google/googletest |
| 110 | Libs: -L${libdir} -lgtest -lpthread | 110 | Libs: -L${libdir} -lgtest -lpthread |
| 111 | Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread | 111 | Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread |
| @@ -162,9 +162,9 @@ TEST(TestSuiteName, TestName) { | |||
| 162 | 162 | ||
| 163 | `TEST()` arguments go from general to specific. The *first* argument is the name | 163 | `TEST()` arguments go from general to specific. The *first* argument is the name |
| 164 | of the test suite, and the *second* argument is the test's name within the test | 164 | of the test suite, and the *second* argument is the test's name within the test |
| 165 | -suite. Both names must be valid C++ identifiers, and they should not contain | 165 | +suite. Both names must be valid C++ identifiers, and they should not contain any |
| 166 | -any underscores (`_`). A test's *full name* consists of its containing test suite and | 166 | +underscores (`_`). A test's *full name* consists of its containing test suite |
| 167 | -its individual name. Tests from different test suites can have the same | 167 | +and its individual name. Tests from different test suites can have the same |
| 168 | individual name. | 168 | individual name. |
| 169 | 169 | ||
| 170 | For example, let's take a simple integer function: | 170 | 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 | |||
| 245 | declaration`". | 245 | declaration`". |
| 246 | 246 | ||
| 247 | For each test defined with `TEST_F()`, googletest will create a *fresh* test | 247 | For each test defined with `TEST_F()`, googletest will create a *fresh* test |
| 248 | -fixture at runtime, immediately initialize it via `SetUp()`, run the test, | 248 | +fixture at runtime, immediately initialize it via `SetUp()`, run the test, clean |
| 249 | -clean up by calling `TearDown()`, and then delete the test fixture. Note that | 249 | +up by calling `TearDown()`, and then delete the test fixture. Note that |
| 250 | different tests in the same test suite have different test fixture objects, and | 250 | different tests in the same test suite have different test fixture objects, and |
| 251 | googletest always deletes a test fixture before it creates the next one. | 251 | googletest always deletes a test fixture before it creates the next one. |
| 252 | googletest does **not** reuse the same test fixture for multiple tests. Any | 252 | 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 | |||
| 274 | class QueueTest : public ::testing::Test { | 274 | class QueueTest : public ::testing::Test { |
| 275 | protected: | 275 | protected: |
| 276 | void SetUp() override { | 276 | void SetUp() override { |
| 277 | + // q0_ remains empty | ||
| 277 | q1_.Enqueue(1); | 278 | q1_.Enqueue(1); |
| 278 | q2_.Enqueue(2); | 279 | q2_.Enqueue(2); |
| 279 | q2_.Enqueue(3); | 280 | q2_.Enqueue(3); |
| @@ -342,8 +343,8 @@ your defined tests in order to run them. | |||
| 342 | 343 | ||
| 343 | After defining your tests, you can run them with `RUN_ALL_TESTS()`, which | 344 | After defining your tests, you can run them with `RUN_ALL_TESTS()`, which |
| 344 | returns `0` if all the tests are successful, or `1` otherwise. Note that | 345 | returns `0` if all the tests are successful, or `1` otherwise. Note that |
| 345 | -`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from | 346 | +`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from different |
| 346 | -different test suites, or even different source files. | 347 | +test suites, or even different source files. |
| 347 | 348 | ||
| 348 | When invoked, the `RUN_ALL_TESTS()` macro: | 349 | When invoked, the `RUN_ALL_TESTS()` macro: |
| 349 | 350 | ||
| @@ -456,8 +457,8 @@ int main(int argc, char **argv) { | |||
| 456 | 457 | ||
| 457 | The `::testing::InitGoogleTest()` function parses the command line for | 458 | The `::testing::InitGoogleTest()` function parses the command line for |
| 458 | googletest flags, and removes all recognized flags. This allows the user to | 459 | googletest flags, and removes all recognized flags. This allows the user to |
| 459 | -control a test program's behavior via various flags, which we'll cover in | 460 | +control a test program's behavior via various flags, which we'll cover in the |
| 460 | -the [AdvancedGuide](advanced.md). You **must** call this function before calling | 461 | +[AdvancedGuide](advanced.md). You **must** call this function before calling |
| 461 | `RUN_ALL_TESTS()`, or the flags won't be properly initialized. | 462 | `RUN_ALL_TESTS()`, or the flags won't be properly initialized. |
| 462 | 463 | ||
| 463 | On Windows, `InitGoogleTest()` also works with wide strings, so it can be used | 464 | 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. | |||
| 9 | To complete this tutorial, you'll need: | 9 | To complete this tutorial, you'll need: |
| 10 | 10 | ||
| 11 | * A compatible operating system (e.g. Linux, macOS, Windows). | 11 | * A compatible operating system (e.g. Linux, macOS, Windows). |
| 12 | -* A compatible C++ compiler that supports at least C++11. | 12 | +* A compatible C++ compiler that supports at least C++14. |
| 13 | * [Bazel](https://bazel.build/), the preferred build system used by the | 13 | * [Bazel](https://bazel.build/), the preferred build system used by the |
| 14 | GoogleTest team. | 14 | GoogleTest team. |
| 15 | 15 | ||
| @@ -17,16 +17,15 @@ See [Supported Platforms](platforms.md) for more information about platforms | |||
| 17 | compatible with GoogleTest. | 17 | compatible with GoogleTest. |
| 18 | 18 | ||
| 19 | If you don't already have Bazel installed, see the | 19 | If you don't already have Bazel installed, see the |
| 20 | -[Bazel installation guide](https://docs.bazel.build/versions/master/install.html). | 20 | +[Bazel installation guide](https://bazel.build/install). |
| 21 | 21 | ||
| 22 | -{: .callout .note} | 22 | +{: .callout .note} Note: The terminal commands in this tutorial show a Unix |
| 23 | -Note: The terminal commands in this tutorial show a Unix shell prompt, but the | 23 | +shell prompt, but the commands work on the Windows command line as well. |
| 24 | -commands work on the Windows command line as well. | ||
| 25 | 24 | ||
| 26 | ## Set up a Bazel workspace | 25 | ## Set up a Bazel workspace |
| 27 | 26 | ||
| 28 | A | 27 | A |
| 29 | -[Bazel workspace](https://docs.bazel.build/versions/master/build-ref.html#workspace) | 28 | +[Bazel workspace](https://docs.bazel.build/versions/main/build-ref.html#workspace) |
| 30 | is a directory on your filesystem that you use to manage source files for the | 29 | is a directory on your filesystem that you use to manage source files for the |
| 31 | software you want to build. Each workspace directory has a text file named | 30 | software you want to build. Each workspace directory has a text file named |
| 32 | `WORKSPACE` which may be empty, or may contain references to external | 31 | `WORKSPACE` which may be empty, or may contain references to external |
| @@ -40,9 +39,9 @@ $ mkdir my_workspace && cd my_workspace | |||
| 40 | 39 | ||
| 41 | Next, you’ll create the `WORKSPACE` file to specify dependencies. A common and | 40 | Next, you’ll create the `WORKSPACE` file to specify dependencies. A common and |
| 42 | recommended way to depend on GoogleTest is to use a | 41 | recommended way to depend on GoogleTest is to use a |
| 43 | -[Bazel external dependency](https://docs.bazel.build/versions/master/external.html) | 42 | +[Bazel external dependency](https://docs.bazel.build/versions/main/external.html) |
| 44 | via the | 43 | via the |
| 45 | -[`http_archive` rule](https://docs.bazel.build/versions/master/repo/http.html#http_archive). | 44 | +[`http_archive` rule](https://docs.bazel.build/versions/main/repo/http.html#http_archive). |
| 46 | To do this, in the root directory of your workspace (`my_workspace/`), create a | 45 | To do this, in the root directory of your workspace (`my_workspace/`), create a |
| 47 | file named `WORKSPACE` with the following contents: | 46 | file named `WORKSPACE` with the following contents: |
| 48 | 47 | ||
| @@ -51,28 +50,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | |||
| 51 | 50 | ||
| 52 | http_archive( | 51 | http_archive( |
| 53 | name = "com_google_googletest", | 52 | name = "com_google_googletest", |
| 54 | - urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"], | 53 | + urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"], |
| 55 | - strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5", | 54 | + strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015", |
| 56 | ) | 55 | ) |
| 57 | ``` | 56 | ``` |
| 58 | 57 | ||
| 59 | The above configuration declares a dependency on GoogleTest which is downloaded | 58 | The above configuration declares a dependency on GoogleTest which is downloaded |
| 60 | as a ZIP archive from GitHub. In the above example, | 59 | as a ZIP archive from GitHub. In the above example, |
| 61 | -`609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is the Git commit hash of the | 60 | +`5ab508a01f9eb089207ee87fd547d290da39d015` is the Git commit hash of the |
| 62 | GoogleTest version to use; we recommend updating the hash often to point to the | 61 | GoogleTest version to use; we recommend updating the hash often to point to the |
| 63 | -latest version. | 62 | +latest version. Use a recent hash on the `main` branch. |
| 64 | - | ||
| 65 | -Bazel also needs a dependency on the | ||
| 66 | -[`rules_cc` repository](https://github.com/bazelbuild/rules_cc) to build C++ | ||
| 67 | -code, so add the following to the `WORKSPACE` file: | ||
| 68 | - | ||
| 69 | -``` | ||
| 70 | -http_archive( | ||
| 71 | - name = "rules_cc", | ||
| 72 | - urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"], | ||
| 73 | - strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556", | ||
| 74 | -) | ||
| 75 | -``` | ||
| 76 | 63 | ||
| 77 | Now you're ready to build C++ code that uses GoogleTest. | 64 | Now you're ready to build C++ code that uses GoogleTest. |
| 78 | 65 | ||
| @@ -104,8 +91,6 @@ To build the code, create a file named `BUILD` in the same directory with the | |||
| 104 | following contents: | 91 | following contents: |
| 105 | 92 | ||
| 106 | ``` | 93 | ``` |
| 107 | -load("@rules_cc//cc:defs.bzl", "cc_test") | ||
| 108 | - | ||
| 109 | cc_test( | 94 | cc_test( |
| 110 | name = "hello_test", | 95 | name = "hello_test", |
| 111 | size = "small", | 96 | size = "small", |
| @@ -118,7 +103,7 @@ This `cc_test` rule declares the C++ test binary you want to build, and links to | |||
| 118 | GoogleTest (`//:gtest_main`) using the prefix you specified in the `WORKSPACE` | 103 | GoogleTest (`//:gtest_main`) using the prefix you specified in the `WORKSPACE` |
| 119 | file (`@com_google_googletest`). For more information about Bazel `BUILD` files, | 104 | file (`@com_google_googletest`). For more information about Bazel `BUILD` files, |
| 120 | see the | 105 | see the |
| 121 | -[Bazel C++ Tutorial](https://docs.bazel.build/versions/master/tutorial/cpp.html). | 106 | +[Bazel C++ Tutorial](https://docs.bazel.build/versions/main/tutorial/cpp.html). |
| 122 | 107 | ||
| 123 | Now you can build and run your test: | 108 | Now you can build and run your test: |
| 124 | 109 | ||
| @@ -10,7 +10,7 @@ this tutorial as a starting point. If your project uses Bazel, see the | |||
| 10 | To complete this tutorial, you'll need: | 10 | To complete this tutorial, you'll need: |
| 11 | 11 | ||
| 12 | * A compatible operating system (e.g. Linux, macOS, Windows). | 12 | * A compatible operating system (e.g. Linux, macOS, Windows). |
| 13 | -* A compatible C++ compiler that supports at least C++11. | 13 | +* A compatible C++ compiler that supports at least C++14. |
| 14 | * [CMake](https://cmake.org/) and a compatible build tool for building the | 14 | * [CMake](https://cmake.org/) and a compatible build tool for building the |
| 15 | project. | 15 | project. |
| 16 | * Compatible build tools include | 16 | * Compatible build tools include |
| @@ -52,13 +52,13 @@ To do this, in your project directory (`my_project`), create a file named | |||
| 52 | cmake_minimum_required(VERSION 3.14) | 52 | cmake_minimum_required(VERSION 3.14) |
| 53 | project(my_project) | 53 | project(my_project) |
| 54 | 54 | ||
| 55 | -# GoogleTest requires at least C++11 | 55 | +# GoogleTest requires at least C++14 |
| 56 | -set(CMAKE_CXX_STANDARD 11) | 56 | +set(CMAKE_CXX_STANDARD 14) |
| 57 | 57 | ||
| 58 | include(FetchContent) | 58 | include(FetchContent) |
| 59 | FetchContent_Declare( | 59 | FetchContent_Declare( |
| 60 | googletest | 60 | googletest |
| 61 | - URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip | 61 | + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip |
| 62 | ) | 62 | ) |
| 63 | # For Windows: Prevent overriding the parent project's compiler/linker settings | 63 | # For Windows: Prevent overriding the parent project's compiler/linker settings |
| 64 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | 64 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| @@ -66,7 +66,7 @@ FetchContent_MakeAvailable(googletest) | |||
| 66 | ``` | 66 | ``` |
| 67 | 67 | ||
| 68 | The above configuration declares a dependency on GoogleTest which is downloaded | 68 | The above configuration declares a dependency on GoogleTest which is downloaded |
| 69 | -from GitHub. In the above example, `609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is | 69 | +from GitHub. In the above example, `03597a01ee50ed33e9dfd640b249b4be3799d395` is |
| 70 | the Git commit hash of the GoogleTest version to use; we recommend updating the | 70 | the Git commit hash of the GoogleTest version to use; we recommend updating the |
| 71 | hash often to point to the latest version. | 71 | hash often to point to the latest version. |
| 72 | 72 | ||
| @@ -108,7 +108,7 @@ add_executable( | |||
| 108 | ) | 108 | ) |
| 109 | target_link_libraries( | 109 | target_link_libraries( |
| 110 | hello_test | 110 | hello_test |
| 111 | - gtest_main | 111 | + GTest::gtest_main |
| 112 | ) | 112 | ) |
| 113 | 113 | ||
| 114 | include(GoogleTest) | 114 | include(GoogleTest) |
| @@ -6,7 +6,7 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace. | |||
| 6 | 6 | ||
| 7 | ## Returning a Value | 7 | ## Returning a Value |
| 8 | 8 | ||
| 9 | -| | | | 9 | +| Action | Description | |
| 10 | | :-------------------------------- | :-------------------------------------------- | | 10 | | :-------------------------------- | :-------------------------------------------- | |
| 11 | | `Return()` | Return from a `void` mock function. | | 11 | | `Return()` | Return from a `void` mock function. | |
| 12 | | `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. | | 12 | | `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. | |||
| 20 | 20 | ||
| 21 | ## Side Effects | 21 | ## Side Effects |
| 22 | 22 | ||
| 23 | -| | | | 23 | +| Action | Description | |
| 24 | | :--------------------------------- | :-------------------------------------- | | 24 | | :--------------------------------- | :-------------------------------------- | |
| 25 | | `Assign(&variable, value)` | Assign `value` to variable. | | 25 | | `Assign(&variable, value)` | Assign `value` to variable. | |
| 26 | | `DeleteArg<N>()` | Delete the `N`-th (0-based) argument, which must be a pointer. | | 26 | | `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. | |||
| 38 | In the following, by "callable" we mean a free function, `std::function`, | 38 | In the following, by "callable" we mean a free function, `std::function`, |
| 39 | functor, or lambda. | 39 | functor, or lambda. |
| 40 | 40 | ||
| 41 | -| | | | 41 | +| Action | Description | |
| 42 | | :---------------------------------- | :------------------------------------- | | 42 | | :---------------------------------- | :------------------------------------- | |
| 43 | -| `f` | Invoke f with the arguments passed to the mock function, where f is a callable. | | 43 | +| `f` | Invoke `f` with the arguments passed to the mock function, where `f` is a callable. | |
| 44 | | `Invoke(f)` | Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor. | | 44 | | `Invoke(f)` | Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor. | |
| 45 | | `Invoke(object_pointer, &class::method)` | Invoke the method on the object with the arguments passed to the mock function. | | 45 | | `Invoke(object_pointer, &class::method)` | Invoke the method on the object with the arguments passed to the mock function. | |
| 46 | | `InvokeWithoutArgs(f)` | Invoke `f`, which can be a global/static function or a functor. `f` must take no arguments. | | 46 | | `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. | |||
| 86 | 86 | ||
| 87 | ## Default Action | 87 | ## Default Action |
| 88 | 88 | ||
| 89 | -| Matcher | Description | | 89 | +| Action | Description | |
| 90 | | :------------ | :----------------------------------------------------- | | 90 | | :------------ | :----------------------------------------------------- | |
| 91 | | `DoDefault()` | Do the default action (specified by `ON_CALL()` or the built-in one). | | 91 | | `DoDefault()` | Do the default action (specified by `ON_CALL()` or the built-in one). | |
| 92 | 92 | ||
| @@ -96,7 +96,7 @@ composite action - trying to do so will result in a run-time error. | |||
| 96 | 96 | ||
| 97 | ## Composite Actions | 97 | ## Composite Actions |
| 98 | 98 | ||
| 99 | -| | | | 99 | +| Action | Description | |
| 100 | | :----------------------------- | :------------------------------------------ | | 100 | | :----------------------------- | :------------------------------------------ | |
| 101 | | `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. | | 101 | | `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. | |
| 102 | | `IgnoreResult(a)` | Perform action `a` and ignore its result. `a` must not return void. | | 102 | | `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. | |||
| 106 | 106 | ||
| 107 | ## Defining Actions | 107 | ## Defining Actions |
| 108 | 108 | ||
| 109 | -| | | | 109 | +| Macro | Description | |
| 110 | | :--------------------------------- | :-------------------------------------- | | 110 | | :--------------------------------- | :-------------------------------------- | |
| 111 | | `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. | | 111 | | `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. | |
| 112 | | `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`. | | 112 | | `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 | |||
| 8 | | `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. | | 8 | | `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. | |
| 9 | | `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. | | 9 | | `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. | |
| 10 | 10 | ||
| 11 | -{: .callout .note} | 11 | +{: .callout .warning} |
| 12 | -**Note:** Although equality matching via `EXPECT_THAT(actual_value, | 12 | +**WARNING:** Equality matching via `EXPECT_THAT(actual_value, expected_value)` |
| 13 | -expected_value)` is supported, prefer to make the comparison explicit via | 13 | +is supported, however note that implicit conversions can cause surprising |
| 14 | +results. For example, `EXPECT_THAT(some_bool, "some string")` will compile and | ||
| 15 | +may pass unintentionally. | ||
| 16 | + | ||
| 17 | +**BEST PRACTICE:** Prefer to make the comparison explicit via | ||
| 14 | `EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value, | 18 | `EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value, |
| 15 | expected_value)`. | 19 | expected_value)`. |
| 16 | 20 | ||
| @@ -88,16 +92,17 @@ The `argument` can be either a C string or a C++ string object: | |||
| 88 | 92 | ||
| 89 | | Matcher | Description | | 93 | | Matcher | Description | |
| 90 | | :---------------------- | :------------------------------------------------- | | 94 | | :---------------------- | :------------------------------------------------- | |
| 91 | -| `ContainsRegex(string)` | `argument` matches the given regular expression. | | 95 | +| `ContainsRegex(string)` | `argument` matches the given regular expression. | |
| 92 | -| `EndsWith(suffix)` | `argument` ends with string `suffix`. | | 96 | +| `EndsWith(suffix)` | `argument` ends with string `suffix`. | |
| 93 | -| `HasSubstr(string)` | `argument` contains `string` as a sub-string. | | 97 | +| `HasSubstr(string)` | `argument` contains `string` as a sub-string. | |
| 94 | -| `IsEmpty()` | `argument` is an empty string. | | 98 | +| `IsEmpty()` | `argument` is an empty string. | |
| 95 | -| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. | | 99 | +| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. | |
| 96 | -| `StartsWith(prefix)` | `argument` starts with string `prefix`. | | 100 | +| `StartsWith(prefix)` | `argument` starts with string `prefix`. | |
| 97 | -| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. | | 101 | +| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. | |
| 98 | -| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. | | 102 | +| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. | |
| 99 | -| `StrEq(string)` | `argument` is equal to `string`. | | 103 | +| `StrEq(string)` | `argument` is equal to `string`. | |
| 100 | -| `StrNe(string)` | `argument` is not equal to `string`. | | 104 | +| `StrNe(string)` | `argument` is not equal to `string`. | |
| 105 | +| `WhenBase64Unescaped(m)` | `argument` is a base-64 escaped string whose unescaped string matches `m`. | | ||
| 101 | 106 | ||
| 102 | `ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They | 107 | `ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They |
| 103 | use the regular expression syntax defined | 108 | use the regular expression syntax defined |
| @@ -116,6 +121,7 @@ messages, you can use: | |||
| 116 | | `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. | | 121 | | `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. | |
| 117 | | `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. | | 122 | | `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. | |
| 118 | | `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. | | 123 | | `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. | |
| 124 | +| `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)`. | | ||
| 119 | | `Each(e)` | `argument` is a container where *every* element matches `e`, which can be either a value or a matcher. | | 125 | | `Each(e)` | `argument` is a container where *every* element matches `e`, which can be either a value or a matcher. | |
| 120 | | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. | | 126 | | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. | |
| 121 | | `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. | | 127 | | `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: | |||
| 146 | one might write: | 152 | one might write: |
| 147 | 153 | ||
| 148 | ```cpp | 154 | ```cpp |
| 149 | - using ::std::get; | ||
| 150 | MATCHER(FooEq, "") { | 155 | MATCHER(FooEq, "") { |
| 151 | return std::get<0>(arg).Equals(std::get<1>(arg)); | 156 | return std::get<0>(arg).Equals(std::get<1>(arg)); |
| 152 | } | 157 | } |
| @@ -193,6 +198,7 @@ messages, you can use: | |||
| 193 | | Matcher | Description | | 198 | | Matcher | Description | |
| 194 | | :--------------- | :------------------------------------------------ | | 199 | | :--------------- | :------------------------------------------------ | |
| 195 | | `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. | | 200 | | `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. | |
| 201 | +| `ResultOf(result_description, f, m)` | The same as the two-parameter version, but provides a better error message. | ||
| 196 | 202 | ||
| 197 | ## Pointer Matchers | 203 | ## Pointer Matchers |
| 198 | 204 | ||
| @@ -237,6 +243,7 @@ You can make a matcher from one or more other matchers: | |||
| 237 | | `AnyOf(m1, m2, ..., mn)` | `argument` matches at least one of the matchers `m1` to `mn`. | | 243 | | `AnyOf(m1, m2, ..., mn)` | `argument` matches at least one of the matchers `m1` to `mn`. | |
| 238 | | `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. | | 244 | | `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. | |
| 239 | | `Not(m)` | `argument` doesn't match matcher `m`. | | 245 | | `Not(m)` | `argument` doesn't match matcher `m`. | |
| 246 | +| `Conditional(cond, m1, m2)` | Matches matcher `m1` if `cond` evaluates to true, else matches `m2`.| | ||
| 240 | 247 | ||
| 241 | ## Adapters for Matchers | 248 | ## Adapters for Matchers |
| 242 | 249 | ||
| @@ -259,7 +266,7 @@ which must be a permanent callback. | |||
| 259 | 266 | ||
| 260 | ## Defining Matchers | 267 | ## Defining Matchers |
| 261 | 268 | ||
| 262 | -| Matcher | Description | | 269 | +| Macro | Description | |
| 263 | | :----------------------------------- | :------------------------------------ | | 270 | | :----------------------------------- | :------------------------------------ | |
| 264 | | `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. | | 271 | | `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. | |
| 265 | | `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`. | | 272 | | `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()) | |||
| 248 | .WillOnce(Return(3)); | 248 | .WillOnce(Return(3)); |
| 249 | ``` | 249 | ``` |
| 250 | 250 | ||
| 251 | -The `WillOnce` clause can be used any number of times on an expectation. | 251 | +The `WillOnce` clause can be used any number of times on an expectation. Unlike |
| 252 | +`WillRepeatedly`, the action fed to each `WillOnce` call will be called at most | ||
| 253 | +once, so may be a move-only type and/or have an `&&`-qualified call operator. | ||
| 252 | 254 | ||
| 253 | #### WillRepeatedly {#EXPECT_CALL.WillRepeatedly} | 255 | #### WillRepeatedly {#EXPECT_CALL.WillRepeatedly} |
| 254 | 256 | ||
| @@ -109,7 +109,7 @@ namespace: | |||
| 109 | | `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | | 109 | | `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | |
| 110 | | `Bool()` | Yields sequence `{false, true}`. | | 110 | | `Bool()` | Yields sequence `{false, true}`. | |
| 111 | | `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`. | | 111 | | `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`. | |
| 112 | - | 112 | +| `ConvertGenerator<T>(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | |
| 113 | The optional last argument *`name_generator`* is a function or functor that | 113 | The optional last argument *`name_generator`* is a function or functor that |
| 114 | generates custom test name suffixes based on the test parameters. The function | 114 | generates custom test name suffixes based on the test parameters. The function |
| 115 | must accept an argument of type | 115 | must accept an argument of type |
| @@ -518,8 +518,8 @@ Logs a property for the current test, test suite, or entire invocation of the | |||
| 518 | test program. Only the last value for a given key is logged. | 518 | test program. Only the last value for a given key is logged. |
| 519 | 519 | ||
| 520 | The key must be a valid XML attribute name, and cannot conflict with the ones | 520 | The key must be a valid XML attribute name, and cannot conflict with the ones |
| 521 | -already used by GoogleTest (`name`, `status`, `time`, `classname`, `type_param`, | 521 | +already used by GoogleTest (`name`, `file`, `line`, `status`, `time`, |
| 522 | -and `value_param`). | 522 | +`classname`, `type_param`, and `value_param`). |
| 523 | 523 | ||
| 524 | `RecordProperty` is `public static` so it can be called from utility functions | 524 | `RecordProperty` is `public static` so it can be called from utility functions |
| 525 | that are not members of the test fixture. | 525 | that are not members of the test fixture. |
| @@ -1,7 +1,7 @@ | |||
| 1 | # Googletest Samples | 1 | # Googletest Samples |
| 2 | 2 | ||
| 3 | If you're like us, you'd like to look at | 3 | If you're like us, you'd like to look at |
| 4 | -[googletest samples.](https://github.com/google/googletest/tree/master/googletest/samples) | 4 | +[googletest samples.](https://github.com/google/googletest/blob/main/googletest/samples) |
| 5 | The sample directory has a number of well-commented samples showing how to use a | 5 | The sample directory has a number of well-commented samples showing how to use a |
| 6 | variety of googletest features. | 6 | variety of googletest features. |
| 7 | 7 | ||
| @@ -36,13 +36,9 @@ endif() | |||
| 36 | # as ${gmock_SOURCE_DIR} and to the root binary directory as | 36 | # as ${gmock_SOURCE_DIR} and to the root binary directory as |
| 37 | # ${gmock_BINARY_DIR}. | 37 | # ${gmock_BINARY_DIR}. |
| 38 | # Language "C" is required for find_package(Threads). | 38 | # Language "C" is required for find_package(Threads). |
| 39 | -if (CMAKE_VERSION VERSION_LESS 3.0) | 39 | +cmake_minimum_required(VERSION 3.5) |
| 40 | - project(gmock CXX C) | 40 | +cmake_policy(SET CMP0048 NEW) |
| 41 | -else() | 41 | +project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) |
| 42 | - cmake_policy(SET CMP0048 NEW) | ||
| 43 | - project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) | ||
| 44 | -endif() | ||
| 45 | -cmake_minimum_required(VERSION 2.8.12) | ||
| 46 | 42 | ||
| 47 | if (COMMAND set_up_hermetic_build) | 43 | if (COMMAND set_up_hermetic_build) |
| 48 | set_up_hermetic_build() | 44 | set_up_hermetic_build() |
| @@ -109,11 +105,12 @@ endif() | |||
| 109 | # to the targets for when we are part of a parent build (ie being pulled | 105 | # to the targets for when we are part of a parent build (ie being pulled |
| 110 | # in via add_subdirectory() rather than being a standalone build). | 106 | # in via add_subdirectory() rather than being a standalone build). |
| 111 | if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") | 107 | if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") |
| 108 | + string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}") | ||
| 112 | target_include_directories(gmock SYSTEM INTERFACE | 109 | target_include_directories(gmock SYSTEM INTERFACE |
| 113 | - "$<BUILD_INTERFACE:${gmock_build_include_dirs}>" | 110 | + "$<BUILD_INTERFACE:${dirs}>" |
| 114 | "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") | 111 | "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") |
| 115 | target_include_directories(gmock_main SYSTEM INTERFACE | 112 | target_include_directories(gmock_main SYSTEM INTERFACE |
| 116 | - "$<BUILD_INTERFACE:${gmock_build_include_dirs}>" | 113 | + "$<BUILD_INTERFACE:${dirs}>" |
| 117 | "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") | 114 | "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") |
| 118 | endif() | 115 | endif() |
| 119 | 116 | ||
| @@ -154,7 +151,10 @@ if (gmock_build_tests) | |||
| 154 | cxx_test(gmock_ex_test gmock_main) | 151 | cxx_test(gmock_ex_test gmock_main) |
| 155 | cxx_test(gmock-function-mocker_test gmock_main) | 152 | cxx_test(gmock-function-mocker_test gmock_main) |
| 156 | cxx_test(gmock-internal-utils_test gmock_main) | 153 | cxx_test(gmock-internal-utils_test gmock_main) |
| 157 | - cxx_test(gmock-matchers_test gmock_main) | 154 | + cxx_test(gmock-matchers-arithmetic_test gmock_main) |
| 155 | + cxx_test(gmock-matchers-comparisons_test gmock_main) | ||
| 156 | + cxx_test(gmock-matchers-containers_test gmock_main) | ||
| 157 | + cxx_test(gmock-matchers-misc_test gmock_main) | ||
| 158 | cxx_test(gmock-more-actions_test gmock_main) | 158 | cxx_test(gmock-more-actions_test gmock_main) |
| 159 | cxx_test(gmock-nice-strict_test gmock_main) | 159 | cxx_test(gmock-nice-strict_test gmock_main) |
| 160 | cxx_test(gmock-port_test gmock_main) | 160 | cxx_test(gmock-port_test gmock_main) |
| @@ -35,10 +35,6 @@ Details and examples can be found here: | |||
| 35 | * [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) | 35 | * [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) |
| 36 | * [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) | 36 | * [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) |
| 37 | 37 | ||
| 38 | -Please note that code under scripts/generator/ is from the | ||
| 39 | -[cppclean project](http://code.google.com/p/cppclean/) and under the Apache | ||
| 40 | -License, which is different from GoogleMock's license. | ||
| 41 | - | ||
| 42 | GoogleMock is a part of | 38 | GoogleMock is a part of |
| 43 | [GoogleTest C++ testing framework](http://github.com/google/googletest/) and a | 39 | [GoogleTest C++ testing framework](http://github.com/google/googletest/) and a |
| 44 | subject to the same requirements. | 40 | subject to the same requirements. |
| @@ -27,21 +27,23 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements some commonly used cardinalities. More | 32 | // This file implements some commonly used cardinalities. More |
| 34 | // cardinalities can be defined by the user implementing the | 33 | // cardinalities can be defined by the user implementing the |
| 35 | // CardinalityInterface interface if necessary. | 34 | // CardinalityInterface interface if necessary. |
| 36 | 35 | ||
| 37 | -// GOOGLETEST_CM0002 DO NOT DELETE | 36 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 37 | +// IWYU pragma: friend gmock/.* | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | + | ||
| 43 | 44 | ||
| 44 | 45 | ||
| 46 | + | ||
| 45 | 47 | ||
| 46 | 48 | ||
| 47 | 49 | ||
| @@ -116,7 +118,7 @@ class GTEST_API_ Cardinality { | |||
| 116 | // cardinality, i.e. exceed the maximum number of allowed calls. | 118 | // cardinality, i.e. exceed the maximum number of allowed calls. |
| 117 | bool IsOverSaturatedByCallCount(int call_count) const { | 119 | bool IsOverSaturatedByCallCount(int call_count) const { |
| 118 | return impl_->IsSaturatedByCallCount(call_count) && | 120 | return impl_->IsSaturatedByCallCount(call_count) && |
| 119 | - !impl_->IsSatisfiedByCallCount(call_count); | 121 | + !impl_->IsSatisfiedByCallCount(call_count); |
| 120 | } | 122 | } |
| 121 | 123 | ||
| 122 | // Describes self to an ostream | 124 | // Describes self to an ostream |
| @@ -31,10 +31,11 @@ | |||
| 31 | // | 31 | // |
| 32 | // This file implements MOCK_METHOD. | 32 | // This file implements MOCK_METHOD. |
| 33 | 33 | ||
| 34 | -// GOOGLETEST_CM0002 DO NOT DELETE | 34 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 35 | +// IWYU pragma: friend gmock/.* | ||
| 35 | 36 | ||
| 36 | -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT | 37 | +#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ |
| 37 | -#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT | 38 | +#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ |
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | 41 | ||
| @@ -64,6 +65,39 @@ struct ThisRefAdjuster { | |||
| 64 | } | 65 | } |
| 65 | }; | 66 | }; |
| 66 | 67 | ||
| 68 | +constexpr bool PrefixOf(const char* a, const char* b) { | ||
| 69 | + return *a == 0 || (*a == *b && internal::PrefixOf(a + 1, b + 1)); | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +template <int N, int M> | ||
| 73 | +constexpr bool StartsWith(const char (&prefix)[N], const char (&str)[M]) { | ||
| 74 | + return N <= M && internal::PrefixOf(prefix, str); | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +template <int N, int M> | ||
| 78 | +constexpr bool EndsWith(const char (&suffix)[N], const char (&str)[M]) { | ||
| 79 | + return N <= M && internal::PrefixOf(suffix, str + M - N); | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +template <int N, int M> | ||
| 83 | +constexpr bool Equals(const char (&a)[N], const char (&b)[M]) { | ||
| 84 | + return N == M && internal::PrefixOf(a, b); | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +template <int N> | ||
| 88 | +constexpr bool ValidateSpec(const char (&spec)[N]) { | ||
| 89 | + return internal::Equals("const", spec) || | ||
| 90 | + internal::Equals("override", spec) || | ||
| 91 | + internal::Equals("final", spec) || | ||
| 92 | + internal::Equals("noexcept", spec) || | ||
| 93 | + (internal::StartsWith("noexcept(", spec) && | ||
| 94 | + internal::EndsWith(")", spec)) || | ||
| 95 | + internal::Equals("ref(&)", spec) || | ||
| 96 | + internal::Equals("ref(&&)", spec) || | ||
| 97 | + (internal::StartsWith("Calltype(", spec) && | ||
| 98 | + internal::EndsWith(")", spec)); | ||
| 99 | +} | ||
| 100 | + | ||
| 67 | } // namespace internal | 101 | } // namespace internal |
| 68 | 102 | ||
| 69 | // The style guide prohibits "using" statements in a namespace scope | 103 | // The style guide prohibits "using" statements in a namespace scope |
| @@ -74,8 +108,11 @@ struct ThisRefAdjuster { | |||
| 74 | using internal::FunctionMocker; | 108 | using internal::FunctionMocker; |
| 75 | } // namespace testing | 109 | } // namespace testing |
| 76 | 110 | ||
| 77 | -#define MOCK_METHOD(...) \ | 111 | +#define MOCK_METHOD(...) \ |
| 78 | - GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) | 112 | + GMOCK_INTERNAL_WARNING_PUSH() \ |
| 113 | + GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \ | ||
| 114 | + GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) \ | ||
| 115 | + GMOCK_INTERNAL_WARNING_POP() | ||
| 79 | 116 | ||
| 80 | 117 | ||
| 81 | GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) | 118 | GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
| @@ -86,17 +123,18 @@ using internal::FunctionMocker; | |||
| 86 | 123 | ||
| 87 | GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) | 124 | GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) |
| 88 | 125 | ||
| 89 | -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ | 126 | +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ |
| 90 | - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ | 127 | + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ |
| 91 | - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ | 128 | + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ |
| 92 | - GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ | 129 | + GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ |
| 93 | - GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ | 130 | + GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ |
| 94 | - GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ | 131 | + GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ |
| 95 | - GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ | 132 | + GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ |
| 96 | - GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ | 133 | + GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ |
| 97 | - GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ | 134 | + GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ |
| 98 | - GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ | 135 | + GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ |
| 99 | - GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ | 136 | + GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Spec), \ |
| 137 | + GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ | ||
| 100 | (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) | 138 | (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) |
| 101 | 139 | ||
| 102 | 140 | ||
| @@ -166,11 +204,11 @@ using internal::FunctionMocker; | |||
| 166 | GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ | 204 | GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ |
| 167 | } \ | 205 | } \ |
| 168 | mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \ | 206 | mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \ |
| 169 | - GMOCK_MOCKER_(_N, _Constness, _MethodName) | 207 | + GMOCK_MOCKER_(_N, _Constness, _MethodName) |
| 170 | 208 | ||
| 171 | 209 | ||
| 172 | 210 | ||
| 173 | -// Five Valid modifiers. | 211 | +// Valid modifiers. |
| 174 | 212 | ||
| 175 | GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) | 213 | GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) |
| 176 | 214 | ||
| @@ -189,6 +227,14 @@ using internal::FunctionMocker; | |||
| 189 | GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ | 227 | GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ |
| 190 | _elem, ) | 228 | _elem, ) |
| 191 | 229 | ||
| 230 | + | ||
| 231 | + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE, ~, _Tuple) | ||
| 232 | + | ||
| 233 | + | ||
| 234 | + GMOCK_PP_IF( \ | ||
| 235 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem)), \ | ||
| 236 | + GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) | ||
| 237 | + | ||
| 192 | 238 | ||
| 193 | GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) | 239 | GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) |
| 194 | 240 | ||
| @@ -196,19 +242,25 @@ using internal::FunctionMocker; | |||
| 196 | GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ | 242 | GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ |
| 197 | GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) | 243 | GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) |
| 198 | 244 | ||
| 199 | -#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ | 245 | +#ifdef GMOCK_INTERNAL_STRICT_SPEC_ASSERT |
| 200 | - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) | 246 | +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ |
| 201 | - | 247 | + static_assert( \ |
| 202 | -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ | 248 | + ::testing::internal::ValidateSpec(GMOCK_PP_STRINGIZE(_elem)), \ |
| 203 | - static_assert( \ | 249 | + "Token \'" GMOCK_PP_STRINGIZE( \ |
| 204 | - (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ | 250 | + _elem) "\' cannot be recognized as a valid specification " \ |
| 205 | - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ | 251 | + "modifier. Is a ',' missing?"); |
| 206 | - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ | 252 | +#else |
| 207 | - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ | 253 | +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ |
| 208 | - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ | 254 | + static_assert( \ |
| 209 | - GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ | 255 | + (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ |
| 210 | - GMOCK_PP_STRINGIZE( \ | 256 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ |
| 257 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ | ||
| 258 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ | ||
| 259 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ | ||
| 260 | + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem))) == 1, \ | ||
| 261 | + GMOCK_PP_STRINGIZE( \ | ||
| 211 | _elem) " cannot be recognized as a valid specification modifier."); | 262 | _elem) " cannot be recognized as a valid specification modifier."); |
| 263 | + | ||
| 212 | 264 | ||
| 213 | // Modifiers implementation. | 265 | // Modifiers implementation. |
| 214 | 266 | ||
| @@ -238,26 +290,12 @@ using internal::FunctionMocker; | |||
| 238 | 290 | ||
| 239 | 291 | ||
| 240 | 292 | ||
| 241 | -#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ | 293 | +#define GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem) \ |
| 242 | - GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ | 294 | + GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CALLTYPE_I_, _elem) |
| 243 | - GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ | ||
| 244 | - (_elem) | ||
| 245 | 295 | ||
| 246 | -// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and | 296 | +#define GMOCK_INTERNAL_DETECT_CALLTYPE_I_Calltype , |
| 247 | -// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows | ||
| 248 | -// maybe they can be simplified somehow. | ||
| 249 | - | ||
| 250 | - GMOCK_INTERNAL_IS_CALLTYPE_I( \ | ||
| 251 | - GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) | ||
| 252 | - | ||
| 253 | 297 | ||
| 254 | -#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ | 298 | +#define GMOCK_INTERNAL_UNPACK_Calltype(...) __VA_ARGS__ |
| 255 | - GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ | ||
| 256 | - GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) | ||
| 257 | - | ||
| 258 | - GMOCK_PP_IDENTITY _arg | ||
| 259 | - | ||
| 260 | - | ||
| 261 | 299 | ||
| 262 | // Note: The use of `identity_t` here allows _Ret to represent return types that | 300 | // Note: The use of `identity_t` here allows _Ret to represent return types that |
| 263 | // would normally need to be specified in a different way. For example, a method | 301 | // would normally need to be specified in a different way. For example, a method |
| @@ -478,4 +516,4 @@ using internal::FunctionMocker; | |||
| 478 | 516 | ||
| 479 | GTEST_CONCAT_TOKEN_(gmock# | 517 | GTEST_CONCAT_TOKEN_(gmock# |
| 480 | 518 | ||
| 481 | -#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ | 519 | +#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ |
| @@ -27,12 +27,12 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements some commonly used variadic actions. | 32 | // This file implements some commonly used variadic actions. |
| 34 | 33 | ||
| 35 | -// GOOGLETEST_CM0002 DO NOT DELETE | 34 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 35 | +// IWYU pragma: friend gmock/.* | ||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | 38 | ||
| @@ -129,170 +129,207 @@ | |||
| 129 | 129 | ||
| 130 | // Declares the template parameters. | 130 | // Declares the template parameters. |
| 131 | 131 | ||
| 132 | -#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ | 132 | +#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \ |
| 133 | - name1) kind0 name0, kind1 name1 | 133 | + kind0 name0, kind1 name1 |
| 134 | 134 | ||
| 135 | - kind2, name2) kind0 name0, kind1 name1, kind2 name2 | 135 | + kind2, name2) \ |
| 136 | + kind0 name0, kind1 name1, kind2 name2 | ||
| 136 | 137 | ||
| 137 | - kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ | 138 | + kind2, name2, kind3, name3) \ |
| 138 | - kind3 name3 | 139 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3 |
| 139 | -#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 140 | +#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS( \ |
| 140 | - kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ | 141 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \ |
| 141 | - kind2 name2, kind3 name3, kind4 name4 | 142 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4 |
| 142 | 143 | ||
| 143 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ | 144 | + kind2, name2, kind3, name3, \ |
| 144 | - kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 | 145 | + kind4, name4, kind5, name5) \ |
| 145 | -#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 146 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 |
| 146 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ | 147 | +#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS( \ |
| 147 | - name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ | 148 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 148 | - kind5 name5, kind6 name6 | 149 | + kind5, name5, kind6, name6) \ |
| 149 | -#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 150 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ |
| 150 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ | 151 | + kind5 name5, kind6 name6 |
| 151 | - kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ | 152 | +#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS( \ |
| 152 | - kind4 name4, kind5 name5, kind6 name6, kind7 name7 | 153 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 153 | -#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 154 | + kind5, name5, kind6, name6, kind7, name7) \ |
| 154 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ | 155 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ |
| 155 | - kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ | 156 | + kind5 name5, kind6 name6, kind7 name7 |
| 156 | - kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ | 157 | +#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS( \ |
| 157 | - kind8 name8 | 158 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 158 | -#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ | 159 | + kind5, name5, kind6, name6, kind7, name7, kind8, name8) \ |
| 159 | - name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ | 160 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ |
| 160 | - name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ | 161 | + kind5 name5, kind6 name6, kind7 name7, kind8 name8 |
| 161 | - kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ | 162 | +#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS( \ |
| 162 | - kind6 name6, kind7 name7, kind8 name8, kind9 name9 | 163 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 164 | + kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \ | ||
| 165 | + kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ | ||
| 166 | + kind5 name5, kind6 name6, kind7 name7, kind8 name8, kind9 name9 | ||
| 163 | 167 | ||
| 164 | // Lists the template parameters. | 168 | // Lists the template parameters. |
| 165 | 169 | ||
| 166 | -#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ | 170 | +#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \ |
| 167 | - name1) name0, name1 | 171 | + name0, name1 |
| 168 | 172 | ||
| 169 | - kind2, name2) name0, name1, name2 | 173 | + kind2, name2) \ |
| 174 | + name0, name1, name2 | ||
| 170 | 175 | ||
| 171 | - kind2, name2, kind3, name3) name0, name1, name2, name3 | 176 | + kind2, name2, kind3, name3) \ |
| 172 | -#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 177 | + name0, name1, name2, name3 |
| 173 | - kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ | 178 | +#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS( \ |
| 174 | - name4 | 179 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \ |
| 180 | + name0, name1, name2, name3, name4 | ||
| 175 | 181 | ||
| 176 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ | 182 | + kind2, name2, kind3, name3, \ |
| 177 | - name2, name3, name4, name5 | 183 | + kind4, name4, kind5, name5) \ |
| 178 | -#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 184 | + name0, name1, name2, name3, name4, name5 |
| 179 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ | 185 | +#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS( \ |
| 180 | - name6) name0, name1, name2, name3, name4, name5, name6 | 186 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 181 | -#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 187 | + kind5, name5, kind6, name6) \ |
| 182 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ | 188 | + name0, name1, name2, name3, name4, name5, name6 |
| 183 | - kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 | 189 | +#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS( \ |
| 184 | -#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ | 190 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 185 | - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ | 191 | + kind5, name5, kind6, name6, kind7, name7) \ |
| 186 | - kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ | 192 | + name0, name1, name2, name3, name4, name5, name6, name7 |
| 187 | - name6, name7, name8 | 193 | +#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS( \ |
| 188 | -#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ | 194 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ |
| 189 | - name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ | 195 | + kind5, name5, kind6, name6, kind7, name7, kind8, name8) \ |
| 190 | - name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ | 196 | + name0, name1, name2, name3, name4, name5, name6, name7, name8 |
| 191 | - name3, name4, name5, name6, name7, name8, name9 | 197 | +#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS( \ |
| 198 | + kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \ | ||
| 199 | + kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \ | ||
| 200 | + name0, name1, name2, name3, name4, name5, name6, name7, name8, name9 | ||
| 192 | 201 | ||
| 193 | // Declares the types of value parameters. | 202 | // Declares the types of value parameters. |
| 194 | 203 | ||
| 195 | 204 | ||
| 196 | -#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ | 205 | +#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) \ |
| 197 | - typename p0##_type, typename p1##_type | 206 | + , typename p0##_type, typename p1##_type |
| 198 | -#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ | 207 | +#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \ |
| 199 | - typename p0##_type, typename p1##_type, typename p2##_type | 208 | + , typename p0##_type, typename p1##_type, typename p2##_type |
| 200 | -#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ | 209 | +#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \ |
| 201 | - typename p0##_type, typename p1##_type, typename p2##_type, \ | 210 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 202 | - typename p3##_type | 211 | + typename p3##_type |
| 203 | -#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ | 212 | +#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 204 | - typename p0##_type, typename p1##_type, typename p2##_type, \ | 213 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 205 | - typename p3##_type, typename p4##_type | 214 | + typename p3##_type, typename p4##_type |
| 206 | -#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ | 215 | +#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 207 | - typename p0##_type, typename p1##_type, typename p2##_type, \ | 216 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 208 | - typename p3##_type, typename p4##_type, typename p5##_type | 217 | + typename p3##_type, typename p4##_type, typename p5##_type |
| 209 | 218 | ||
| 210 | - p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ | 219 | + p6) \ |
| 211 | - typename p3##_type, typename p4##_type, typename p5##_type, \ | 220 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 212 | - typename p6##_type | 221 | + typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 222 | + typename p6##_type | ||
| 213 | 223 | ||
| 214 | - p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ | 224 | + p6, p7) \ |
| 215 | - typename p3##_type, typename p4##_type, typename p5##_type, \ | 225 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 216 | - typename p6##_type, typename p7##_type | 226 | + typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 227 | + typename p6##_type, typename p7##_type | ||
| 217 | 228 | ||
| 218 | - p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ | 229 | + p6, p7, p8) \ |
| 219 | - typename p3##_type, typename p4##_type, typename p5##_type, \ | 230 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 220 | - typename p6##_type, typename p7##_type, typename p8##_type | 231 | + typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 232 | + typename p6##_type, typename p7##_type, typename p8##_type | ||
| 221 | 233 | ||
| 222 | - p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ | 234 | + p6, p7, p8, p9) \ |
| 223 | - typename p2##_type, typename p3##_type, typename p4##_type, \ | 235 | + , typename p0##_type, typename p1##_type, typename p2##_type, \ |
| 224 | - typename p5##_type, typename p6##_type, typename p7##_type, \ | 236 | + typename p3##_type, typename p4##_type, typename p5##_type, \ |
| 225 | - typename p8##_type, typename p9##_type | 237 | + typename p6##_type, typename p7##_type, typename p8##_type, \ |
| 238 | + typename p9##_type | ||
| 226 | 239 | ||
| 227 | // Initializes the value parameters. | 240 | // Initializes the value parameters. |
| 228 | -#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ | 241 | +#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS() () |
| 229 | - () | 242 | +#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0) \ |
| 230 | -#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ | 243 | + (p0##_type gmock_p0) : p0(::std::move(gmock_p0)) |
| 231 | - (p0##_type gmock_p0) : p0(::std::move(gmock_p0)) | 244 | +#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1) \ |
| 232 | -#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ | 245 | + (p0##_type gmock_p0, p1##_type gmock_p1) \ |
| 233 | - (p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \ | 246 | + : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) |
| 234 | - p1(::std::move(gmock_p1)) | 247 | +#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2) \ |
| 235 | -#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ | 248 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2) \ |
| 236 | - (p0##_type gmock_p0, p1##_type gmock_p1, \ | 249 | + : p0(::std::move(gmock_p0)), \ |
| 237 | - p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \ | 250 | + p1(::std::move(gmock_p1)), \ |
| 238 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) | 251 | + p2(::std::move(gmock_p2)) |
| 239 | -#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ | 252 | +#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \ |
| 240 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 253 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 241 | - p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \ | 254 | + p3##_type gmock_p3) \ |
| 242 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 255 | + : p0(::std::move(gmock_p0)), \ |
| 256 | + p1(::std::move(gmock_p1)), \ | ||
| 257 | + p2(::std::move(gmock_p2)), \ | ||
| 243 | p3(::std::move(gmock_p3)) | 258 | p3(::std::move(gmock_p3)) |
| 244 | -#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ | 259 | +#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 245 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 260 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 246 | - p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \ | 261 | + p3##_type gmock_p3, p4##_type gmock_p4) \ |
| 247 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 262 | + : p0(::std::move(gmock_p0)), \ |
| 248 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) | 263 | + p1(::std::move(gmock_p1)), \ |
| 249 | -#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ | 264 | + p2(::std::move(gmock_p2)), \ |
| 250 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 265 | + p3(::std::move(gmock_p3)), \ |
| 251 | - p3##_type gmock_p3, p4##_type gmock_p4, \ | 266 | + p4(::std::move(gmock_p4)) |
| 252 | - p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \ | 267 | +#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 253 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 268 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 254 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ | 269 | + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5) \ |
| 270 | + : p0(::std::move(gmock_p0)), \ | ||
| 271 | + p1(::std::move(gmock_p1)), \ | ||
| 272 | + p2(::std::move(gmock_p2)), \ | ||
| 273 | + p3(::std::move(gmock_p3)), \ | ||
| 274 | + p4(::std::move(gmock_p4)), \ | ||
| 255 | p5(::std::move(gmock_p5)) | 275 | p5(::std::move(gmock_p5)) |
| 256 | -#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ | 276 | +#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \ |
| 257 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 277 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 258 | - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ | 278 | + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 259 | - p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \ | 279 | + p6##_type gmock_p6) \ |
| 260 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 280 | + : p0(::std::move(gmock_p0)), \ |
| 261 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ | 281 | + p1(::std::move(gmock_p1)), \ |
| 262 | - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) | 282 | + p2(::std::move(gmock_p2)), \ |
| 263 | -#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ | 283 | + p3(::std::move(gmock_p3)), \ |
| 264 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 284 | + p4(::std::move(gmock_p4)), \ |
| 265 | - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ | 285 | + p5(::std::move(gmock_p5)), \ |
| 266 | - p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \ | 286 | + p6(::std::move(gmock_p6)) |
| 267 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 287 | +#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 268 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ | 288 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 269 | - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ | 289 | + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 290 | + p6##_type gmock_p6, p7##_type gmock_p7) \ | ||
| 291 | + : p0(::std::move(gmock_p0)), \ | ||
| 292 | + p1(::std::move(gmock_p1)), \ | ||
| 293 | + p2(::std::move(gmock_p2)), \ | ||
| 294 | + p3(::std::move(gmock_p3)), \ | ||
| 295 | + p4(::std::move(gmock_p4)), \ | ||
| 296 | + p5(::std::move(gmock_p5)), \ | ||
| 297 | + p6(::std::move(gmock_p6)), \ | ||
| 270 | p7(::std::move(gmock_p7)) | 298 | p7(::std::move(gmock_p7)) |
| 271 | -#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 299 | +#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \ |
| 272 | - p7, p8)\ | 300 | + p8) \ |
| 273 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 301 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 274 | - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ | 302 | + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 275 | - p6##_type gmock_p6, p7##_type gmock_p7, \ | 303 | + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8) \ |
| 276 | - p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \ | 304 | + : p0(::std::move(gmock_p0)), \ |
| 277 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 305 | + p1(::std::move(gmock_p1)), \ |
| 278 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ | 306 | + p2(::std::move(gmock_p2)), \ |
| 279 | - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ | 307 | + p3(::std::move(gmock_p3)), \ |
| 280 | - p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) | 308 | + p4(::std::move(gmock_p4)), \ |
| 309 | + p5(::std::move(gmock_p5)), \ | ||
| 310 | + p6(::std::move(gmock_p6)), \ | ||
| 311 | + p7(::std::move(gmock_p7)), \ | ||
| 312 | + p8(::std::move(gmock_p8)) | ||
| 281 | 313 | ||
| 282 | - p7, p8, p9)\ | 314 | + p7, p8, p9) \ |
| 283 | - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ | 315 | + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
| 284 | - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ | 316 | + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
| 285 | - p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ | 317 | + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
| 286 | - p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \ | 318 | + p9##_type gmock_p9) \ |
| 287 | - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ | 319 | + : p0(::std::move(gmock_p0)), \ |
| 288 | - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ | 320 | + p1(::std::move(gmock_p1)), \ |
| 289 | - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ | 321 | + p2(::std::move(gmock_p2)), \ |
| 290 | - p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \ | 322 | + p3(::std::move(gmock_p3)), \ |
| 323 | + p4(::std::move(gmock_p4)), \ | ||
| 324 | + p5(::std::move(gmock_p5)), \ | ||
| 325 | + p6(::std::move(gmock_p6)), \ | ||
| 326 | + p7(::std::move(gmock_p7)), \ | ||
| 327 | + p8(::std::move(gmock_p8)), \ | ||
| 291 | p9(::std::move(gmock_p9)) | 328 | p9(::std::move(gmock_p9)) |
| 292 | 329 | ||
| 293 | // Defines the copy constructor | 330 | // Defines the copy constructor |
| 294 | 331 | ||
| 295 | - {} // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134 | 332 | + {} // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134 |
| 296 | 333 | ||
| 297 | 334 | ||
| 298 | 335 | ||
| @@ -307,30 +344,71 @@ | |||
| 307 | // Declares the fields for storing the value parameters. | 344 | // Declares the fields for storing the value parameters. |
| 308 | 345 | ||
| 309 | 346 | ||
| 310 | -#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ | 347 | +#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) \ |
| 311 | - p1##_type p1; | 348 | + p0##_type p0; \ |
| 312 | -#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ | 349 | + p1##_type p1; |
| 313 | - p1##_type p1; p2##_type p2; | 350 | +#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) \ |
| 314 | -#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ | 351 | + p0##_type p0; \ |
| 315 | - p1##_type p1; p2##_type p2; p3##_type p3; | 352 | + p1##_type p1; \ |
| 316 | -#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ | 353 | + p2##_type p2; |
| 317 | - p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; | 354 | +#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \ |
| 318 | -#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ | 355 | + p0##_type p0; \ |
| 319 | - p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ | 356 | + p1##_type p1; \ |
| 320 | - p5##_type p5; | 357 | + p2##_type p2; \ |
| 321 | -#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ | 358 | + p3##_type p3; |
| 322 | - p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ | 359 | +#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 323 | - p5##_type p5; p6##_type p6; | 360 | + p0##_type p0; \ |
| 324 | -#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 361 | + p1##_type p1; \ |
| 325 | - p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ | 362 | + p2##_type p2; \ |
| 326 | - p5##_type p5; p6##_type p6; p7##_type p7; | 363 | + p3##_type p3; \ |
| 327 | -#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 364 | + p4##_type p4; |
| 328 | - p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ | 365 | +#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 329 | - p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; | 366 | + p0##_type p0; \ |
| 367 | + p1##_type p1; \ | ||
| 368 | + p2##_type p2; \ | ||
| 369 | + p3##_type p3; \ | ||
| 370 | + p4##_type p4; \ | ||
| 371 | + p5##_type p5; | ||
| 372 | + | ||
| 373 | + p0##_type p0; \ | ||
| 374 | + p1##_type p1; \ | ||
| 375 | + p2##_type p2; \ | ||
| 376 | + p3##_type p3; \ | ||
| 377 | + p4##_type p4; \ | ||
| 378 | + p5##_type p5; \ | ||
| 379 | + p6##_type p6; | ||
| 380 | + | ||
| 381 | + p0##_type p0; \ | ||
| 382 | + p1##_type p1; \ | ||
| 383 | + p2##_type p2; \ | ||
| 384 | + p3##_type p3; \ | ||
| 385 | + p4##_type p4; \ | ||
| 386 | + p5##_type p5; \ | ||
| 387 | + p6##_type p6; \ | ||
| 388 | + p7##_type p7; | ||
| 389 | + | ||
| 390 | + p8) \ | ||
| 391 | + p0##_type p0; \ | ||
| 392 | + p1##_type p1; \ | ||
| 393 | + p2##_type p2; \ | ||
| 394 | + p3##_type p3; \ | ||
| 395 | + p4##_type p4; \ | ||
| 396 | + p5##_type p5; \ | ||
| 397 | + p6##_type p6; \ | ||
| 398 | + p7##_type p7; \ | ||
| 399 | + p8##_type p8; | ||
| 330 | 400 | ||
| 331 | - p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ | 401 | + p7, p8, p9) \ |
| 332 | - p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ | 402 | + p0##_type p0; \ |
| 333 | - p9##_type p9; | 403 | + p1##_type p1; \ |
| 404 | + p2##_type p2; \ | ||
| 405 | + p3##_type p3; \ | ||
| 406 | + p4##_type p4; \ | ||
| 407 | + p5##_type p5; \ | ||
| 408 | + p6##_type p6; \ | ||
| 409 | + p7##_type p7; \ | ||
| 410 | + p8##_type p8; \ | ||
| 411 | + p9##_type p9; | ||
| 334 | 412 | ||
| 335 | // Lists the value parameters. | 413 | // Lists the value parameters. |
| 336 | 414 | ||
| @@ -338,72 +416,78 @@ | |||
| 338 | 416 | ||
| 339 | 417 | ||
| 340 | 418 | ||
| 341 | -#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ | 419 | +#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 342 | - p2, p3, p4 | 420 | + p0, p1, p2, p3, p4 |
| 343 | -#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ | 421 | +#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 344 | - p1, p2, p3, p4, p5 | 422 | + p0, p1, p2, p3, p4, p5 |
| 345 | -#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ | 423 | +#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \ |
| 346 | - p6) p0, p1, p2, p3, p4, p5, p6 | 424 | + p0, p1, p2, p3, p4, p5, p6 |
| 347 | -#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 425 | +#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 348 | - p7) p0, p1, p2, p3, p4, p5, p6, p7 | 426 | + p0, p1, p2, p3, p4, p5, p6, p7 |
| 349 | -#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 427 | +#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \ |
| 350 | - p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 | 428 | + p8) \ |
| 429 | + p0, p1, p2, p3, p4, p5, p6, p7, p8 | ||
| 351 | 430 | ||
| 352 | - p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 | 431 | + p7, p8, p9) \ |
| 432 | + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 | ||
| 353 | 433 | ||
| 354 | // Lists the value parameter types. | 434 | // Lists the value parameter types. |
| 355 | 435 | ||
| 356 | 436 | ||
| 357 | -#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ | 437 | +#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) \ |
| 358 | - p1##_type | 438 | + , p0##_type, p1##_type |
| 359 | -#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ | 439 | +#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \ |
| 360 | - p1##_type, p2##_type | 440 | + , p0##_type, p1##_type, p2##_type |
| 361 | -#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ | 441 | +#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \ |
| 362 | - p0##_type, p1##_type, p2##_type, p3##_type | 442 | + , p0##_type, p1##_type, p2##_type, p3##_type |
| 363 | -#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ | 443 | +#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 364 | - p0##_type, p1##_type, p2##_type, p3##_type, p4##_type | 444 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type |
| 365 | -#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ | 445 | +#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 366 | - p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type | 446 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type |
| 367 | 447 | ||
| 368 | - p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ | 448 | + p6) \ |
| 369 | - p6##_type | 449 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type |
| 370 | 450 | ||
| 371 | - p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ | 451 | + p6, p7) \ |
| 372 | - p5##_type, p6##_type, p7##_type | 452 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ |
| 453 | + p6##_type, p7##_type | ||
| 373 | 454 | ||
| 374 | - p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ | 455 | + p6, p7, p8) \ |
| 375 | - p5##_type, p6##_type, p7##_type, p8##_type | 456 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ |
| 457 | + p6##_type, p7##_type, p8##_type | ||
| 376 | 458 | ||
| 377 | - p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ | 459 | + p6, p7, p8, p9) \ |
| 378 | - p5##_type, p6##_type, p7##_type, p8##_type, p9##_type | 460 | + , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ |
| 461 | + p6##_type, p7##_type, p8##_type, p9##_type | ||
| 379 | 462 | ||
| 380 | // Declares the value parameters. | 463 | // Declares the value parameters. |
| 381 | 464 | ||
| 382 | 465 | ||
| 383 | -#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ | 466 | +#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) \ |
| 384 | - p1##_type p1 | 467 | + p0##_type p0, p1##_type p1 |
| 385 | -#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ | 468 | +#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) \ |
| 386 | - p1##_type p1, p2##_type p2 | 469 | + p0##_type p0, p1##_type p1, p2##_type p2 |
| 387 | -#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ | 470 | +#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \ |
| 388 | - p1##_type p1, p2##_type p2, p3##_type p3 | 471 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3 |
| 389 | -#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ | 472 | +#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \ |
| 390 | - p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 | 473 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 |
| 391 | -#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ | 474 | +#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \ |
| 392 | - p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ | 475 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 393 | - p5##_type p5 | 476 | + p5##_type p5 |
| 394 | -#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ | 477 | +#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \ |
| 395 | - p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ | 478 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 396 | - p5##_type p5, p6##_type p6 | 479 | + p5##_type p5, p6##_type p6 |
| 397 | -#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 480 | +#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \ |
| 398 | - p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ | 481 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 399 | - p5##_type p5, p6##_type p6, p7##_type p7 | 482 | + p5##_type p5, p6##_type p6, p7##_type p7 |
| 400 | -#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ | 483 | +#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \ |
| 401 | - p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ | 484 | + p8) \ |
| 402 | - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 | 485 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 486 | + p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 | ||
| 403 | 487 | ||
| 404 | - p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ | 488 | + p7, p8, p9) \ |
| 405 | - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ | 489 | + p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
| 406 | - p9##_type p9 | 490 | + p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, p9##_type p9 |
| 407 | 491 | ||
| 408 | // The suffix of the class template implementing the action template. | 492 | // The suffix of the class template implementing the action template. |
| 409 | 493 | ||
| @@ -415,40 +499,43 @@ | |||
| 415 | 499 | ||
| 416 | 500 | ||
| 417 | 501 | ||
| 418 | - p7) P8 | 502 | + p7) \ |
| 503 | + P8 | ||
| 419 | 504 | ||
| 420 | - p7, p8) P9 | 505 | + p7, p8) \ |
| 506 | + P9 | ||
| 421 | 507 | ||
| 422 | - p7, p8, p9) P10 | 508 | + p7, p8, p9) \ |
| 509 | + P10 | ||
| 423 | 510 | ||
| 424 | // The name of the class template implementing the action template. | 511 | // The name of the class template implementing the action template. |
| 425 | -#define GMOCK_ACTION_CLASS_(name, value_params)\ | 512 | +#define GMOCK_ACTION_CLASS_(name, value_params) \ |
| 426 | - GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) | 513 | + GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) |
| 427 | 514 | ||
| 428 | 515 | ||
| 429 | template <GMOCK_INTERNAL_DECL_##template_params \ | 516 | template <GMOCK_INTERNAL_DECL_##template_params \ |
| 430 | - GMOCK_INTERNAL_DECL_TYPE_##value_params> \ | 517 | + GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
| 431 | class GMOCK_ACTION_CLASS_(name, value_params) { \ | 518 | class GMOCK_ACTION_CLASS_(name, value_params) { \ |
| 432 | public: \ | 519 | public: \ |
| 433 | explicit GMOCK_ACTION_CLASS_(name, value_params)( \ | 520 | explicit GMOCK_ACTION_CLASS_(name, value_params)( \ |
| 434 | GMOCK_INTERNAL_DECL_##value_params) \ | 521 | GMOCK_INTERNAL_DECL_##value_params) \ |
| 435 | GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ | 522 | GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ |
| 436 | - = default; , \ | 523 | + = default; \ |
| 524 | + , \ | ||
| 437 | : impl_(std::make_shared<gmock_Impl>( \ | 525 | : impl_(std::make_shared<gmock_Impl>( \ |
| 438 | - GMOCK_INTERNAL_LIST_##value_params)) { }) \ | 526 | + GMOCK_INTERNAL_LIST_##value_params)){}) \ |
| 439 | - GMOCK_ACTION_CLASS_(name, value_params)( \ | 527 | + GMOCK_ACTION_CLASS_(name, value_params)(const GMOCK_ACTION_CLASS_( \ |
| 440 | - const GMOCK_ACTION_CLASS_(name, value_params)&) noexcept \ | 528 | + name, value_params) &) noexcept GMOCK_INTERNAL_DEFN_COPY_ \ |
| 441 | - GMOCK_INTERNAL_DEFN_COPY_##value_params \ | 529 | + ##value_params GMOCK_ACTION_CLASS_(name, value_params)( \ |
| 442 | - GMOCK_ACTION_CLASS_(name, value_params)( \ | 530 | + GMOCK_ACTION_CLASS_(name, value_params) &&) noexcept \ |
| 443 | - GMOCK_ACTION_CLASS_(name, value_params)&&) noexcept \ | 531 | + GMOCK_INTERNAL_DEFN_COPY_##value_params template <typename F> \ |
| 444 | - GMOCK_INTERNAL_DEFN_COPY_##value_params \ | 532 | + operator ::testing::Action<F>() const { \ |
| 445 | - template <typename F> \ | ||
| 446 | - operator ::testing::Action<F>() const { \ | ||
| 447 | return GMOCK_PP_IF( \ | 533 | return GMOCK_PP_IF( \ |
| 448 | GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ | 534 | GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ |
| 449 | - (::testing::internal::MakeAction<F, gmock_Impl>()), \ | 535 | + (::testing::internal::MakeAction<F, gmock_Impl>()), \ |
| 450 | - (::testing::internal::MakeAction<F>(impl_))); \ | 536 | + (::testing::internal::MakeAction<F>(impl_))); \ |
| 451 | } \ | 537 | } \ |
| 538 | + \ | ||
| 452 | private: \ | 539 | private: \ |
| 453 | class gmock_Impl { \ | 540 | class gmock_Impl { \ |
| 454 | public: \ | 541 | public: \ |
| @@ -458,34 +545,35 @@ | |||
| 458 | return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ | 545 | return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ |
| 459 | GMOCK_INTERNAL_DEFN_##value_params \ | 546 | GMOCK_INTERNAL_DEFN_##value_params \ |
| 460 | }; \ | 547 | }; \ |
| 461 | - GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ | 548 | + GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), , \ |
| 462 | - , std::shared_ptr<const gmock_Impl> impl_;) \ | 549 | + std::shared_ptr<const gmock_Impl> impl_;) \ |
| 463 | }; \ | 550 | }; \ |
| 464 | template <GMOCK_INTERNAL_DECL_##template_params \ | 551 | template <GMOCK_INTERNAL_DECL_##template_params \ |
| 465 | - GMOCK_INTERNAL_DECL_TYPE_##value_params> \ | 552 | + GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
| 466 | - GMOCK_ACTION_CLASS_(name, value_params)< \ | 553 | + GMOCK_ACTION_CLASS_( \ |
| 467 | - GMOCK_INTERNAL_LIST_##template_params \ | 554 | + name, value_params)<GMOCK_INTERNAL_LIST_##template_params \ |
| 468 | - GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ | 555 | + GMOCK_INTERNAL_LIST_TYPE_##value_params> \ |
| 469 | - GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \ | 556 | + name(GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \ |
| 470 | template <GMOCK_INTERNAL_DECL_##template_params \ | 557 | template <GMOCK_INTERNAL_DECL_##template_params \ |
| 471 | - GMOCK_INTERNAL_DECL_TYPE_##value_params> \ | 558 | + GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
| 472 | - inline GMOCK_ACTION_CLASS_(name, value_params)< \ | 559 | + inline GMOCK_ACTION_CLASS_( \ |
| 473 | - GMOCK_INTERNAL_LIST_##template_params \ | 560 | + name, value_params)<GMOCK_INTERNAL_LIST_##template_params \ |
| 474 | - GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ | 561 | + GMOCK_INTERNAL_LIST_TYPE_##value_params> \ |
| 475 | - GMOCK_INTERNAL_DECL_##value_params) { \ | 562 | + name(GMOCK_INTERNAL_DECL_##value_params) { \ |
| 476 | - return GMOCK_ACTION_CLASS_(name, value_params)< \ | 563 | + return GMOCK_ACTION_CLASS_( \ |
| 477 | - GMOCK_INTERNAL_LIST_##template_params \ | 564 | + name, value_params)<GMOCK_INTERNAL_LIST_##template_params \ |
| 478 | - GMOCK_INTERNAL_LIST_TYPE_##value_params>( \ | 565 | + GMOCK_INTERNAL_LIST_TYPE_##value_params>( \ |
| 479 | - GMOCK_INTERNAL_LIST_##value_params); \ | 566 | + GMOCK_INTERNAL_LIST_##value_params); \ |
| 480 | } \ | 567 | } \ |
| 481 | template <GMOCK_INTERNAL_DECL_##template_params \ | 568 | template <GMOCK_INTERNAL_DECL_##template_params \ |
| 482 | - GMOCK_INTERNAL_DECL_TYPE_##value_params> \ | 569 | + GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
| 483 | template <typename function_type, typename return_type, typename args_type, \ | 570 | template <typename function_type, typename return_type, typename args_type, \ |
| 484 | GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ | 571 | GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
| 485 | - return_type GMOCK_ACTION_CLASS_(name, value_params)< \ | 572 | + return_type GMOCK_ACTION_CLASS_( \ |
| 486 | - GMOCK_INTERNAL_LIST_##template_params \ | 573 | + name, value_params)<GMOCK_INTERNAL_LIST_##template_params \ |
| 487 | - GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::gmock_PerformImpl( \ | 574 | + GMOCK_INTERNAL_LIST_TYPE_##value_params>:: \ |
| 488 | - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const | 575 | + gmock_Impl::gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) \ |
| 576 | + const | ||
| 489 | 577 | ||
| 490 | namespace testing { | 578 | namespace testing { |
| 491 | 579 | ||
| @@ -495,8 +583,8 @@ namespace testing { | |||
| 495 | // is expanded and macro expansion cannot contain #pragma. Therefore | 583 | // is expanded and macro expansion cannot contain #pragma. Therefore |
| 496 | // we suppress them here. | 584 | // we suppress them here. |
| 497 | 585 | ||
| 498 | -# pragma warning(push) | 586 | +#pragma warning(push) |
| 499 | -# pragma warning(disable:4100) | 587 | +#pragma warning(disable : 4100) |
| 500 | 588 | ||
| 501 | 589 | ||
| 502 | namespace internal { | 590 | namespace internal { |
| @@ -512,7 +600,8 @@ auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) { | |||
| 512 | 600 | ||
| 513 | template <std::size_t index, typename... Params> | 601 | template <std::size_t index, typename... Params> |
| 514 | struct InvokeArgumentAction { | 602 | struct InvokeArgumentAction { |
| 515 | - template <typename... Args> | 603 | + template <typename... Args, |
| 604 | + typename = typename std::enable_if<(index < sizeof...(Args))>::type> | ||
| 516 | auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( | 605 | auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( |
| 517 | std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)), | 606 | std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)), |
| 518 | std::declval<const Params&>()...)) { | 607 | std::declval<const Params&>()...)) { |
| @@ -565,7 +654,7 @@ InvokeArgument(Params&&... params) { | |||
| 565 | } | 654 | } |
| 566 | 655 | ||
| 567 | 656 | ||
| 568 | -# pragma warning(pop) | 657 | +#pragma warning(pop) |
| 569 | 658 | ||
| 570 | 659 | ||
| 571 | } // namespace testing | 660 | } // namespace testing |
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements some matchers that depend on gmock-matchers.h. | 32 | // This file implements some matchers that depend on gmock-matchers.h. |
| @@ -35,11 +34,15 @@ | |||
| 35 | // Note that tests are implemented in gmock-matchers_test.cc rather than | 34 | // Note that tests are implemented in gmock-matchers_test.cc rather than |
| 36 | // gmock-more-matchers-test.cc. | 35 | // gmock-more-matchers-test.cc. |
| 37 | 36 | ||
| 38 | -// GOOGLETEST_CM0002 DO NOT DELETE | 37 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 38 | +// IWYU pragma: friend gmock/.* | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + | ||
| 43 | 46 | ||
| 44 | 47 | ||
| 45 | namespace testing { | 48 | namespace testing { |
| @@ -47,23 +50,51 @@ namespace testing { | |||
| 47 | // Silence C4100 (unreferenced formal | 50 | // Silence C4100 (unreferenced formal |
| 48 | // parameter) for MSVC | 51 | // parameter) for MSVC |
| 49 | 52 | ||
| 50 | -# pragma warning(push) | 53 | +#pragma warning(push) |
| 51 | -# pragma warning(disable:4100) | 54 | +#pragma warning(disable : 4100) |
| 52 | 55 | ||
| 53 | // and silence C4800 (C4800: 'int *const ': forcing value | 56 | // and silence C4800 (C4800: 'int *const ': forcing value |
| 54 | // to bool 'true' or 'false') for MSVC 14 | 57 | // to bool 'true' or 'false') for MSVC 14 |
| 55 | -# pragma warning(disable:4800) | 58 | +#pragma warning(disable : 4800) |
| 56 | - #endif | 59 | +#endif |
| 57 | 60 | ||
| 58 | 61 | ||
| 59 | -// Defines a matcher that matches an empty container. The container must | 62 | +namespace internal { |
| 60 | -// support both size() and empty(), which all STL-like containers provide. | 63 | + |
| 61 | -MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { | 64 | +// Implements the polymorphic IsEmpty matcher, which |
| 62 | - if (arg.empty()) { | 65 | +// can be used as a Matcher<T> as long as T is either a container that defines |
| 63 | - return true; | 66 | +// empty() and size() (e.g. std::vector or std::string), or a C-style string. |
| 67 | +class IsEmptyMatcher { | ||
| 68 | + public: | ||
| 69 | + // Matches anything that defines empty() and size(). | ||
| 70 | + template <typename MatcheeContainerType> | ||
| 71 | + bool MatchAndExplain(const MatcheeContainerType& c, | ||
| 72 | + MatchResultListener* listener) const { | ||
| 73 | + if (c.empty()) { | ||
| 74 | + return true; | ||
| 75 | + } | ||
| 76 | + *listener << "whose size is " << c.size(); | ||
| 77 | + return false; | ||
| 64 | } | 78 | } |
| 65 | - *result_listener << "whose size is " << arg.size(); | 79 | + |
| 66 | - return false; | 80 | + // Matches C-style strings. |
| 81 | + bool MatchAndExplain(const char* s, MatchResultListener* listener) const { | ||
| 82 | + return MatchAndExplain(std::string(s), listener); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + // Describes what this matcher matches. | ||
| 86 | + void DescribeTo(std::ostream* os) const { *os << "is empty"; } | ||
| 87 | + | ||
| 88 | + void DescribeNegationTo(std::ostream* os) const { *os << "isn't empty"; } | ||
| 89 | +}; | ||
| 90 | + | ||
| 91 | +} // namespace internal | ||
| 92 | + | ||
| 93 | +// Creates a polymorphic matcher that matches an empty container or C-style | ||
| 94 | +// string. The container must support both size() and empty(), which all | ||
| 95 | +// STL-like containers provide. | ||
| 96 | +inline PolymorphicMatcher<internal::IsEmptyMatcher> IsEmpty() { | ||
| 97 | + return MakePolymorphicMatcher(internal::IsEmptyMatcher()); | ||
| 67 | } | 98 | } |
| 68 | 99 | ||
| 69 | // Define a matcher that matches a value that evaluates in boolean | 100 | // Define a matcher that matches a value that evaluates in boolean |
| @@ -83,10 +114,9 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { | |||
| 83 | } | 114 | } |
| 84 | 115 | ||
| 85 | 116 | ||
| 86 | -# pragma warning(pop) | 117 | +#pragma warning(pop) |
| 87 | 118 | ||
| 88 | 119 | ||
| 89 | - | ||
| 90 | } // namespace testing | 120 | } // namespace testing |
| 91 | 121 | ||
| 92 | 122 | ||
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Implements class templates NiceMock, NaggyMock, and StrictMock. | 30 | // Implements class templates NiceMock, NaggyMock, and StrictMock. |
| 32 | // | 31 | // |
| 33 | // Given a mock class MockFoo that is created using Google Mock, | 32 | // Given a mock class MockFoo that is created using Google Mock, |
| @@ -58,11 +57,13 @@ | |||
| 58 | // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT | 57 | // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT |
| 59 | // supported. | 58 | // supported. |
| 60 | 59 | ||
| 61 | -// GOOGLETEST_CM0002 DO NOT DELETE | 60 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 61 | +// IWYU pragma: friend gmock/.* | ||
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | + | ||
| 66 | 67 | ||
| 67 | 68 | ||
| 68 | 69 | ||
| @@ -109,25 +110,37 @@ constexpr bool HasStrictnessModifier() { | |||
| 109 | template <typename Base> | 110 | template <typename Base> |
| 110 | class NiceMockImpl { | 111 | class NiceMockImpl { |
| 111 | public: | 112 | public: |
| 112 | - NiceMockImpl() { ::testing::Mock::AllowUninterestingCalls(this); } | 113 | + NiceMockImpl() { |
| 114 | + ::testing::Mock::AllowUninterestingCalls(reinterpret_cast<uintptr_t>(this)); | ||
| 115 | + } | ||
| 113 | 116 | ||
| 114 | - ~NiceMockImpl() { ::testing::Mock::UnregisterCallReaction(this); } | 117 | + ~NiceMockImpl() { |
| 118 | + ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this)); | ||
| 119 | + } | ||
| 115 | }; | 120 | }; |
| 116 | 121 | ||
| 117 | template <typename Base> | 122 | template <typename Base> |
| 118 | class NaggyMockImpl { | 123 | class NaggyMockImpl { |
| 119 | public: | 124 | public: |
| 120 | - NaggyMockImpl() { ::testing::Mock::WarnUninterestingCalls(this); } | 125 | + NaggyMockImpl() { |
| 126 | + ::testing::Mock::WarnUninterestingCalls(reinterpret_cast<uintptr_t>(this)); | ||
| 127 | + } | ||
| 121 | 128 | ||
| 122 | - ~NaggyMockImpl() { ::testing::Mock::UnregisterCallReaction(this); } | 129 | + ~NaggyMockImpl() { |
| 130 | + ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this)); | ||
| 131 | + } | ||
| 123 | }; | 132 | }; |
| 124 | 133 | ||
| 125 | template <typename Base> | 134 | template <typename Base> |
| 126 | class StrictMockImpl { | 135 | class StrictMockImpl { |
| 127 | public: | 136 | public: |
| 128 | - StrictMockImpl() { ::testing::Mock::FailUninterestingCalls(this); } | 137 | + StrictMockImpl() { |
| 138 | + ::testing::Mock::FailUninterestingCalls(reinterpret_cast<uintptr_t>(this)); | ||
| 139 | + } | ||
| 129 | 140 | ||
| 130 | - ~StrictMockImpl() { ::testing::Mock::UnregisterCallReaction(this); } | 141 | + ~StrictMockImpl() { |
| 142 | + ::testing::Mock::UnregisterCallReaction(reinterpret_cast<uintptr_t>(this)); | ||
| 143 | + } | ||
| 131 | }; | 144 | }; |
| 132 | 145 | ||
| 133 | } // namespace internal | 146 | } // namespace internal |
| @@ -169,7 +182,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock | |||
| 169 | } | 182 | } |
| 170 | 183 | ||
| 171 | private: | 184 | private: |
| 172 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); | 185 | + NiceMock(const NiceMock&) = delete; |
| 186 | + NiceMock& operator=(const NiceMock&) = delete; | ||
| 173 | }; | 187 | }; |
| 174 | 188 | ||
| 175 | template <class MockClass> | 189 | template <class MockClass> |
| @@ -210,7 +224,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock | |||
| 210 | } | 224 | } |
| 211 | 225 | ||
| 212 | private: | 226 | private: |
| 213 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); | 227 | + NaggyMock(const NaggyMock&) = delete; |
| 228 | + NaggyMock& operator=(const NaggyMock&) = delete; | ||
| 214 | }; | 229 | }; |
| 215 | 230 | ||
| 216 | template <class MockClass> | 231 | template <class MockClass> |
| @@ -251,7 +266,8 @@ class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock | |||
| 251 | } | 266 | } |
| 252 | 267 | ||
| 253 | private: | 268 | private: |
| 254 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); | 269 | + StrictMock(const StrictMock&) = delete; |
| 270 | + StrictMock& operator=(const StrictMock&) = delete; | ||
| 255 | }; | 271 | }; |
| 256 | 272 | ||
| 257 | 273 | ||
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements the ON_CALL() and EXPECT_CALL() macros. | 32 | // This file implements the ON_CALL() and EXPECT_CALL() macros. |
| @@ -56,20 +55,24 @@ | |||
| 56 | // where all clauses are optional, and .InSequence()/.After()/ | 55 | // where all clauses are optional, and .InSequence()/.After()/ |
| 57 | // .WillOnce() can appear any number of times. | 56 | // .WillOnce() can appear any number of times. |
| 58 | 57 | ||
| 59 | -// GOOGLETEST_CM0002 DO NOT DELETE | 58 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 59 | +// IWYU pragma: friend gmock/.* | ||
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | + | ||
| 64 | 65 | ||
| 65 | 66 | ||
| 66 | 67 | ||
| 68 | + | ||
| 67 | 69 | ||
| 68 | 70 | ||
| 69 | 71 | ||
| 70 | 72 | ||
| 71 | 73 | ||
| 72 | 74 | ||
| 75 | + | ||
| 73 | 76 | ||
| 74 | 77 | ||
| 75 | 78 | ||
| @@ -78,7 +81,7 @@ | |||
| 78 | 81 | ||
| 79 | 82 | ||
| 80 | 83 | ||
| 81 | -# include <stdexcept> // NOLINT | 84 | +#include <stdexcept> // NOLINT |
| 82 | 85 | ||
| 83 | 86 | ||
| 84 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | 87 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ |
| @@ -97,13 +100,15 @@ class ExpectationSet; | |||
| 97 | namespace internal { | 100 | namespace internal { |
| 98 | 101 | ||
| 99 | // Implements a mock function. | 102 | // Implements a mock function. |
| 100 | -template <typename F> class FunctionMocker; | 103 | +template <typename F> |
| 104 | +class FunctionMocker; | ||
| 101 | 105 | ||
| 102 | // Base class for expectations. | 106 | // Base class for expectations. |
| 103 | class ExpectationBase; | 107 | class ExpectationBase; |
| 104 | 108 | ||
| 105 | // Implements an expectation. | 109 | // Implements an expectation. |
| 106 | -template <typename F> class TypedExpectation; | 110 | +template <typename F> |
| 111 | +class TypedExpectation; | ||
| 107 | 112 | ||
| 108 | // Helper class for testing the Expectation class template. | 113 | // Helper class for testing the Expectation class template. |
| 109 | class ExpectationTester; | 114 | class ExpectationTester; |
| @@ -129,9 +134,6 @@ class NaggyMockImpl; | |||
| 129 | // calls to ensure the integrity of the mock objects' states. | 134 | // calls to ensure the integrity of the mock objects' states. |
| 130 | GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); | 135 | GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); |
| 131 | 136 | ||
| 132 | -// Untyped base class for ActionResultHolder<R>. | ||
| 133 | -class UntypedActionResultHolderBase; | ||
| 134 | - | ||
| 135 | // Abstract base class of FunctionMocker. This is the | 137 | // Abstract base class of FunctionMocker. This is the |
| 136 | // type-agnostic part of the function mocker interface. Its pure | 138 | // type-agnostic part of the function mocker interface. Its pure |
| 137 | // virtual methods are implemented by FunctionMocker. | 139 | // virtual methods are implemented by FunctionMocker. |
| @@ -154,27 +156,12 @@ class GTEST_API_ UntypedFunctionMockerBase { | |||
| 154 | // responsibility to guarantee the correctness of the arguments' | 156 | // responsibility to guarantee the correctness of the arguments' |
| 155 | // types. | 157 | // types. |
| 156 | 158 | ||
| 157 | - // Performs the default action with the given arguments and returns | ||
| 158 | - // the action's result. The call description string will be used in | ||
| 159 | - // the error message to describe the call in the case the default | ||
| 160 | - // action fails. | ||
| 161 | - // L = * | ||
| 162 | - virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( | ||
| 163 | - void* untyped_args, const std::string& call_description) const = 0; | ||
| 164 | - | ||
| 165 | - // Performs the given action with the given arguments and returns | ||
| 166 | - // the action's result. | ||
| 167 | - // L = * | ||
| 168 | - virtual UntypedActionResultHolderBase* UntypedPerformAction( | ||
| 169 | - const void* untyped_action, void* untyped_args) const = 0; | ||
| 170 | - | ||
| 171 | // Writes a message that the call is uninteresting (i.e. neither | 159 | // Writes a message that the call is uninteresting (i.e. neither |
| 172 | // explicitly expected nor explicitly unexpected) to the given | 160 | // explicitly expected nor explicitly unexpected) to the given |
| 173 | // ostream. | 161 | // ostream. |
| 174 | - virtual void UntypedDescribeUninterestingCall( | 162 | + virtual void UntypedDescribeUninterestingCall(const void* untyped_args, |
| 175 | - const void* untyped_args, | 163 | + ::std::ostream* os) const |
| 176 | - ::std::ostream* os) const | 164 | + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; |
| 177 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; | ||
| 178 | 165 | ||
| 179 | // Returns the expectation that matches the given function arguments | 166 | // Returns the expectation that matches the given function arguments |
| 180 | // (or NULL is there's no match); when a match is found, | 167 | // (or NULL is there's no match); when a match is found, |
| @@ -183,10 +170,9 @@ class GTEST_API_ UntypedFunctionMockerBase { | |||
| 183 | // is_excessive is modified to indicate whether the call exceeds the | 170 | // is_excessive is modified to indicate whether the call exceeds the |
| 184 | // expected number. | 171 | // expected number. |
| 185 | virtual const ExpectationBase* UntypedFindMatchingExpectation( | 172 | virtual const ExpectationBase* UntypedFindMatchingExpectation( |
| 186 | - const void* untyped_args, | 173 | + const void* untyped_args, const void** untyped_action, bool* is_excessive, |
| 187 | - const void** untyped_action, bool* is_excessive, | ||
| 188 | ::std::ostream* what, ::std::ostream* why) | 174 | ::std::ostream* what, ::std::ostream* why) |
| 189 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; | 175 | + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; |
| 190 | 176 | ||
| 191 | // Prints the given function arguments to the ostream. | 177 | // Prints the given function arguments to the ostream. |
| 192 | virtual void UntypedPrintArgs(const void* untyped_args, | 178 | virtual void UntypedPrintArgs(const void* untyped_args, |
| @@ -196,8 +182,7 @@ class GTEST_API_ UntypedFunctionMockerBase { | |||
| 196 | // this information in the global mock registry. Will be called | 182 | // this information in the global mock registry. Will be called |
| 197 | // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock | 183 | // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock |
| 198 | // method. | 184 | // method. |
| 199 | - void RegisterOwner(const void* mock_obj) | 185 | + void RegisterOwner(const void* mock_obj) GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 200 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); | ||
| 201 | 186 | ||
| 202 | // Sets the mock object this mock method belongs to, and sets the | 187 | // Sets the mock object this mock method belongs to, and sets the |
| 203 | // name of the mock function. Will be called upon each invocation | 188 | // name of the mock function. Will be called upon each invocation |
| @@ -208,20 +193,11 @@ class GTEST_API_ UntypedFunctionMockerBase { | |||
| 208 | // Returns the mock object this mock method belongs to. Must be | 193 | // Returns the mock object this mock method belongs to. Must be |
| 209 | // called after RegisterOwner() or SetOwnerAndName() has been | 194 | // called after RegisterOwner() or SetOwnerAndName() has been |
| 210 | // called. | 195 | // called. |
| 211 | - const void* MockObject() const | 196 | + const void* MockObject() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 212 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); | ||
| 213 | 197 | ||
| 214 | // Returns the name of this mock method. Must be called after | 198 | // Returns the name of this mock method. Must be called after |
| 215 | // SetOwnerAndName() has been called. | 199 | // SetOwnerAndName() has been called. |
| 216 | - const char* Name() const | 200 | + const char* Name() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 217 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); | ||
| 218 | - | ||
| 219 | - // Returns the result of invoking this mock function with the given | ||
| 220 | - // arguments. This function can be safely called from multiple | ||
| 221 | - // threads concurrently. The caller is responsible for deleting the | ||
| 222 | - // result. | ||
| 223 | - UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args) | ||
| 224 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); | ||
| 225 | 201 | ||
| 226 | protected: | 202 | protected: |
| 227 | typedef std::vector<const void*> UntypedOnCallSpecs; | 203 | typedef std::vector<const void*> UntypedOnCallSpecs; |
| @@ -430,29 +406,28 @@ class GTEST_API_ Mock { | |||
| 430 | 406 | ||
| 431 | // Tells Google Mock to allow uninteresting calls on the given mock | 407 | // Tells Google Mock to allow uninteresting calls on the given mock |
| 432 | // object. | 408 | // object. |
| 433 | - static void AllowUninterestingCalls(const void* mock_obj) | 409 | + static void AllowUninterestingCalls(uintptr_t mock_obj) |
| 434 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | 410 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 435 | 411 | ||
| 436 | // Tells Google Mock to warn the user about uninteresting calls on | 412 | // Tells Google Mock to warn the user about uninteresting calls on |
| 437 | // the given mock object. | 413 | // the given mock object. |
| 438 | - static void WarnUninterestingCalls(const void* mock_obj) | 414 | + static void WarnUninterestingCalls(uintptr_t mock_obj) |
| 439 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | 415 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 440 | 416 | ||
| 441 | // Tells Google Mock to fail uninteresting calls on the given mock | 417 | // Tells Google Mock to fail uninteresting calls on the given mock |
| 442 | // object. | 418 | // object. |
| 443 | - static void FailUninterestingCalls(const void* mock_obj) | 419 | + static void FailUninterestingCalls(uintptr_t mock_obj) |
| 444 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | 420 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 445 | 421 | ||
| 446 | // Tells Google Mock the given mock object is being destroyed and | 422 | // Tells Google Mock the given mock object is being destroyed and |
| 447 | // its entry in the call-reaction table should be removed. | 423 | // its entry in the call-reaction table should be removed. |
| 448 | - static void UnregisterCallReaction(const void* mock_obj) | 424 | + static void UnregisterCallReaction(uintptr_t mock_obj) |
| 449 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | 425 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 450 | 426 | ||
| 451 | // Returns the reaction Google Mock will have on uninteresting calls | 427 | // Returns the reaction Google Mock will have on uninteresting calls |
| 452 | // made on the given mock object. | 428 | // made on the given mock object. |
| 453 | static internal::CallReaction GetReactionOnUninterestingCalls( | 429 | static internal::CallReaction GetReactionOnUninterestingCalls( |
| 454 | - const void* mock_obj) | 430 | + const void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 455 | - GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | ||
| 456 | 431 | ||
| 457 | // Verifies that all expectations on the given mock object have been | 432 | // Verifies that all expectations on the given mock object have been |
| 458 | // satisfied. Reports one or more Google Test non-fatal failures | 433 | // satisfied. Reports one or more Google Test non-fatal failures |
| @@ -465,17 +440,16 @@ class GTEST_API_ Mock { | |||
| 465 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); | 440 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); |
| 466 | 441 | ||
| 467 | // Registers a mock object and a mock method it owns. | 442 | // Registers a mock object and a mock method it owns. |
| 468 | - static void Register( | 443 | + static void Register(const void* mock_obj, |
| 469 | - const void* mock_obj, | 444 | + internal::UntypedFunctionMockerBase* mocker) |
| 470 | - internal::UntypedFunctionMockerBase* mocker) | 445 | + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 471 | - GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | ||
| 472 | 446 | ||
| 473 | // Tells Google Mock where in the source code mock_obj is used in an | 447 | // Tells Google Mock where in the source code mock_obj is used in an |
| 474 | // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this | 448 | // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this |
| 475 | // information helps the user identify which object it is. | 449 | // information helps the user identify which object it is. |
| 476 | - static void RegisterUseByOnCallOrExpectCall( | 450 | + static void RegisterUseByOnCallOrExpectCall(const void* mock_obj, |
| 477 | - const void* mock_obj, const char* file, int line) | 451 | + const char* file, int line) |
| 478 | - GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); | 452 | + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 479 | 453 | ||
| 480 | // Unregisters a mock method; removes the owning mock object from | 454 | // Unregisters a mock method; removes the owning mock object from |
| 481 | // the registry when the last mock method associated with it has | 455 | // the registry when the last mock method associated with it has |
| @@ -632,7 +606,6 @@ class ExpectationSet { | |||
| 632 | Expectation::Set expectations_; | 606 | Expectation::Set expectations_; |
| 633 | }; | 607 | }; |
| 634 | 608 | ||
| 635 | - | ||
| 636 | // Sequence objects are used by a user to specify the relative order | 609 | // Sequence objects are used by a user to specify the relative order |
| 637 | // in which the expectations should match. They are copyable (we rely | 610 | // in which the expectations should match. They are copyable (we rely |
| 638 | // on the compiler-defined copy constructor and assignment operator). | 611 | // on the compiler-defined copy constructor and assignment operator). |
| @@ -678,11 +651,13 @@ class GTEST_API_ InSequence { | |||
| 678 | public: | 651 | public: |
| 679 | InSequence(); | 652 | InSequence(); |
| 680 | ~InSequence(); | 653 | ~InSequence(); |
| 654 | + | ||
| 681 | private: | 655 | private: |
| 682 | bool sequence_created_; | 656 | bool sequence_created_; |
| 683 | 657 | ||
| 684 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT | 658 | + InSequence(const InSequence&) = delete; |
| 685 | -} GTEST_ATTRIBUTE_UNUSED_; | 659 | + InSequence& operator=(const InSequence&) = delete; |
| 660 | +}; | ||
| 686 | 661 | ||
| 687 | namespace internal { | 662 | namespace internal { |
| 688 | 663 | ||
| @@ -732,6 +707,12 @@ class GTEST_API_ ExpectationBase { | |||
| 732 | // describes it to the ostream. | 707 | // describes it to the ostream. |
| 733 | virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; | 708 | virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; |
| 734 | 709 | ||
| 710 | + // Do not rely on this for correctness. | ||
| 711 | + // This is only for making human-readable test output easier to understand. | ||
| 712 | + void UntypedDescription(std::string description) { | ||
| 713 | + description_ = std::move(description); | ||
| 714 | + } | ||
| 715 | + | ||
| 735 | protected: | 716 | protected: |
| 736 | friend class ::testing::Expectation; | 717 | friend class ::testing::Expectation; |
| 737 | friend class UntypedFunctionMockerBase; | 718 | friend class UntypedFunctionMockerBase; |
| @@ -784,40 +765,38 @@ class GTEST_API_ ExpectationBase { | |||
| 784 | // the current thread. | 765 | // the current thread. |
| 785 | 766 | ||
| 786 | // Retires all pre-requisites of this expectation. | 767 | // Retires all pre-requisites of this expectation. |
| 787 | - void RetireAllPreRequisites() | 768 | + void RetireAllPreRequisites() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 788 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); | ||
| 789 | 769 | ||
| 790 | // Returns true if and only if this expectation is retired. | 770 | // Returns true if and only if this expectation is retired. |
| 791 | - bool is_retired() const | 771 | + bool is_retired() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 792 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 793 | g_gmock_mutex.AssertHeld(); | 772 | g_gmock_mutex.AssertHeld(); |
| 794 | return retired_; | 773 | return retired_; |
| 795 | } | 774 | } |
| 796 | 775 | ||
| 797 | // Retires this expectation. | 776 | // Retires this expectation. |
| 798 | - void Retire() | 777 | + void Retire() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 799 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 800 | g_gmock_mutex.AssertHeld(); | 778 | g_gmock_mutex.AssertHeld(); |
| 801 | retired_ = true; | 779 | retired_ = true; |
| 802 | } | 780 | } |
| 803 | 781 | ||
| 782 | + // Returns a human-readable description of this expectation. | ||
| 783 | + // Do not rely on this for correctness. It is only for human readability. | ||
| 784 | + const std::string& GetDescription() const { return description_; } | ||
| 785 | + | ||
| 804 | // Returns true if and only if this expectation is satisfied. | 786 | // Returns true if and only if this expectation is satisfied. |
| 805 | - bool IsSatisfied() const | 787 | + bool IsSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 806 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 807 | g_gmock_mutex.AssertHeld(); | 788 | g_gmock_mutex.AssertHeld(); |
| 808 | return cardinality().IsSatisfiedByCallCount(call_count_); | 789 | return cardinality().IsSatisfiedByCallCount(call_count_); |
| 809 | } | 790 | } |
| 810 | 791 | ||
| 811 | // Returns true if and only if this expectation is saturated. | 792 | // Returns true if and only if this expectation is saturated. |
| 812 | - bool IsSaturated() const | 793 | + bool IsSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 813 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 814 | g_gmock_mutex.AssertHeld(); | 794 | g_gmock_mutex.AssertHeld(); |
| 815 | return cardinality().IsSaturatedByCallCount(call_count_); | 795 | return cardinality().IsSaturatedByCallCount(call_count_); |
| 816 | } | 796 | } |
| 817 | 797 | ||
| 818 | // Returns true if and only if this expectation is over-saturated. | 798 | // Returns true if and only if this expectation is over-saturated. |
| 819 | - bool IsOverSaturated() const | 799 | + bool IsOverSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 820 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 821 | g_gmock_mutex.AssertHeld(); | 800 | g_gmock_mutex.AssertHeld(); |
| 822 | return cardinality().IsOverSaturatedByCallCount(call_count_); | 801 | return cardinality().IsOverSaturatedByCallCount(call_count_); |
| 823 | } | 802 | } |
| @@ -832,15 +811,13 @@ class GTEST_API_ ExpectationBase { | |||
| 832 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); | 811 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 833 | 812 | ||
| 834 | // Returns the number this expectation has been invoked. | 813 | // Returns the number this expectation has been invoked. |
| 835 | - int call_count() const | 814 | + int call_count() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 836 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 837 | g_gmock_mutex.AssertHeld(); | 815 | g_gmock_mutex.AssertHeld(); |
| 838 | return call_count_; | 816 | return call_count_; |
| 839 | } | 817 | } |
| 840 | 818 | ||
| 841 | // Increments the number this expectation has been invoked. | 819 | // Increments the number this expectation has been invoked. |
| 842 | - void IncrementCallCount() | 820 | + void IncrementCallCount() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 843 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 844 | g_gmock_mutex.AssertHeld(); | 821 | g_gmock_mutex.AssertHeld(); |
| 845 | call_count_++; | 822 | call_count_++; |
| 846 | } | 823 | } |
| @@ -849,8 +826,7 @@ class GTEST_API_ ExpectationBase { | |||
| 849 | // WillRepeatedly() clauses) against the cardinality if this hasn't | 826 | // WillRepeatedly() clauses) against the cardinality if this hasn't |
| 850 | // been done before. Prints a warning if there are too many or too | 827 | // been done before. Prints a warning if there are too many or too |
| 851 | // few actions. | 828 | // few actions. |
| 852 | - void CheckActionCountIfNotDone() const | 829 | + void CheckActionCountIfNotDone() const GTEST_LOCK_EXCLUDED_(mutex_); |
| 853 | - GTEST_LOCK_EXCLUDED_(mutex_); | ||
| 854 | 830 | ||
| 855 | friend class ::testing::Sequence; | 831 | friend class ::testing::Sequence; |
| 856 | friend class ::testing::internal::ExpectationTester; | 832 | friend class ::testing::internal::ExpectationTester; |
| @@ -863,12 +839,13 @@ class GTEST_API_ ExpectationBase { | |||
| 863 | 839 | ||
| 864 | // This group of fields are part of the spec and won't change after | 840 | // This group of fields are part of the spec and won't change after |
| 865 | // an EXPECT_CALL() statement finishes. | 841 | // an EXPECT_CALL() statement finishes. |
| 866 | - const char* file_; // The file that contains the expectation. | 842 | + const char* file_; // The file that contains the expectation. |
| 867 | - int line_; // The line number of the expectation. | 843 | + int line_; // The line number of the expectation. |
| 868 | const std::string source_text_; // The EXPECT_CALL(...) source text. | 844 | const std::string source_text_; // The EXPECT_CALL(...) source text. |
| 845 | + std::string description_; // User-readable name for the expectation. | ||
| 869 | // True if and only if the cardinality is specified explicitly. | 846 | // True if and only if the cardinality is specified explicitly. |
| 870 | bool cardinality_specified_; | 847 | bool cardinality_specified_; |
| 871 | - Cardinality cardinality_; // The cardinality of the expectation. | 848 | + Cardinality cardinality_; // The cardinality of the expectation. |
| 872 | // The immediate pre-requisites (i.e. expectations that must be | 849 | // The immediate pre-requisites (i.e. expectations that must be |
| 873 | // satisfied before this expectation can be matched) of this | 850 | // satisfied before this expectation can be matched) of this |
| 874 | // expectation. We use std::shared_ptr in the set because we want an | 851 | // expectation. We use std::shared_ptr in the set because we want an |
| @@ -887,12 +864,18 @@ class GTEST_API_ ExpectationBase { | |||
| 887 | bool retires_on_saturation_; | 864 | bool retires_on_saturation_; |
| 888 | Clause last_clause_; | 865 | Clause last_clause_; |
| 889 | mutable bool action_count_checked_; // Under mutex_. | 866 | mutable bool action_count_checked_; // Under mutex_. |
| 890 | - mutable Mutex mutex_; // Protects action_count_checked_. | 867 | + mutable Mutex mutex_; // Protects action_count_checked_. |
| 891 | -}; // class ExpectationBase | 868 | +}; // class ExpectationBase |
| 892 | 869 | ||
| 893 | -// Impements an expectation for the given function type. | ||
| 894 | template <typename F> | 870 | template <typename F> |
| 895 | -class TypedExpectation : public ExpectationBase { | 871 | +class TypedExpectation; |
| 872 | + | ||
| 873 | +// Implements an expectation for the given function type. | ||
| 874 | +template <typename R, typename... Args> | ||
| 875 | +class TypedExpectation<R(Args...)> : public ExpectationBase { | ||
| 876 | + private: | ||
| 877 | + using F = R(Args...); | ||
| 878 | + | ||
| 896 | public: | 879 | public: |
| 897 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; | 880 | typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 898 | typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; | 881 | typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| @@ -938,6 +921,13 @@ class TypedExpectation : public ExpectationBase { | |||
| 938 | return *this; | 921 | return *this; |
| 939 | } | 922 | } |
| 940 | 923 | ||
| 924 | + // Do not rely on this for correctness. | ||
| 925 | + // This is only for making human-readable test output easier to understand. | ||
| 926 | + TypedExpectation& Description(std::string name) { | ||
| 927 | + ExpectationBase::UntypedDescription(std::move(name)); | ||
| 928 | + return *this; | ||
| 929 | + } | ||
| 930 | + | ||
| 941 | // Implements the .Times() clause. | 931 | // Implements the .Times() clause. |
| 942 | TypedExpectation& Times(const Cardinality& a_cardinality) { | 932 | TypedExpectation& Times(const Cardinality& a_cardinality) { |
| 943 | ExpectationBase::UntypedTimes(a_cardinality); | 933 | ExpectationBase::UntypedTimes(a_cardinality); |
| @@ -945,9 +935,7 @@ class TypedExpectation : public ExpectationBase { | |||
| 945 | } | 935 | } |
| 946 | 936 | ||
| 947 | // Implements the .Times() clause. | 937 | // Implements the .Times() clause. |
| 948 | - TypedExpectation& Times(int n) { | 938 | + TypedExpectation& Times(int n) { return Times(Exactly(n)); } |
| 949 | - return Times(Exactly(n)); | ||
| 950 | - } | ||
| 951 | 939 | ||
| 952 | // Implements the .InSequence() clause. | 940 | // Implements the .InSequence() clause. |
| 953 | TypedExpectation& InSequence(const Sequence& s) { | 941 | TypedExpectation& InSequence(const Sequence& s) { |
| @@ -1007,14 +995,31 @@ class TypedExpectation : public ExpectationBase { | |||
| 1007 | return After(s1, s2, s3, s4).After(s5); | 995 | return After(s1, s2, s3, s4).After(s5); |
| 1008 | } | 996 | } |
| 1009 | 997 | ||
| 1010 | - // Implements the .WillOnce() clause. | 998 | + // Preferred, type-safe overload: consume anything that can be directly |
| 1011 | - TypedExpectation& WillOnce(const Action<F>& action) { | 999 | + // converted to a OnceAction, except for Action<F> objects themselves. |
| 1000 | + TypedExpectation& WillOnce(OnceAction<F> once_action) { | ||
| 1001 | + // Call the overload below, smuggling the OnceAction as a copyable callable. | ||
| 1002 | + // We know this is safe because a WillOnce action will not be called more | ||
| 1003 | + // than once. | ||
| 1004 | + return WillOnce(Action<F>(ActionAdaptor{ | ||
| 1005 | + std::make_shared<OnceAction<F>>(std::move(once_action)), | ||
| 1006 | + })); | ||
| 1007 | + } | ||
| 1008 | + | ||
| 1009 | + // Fallback overload: accept Action<F> objects and those actions that define | ||
| 1010 | + // `operator Action<F>` but not `operator OnceAction<F>`. | ||
| 1011 | + // | ||
| 1012 | + // This is templated in order to cause the overload above to be preferred | ||
| 1013 | + // when the input is convertible to either type. | ||
| 1014 | + template <int&... ExplicitArgumentBarrier, typename = void> | ||
| 1015 | + TypedExpectation& WillOnce(Action<F> action) { | ||
| 1012 | ExpectSpecProperty(last_clause_ <= kWillOnce, | 1016 | ExpectSpecProperty(last_clause_ <= kWillOnce, |
| 1013 | ".WillOnce() cannot appear after " | 1017 | ".WillOnce() cannot appear after " |
| 1014 | ".WillRepeatedly() or .RetiresOnSaturation()."); | 1018 | ".WillRepeatedly() or .RetiresOnSaturation()."); |
| 1015 | last_clause_ = kWillOnce; | 1019 | last_clause_ = kWillOnce; |
| 1016 | 1020 | ||
| 1017 | - untyped_actions_.push_back(new Action<F>(action)); | 1021 | + untyped_actions_.push_back(new Action<F>(std::move(action))); |
| 1022 | + | ||
| 1018 | if (!cardinality_specified()) { | 1023 | if (!cardinality_specified()) { |
| 1019 | set_cardinality(Exactly(static_cast<int>(untyped_actions_.size()))); | 1024 | set_cardinality(Exactly(static_cast<int>(untyped_actions_.size()))); |
| 1020 | } | 1025 | } |
| @@ -1062,9 +1067,7 @@ class TypedExpectation : public ExpectationBase { | |||
| 1062 | 1067 | ||
| 1063 | // Returns the matchers for the arguments as specified inside the | 1068 | // Returns the matchers for the arguments as specified inside the |
| 1064 | // EXPECT_CALL() macro. | 1069 | // EXPECT_CALL() macro. |
| 1065 | - const ArgumentMatcherTuple& matchers() const { | 1070 | + const ArgumentMatcherTuple& matchers() const { return matchers_; } |
| 1066 | - return matchers_; | ||
| 1067 | - } | ||
| 1068 | 1071 | ||
| 1069 | // Returns the matcher specified by the .With() clause. | 1072 | // Returns the matcher specified by the .With() clause. |
| 1070 | const Matcher<const ArgumentTuple&>& extra_matcher() const { | 1073 | const Matcher<const ArgumentTuple&>& extra_matcher() const { |
| @@ -1088,6 +1091,16 @@ class TypedExpectation : public ExpectationBase { | |||
| 1088 | template <typename Function> | 1091 | template <typename Function> |
| 1089 | friend class FunctionMocker; | 1092 | friend class FunctionMocker; |
| 1090 | 1093 | ||
| 1094 | + // An adaptor that turns a OneAction<F> into something compatible with | ||
| 1095 | + // Action<F>. Must be called at most once. | ||
| 1096 | + struct ActionAdaptor { | ||
| 1097 | + std::shared_ptr<OnceAction<R(Args...)>> once_action; | ||
| 1098 | + | ||
| 1099 | + R operator()(Args&&... args) const { | ||
| 1100 | + return std::move(*once_action).Call(std::forward<Args>(args)...); | ||
| 1101 | + } | ||
| 1102 | + }; | ||
| 1103 | + | ||
| 1091 | // Returns an Expectation object that references and co-owns this | 1104 | // Returns an Expectation object that references and co-owns this |
| 1092 | // expectation. | 1105 | // expectation. |
| 1093 | Expectation GetHandle() override { return owner_->GetHandleOf(this); } | 1106 | Expectation GetHandle() override { return owner_->GetHandleOf(this); } |
| @@ -1119,10 +1132,8 @@ class TypedExpectation : public ExpectationBase { | |||
| 1119 | 1132 | ||
| 1120 | // Describes the result of matching the arguments against this | 1133 | // Describes the result of matching the arguments against this |
| 1121 | // expectation to the given ostream. | 1134 | // expectation to the given ostream. |
| 1122 | - void ExplainMatchResultTo( | 1135 | + void ExplainMatchResultTo(const ArgumentTuple& args, ::std::ostream* os) const |
| 1123 | - const ArgumentTuple& args, | 1136 | + GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1124 | - ::std::ostream* os) const | ||
| 1125 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 1126 | g_gmock_mutex.AssertHeld(); | 1137 | g_gmock_mutex.AssertHeld(); |
| 1127 | 1138 | ||
| 1128 | if (is_retired()) { | 1139 | if (is_retired()) { |
| @@ -1181,9 +1192,9 @@ class TypedExpectation : public ExpectationBase { | |||
| 1181 | ::std::stringstream ss; | 1192 | ::std::stringstream ss; |
| 1182 | DescribeLocationTo(&ss); | 1193 | DescribeLocationTo(&ss); |
| 1183 | ss << "Actions ran out in " << source_text() << "...\n" | 1194 | ss << "Actions ran out in " << source_text() << "...\n" |
| 1184 | - << "Called " << count << " times, but only " | 1195 | + << "Called " << count << " times, but only " << action_count |
| 1185 | - << action_count << " WillOnce()" | 1196 | + << " WillOnce()" << (action_count == 1 ? " is" : "s are") |
| 1186 | - << (action_count == 1 ? " is" : "s are") << " specified - "; | 1197 | + << " specified - "; |
| 1187 | mocker->DescribeDefaultActionTo(args, &ss); | 1198 | mocker->DescribeDefaultActionTo(args, &ss); |
| 1188 | Log(kWarning, ss.str(), 1); | 1199 | Log(kWarning, ss.str(), 1); |
| 1189 | } | 1200 | } |
| @@ -1207,10 +1218,15 @@ class TypedExpectation : public ExpectationBase { | |||
| 1207 | ::std::ostream* why) | 1218 | ::std::ostream* why) |
| 1208 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | 1219 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1209 | g_gmock_mutex.AssertHeld(); | 1220 | g_gmock_mutex.AssertHeld(); |
| 1221 | + const ::std::string& expectation_description = GetDescription(); | ||
| 1210 | if (IsSaturated()) { | 1222 | if (IsSaturated()) { |
| 1211 | // We have an excessive call. | 1223 | // We have an excessive call. |
| 1212 | IncrementCallCount(); | 1224 | IncrementCallCount(); |
| 1213 | - *what << "Mock function called more times than expected - "; | 1225 | + *what << "Mock function "; |
| 1226 | + if (!expectation_description.empty()) { | ||
| 1227 | + *what << "\"" << expectation_description << "\" "; | ||
| 1228 | + } | ||
| 1229 | + *what << "called more times than expected - "; | ||
| 1214 | mocker->DescribeDefaultActionTo(args, what); | 1230 | mocker->DescribeDefaultActionTo(args, what); |
| 1215 | DescribeCallCountTo(why); | 1231 | DescribeCallCountTo(why); |
| 1216 | 1232 | ||
| @@ -1225,7 +1241,11 @@ class TypedExpectation : public ExpectationBase { | |||
| 1225 | } | 1241 | } |
| 1226 | 1242 | ||
| 1227 | // Must be done after IncrementCount()! | 1243 | // Must be done after IncrementCount()! |
| 1228 | - *what << "Mock function call matches " << source_text() <<"...\n"; | 1244 | + *what << "Mock function "; |
| 1245 | + if (!expectation_description.empty()) { | ||
| 1246 | + *what << "\"" << expectation_description << "\" "; | ||
| 1247 | + } | ||
| 1248 | + *what << "call matches " << source_text() << "...\n"; | ||
| 1229 | return &(GetCurrentAction(mocker, args)); | 1249 | return &(GetCurrentAction(mocker, args)); |
| 1230 | } | 1250 | } |
| 1231 | 1251 | ||
| @@ -1236,7 +1256,8 @@ class TypedExpectation : public ExpectationBase { | |||
| 1236 | Matcher<const ArgumentTuple&> extra_matcher_; | 1256 | Matcher<const ArgumentTuple&> extra_matcher_; |
| 1237 | Action<F> repeated_action_; | 1257 | Action<F> repeated_action_; |
| 1238 | 1258 | ||
| 1239 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); | 1259 | + TypedExpectation(const TypedExpectation&) = delete; |
| 1260 | + TypedExpectation& operator=(const TypedExpectation&) = delete; | ||
| 1240 | }; // class TypedExpectation | 1261 | }; // class TypedExpectation |
| 1241 | 1262 | ||
| 1242 | // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for | 1263 | // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for |
| @@ -1258,8 +1279,8 @@ template <typename F> | |||
| 1258 | class MockSpec { | 1279 | class MockSpec { |
| 1259 | public: | 1280 | public: |
| 1260 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; | 1281 | typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1261 | - typedef typename internal::Function<F>::ArgumentMatcherTuple | 1282 | + typedef |
| 1262 | - ArgumentMatcherTuple; | 1283 | + typename internal::Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 1263 | 1284 | ||
| 1264 | // Constructs a MockSpec object, given the function mocker object | 1285 | // Constructs a MockSpec object, given the function mocker object |
| 1265 | // that the spec is associated with. | 1286 | // that the spec is associated with. |
| @@ -1269,8 +1290,9 @@ class MockSpec { | |||
| 1269 | 1290 | ||
| 1270 | // Adds a new default action spec to the function mocker and returns | 1291 | // Adds a new default action spec to the function mocker and returns |
| 1271 | // the newly created spec. | 1292 | // the newly created spec. |
| 1272 | - internal::OnCallSpec<F>& InternalDefaultActionSetAt( | 1293 | + internal::OnCallSpec<F>& InternalDefaultActionSetAt(const char* file, |
| 1273 | - const char* file, int line, const char* obj, const char* call) { | 1294 | + int line, const char* obj, |
| 1295 | + const char* call) { | ||
| 1274 | LogWithLocation(internal::kInfo, file, line, | 1296 | LogWithLocation(internal::kInfo, file, line, |
| 1275 | std::string("ON_CALL(") + obj + ", " + call + ") invoked"); | 1297 | std::string("ON_CALL(") + obj + ", " + call + ") invoked"); |
| 1276 | return function_mocker_->AddNewOnCallSpec(file, line, matchers_); | 1298 | return function_mocker_->AddNewOnCallSpec(file, line, matchers_); |
| @@ -1278,13 +1300,14 @@ class MockSpec { | |||
| 1278 | 1300 | ||
| 1279 | // Adds a new expectation spec to the function mocker and returns | 1301 | // Adds a new expectation spec to the function mocker and returns |
| 1280 | // the newly created spec. | 1302 | // the newly created spec. |
| 1281 | - internal::TypedExpectation<F>& InternalExpectedAt( | 1303 | + internal::TypedExpectation<F>& InternalExpectedAt(const char* file, int line, |
| 1282 | - const char* file, int line, const char* obj, const char* call) { | 1304 | + const char* obj, |
| 1305 | + const char* call) { | ||
| 1283 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + | 1306 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + |
| 1284 | call + ")"); | 1307 | call + ")"); |
| 1285 | LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); | 1308 | LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); |
| 1286 | - return function_mocker_->AddNewExpectation( | 1309 | + return function_mocker_->AddNewExpectation(file, line, source_text, |
| 1287 | - file, line, source_text, matchers_); | 1310 | + matchers_); |
| 1288 | } | 1311 | } |
| 1289 | 1312 | ||
| 1290 | // This operator overload is used to swallow the superfluous parameter list | 1313 | // This operator overload is used to swallow the superfluous parameter list |
| @@ -1317,9 +1340,7 @@ template <typename T> | |||
| 1317 | class ReferenceOrValueWrapper { | 1340 | class ReferenceOrValueWrapper { |
| 1318 | public: | 1341 | public: |
| 1319 | // Constructs a wrapper from the given value/reference. | 1342 | // Constructs a wrapper from the given value/reference. |
| 1320 | - explicit ReferenceOrValueWrapper(T value) | 1343 | + explicit ReferenceOrValueWrapper(T value) : value_(std::move(value)) {} |
| 1321 | - : value_(std::move(value)) { | ||
| 1322 | - } | ||
| 1323 | 1344 | ||
| 1324 | // Unwraps and returns the underlying value/reference, exactly as | 1345 | // Unwraps and returns the underlying value/reference, exactly as |
| 1325 | // originally passed. The behavior of calling this more than once on | 1346 | // originally passed. The behavior of calling this more than once on |
| @@ -1330,9 +1351,7 @@ class ReferenceOrValueWrapper { | |||
| 1330 | // Always returns a const reference (more precisely, | 1351 | // Always returns a const reference (more precisely, |
| 1331 | // const std::add_lvalue_reference<T>::type). The behavior of calling this | 1352 | // const std::add_lvalue_reference<T>::type). The behavior of calling this |
| 1332 | // after calling Unwrap on the same object is unspecified. | 1353 | // after calling Unwrap on the same object is unspecified. |
| 1333 | - const T& Peek() const { | 1354 | + const T& Peek() const { return value_; } |
| 1334 | - return value_; | ||
| 1335 | - } | ||
| 1336 | 1355 | ||
| 1337 | private: | 1356 | private: |
| 1338 | T value_; | 1357 | T value_; |
| @@ -1346,8 +1365,7 @@ class ReferenceOrValueWrapper<T&> { | |||
| 1346 | // Workaround for debatable pass-by-reference lint warning (c-library-team | 1365 | // Workaround for debatable pass-by-reference lint warning (c-library-team |
| 1347 | // policy precludes NOLINT in this context) | 1366 | // policy precludes NOLINT in this context) |
| 1348 | typedef T& reference; | 1367 | typedef T& reference; |
| 1349 | - explicit ReferenceOrValueWrapper(reference ref) | 1368 | + explicit ReferenceOrValueWrapper(reference ref) : value_ptr_(&ref) {} |
| 1350 | - : value_ptr_(&ref) {} | ||
| 1351 | T& Unwrap() { return *value_ptr_; } | 1369 | T& Unwrap() { return *value_ptr_; } |
| 1352 | const T& Peek() const { return *value_ptr_; } | 1370 | const T& Peek() const { return *value_ptr_; } |
| 1353 | 1371 | ||
| @@ -1355,102 +1373,27 @@ class ReferenceOrValueWrapper<T&> { | |||
| 1355 | T* value_ptr_; | 1373 | T* value_ptr_; |
| 1356 | }; | 1374 | }; |
| 1357 | 1375 | ||
| 1358 | -// C++ treats the void type specially. For example, you cannot define | 1376 | +// Prints the held value as an action's result to os. |
| 1359 | -// a void-typed variable or pass a void value to a function. | ||
| 1360 | -// ActionResultHolder<T> holds a value of type T, where T must be a | ||
| 1361 | -// copyable type or void (T doesn't need to be default-constructable). | ||
| 1362 | -// It hides the syntactic difference between void and other types, and | ||
| 1363 | -// is used to unify the code for invoking both void-returning and | ||
| 1364 | -// non-void-returning mock functions. | ||
| 1365 | - | ||
| 1366 | -// Untyped base class for ActionResultHolder<T>. | ||
| 1367 | -class UntypedActionResultHolderBase { | ||
| 1368 | - public: | ||
| 1369 | - virtual ~UntypedActionResultHolderBase() {} | ||
| 1370 | - | ||
| 1371 | - // Prints the held value as an action's result to os. | ||
| 1372 | - virtual void PrintAsActionResult(::std::ostream* os) const = 0; | ||
| 1373 | -}; | ||
| 1374 | - | ||
| 1375 | -// This generic definition is used when T is not void. | ||
| 1376 | template <typename T> | 1377 | template <typename T> |
| 1377 | -class ActionResultHolder : public UntypedActionResultHolderBase { | 1378 | +void PrintAsActionResult(const T& result, std::ostream& os) { |
| 1379 | + os << "\n Returns: "; | ||
| 1380 | + // T may be a reference type, so we don't use UniversalPrint(). | ||
| 1381 | + UniversalPrinter<T>::Print(result, &os); | ||
| 1382 | +} | ||
| 1383 | + | ||
| 1384 | +// Reports an uninteresting call (whose description is in msg) in the | ||
| 1385 | +// manner specified by 'reaction'. | ||
| 1386 | +GTEST_API_ void ReportUninterestingCall(CallReaction reaction, | ||
| 1387 | + const std::string& msg); | ||
| 1388 | + | ||
| 1389 | +// A generic RAII type that runs a user-provided function in its destructor. | ||
| 1390 | +class Cleanup final { | ||
| 1378 | public: | 1391 | public: |
| 1379 | - // Returns the held value. Must not be called more than once. | 1392 | + explicit Cleanup(std::function<void()> f) : f_(std::move(f)) {} |
| 1380 | - T Unwrap() { | 1393 | + ~Cleanup() { f_(); } |
| 1381 | - return result_.Unwrap(); | ||
| 1382 | - } | ||
| 1383 | - | ||
| 1384 | - // Prints the held value as an action's result to os. | ||
| 1385 | - void PrintAsActionResult(::std::ostream* os) const override { | ||
| 1386 | - *os << "\n Returns: "; | ||
| 1387 | - // T may be a reference type, so we don't use UniversalPrint(). | ||
| 1388 | - UniversalPrinter<T>::Print(result_.Peek(), os); | ||
| 1389 | - } | ||
| 1390 | - | ||
| 1391 | - // Performs the given mock function's default action and returns the | ||
| 1392 | - // result in a new-ed ActionResultHolder. | ||
| 1393 | - template <typename F> | ||
| 1394 | - static ActionResultHolder* PerformDefaultAction( | ||
| 1395 | - const FunctionMocker<F>* func_mocker, | ||
| 1396 | - typename Function<F>::ArgumentTuple&& args, | ||
| 1397 | - const std::string& call_description) { | ||
| 1398 | - return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction( | ||
| 1399 | - std::move(args), call_description))); | ||
| 1400 | - } | ||
| 1401 | - | ||
| 1402 | - // Performs the given action and returns the result in a new-ed | ||
| 1403 | - // ActionResultHolder. | ||
| 1404 | - template <typename F> | ||
| 1405 | - static ActionResultHolder* PerformAction( | ||
| 1406 | - const Action<F>& action, typename Function<F>::ArgumentTuple&& args) { | ||
| 1407 | - return new ActionResultHolder( | ||
| 1408 | - Wrapper(action.Perform(std::move(args)))); | ||
| 1409 | - } | ||
| 1410 | 1394 | ||
| 1411 | private: | 1395 | private: |
| 1412 | - typedef ReferenceOrValueWrapper<T> Wrapper; | 1396 | + std::function<void()> f_; |
| 1413 | - | ||
| 1414 | - explicit ActionResultHolder(Wrapper result) | ||
| 1415 | - : result_(std::move(result)) { | ||
| 1416 | - } | ||
| 1417 | - | ||
| 1418 | - Wrapper result_; | ||
| 1419 | - | ||
| 1420 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder); | ||
| 1421 | -}; | ||
| 1422 | - | ||
| 1423 | -// Specialization for T = void. | ||
| 1424 | -template <> | ||
| 1425 | -class ActionResultHolder<void> : public UntypedActionResultHolderBase { | ||
| 1426 | - public: | ||
| 1427 | - void Unwrap() { } | ||
| 1428 | - | ||
| 1429 | - void PrintAsActionResult(::std::ostream* /* os */) const override {} | ||
| 1430 | - | ||
| 1431 | - // Performs the given mock function's default action and returns ownership | ||
| 1432 | - // of an empty ActionResultHolder*. | ||
| 1433 | - template <typename F> | ||
| 1434 | - static ActionResultHolder* PerformDefaultAction( | ||
| 1435 | - const FunctionMocker<F>* func_mocker, | ||
| 1436 | - typename Function<F>::ArgumentTuple&& args, | ||
| 1437 | - const std::string& call_description) { | ||
| 1438 | - func_mocker->PerformDefaultAction(std::move(args), call_description); | ||
| 1439 | - return new ActionResultHolder; | ||
| 1440 | - } | ||
| 1441 | - | ||
| 1442 | - // Performs the given action and returns ownership of an empty | ||
| 1443 | - // ActionResultHolder*. | ||
| 1444 | - template <typename F> | ||
| 1445 | - static ActionResultHolder* PerformAction( | ||
| 1446 | - const Action<F>& action, typename Function<F>::ArgumentTuple&& args) { | ||
| 1447 | - action.Perform(std::move(args)); | ||
| 1448 | - return new ActionResultHolder; | ||
| 1449 | - } | ||
| 1450 | - | ||
| 1451 | - private: | ||
| 1452 | - ActionResultHolder() {} | ||
| 1453 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder); | ||
| 1454 | }; | 1397 | }; |
| 1455 | 1398 | ||
| 1456 | template <typename F> | 1399 | template <typename F> |
| @@ -1495,14 +1438,12 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1495 | // Returns the ON_CALL spec that matches this mock function with the | 1438 | // Returns the ON_CALL spec that matches this mock function with the |
| 1496 | // given arguments; returns NULL if no matching ON_CALL is found. | 1439 | // given arguments; returns NULL if no matching ON_CALL is found. |
| 1497 | // L = * | 1440 | // L = * |
| 1498 | - const OnCallSpec<F>* FindOnCallSpec( | 1441 | + const OnCallSpec<F>* FindOnCallSpec(const ArgumentTuple& args) const { |
| 1499 | - const ArgumentTuple& args) const { | 1442 | + for (UntypedOnCallSpecs::const_reverse_iterator it = |
| 1500 | - for (UntypedOnCallSpecs::const_reverse_iterator it | 1443 | + untyped_on_call_specs_.rbegin(); |
| 1501 | - = untyped_on_call_specs_.rbegin(); | ||
| 1502 | it != untyped_on_call_specs_.rend(); ++it) { | 1444 | it != untyped_on_call_specs_.rend(); ++it) { |
| 1503 | const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it); | 1445 | const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it); |
| 1504 | - if (spec->Matches(args)) | 1446 | + if (spec->Matches(args)) return spec; |
| 1505 | - return spec; | ||
| 1506 | } | 1447 | } |
| 1507 | 1448 | ||
| 1508 | return nullptr; | 1449 | return nullptr; |
| @@ -1510,15 +1451,14 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1510 | 1451 | ||
| 1511 | // Performs the default action of this mock function on the given | 1452 | // Performs the default action of this mock function on the given |
| 1512 | // arguments and returns the result. Asserts (or throws if | 1453 | // arguments and returns the result. Asserts (or throws if |
| 1513 | - // exceptions are enabled) with a helpful call descrption if there | 1454 | + // exceptions are enabled) with a helpful call description if there |
| 1514 | // is no valid return value. This method doesn't depend on the | 1455 | // is no valid return value. This method doesn't depend on the |
| 1515 | // mutable state of this object, and thus can be called concurrently | 1456 | // mutable state of this object, and thus can be called concurrently |
| 1516 | // without locking. | 1457 | // without locking. |
| 1517 | // L = * | 1458 | // L = * |
| 1518 | Result PerformDefaultAction(ArgumentTuple&& args, | 1459 | Result PerformDefaultAction(ArgumentTuple&& args, |
| 1519 | const std::string& call_description) const { | 1460 | const std::string& call_description) const { |
| 1520 | - const OnCallSpec<F>* const spec = | 1461 | + const OnCallSpec<F>* const spec = this->FindOnCallSpec(args); |
| 1521 | - this->FindOnCallSpec(args); | ||
| 1522 | if (spec != nullptr) { | 1462 | if (spec != nullptr) { |
| 1523 | return spec->GetAction().Perform(std::move(args)); | 1463 | return spec->GetAction().Perform(std::move(args)); |
| 1524 | } | 1464 | } |
| @@ -1536,32 +1476,6 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1536 | return DefaultValue<Result>::Get(); | 1476 | return DefaultValue<Result>::Get(); |
| 1537 | } | 1477 | } |
| 1538 | 1478 | ||
| 1539 | - // Performs the default action with the given arguments and returns | ||
| 1540 | - // the action's result. The call description string will be used in | ||
| 1541 | - // the error message to describe the call in the case the default | ||
| 1542 | - // action fails. The caller is responsible for deleting the result. | ||
| 1543 | - // L = * | ||
| 1544 | - UntypedActionResultHolderBase* UntypedPerformDefaultAction( | ||
| 1545 | - void* untyped_args, // must point to an ArgumentTuple | ||
| 1546 | - const std::string& call_description) const override { | ||
| 1547 | - ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); | ||
| 1548 | - return ResultHolder::PerformDefaultAction(this, std::move(*args), | ||
| 1549 | - call_description); | ||
| 1550 | - } | ||
| 1551 | - | ||
| 1552 | - // Performs the given action with the given arguments and returns | ||
| 1553 | - // the action's result. The caller is responsible for deleting the | ||
| 1554 | - // result. | ||
| 1555 | - // L = * | ||
| 1556 | - UntypedActionResultHolderBase* UntypedPerformAction( | ||
| 1557 | - const void* untyped_action, void* untyped_args) const override { | ||
| 1558 | - // Make a copy of the action before performing it, in case the | ||
| 1559 | - // action deletes the mock object (and thus deletes itself). | ||
| 1560 | - const Action<F> action = *static_cast<const Action<F>*>(untyped_action); | ||
| 1561 | - ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); | ||
| 1562 | - return ResultHolder::PerformAction(action, std::move(*args)); | ||
| 1563 | - } | ||
| 1564 | - | ||
| 1565 | // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): | 1479 | // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): |
| 1566 | // clears the ON_CALL()s set on this mock function. | 1480 | // clears the ON_CALL()s set on this mock function. |
| 1567 | void ClearDefaultActionsLocked() override | 1481 | void ClearDefaultActionsLocked() override |
| @@ -1579,8 +1493,7 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1579 | untyped_on_call_specs_.swap(specs_to_delete); | 1493 | untyped_on_call_specs_.swap(specs_to_delete); |
| 1580 | 1494 | ||
| 1581 | g_gmock_mutex.Unlock(); | 1495 | g_gmock_mutex.Unlock(); |
| 1582 | - for (UntypedOnCallSpecs::const_iterator it = | 1496 | + for (UntypedOnCallSpecs::const_iterator it = specs_to_delete.begin(); |
| 1583 | - specs_to_delete.begin(); | ||
| 1584 | it != specs_to_delete.end(); ++it) { | 1497 | it != specs_to_delete.end(); ++it) { |
| 1585 | delete static_cast<const OnCallSpec<F>*>(*it); | 1498 | delete static_cast<const OnCallSpec<F>*>(*it); |
| 1586 | } | 1499 | } |
| @@ -1594,10 +1507,7 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1594 | // arguments. This function can be safely called from multiple | 1507 | // arguments. This function can be safely called from multiple |
| 1595 | // threads concurrently. | 1508 | // threads concurrently. |
| 1596 | Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { | 1509 | Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1597 | - ArgumentTuple tuple(std::forward<Args>(args)...); | 1510 | + return InvokeWith(ArgumentTuple(std::forward<Args>(args)...)); |
| 1598 | - std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>( | ||
| 1599 | - this->UntypedInvokeWith(static_cast<void*>(&tuple)))); | ||
| 1600 | - return holder->Unwrap(); | ||
| 1601 | } | 1511 | } |
| 1602 | 1512 | ||
| 1603 | MockSpec<F> With(Matcher<Args>... m) { | 1513 | MockSpec<F> With(Matcher<Args>... m) { |
| @@ -1608,13 +1518,10 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1608 | template <typename Function> | 1518 | template <typename Function> |
| 1609 | friend class MockSpec; | 1519 | friend class MockSpec; |
| 1610 | 1520 | ||
| 1611 | - typedef ActionResultHolder<Result> ResultHolder; | ||
| 1612 | - | ||
| 1613 | // Adds and returns a default action spec for this mock function. | 1521 | // Adds and returns a default action spec for this mock function. |
| 1614 | - OnCallSpec<F>& AddNewOnCallSpec( | 1522 | + OnCallSpec<F>& AddNewOnCallSpec(const char* file, int line, |
| 1615 | - const char* file, int line, | 1523 | + const ArgumentMatcherTuple& m) |
| 1616 | - const ArgumentMatcherTuple& m) | 1524 | + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1617 | - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { | ||
| 1618 | Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); | 1525 | Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); |
| 1619 | OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m); | 1526 | OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m); |
| 1620 | untyped_on_call_specs_.push_back(on_call_spec); | 1527 | untyped_on_call_specs_.push_back(on_call_spec); |
| @@ -1644,7 +1551,8 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1644 | } | 1551 | } |
| 1645 | 1552 | ||
| 1646 | private: | 1553 | private: |
| 1647 | - template <typename Func> friend class TypedExpectation; | 1554 | + template <typename Func> |
| 1555 | + friend class TypedExpectation; | ||
| 1648 | 1556 | ||
| 1649 | // Some utilities needed for implementing UntypedInvokeWith(). | 1557 | // Some utilities needed for implementing UntypedInvokeWith(). |
| 1650 | 1558 | ||
| @@ -1728,9 +1636,8 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1728 | 1636 | ||
| 1729 | // Returns the expectation that matches the arguments, or NULL if no | 1637 | // Returns the expectation that matches the arguments, or NULL if no |
| 1730 | // expectation matches them. | 1638 | // expectation matches them. |
| 1731 | - TypedExpectation<F>* FindMatchingExpectationLocked( | 1639 | + TypedExpectation<F>* FindMatchingExpectationLocked(const ArgumentTuple& args) |
| 1732 | - const ArgumentTuple& args) const | 1640 | + const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1733 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 1734 | g_gmock_mutex.AssertHeld(); | 1641 | g_gmock_mutex.AssertHeld(); |
| 1735 | // See the definition of untyped_expectations_ for why access to | 1642 | // See the definition of untyped_expectations_ for why access to |
| 1736 | // it is unprotected here. | 1643 | // it is unprotected here. |
| @@ -1747,11 +1654,10 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1747 | } | 1654 | } |
| 1748 | 1655 | ||
| 1749 | // Returns a message that the arguments don't match any expectation. | 1656 | // Returns a message that the arguments don't match any expectation. |
| 1750 | - void FormatUnexpectedCallMessageLocked( | 1657 | + void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args, |
| 1751 | - const ArgumentTuple& args, | 1658 | + ::std::ostream* os, |
| 1752 | - ::std::ostream* os, | 1659 | + ::std::ostream* why) const |
| 1753 | - ::std::ostream* why) const | 1660 | + GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1754 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 1755 | g_gmock_mutex.AssertHeld(); | 1661 | g_gmock_mutex.AssertHeld(); |
| 1756 | *os << "\nUnexpected mock function call - "; | 1662 | *os << "\nUnexpected mock function call - "; |
| 1757 | DescribeDefaultActionTo(args, os); | 1663 | DescribeDefaultActionTo(args, os); |
| @@ -1760,15 +1666,14 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1760 | 1666 | ||
| 1761 | // Prints a list of expectations that have been tried against the | 1667 | // Prints a list of expectations that have been tried against the |
| 1762 | // current mock function call. | 1668 | // current mock function call. |
| 1763 | - void PrintTriedExpectationsLocked( | 1669 | + void PrintTriedExpectationsLocked(const ArgumentTuple& args, |
| 1764 | - const ArgumentTuple& args, | 1670 | + ::std::ostream* why) const |
| 1765 | - ::std::ostream* why) const | 1671 | + GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1766 | - GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | ||
| 1767 | g_gmock_mutex.AssertHeld(); | 1672 | g_gmock_mutex.AssertHeld(); |
| 1768 | const size_t count = untyped_expectations_.size(); | 1673 | const size_t count = untyped_expectations_.size(); |
| 1769 | *why << "Google Mock tried the following " << count << " " | 1674 | *why << "Google Mock tried the following " << count << " " |
| 1770 | - << (count == 1 ? "expectation, but it didn't match" : | 1675 | + << (count == 1 ? "expectation, but it didn't match" |
| 1771 | - "expectations, but none matched") | 1676 | + : "expectations, but none matched") |
| 1772 | << ":\n"; | 1677 | << ":\n"; |
| 1773 | for (size_t i = 0; i < count; i++) { | 1678 | for (size_t i = 0; i < count; i++) { |
| 1774 | TypedExpectation<F>* const expectation = | 1679 | TypedExpectation<F>* const expectation = |
| @@ -1783,11 +1688,177 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { | |||
| 1783 | expectation->DescribeCallCountTo(why); | 1688 | expectation->DescribeCallCountTo(why); |
| 1784 | } | 1689 | } |
| 1785 | } | 1690 | } |
| 1691 | + | ||
| 1692 | + // Performs the given action (or the default if it's null) with the given | ||
| 1693 | + // arguments and returns the action's result. | ||
| 1694 | + // L = * | ||
| 1695 | + R PerformAction(const void* untyped_action, ArgumentTuple&& args, | ||
| 1696 | + const std::string& call_description) const { | ||
| 1697 | + if (untyped_action == nullptr) { | ||
| 1698 | + return PerformDefaultAction(std::move(args), call_description); | ||
| 1699 | + } | ||
| 1700 | + | ||
| 1701 | + // Make a copy of the action before performing it, in case the | ||
| 1702 | + // action deletes the mock object (and thus deletes itself). | ||
| 1703 | + const Action<F> action = *static_cast<const Action<F>*>(untyped_action); | ||
| 1704 | + return action.Perform(std::move(args)); | ||
| 1705 | + } | ||
| 1706 | + | ||
| 1707 | + // Is it possible to store an object of the supplied type in a local variable | ||
| 1708 | + // for the sake of printing it, then return it on to the caller? | ||
| 1709 | + template <typename T> | ||
| 1710 | + using can_print_result = internal::conjunction< | ||
| 1711 | + // void can't be stored as an object (and we also don't need to print it). | ||
| 1712 | + internal::negation<std::is_void<T>>, | ||
| 1713 | + // Non-moveable types can't be returned on to the user, so there's no way | ||
| 1714 | + // for us to intercept and print them. | ||
| 1715 | + std::is_move_constructible<T>>; | ||
| 1716 | + | ||
| 1717 | + // Perform the supplied action, printing the result to os. | ||
| 1718 | + template <typename T = R, | ||
| 1719 | + typename std::enable_if<can_print_result<T>::value, int>::type = 0> | ||
| 1720 | + R PerformActionAndPrintResult(const void* const untyped_action, | ||
| 1721 | + ArgumentTuple&& args, | ||
| 1722 | + const std::string& call_description, | ||
| 1723 | + std::ostream& os) { | ||
| 1724 | + R result = PerformAction(untyped_action, std::move(args), call_description); | ||
| 1725 | + | ||
| 1726 | + PrintAsActionResult(result, os); | ||
| 1727 | + return std::forward<R>(result); | ||
| 1728 | + } | ||
| 1729 | + | ||
| 1730 | + // An overload for when it's not possible to print the result. In this case we | ||
| 1731 | + // simply perform the action. | ||
| 1732 | + template <typename T = R, | ||
| 1733 | + typename std::enable_if< | ||
| 1734 | + internal::negation<can_print_result<T>>::value, int>::type = 0> | ||
| 1735 | + R PerformActionAndPrintResult(const void* const untyped_action, | ||
| 1736 | + ArgumentTuple&& args, | ||
| 1737 | + const std::string& call_description, | ||
| 1738 | + std::ostream&) { | ||
| 1739 | + return PerformAction(untyped_action, std::move(args), call_description); | ||
| 1740 | + } | ||
| 1741 | + | ||
| 1742 | + // Returns the result of invoking this mock function with the given | ||
| 1743 | + // arguments. This function can be safely called from multiple | ||
| 1744 | + // threads concurrently. | ||
| 1745 | + R InvokeWith(ArgumentTuple&& args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex); | ||
| 1786 | }; // class FunctionMocker | 1746 | }; // class FunctionMocker |
| 1787 | 1747 | ||
| 1788 | -// Reports an uninteresting call (whose description is in msg) in the | 1748 | +// Calculates the result of invoking this mock function with the given |
| 1789 | -// manner specified by 'reaction'. | 1749 | +// arguments, prints it, and returns it. |
| 1790 | -void ReportUninterestingCall(CallReaction reaction, const std::string& msg); | 1750 | +template <typename R, typename... Args> |
| 1751 | +R FunctionMocker<R(Args...)>::InvokeWith(ArgumentTuple&& args) | ||
| 1752 | + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { | ||
| 1753 | + // See the definition of untyped_expectations_ for why access to it | ||
| 1754 | + // is unprotected here. | ||
| 1755 | + if (untyped_expectations_.size() == 0) { | ||
| 1756 | + // No expectation is set on this mock method - we have an | ||
| 1757 | + // uninteresting call. | ||
| 1758 | + | ||
| 1759 | + // We must get Google Mock's reaction on uninteresting calls | ||
| 1760 | + // made on this mock object BEFORE performing the action, | ||
| 1761 | + // because the action may DELETE the mock object and make the | ||
| 1762 | + // following expression meaningless. | ||
| 1763 | + const CallReaction reaction = | ||
| 1764 | + Mock::GetReactionOnUninterestingCalls(MockObject()); | ||
| 1765 | + | ||
| 1766 | + // True if and only if we need to print this call's arguments and return | ||
| 1767 | + // value. This definition must be kept in sync with | ||
| 1768 | + // the behavior of ReportUninterestingCall(). | ||
| 1769 | + const bool need_to_report_uninteresting_call = | ||
| 1770 | + // If the user allows this uninteresting call, we print it | ||
| 1771 | + // only when they want informational messages. | ||
| 1772 | + reaction == kAllow ? LogIsVisible(kInfo) : | ||
| 1773 | + // If the user wants this to be a warning, we print | ||
| 1774 | + // it only when they want to see warnings. | ||
| 1775 | + reaction == kWarn | ||
| 1776 | + ? LogIsVisible(kWarning) | ||
| 1777 | + : | ||
| 1778 | + // Otherwise, the user wants this to be an error, and we | ||
| 1779 | + // should always print detailed information in the error. | ||
| 1780 | + true; | ||
| 1781 | + | ||
| 1782 | + if (!need_to_report_uninteresting_call) { | ||
| 1783 | + // Perform the action without printing the call information. | ||
| 1784 | + return this->PerformDefaultAction( | ||
| 1785 | + std::move(args), "Function call: " + std::string(Name())); | ||
| 1786 | + } | ||
| 1787 | + | ||
| 1788 | + // Warns about the uninteresting call. | ||
| 1789 | + ::std::stringstream ss; | ||
| 1790 | + this->UntypedDescribeUninterestingCall(&args, &ss); | ||
| 1791 | + | ||
| 1792 | + // Perform the action, print the result, and then report the uninteresting | ||
| 1793 | + // call. | ||
| 1794 | + // | ||
| 1795 | + // We use RAII to do the latter in case R is void or a non-moveable type. In | ||
| 1796 | + // either case we can't assign it to a local variable. | ||
| 1797 | + const Cleanup report_uninteresting_call( | ||
| 1798 | + [&] { ReportUninterestingCall(reaction, ss.str()); }); | ||
| 1799 | + | ||
| 1800 | + return PerformActionAndPrintResult(nullptr, std::move(args), ss.str(), ss); | ||
| 1801 | + } | ||
| 1802 | + | ||
| 1803 | + bool is_excessive = false; | ||
| 1804 | + ::std::stringstream ss; | ||
| 1805 | + ::std::stringstream why; | ||
| 1806 | + ::std::stringstream loc; | ||
| 1807 | + const void* untyped_action = nullptr; | ||
| 1808 | + | ||
| 1809 | + // The UntypedFindMatchingExpectation() function acquires and | ||
| 1810 | + // releases g_gmock_mutex. | ||
| 1811 | + | ||
| 1812 | + const ExpectationBase* const untyped_expectation = | ||
| 1813 | + this->UntypedFindMatchingExpectation(&args, &untyped_action, | ||
| 1814 | + &is_excessive, &ss, &why); | ||
| 1815 | + const bool found = untyped_expectation != nullptr; | ||
| 1816 | + | ||
| 1817 | + // True if and only if we need to print the call's arguments | ||
| 1818 | + // and return value. | ||
| 1819 | + // This definition must be kept in sync with the uses of Expect() | ||
| 1820 | + // and Log() in this function. | ||
| 1821 | + const bool need_to_report_call = | ||
| 1822 | + !found || is_excessive || LogIsVisible(kInfo); | ||
| 1823 | + if (!need_to_report_call) { | ||
| 1824 | + // Perform the action without printing the call information. | ||
| 1825 | + return PerformAction(untyped_action, std::move(args), ""); | ||
| 1826 | + } | ||
| 1827 | + | ||
| 1828 | + ss << " Function call: " << Name(); | ||
| 1829 | + this->UntypedPrintArgs(&args, &ss); | ||
| 1830 | + | ||
| 1831 | + // In case the action deletes a piece of the expectation, we | ||
| 1832 | + // generate the message beforehand. | ||
| 1833 | + if (found && !is_excessive) { | ||
| 1834 | + untyped_expectation->DescribeLocationTo(&loc); | ||
| 1835 | + } | ||
| 1836 | + | ||
| 1837 | + // Perform the action, print the result, and then fail or log in whatever way | ||
| 1838 | + // is appropriate. | ||
| 1839 | + // | ||
| 1840 | + // We use RAII to do the latter in case R is void or a non-moveable type. In | ||
| 1841 | + // either case we can't assign it to a local variable. | ||
| 1842 | + const Cleanup handle_failures([&] { | ||
| 1843 | + ss << "\n" << why.str(); | ||
| 1844 | + | ||
| 1845 | + if (!found) { | ||
| 1846 | + // No expectation matches this call - reports a failure. | ||
| 1847 | + Expect(false, nullptr, -1, ss.str()); | ||
| 1848 | + } else if (is_excessive) { | ||
| 1849 | + // We had an upper-bound violation and the failure message is in ss. | ||
| 1850 | + Expect(false, untyped_expectation->file(), untyped_expectation->line(), | ||
| 1851 | + ss.str()); | ||
| 1852 | + } else { | ||
| 1853 | + // We had an expected call and the matching expectation is | ||
| 1854 | + // described in ss. | ||
| 1855 | + Log(kInfo, loc.str() + ss.str(), 2); | ||
| 1856 | + } | ||
| 1857 | + }); | ||
| 1858 | + | ||
| 1859 | + return PerformActionAndPrintResult(untyped_action, std::move(args), ss.str(), | ||
| 1860 | + ss); | ||
| 1861 | +} | ||
| 1791 | 1862 | ||
| 1792 | } // namespace internal | 1863 | } // namespace internal |
| 1793 | 1864 | ||
| @@ -1952,7 +2023,9 @@ using internal::MockSpec; | |||
| 1952 | // // Expects a call to const MockFoo::Bar(). | 2023 | // // Expects a call to const MockFoo::Bar(). |
| 1953 | // EXPECT_CALL(Const(foo), Bar()); | 2024 | // EXPECT_CALL(Const(foo), Bar()); |
| 1954 | template <typename T> | 2025 | template <typename T> |
| 1955 | -inline const T& Const(const T& x) { return x; } | 2026 | +inline const T& Const(const T& x) { |
| 2027 | + return x; | ||
| 2028 | +} | ||
| 1956 | 2029 | ||
| 1957 | // Constructs an Expectation object that references and co-owns exp. | 2030 | // Constructs an Expectation object that references and co-owns exp. |
| 1958 | inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT | 2031 | inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT |
| @@ -27,13 +27,10 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This is the main header file a user should include. | 32 | // This is the main header file a user should include. |
| 34 | 33 | ||
| 35 | -// GOOGLETEST_CM0002 DO NOT DELETE | ||
| 36 | - | ||
| 37 | 34 | ||
| 38 | 35 | ||
| 39 | 36 | ||
| @@ -64,14 +61,15 @@ | |||
| 64 | 61 | ||
| 65 | 62 | ||
| 66 | 63 | ||
| 67 | - | 64 | +#include "gmock/internal/gmock-port.h" |
| 68 | -namespace testing { | ||
| 69 | 65 | ||
| 70 | // Declares Google Mock flags that we want a user to use programmatically. | 66 | // Declares Google Mock flags that we want a user to use programmatically. |
| 71 | GMOCK_DECLARE_bool_(catch_leaked_mocks); | 67 | GMOCK_DECLARE_bool_(catch_leaked_mocks); |
| 72 | GMOCK_DECLARE_string_(verbose); | 68 | GMOCK_DECLARE_string_(verbose); |
| 73 | GMOCK_DECLARE_int32_(default_mock_behavior); | 69 | GMOCK_DECLARE_int32_(default_mock_behavior); |
| 74 | 70 | ||
| 71 | +namespace testing { | ||
| 72 | + | ||
| 75 | // Initializes Google Mock. This must be called before running the | 73 | // Initializes Google Mock. This must be called before running the |
| 76 | // tests. In particular, it parses the command line for the flags | 74 | // tests. In particular, it parses the command line for the flags |
| 77 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, | 75 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, |
| @@ -14,3 +14,5 @@ The following macros can be defined: | |||
| 14 | * `GMOCK_DEFINE_bool_(name, default_val, doc)` | 14 | * `GMOCK_DEFINE_bool_(name, default_val, doc)` |
| 15 | * `GMOCK_DEFINE_int32_(name, default_val, doc)` | 15 | * `GMOCK_DEFINE_int32_(name, default_val, doc)` |
| 16 | * `GMOCK_DEFINE_string_(name, default_val, doc)` | 16 | * `GMOCK_DEFINE_string_(name, default_val, doc)` |
| 17 | +* `GMOCK_FLAG_GET(flag_name)` | ||
| 18 | +* `GMOCK_FLAG_SET(flag_name, value)` | ||
| @@ -1,4 +1,5 @@ | |||
| 1 | -// GOOGLETEST_CM0002 DO NOT DELETE | 1 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 2 | +// IWYU pragma: friend gmock/.* | ||
| 2 | 3 | ||
| 3 | 4 | ||
| 4 | 5 | ||
| @@ -26,10 +26,11 @@ | |||
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | -// | 29 | + |
| 30 | // Injection point for custom user configurations. See README for details | 30 | // Injection point for custom user configurations. See README for details |
| 31 | -// | 31 | + |
| 32 | -// GOOGLETEST_CM0002 DO NOT DELETE | 32 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 33 | +// IWYU pragma: friend gmock/.* | ||
| 33 | 34 | ||
| 34 | 35 | ||
| 35 | 36 | ||
| @@ -26,12 +26,13 @@ | |||
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | -// | 29 | + |
| 30 | // Injection point for custom user configurations. See README for details | 30 | // Injection point for custom user configurations. See README for details |
| 31 | // | 31 | // |
| 32 | // ** Custom implementation starts here ** | 32 | // ** Custom implementation starts here ** |
| 33 | 33 | ||
| 34 | -// GOOGLETEST_CM0002 DO NOT DELETE | 34 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 35 | +// IWYU pragma: friend gmock/.* | ||
| 35 | 36 | ||
| 36 | 37 | ||
| 37 | 38 | ||
| @@ -27,22 +27,25 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file defines some utilities useful for implementing Google | 32 | // This file defines some utilities useful for implementing Google |
| 34 | // Mock. They are subject to change without notice, so please DO NOT | 33 | // Mock. They are subject to change without notice, so please DO NOT |
| 35 | // USE THEM IN USER CODE. | 34 | // USE THEM IN USER CODE. |
| 36 | 35 | ||
| 37 | -// GOOGLETEST_CM0002 DO NOT DELETE | 36 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 37 | +// IWYU pragma: friend gmock/.* | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | + | ||
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | 46 | ||
| 47 | + | ||
| 48 | + | ||
| 46 | 49 | ||
| 47 | 50 | ||
| 48 | 51 | ||
| @@ -56,14 +59,15 @@ namespace internal { | |||
| 56 | // Silence MSVC C4100 (unreferenced formal parameter) and | 59 | // Silence MSVC C4100 (unreferenced formal parameter) and |
| 57 | // C4805('==': unsafe mix of type 'const int' and type 'const bool') | 60 | // C4805('==': unsafe mix of type 'const int' and type 'const bool') |
| 58 | 61 | ||
| 59 | -# pragma warning(push) | 62 | +#pragma warning(push) |
| 60 | -# pragma warning(disable:4100) | 63 | +#pragma warning(disable : 4100) |
| 61 | -# pragma warning(disable:4805) | 64 | +#pragma warning(disable : 4805) |
| 62 | 65 | ||
| 63 | 66 | ||
| 64 | // Joins a vector of strings as if they are fields of a tuple; returns | 67 | // Joins a vector of strings as if they are fields of a tuple; returns |
| 65 | // the joined string. | 68 | // the joined string. |
| 66 | -GTEST_API_ std::string JoinAsTuple(const Strings& fields); | 69 | +GTEST_API_ std::string JoinAsKeyValueTuple( |
| 70 | + const std::vector<const char*>& names, const Strings& values); | ||
| 67 | 71 | ||
| 68 | // Converts an identifier name to a space-separated list of lower-case | 72 | // Converts an identifier name to a space-separated list of lower-case |
| 69 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is | 73 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is |
| @@ -78,9 +82,36 @@ template <typename Pointer> | |||
| 78 | inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { | 82 | inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { |
| 79 | return p.get(); | 83 | return p.get(); |
| 80 | } | 84 | } |
| 85 | +// This overload version is for std::reference_wrapper, which does not work with | ||
| 86 | +// the overload above, as it does not have an `element_type`. | ||
| 87 | +template <typename Element> | ||
| 88 | +inline const Element* GetRawPointer(const std::reference_wrapper<Element>& r) { | ||
| 89 | + return &r.get(); | ||
| 90 | +} | ||
| 91 | + | ||
| 81 | // This overloaded version is for the raw pointer case. | 92 | // This overloaded version is for the raw pointer case. |
| 82 | template <typename Element> | 93 | template <typename Element> |
| 83 | -inline Element* GetRawPointer(Element* p) { return p; } | 94 | +inline Element* GetRawPointer(Element* p) { |
| 95 | + return p; | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +// Default definitions for all compilers. | ||
| 99 | +// NOTE: If you implement support for other compilers, make sure to avoid | ||
| 100 | +// unexpected overlaps. | ||
| 101 | +// (e.g., Clang also processes #pragma GCC, and clang-cl also handles _MSC_VER.) | ||
| 102 | + | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + | ||
| 111 | + _Pragma(GMOCK_PP_INTERNAL_STRINGIZE(clang diagnostic Level Warning)) | ||
| 112 | + | ||
| 113 | + | ||
| 114 | + | ||
| 84 | 115 | ||
| 85 | // MSVC treats wchar_t as a native type usually, but treats it as the | 116 | // MSVC treats wchar_t as a native type usually, but treats it as the |
| 86 | // same as unsigned short when the compiler option /Zc:wchar_t- is | 117 | // same as unsigned short when the compiler option /Zc:wchar_t- is |
| @@ -89,7 +120,7 @@ inline Element* GetRawPointer(Element* p) { return p; } | |||
| 89 | 120 | ||
| 90 | // wchar_t is a typedef. | 121 | // wchar_t is a typedef. |
| 91 | 122 | ||
| 92 | -# define GMOCK_WCHAR_T_IS_NATIVE_ 1 | 123 | +#define GMOCK_WCHAR_T_IS_NATIVE_ 1 |
| 93 | 124 | ||
| 94 | 125 | ||
| 95 | // In what follows, we use the term "kind" to indicate whether a type | 126 | // In what follows, we use the term "kind" to indicate whether a type |
| @@ -97,18 +128,20 @@ inline Element* GetRawPointer(Element* p) { return p; } | |||
| 97 | // or none of them. This categorization is useful for determining | 128 | // or none of them. This categorization is useful for determining |
| 98 | // when a matcher argument type can be safely converted to another | 129 | // when a matcher argument type can be safely converted to another |
| 99 | // type in the implementation of SafeMatcherCast. | 130 | // type in the implementation of SafeMatcherCast. |
| 100 | -enum TypeKind { | 131 | +enum TypeKind { kBool, kInteger, kFloatingPoint, kOther }; |
| 101 | - kBool, kInteger, kFloatingPoint, kOther | ||
| 102 | -}; | ||
| 103 | 132 | ||
| 104 | // KindOf<T>::value is the kind of type T. | 133 | // KindOf<T>::value is the kind of type T. |
| 105 | -template <typename T> struct KindOf { | 134 | +template <typename T> |
| 135 | +struct KindOf { | ||
| 106 | enum { value = kOther }; // The default kind. | 136 | enum { value = kOther }; // The default kind. |
| 107 | }; | 137 | }; |
| 108 | 138 | ||
| 109 | // This macro declares that the kind of 'type' is 'kind'. | 139 | // This macro declares that the kind of 'type' is 'kind'. |
| 110 | 140 | ||
| 111 | - template <> struct KindOf<type> { enum { value = kind }; } | 141 | + template <> \ |
| 142 | + struct KindOf<type> { \ | ||
| 143 | + enum { value = kind }; \ | ||
| 144 | + } | ||
| 112 | 145 | ||
| 113 | GMOCK_DECLARE_KIND_(bool, kBool); | 146 | GMOCK_DECLARE_KIND_(bool, kBool); |
| 114 | 147 | ||
| @@ -116,13 +149,13 @@ GMOCK_DECLARE_KIND_(bool, kBool); | |||
| 116 | GMOCK_DECLARE_KIND_(char, kInteger); | 149 | GMOCK_DECLARE_KIND_(char, kInteger); |
| 117 | GMOCK_DECLARE_KIND_(signed char, kInteger); | 150 | GMOCK_DECLARE_KIND_(signed char, kInteger); |
| 118 | GMOCK_DECLARE_KIND_(unsigned char, kInteger); | 151 | GMOCK_DECLARE_KIND_(unsigned char, kInteger); |
| 119 | -GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT | 152 | +GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT |
| 120 | GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT | 153 | GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT |
| 121 | GMOCK_DECLARE_KIND_(int, kInteger); | 154 | GMOCK_DECLARE_KIND_(int, kInteger); |
| 122 | GMOCK_DECLARE_KIND_(unsigned int, kInteger); | 155 | GMOCK_DECLARE_KIND_(unsigned int, kInteger); |
| 123 | -GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT | 156 | +GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT |
| 124 | -GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT | 157 | +GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT |
| 125 | -GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT | 158 | +GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT |
| 126 | GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT | 159 | GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT |
| 127 | 160 | ||
| 128 | 161 | ||
| @@ -137,7 +170,7 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); | |||
| 137 | 170 | ||
| 138 | 171 | ||
| 139 | // Evaluates to the kind of 'type'. | 172 | // Evaluates to the kind of 'type'. |
| 140 | -#define GMOCK_KIND_OF_(type) \ | 173 | +#define GMOCK_KIND_OF_(type) \ |
| 141 | static_cast< ::testing::internal::TypeKind>( \ | 174 | static_cast< ::testing::internal::TypeKind>( \ |
| 142 | ::testing::internal::KindOf<type>::value) | 175 | ::testing::internal::KindOf<type>::value) |
| 143 | 176 | ||
| @@ -193,9 +226,7 @@ using LosslessArithmeticConvertible = | |||
| 193 | class FailureReporterInterface { | 226 | class FailureReporterInterface { |
| 194 | public: | 227 | public: |
| 195 | // The type of a failure (either non-fatal or fatal). | 228 | // The type of a failure (either non-fatal or fatal). |
| 196 | - enum FailureType { | 229 | + enum FailureType { kNonfatal, kFatal }; |
| 197 | - kNonfatal, kFatal | ||
| 198 | - }; | ||
| 199 | 230 | ||
| 200 | virtual ~FailureReporterInterface() {} | 231 | virtual ~FailureReporterInterface() {} |
| 201 | 232 | ||
| @@ -215,8 +246,8 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter(); | |||
| 215 | inline void Assert(bool condition, const char* file, int line, | 246 | inline void Assert(bool condition, const char* file, int line, |
| 216 | const std::string& msg) { | 247 | const std::string& msg) { |
| 217 | if (!condition) { | 248 | if (!condition) { |
| 218 | - GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, | 249 | + GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file, |
| 219 | - file, line, msg); | 250 | + line, msg); |
| 220 | } | 251 | } |
| 221 | } | 252 | } |
| 222 | inline void Assert(bool condition, const char* file, int line) { | 253 | inline void Assert(bool condition, const char* file, int line) { |
| @@ -237,10 +268,7 @@ inline void Expect(bool condition, const char* file, int line) { | |||
| 237 | } | 268 | } |
| 238 | 269 | ||
| 239 | // Severity level of a log. | 270 | // Severity level of a log. |
| 240 | -enum LogSeverity { | 271 | +enum LogSeverity { kInfo = 0, kWarning = 1 }; |
| 241 | - kInfo = 0, | ||
| 242 | - kWarning = 1 | ||
| 243 | -}; | ||
| 244 | 272 | ||
| 245 | // Valid values for the --gmock_verbose flag. | 273 | // Valid values for the --gmock_verbose flag. |
| 246 | 274 | ||
| @@ -280,13 +308,6 @@ class WithoutMatchers { | |||
| 280 | // Internal use only: access the singleton instance of WithoutMatchers. | 308 | // Internal use only: access the singleton instance of WithoutMatchers. |
| 281 | GTEST_API_ WithoutMatchers GetWithoutMatchers(); | 309 | GTEST_API_ WithoutMatchers GetWithoutMatchers(); |
| 282 | 310 | ||
| 283 | -// Disable MSVC warnings for infinite recursion, since in this case the | ||
| 284 | -// the recursion is unreachable. | ||
| 285 | - | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - | ||
| 289 | - | ||
| 290 | // Invalid<T>() is usable as an expression of type T, but will terminate | 311 | // Invalid<T>() is usable as an expression of type T, but will terminate |
| 291 | // the program with an assertion failure if actually run. This is useful | 312 | // the program with an assertion failure if actually run. This is useful |
| 292 | // when a value of type T is needed for compilation, but the statement | 313 | // when a value of type T is needed for compilation, but the statement |
| @@ -295,15 +316,14 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers(); | |||
| 295 | template <typename T> | 316 | template <typename T> |
| 296 | inline T Invalid() { | 317 | inline T Invalid() { |
| 297 | Assert(false, "", -1, "Internal error: attempt to return invalid value"); | 318 | Assert(false, "", -1, "Internal error: attempt to return invalid value"); |
| 298 | - // This statement is unreachable, and would never terminate even if it | 319 | +#if defined(__GNUC__) || defined(__clang__) |
| 299 | - // could be reached. It is provided only to placate compiler warnings | 320 | + __builtin_unreachable(); |
| 300 | - // about missing return statements. | 321 | +#elif defined(_MSC_VER) |
| 322 | + __assume(0); | ||
| 323 | + | ||
| 301 | return Invalid<T>(); | 324 | return Invalid<T>(); |
| 302 | -} | ||
| 303 | - | ||
| 304 | - | ||
| 305 | - | ||
| 306 | 325 | ||
| 326 | +} | ||
| 307 | 327 | ||
| 308 | // Given a raw type (i.e. having no top-level reference or const | 328 | // Given a raw type (i.e. having no top-level reference or const |
| 309 | // modifier) RawContainer that's either an STL-style container or a | 329 | // modifier) RawContainer that's either an STL-style container or a |
| @@ -381,7 +401,8 @@ class StlContainerView< ::std::tuple<ElementPointer, Size> > { | |||
| 381 | 401 | ||
| 382 | // The following specialization prevents the user from instantiating | 402 | // The following specialization prevents the user from instantiating |
| 383 | // StlContainer with a reference type. | 403 | // StlContainer with a reference type. |
| 384 | -template <typename T> class StlContainerView<T&>; | 404 | +template <typename T> |
| 405 | +class StlContainerView<T&>; | ||
| 385 | 406 | ||
| 386 | // A type transform to remove constness from the first part of a pair. | 407 | // A type transform to remove constness from the first part of a pair. |
| 387 | // Pairs like that are used as the value_type of associative containers, | 408 | // Pairs like that are used as the value_type of associative containers, |
| @@ -402,17 +423,18 @@ struct RemoveConstFromKey<std::pair<const K, V> > { | |||
| 402 | GTEST_API_ void IllegalDoDefault(const char* file, int line); | 423 | GTEST_API_ void IllegalDoDefault(const char* file, int line); |
| 403 | 424 | ||
| 404 | template <typename F, typename Tuple, size_t... Idx> | 425 | template <typename F, typename Tuple, size_t... Idx> |
| 405 | -auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype( | 426 | +auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) |
| 406 | - std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) { | 427 | + -> decltype(std::forward<F>(f)( |
| 428 | + std::get<Idx>(std::forward<Tuple>(args))...)) { | ||
| 407 | return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...); | 429 | return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...); |
| 408 | } | 430 | } |
| 409 | 431 | ||
| 410 | // Apply the function to a tuple of arguments. | 432 | // Apply the function to a tuple of arguments. |
| 411 | template <typename F, typename Tuple> | 433 | template <typename F, typename Tuple> |
| 412 | -auto Apply(F&& f, Tuple&& args) -> decltype( | 434 | +auto Apply(F&& f, Tuple&& args) -> decltype(ApplyImpl( |
| 413 | - ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), | 435 | + std::forward<F>(f), std::forward<Tuple>(args), |
| 414 | - MakeIndexSequence<std::tuple_size< | 436 | + MakeIndexSequence<std::tuple_size< |
| 415 | - typename std::remove_reference<Tuple>::type>::value>())) { | 437 | + typename std::remove_reference<Tuple>::type>::value>())) { |
| 416 | return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), | 438 | return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), |
| 417 | MakeIndexSequence<std::tuple_size< | 439 | MakeIndexSequence<std::tuple_size< |
| 418 | typename std::remove_reference<Tuple>::type>::value>()); | 440 | typename std::remove_reference<Tuple>::type>::value>()); |
| @@ -449,8 +471,17 @@ struct Function<R(Args...)> { | |||
| 449 | template <typename R, typename... Args> | 471 | template <typename R, typename... Args> |
| 450 | constexpr size_t Function<R(Args...)>::ArgumentCount; | 472 | constexpr size_t Function<R(Args...)>::ArgumentCount; |
| 451 | 473 | ||
| 474 | +// Workaround for MSVC error C2039: 'type': is not a member of 'std' | ||
| 475 | +// when std::tuple_element is used. | ||
| 476 | +// See: https://github.com/google/googletest/issues/3931 | ||
| 477 | +// Can be replaced with std::tuple_element_t in C++14. | ||
| 478 | +template <size_t I, typename T> | ||
| 479 | +using TupleElement = typename std::tuple_element<I, T>::type; | ||
| 480 | + | ||
| 481 | +bool Base64Unescape(const std::string& encoded, std::string* decoded); | ||
| 482 | + | ||
| 452 | 483 | ||
| 453 | -# pragma warning(pop) | 484 | +#pragma warning(pop) |
| 454 | 485 | ||
| 455 | 486 | ||
| 456 | } // namespace internal | 487 | } // namespace internal |
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | -// | ||
| 31 | // Low-level types and utilities for porting Google Mock to various | 30 | // Low-level types and utilities for porting Google Mock to various |
| 32 | // platforms. All macros ending with _ and symbols defined in an | 31 | // platforms. All macros ending with _ and symbols defined in an |
| 33 | // internal namespace are subject to change without notice. Code | 32 | // internal namespace are subject to change without notice. Code |
| @@ -35,7 +34,8 @@ | |||
| 35 | // end with _ are part of Google Mock's public API and can be used by | 34 | // end with _ are part of Google Mock's public API and can be used by |
| 36 | // code outside Google Mock. | 35 | // code outside Google Mock. |
| 37 | 36 | ||
| 38 | -// GOOGLETEST_CM0002 DO NOT DELETE | 37 | +// IWYU pragma: private, include "gmock/gmock.h" |
| 38 | +// IWYU pragma: friend gmock/.* | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| @@ -53,35 +53,87 @@ | |||
| 53 | // here, as Google Mock depends on Google Test. Only add a utility | 53 | // here, as Google Mock depends on Google Test. Only add a utility |
| 54 | // here if it's truly specific to Google Mock. | 54 | // here if it's truly specific to Google Mock. |
| 55 | 55 | ||
| 56 | - | ||
| 57 | 56 | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + | ||
| 58 | 63 | ||
| 59 | // For MS Visual C++, check the compiler version. At least VS 2015 is | 64 | // For MS Visual C++, check the compiler version. At least VS 2015 is |
| 60 | // required to compile Google Mock. | 65 | // required to compile Google Mock. |
| 61 | 66 | ||
| 62 | -# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." | 67 | +#error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." |
| 63 | 68 | ||
| 64 | 69 | ||
| 65 | // Macro for referencing flags. This is public as we want the user to | 70 | // Macro for referencing flags. This is public as we want the user to |
| 66 | // use this syntax to reference Google Mock flags. | 71 | // use this syntax to reference Google Mock flags. |
| 72 | + | ||
| 67 | 73 | ||
| 68 | 74 | ||
| 69 | -#if !defined(GMOCK_DECLARE_bool_) | 75 | +// Pick a command line flags implementation. |
| 70 | - | 76 | +#if GTEST_HAS_ABSL |
| 71 | -// Macros for declaring flags. | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - extern GTEST_API_ ::std::string GMOCK_FLAG(name) | ||
| 76 | 77 | ||
| 77 | // Macros for defining flags. | 78 | // Macros for defining flags. |
| 78 | -# define GMOCK_DEFINE_bool_(name, default_val, doc) \ | 79 | +#define GMOCK_DEFINE_bool_(name, default_val, doc) \ |
| 79 | - GTEST_API_ bool GMOCK_FLAG(name) = (default_val) | 80 | + ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc) |
| 80 | -# define GMOCK_DEFINE_int32_(name, default_val, doc) \ | 81 | +#define GMOCK_DEFINE_int32_(name, default_val, doc) \ |
| 81 | - GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val) | 82 | + ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc) |
| 82 | -# define GMOCK_DEFINE_string_(name, default_val, doc) \ | 83 | +#define GMOCK_DEFINE_string_(name, default_val, doc) \ |
| 83 | - GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) | 84 | + ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc) |
| 84 | 85 | ||
| 85 | -#endif // !defined(GMOCK_DECLARE_bool_) | 86 | +// Macros for declaring flags. |
| 87 | + | ||
| 88 | + ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name)) | ||
| 89 | + | ||
| 90 | + ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name)) | ||
| 91 | + | ||
| 92 | + ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name)) | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + | ||
| 96 | + (void)(::absl::SetFlag(&GMOCK_FLAG(name), value)) | ||
| 97 | + | ||
| 98 | + | ||
| 99 | + | ||
| 100 | +// Macros for defining flags. | ||
| 101 | + | ||
| 102 | + namespace testing { \ | ||
| 103 | + GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \ | ||
| 104 | + } \ | ||
| 105 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 106 | + | ||
| 107 | + namespace testing { \ | ||
| 108 | + GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val); \ | ||
| 109 | + } \ | ||
| 110 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 111 | + | ||
| 112 | + namespace testing { \ | ||
| 113 | + GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \ | ||
| 114 | + } \ | ||
| 115 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 116 | + | ||
| 117 | +// Macros for declaring flags. | ||
| 118 | + | ||
| 119 | + namespace testing { \ | ||
| 120 | + GTEST_API_ extern bool GMOCK_FLAG(name); \ | ||
| 121 | + } \ | ||
| 122 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 123 | + | ||
| 124 | + namespace testing { \ | ||
| 125 | + GTEST_API_ extern int32_t GMOCK_FLAG(name); \ | ||
| 126 | + } \ | ||
| 127 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 128 | + | ||
| 129 | + namespace testing { \ | ||
| 130 | + GTEST_API_ extern ::std::string GMOCK_FLAG(name); \ | ||
| 131 | + } \ | ||
| 132 | + static_assert(true, "no-op to require trailing semicolon") | ||
| 133 | + | ||
| 134 | + | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + | ||
| 86 | 138 | ||
| 87 | 139 | ||
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements cardinalities. | 32 | // This file implements cardinalities. |
| @@ -35,9 +34,11 @@ | |||
| 35 | 34 | ||
| 36 | 35 | ||
| 37 | 36 | ||
| 37 | + | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | + | ||
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | 44 | ||
| @@ -49,8 +50,7 @@ namespace { | |||
| 49 | class BetweenCardinalityImpl : public CardinalityInterface { | 50 | class BetweenCardinalityImpl : public CardinalityInterface { |
| 50 | public: | 51 | public: |
| 51 | BetweenCardinalityImpl(int min, int max) | 52 | BetweenCardinalityImpl(int min, int max) |
| 52 | - : min_(min >= 0 ? min : 0), | 53 | + : min_(min >= 0 ? min : 0), max_(max >= min_ ? max : min_) { |
| 53 | - max_(max >= min_ ? max : min_) { | ||
| 54 | std::stringstream ss; | 54 | std::stringstream ss; |
| 55 | if (min < 0) { | 55 | if (min < 0) { |
| 56 | ss << "The invocation lower bound must be >= 0, " | 56 | ss << "The invocation lower bound must be >= 0, " |
| @@ -62,8 +62,7 @@ class BetweenCardinalityImpl : public CardinalityInterface { | |||
| 62 | internal::Expect(false, __FILE__, __LINE__, ss.str()); | 62 | internal::Expect(false, __FILE__, __LINE__, ss.str()); |
| 63 | } else if (min > max) { | 63 | } else if (min > max) { |
| 64 | ss << "The invocation upper bound (" << max | 64 | ss << "The invocation upper bound (" << max |
| 65 | - << ") must be >= the invocation lower bound (" << min | 65 | + << ") must be >= the invocation lower bound (" << min << ")."; |
| 66 | - << ")."; | ||
| 67 | internal::Expect(false, __FILE__, __LINE__, ss.str()); | 66 | internal::Expect(false, __FILE__, __LINE__, ss.str()); |
| 68 | } | 67 | } |
| 69 | } | 68 | } |
| @@ -87,7 +86,8 @@ class BetweenCardinalityImpl : public CardinalityInterface { | |||
| 87 | const int min_; | 86 | const int min_; |
| 88 | const int max_; | 87 | const int max_; |
| 89 | 88 | ||
| 90 | - GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl); | 89 | + BetweenCardinalityImpl(const BetweenCardinalityImpl&) = delete; |
| 90 | + BetweenCardinalityImpl& operator=(const BetweenCardinalityImpl&) = delete; | ||
| 91 | }; | 91 | }; |
| 92 | 92 | ||
| 93 | // Formats "n times" in a human-friendly way. | 93 | // Formats "n times" in a human-friendly way. |
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file defines some utilities useful for implementing Google | 32 | // This file defines some utilities useful for implementing Google |
| @@ -37,8 +36,15 @@ | |||
| 37 | 36 | ||
| 38 | 37 | ||
| 39 | 38 | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + | ||
| 40 | 44 | ||
| 41 | 45 | ||
| 46 | + | ||
| 47 | + | ||
| 42 | 48 | ||
| 43 | 49 | ||
| 44 | 50 | ||
| @@ -48,21 +54,22 @@ namespace internal { | |||
| 48 | 54 | ||
| 49 | // Joins a vector of strings as if they are fields of a tuple; returns | 55 | // Joins a vector of strings as if they are fields of a tuple; returns |
| 50 | // the joined string. | 56 | // the joined string. |
| 51 | -GTEST_API_ std::string JoinAsTuple(const Strings& fields) { | 57 | +GTEST_API_ std::string JoinAsKeyValueTuple( |
| 52 | - switch (fields.size()) { | 58 | + const std::vector<const char*>& names, const Strings& values) { |
| 53 | - case 0: | 59 | + GTEST_CHECK_(names.size() == values.size()); |
| 54 | - return ""; | 60 | + if (values.empty()) { |
| 55 | - case 1: | 61 | + return ""; |
| 56 | - return fields[0]; | ||
| 57 | - default: | ||
| 58 | - std::string result = "(" + fields[0]; | ||
| 59 | - for (size_t i = 1; i < fields.size(); i++) { | ||
| 60 | - result += ", "; | ||
| 61 | - result += fields[i]; | ||
| 62 | - } | ||
| 63 | - result += ")"; | ||
| 64 | - return result; | ||
| 65 | } | 62 | } |
| 63 | + const auto build_one = [&](const size_t i) { | ||
| 64 | + return std::string(names[i]) + ": " + values[i]; | ||
| 65 | + }; | ||
| 66 | + std::string result = "(" + build_one(0); | ||
| 67 | + for (size_t i = 1; i < values.size(); i++) { | ||
| 68 | + result += ", "; | ||
| 69 | + result += build_one(i); | ||
| 70 | + } | ||
| 71 | + result += ")"; | ||
| 72 | + return result; | ||
| 66 | } | 73 | } |
| 67 | 74 | ||
| 68 | // Converts an identifier name to a space-separated list of lower-case | 75 | // 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) { | |||
| 76 | // We don't care about the current locale as the input is | 83 | // We don't care about the current locale as the input is |
| 77 | // guaranteed to be a valid C++ identifier name. | 84 | // guaranteed to be a valid C++ identifier name. |
| 78 | const bool starts_new_word = IsUpper(*p) || | 85 | const bool starts_new_word = IsUpper(*p) || |
| 79 | - (!IsAlpha(prev_char) && IsLower(*p)) || | 86 | + (!IsAlpha(prev_char) && IsLower(*p)) || |
| 80 | - (!IsDigit(prev_char) && IsDigit(*p)); | 87 | + (!IsDigit(prev_char) && IsDigit(*p)); |
| 81 | 88 | ||
| 82 | if (IsAlNum(*p)) { | 89 | if (IsAlNum(*p)) { |
| 83 | - if (starts_new_word && result != "") | 90 | + if (starts_new_word && result != "") result += ' '; |
| 84 | - result += ' '; | ||
| 85 | result += ToLower(*p); | 91 | result += ToLower(*p); |
| 86 | } | 92 | } |
| 87 | } | 93 | } |
| @@ -95,12 +101,9 @@ class GoogleTestFailureReporter : public FailureReporterInterface { | |||
| 95 | public: | 101 | public: |
| 96 | void ReportFailure(FailureType type, const char* file, int line, | 102 | void ReportFailure(FailureType type, const char* file, int line, |
| 97 | const std::string& message) override { | 103 | const std::string& message) override { |
| 98 | - AssertHelper(type == kFatal ? | 104 | + AssertHelper(type == kFatal ? TestPartResult::kFatalFailure |
| 99 | - TestPartResult::kFatalFailure : | 105 | + : TestPartResult::kNonFatalFailure, |
| 100 | - TestPartResult::kNonFatalFailure, | 106 | + file, line, message.c_str()) = Message(); |
| 101 | - file, | ||
| 102 | - line, | ||
| 103 | - message.c_str()) = Message(); | ||
| 104 | if (type == kFatal) { | 107 | if (type == kFatal) { |
| 105 | posix::Abort(); | 108 | posix::Abort(); |
| 106 | } | 109 | } |
| @@ -126,10 +129,10 @@ static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex); | |||
| 126 | // Returns true if and only if a log with the given severity is visible | 129 | // Returns true if and only if a log with the given severity is visible |
| 127 | // according to the --gmock_verbose flag. | 130 | // according to the --gmock_verbose flag. |
| 128 | GTEST_API_ bool LogIsVisible(LogSeverity severity) { | 131 | GTEST_API_ bool LogIsVisible(LogSeverity severity) { |
| 129 | - if (GMOCK_FLAG(verbose) == kInfoVerbosity) { | 132 | + if (GMOCK_FLAG_GET(verbose) == kInfoVerbosity) { |
| 130 | // Always show the log if --gmock_verbose=info. | 133 | // Always show the log if --gmock_verbose=info. |
| 131 | return true; | 134 | return true; |
| 132 | - } else if (GMOCK_FLAG(verbose) == kErrorVerbosity) { | 135 | + } else if (GMOCK_FLAG_GET(verbose) == kErrorVerbosity) { |
| 133 | // Always hide it if --gmock_verbose=error. | 136 | // Always hide it if --gmock_verbose=error. |
| 134 | return false; | 137 | return false; |
| 135 | } else { | 138 | } else { |
| @@ -148,8 +151,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) { | |||
| 148 | // conservative. | 151 | // conservative. |
| 149 | GTEST_API_ void Log(LogSeverity severity, const std::string& message, | 152 | GTEST_API_ void Log(LogSeverity severity, const std::string& message, |
| 150 | int stack_frames_to_skip) { | 153 | int stack_frames_to_skip) { |
| 151 | - if (!LogIsVisible(severity)) | 154 | + if (!LogIsVisible(severity)) return; |
| 152 | - return; | ||
| 153 | 155 | ||
| 154 | // Ensures that logs from different threads don't interleave. | 156 | // Ensures that logs from different threads don't interleave. |
| 155 | MutexLock l(&g_log_mutex); | 157 | MutexLock l(&g_log_mutex); |
| @@ -178,8 +180,8 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, | |||
| 178 | std::cout << "\n"; | 180 | std::cout << "\n"; |
| 179 | } | 181 | } |
| 180 | std::cout << "Stack trace:\n" | 182 | std::cout << "Stack trace:\n" |
| 181 | - << ::testing::internal::GetCurrentOsStackTraceExceptTop( | 183 | + << ::testing::internal::GetCurrentOsStackTraceExceptTop( |
| 182 | - ::testing::UnitTest::GetInstance(), actual_to_skip); | 184 | + actual_to_skip); |
| 183 | } | 185 | } |
| 184 | std::cout << ::std::flush; | 186 | std::cout << ::std::flush; |
| 185 | } | 187 | } |
| @@ -196,5 +198,54 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) { | |||
| 196 | "the variable in various places."); | 198 | "the variable in various places."); |
| 197 | } | 199 | } |
| 198 | 200 | ||
| 201 | +constexpr char UnBase64Impl(char c, const char* const base64, char carry) { | ||
| 202 | + return *base64 == 0 ? static_cast<char>(65) | ||
| 203 | + : *base64 == c | ||
| 204 | + ? carry | ||
| 205 | + : UnBase64Impl(c, base64 + 1, static_cast<char>(carry + 1)); | ||
| 206 | +} | ||
| 207 | + | ||
| 208 | +template <size_t... I> | ||
| 209 | +constexpr std::array<char, 256> UnBase64Impl(IndexSequence<I...>, | ||
| 210 | + const char* const base64) { | ||
| 211 | + return {{UnBase64Impl(static_cast<char>(I), base64, 0)...}}; | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +constexpr std::array<char, 256> UnBase64(const char* const base64) { | ||
| 215 | + return UnBase64Impl(MakeIndexSequence<256>{}, base64); | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +static constexpr char kBase64[] = | ||
| 219 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
| 220 | +static constexpr std::array<char, 256> kUnBase64 = UnBase64(kBase64); | ||
| 221 | + | ||
| 222 | +bool Base64Unescape(const std::string& encoded, std::string* decoded) { | ||
| 223 | + decoded->clear(); | ||
| 224 | + size_t encoded_len = encoded.size(); | ||
| 225 | + decoded->reserve(3 * (encoded_len / 4) + (encoded_len % 4)); | ||
| 226 | + int bit_pos = 0; | ||
| 227 | + char dst = 0; | ||
| 228 | + for (int src : encoded) { | ||
| 229 | + if (std::isspace(src) || src == '=') { | ||
| 230 | + continue; | ||
| 231 | + } | ||
| 232 | + char src_bin = kUnBase64[static_cast<size_t>(src)]; | ||
| 233 | + if (src_bin >= 64) { | ||
| 234 | + decoded->clear(); | ||
| 235 | + return false; | ||
| 236 | + } | ||
| 237 | + if (bit_pos == 0) { | ||
| 238 | + dst |= static_cast<char>(src_bin << 2); | ||
| 239 | + bit_pos = 6; | ||
| 240 | + } else { | ||
| 241 | + dst |= static_cast<char>(src_bin >> (bit_pos - 2)); | ||
| 242 | + decoded->push_back(dst); | ||
| 243 | + dst = static_cast<char>(src_bin << (10 - bit_pos)); | ||
| 244 | + bit_pos = (bit_pos + 6) % 8; | ||
| 245 | + } | ||
| 246 | + } | ||
| 247 | + return true; | ||
| 248 | +} | ||
| 249 | + | ||
| 199 | } // namespace internal | 250 | } // namespace internal |
| 200 | } // namespace testing | 251 | } // namespace testing |
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements Matcher<const string&>, Matcher<string>, and | 32 | // This file implements Matcher<const string&>, Matcher<string>, and |
| @@ -36,9 +35,11 @@ | |||
| 36 | 35 | ||
| 37 | 36 | ||
| 38 | 37 | ||
| 38 | + | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | + | ||
| 42 | 43 | ||
| 43 | namespace testing { | 44 | namespace testing { |
| 44 | namespace internal { | 45 | namespace internal { |
| @@ -48,11 +49,13 @@ namespace internal { | |||
| 48 | // 'negation' is false; otherwise returns the description of the | 49 | // 'negation' is false; otherwise returns the description of the |
| 49 | // negation of the matcher. 'param_values' contains a list of strings | 50 | // negation of the matcher. 'param_values' contains a list of strings |
| 50 | // that are the print-out of the matcher's parameters. | 51 | // that are the print-out of the matcher's parameters. |
| 51 | -GTEST_API_ std::string FormatMatcherDescription(bool negation, | 52 | +GTEST_API_ std::string FormatMatcherDescription( |
| 52 | - const char* matcher_name, | 53 | + bool negation, const char* matcher_name, |
| 53 | - const Strings& param_values) { | 54 | + const std::vector<const char*>& param_names, const Strings& param_values) { |
| 54 | std::string result = ConvertIdentifierNameToWords(matcher_name); | 55 | std::string result = ConvertIdentifierNameToWords(matcher_name); |
| 55 | - if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values); | 56 | + if (param_values.size() >= 1) { |
| 57 | + result += " " + JoinAsKeyValueTuple(param_names, param_values); | ||
| 58 | + } | ||
| 56 | return negation ? "not (" + result + ")" : result; | 59 | return negation ? "not (" + result + ")" : result; |
| 57 | } | 60 | } |
| 58 | 61 | ||
| @@ -367,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( | |||
| 367 | bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( | 370 | bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( |
| 368 | const ::std::vector<std::string>& element_printouts, | 371 | const ::std::vector<std::string>& element_printouts, |
| 369 | const MatchMatrix& matrix, MatchResultListener* listener) const { | 372 | const MatchMatrix& matrix, MatchResultListener* listener) const { |
| 373 | + if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { | ||
| 374 | + return true; | ||
| 375 | + } | ||
| 376 | + | ||
| 377 | + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { | ||
| 378 | + if (matrix.LhsSize() != matrix.RhsSize()) { | ||
| 379 | + // The element count doesn't match. If the container is empty, | ||
| 380 | + // there's no need to explain anything as Google Mock already | ||
| 381 | + // prints the empty container. Otherwise we just need to show | ||
| 382 | + // how many elements there actually are. | ||
| 383 | + if (matrix.LhsSize() != 0 && listener->IsInterested()) { | ||
| 384 | + *listener << "which has " << Elements(matrix.LhsSize()); | ||
| 385 | + } | ||
| 386 | + return false; | ||
| 387 | + } | ||
| 388 | + } | ||
| 389 | + | ||
| 370 | bool result = true; | 390 | bool result = true; |
| 371 | ::std::vector<char> element_matched(matrix.LhsSize(), 0); | 391 | ::std::vector<char> element_matched(matrix.LhsSize(), 0); |
| 372 | ::std::vector<char> matcher_matched(matrix.RhsSize(), 0); | 392 | ::std::vector<char> matcher_matched(matrix.RhsSize(), 0); |
| @@ -27,7 +27,6 @@ | |||
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 | ||
| 30 | - | ||
| 31 | // Google Mock - a framework for writing C++ mock classes. | 30 | // Google Mock - a framework for writing C++ mock classes. |
| 32 | // | 31 | // |
| 33 | // This file implements the spec builder syntax (ON_CALL and | 32 | // This file implements the spec builder syntax (ON_CALL and |
| @@ -42,6 +41,7 @@ | |||
| 42 | 41 | ||
| 43 | 42 | ||
| 44 | 43 | ||
| 44 | + | ||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | 47 | ||
| @@ -49,15 +49,18 @@ | |||
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | -# include <unistd.h> // NOLINT | 52 | +#include <unistd.h> // NOLINT |
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 53 | 56 | ||
| 54 | 57 | ||
| 55 | // Silence C4800 (C4800: 'int *const ': forcing value | 58 | // Silence C4800 (C4800: 'int *const ': forcing value |
| 56 | // to bool 'true' or 'false') for MSVC 15 | 59 | // to bool 'true' or 'false') for MSVC 15 |
| 57 | 60 | ||
| 58 | 61 | ||
| 59 | -# pragma warning(push) | 62 | +#pragma warning(push) |
| 60 | -# pragma warning(disable:4800) | 63 | +#pragma warning(disable : 4800) |
| 61 | 64 | ||
| 62 | 65 | ||
| 63 | 66 | ||
| @@ -195,11 +198,12 @@ void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const | |||
| 195 | 198 | ||
| 196 | // Describes the state of the expectation (e.g. is it satisfied? | 199 | // Describes the state of the expectation (e.g. is it satisfied? |
| 197 | // is it active?). | 200 | // is it active?). |
| 198 | - *os << " - " << (IsOverSaturated() ? "over-saturated" : | 201 | + *os << " - " |
| 199 | - IsSaturated() ? "saturated" : | 202 | + << (IsOverSaturated() ? "over-saturated" |
| 200 | - IsSatisfied() ? "satisfied" : "unsatisfied") | 203 | + : IsSaturated() ? "saturated" |
| 201 | - << " and " | 204 | + : IsSatisfied() ? "satisfied" |
| 202 | - << (is_retired() ? "retired" : "active"); | 205 | + : "unsatisfied") |
| 206 | + << " and " << (is_retired() ? "retired" : "active"); | ||
| 203 | } | 207 | } |
| 204 | 208 | ||
| 205 | // Checks the action count (i.e. the number of WillOnce() and | 209 | // Checks the action count (i.e. the number of WillOnce() and |
| @@ -242,13 +246,12 @@ void ExpectationBase::CheckActionCountIfNotDone() const | |||
| 242 | 246 | ||
| 243 | ::std::stringstream ss; | 247 | ::std::stringstream ss; |
| 244 | DescribeLocationTo(&ss); | 248 | DescribeLocationTo(&ss); |
| 245 | - ss << "Too " << (too_many ? "many" : "few") | 249 | + ss << "Too " << (too_many ? "many" : "few") << " actions specified in " |
| 246 | - << " actions specified in " << source_text() << "...\n" | 250 | + << source_text() << "...\n" |
| 247 | << "Expected to be "; | 251 | << "Expected to be "; |
| 248 | cardinality().DescribeTo(&ss); | 252 | cardinality().DescribeTo(&ss); |
| 249 | - ss << ", but has " << (too_many ? "" : "only ") | 253 | + ss << ", but has " << (too_many ? "" : "only ") << action_count |
| 250 | - << action_count << " WillOnce()" | 254 | + << " WillOnce()" << (action_count == 1 ? "" : "s"); |
| 251 | - << (action_count == 1 ? "" : "s"); | ||
| 252 | if (repeated_action_specified_) { | 255 | if (repeated_action_specified_) { |
| 253 | ss << " and a WillRepeatedly()"; | 256 | ss << " and a WillRepeatedly()"; |
| 254 | } | 257 | } |
| @@ -264,10 +267,10 @@ void ExpectationBase::UntypedTimes(const Cardinality& a_cardinality) { | |||
| 264 | ".Times() cannot appear " | 267 | ".Times() cannot appear " |
| 265 | "more than once in an EXPECT_CALL()."); | 268 | "more than once in an EXPECT_CALL()."); |
| 266 | } else { | 269 | } else { |
| 267 | - ExpectSpecProperty(last_clause_ < kTimes, | 270 | + ExpectSpecProperty( |
| 268 | - ".Times() cannot appear after " | 271 | + last_clause_ < kTimes, |
| 269 | - ".InSequence(), .WillOnce(), .WillRepeatedly(), " | 272 | + ".Times() may only appear *before* .InSequence(), .WillOnce(), " |
| 270 | - "or .RetiresOnSaturation()."); | 273 | + ".WillRepeatedly(), or .RetiresOnSaturation(), not after."); |
| 271 | } | 274 | } |
| 272 | last_clause_ = kTimes; | 275 | last_clause_ = kTimes; |
| 273 | 276 | ||
| @@ -283,7 +286,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence; | |||
| 283 | void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { | 286 | void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { |
| 284 | // Include a stack trace only if --gmock_verbose=info is specified. | 287 | // Include a stack trace only if --gmock_verbose=info is specified. |
| 285 | const int stack_frames_to_skip = | 288 | const int stack_frames_to_skip = |
| 286 | - GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1; | 289 | + GMOCK_FLAG_GET(verbose) == kInfoVerbosity ? 3 : -1; |
| 287 | switch (reaction) { | 290 | switch (reaction) { |
| 288 | case kAllow: | 291 | case kAllow: |
| 289 | Log(kInfo, msg, stack_frames_to_skip); | 292 | Log(kInfo, msg, stack_frames_to_skip); |
| @@ -295,7 +298,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { | |||
| 295 | "call should not happen. Do not suppress it by blindly adding " | 298 | "call should not happen. Do not suppress it by blindly adding " |
| 296 | "an EXPECT_CALL() if you don't mean to enforce the call. " | 299 | "an EXPECT_CALL() if you don't mean to enforce the call. " |
| 297 | "See " | 300 | "See " |
| 298 | - "https://github.com/google/googletest/blob/master/docs/" | 301 | + "https://github.com/google/googletest/blob/main/docs/" |
| 299 | "gmock_cook_book.md#" | 302 | "gmock_cook_book.md#" |
| 300 | "knowing-when-to-expect for details.\n", | 303 | "knowing-when-to-expect for details.\n", |
| 301 | stack_frames_to_skip); | 304 | stack_frames_to_skip); |
| @@ -370,143 +373,12 @@ const char* UntypedFunctionMockerBase::Name() const | |||
| 370 | return name; | 373 | return name; |
| 371 | } | 374 | } |
| 372 | 375 | ||
| 373 | -// Calculates the result of invoking this mock function with the given | ||
| 374 | -// arguments, prints it, and returns it. The caller is responsible | ||
| 375 | -// for deleting the result. | ||
| 376 | -UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( | ||
| 377 | - void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { | ||
| 378 | - // See the definition of untyped_expectations_ for why access to it | ||
| 379 | - // is unprotected here. | ||
| 380 | - if (untyped_expectations_.size() == 0) { | ||
| 381 | - // No expectation is set on this mock method - we have an | ||
| 382 | - // uninteresting call. | ||
| 383 | - | ||
| 384 | - // We must get Google Mock's reaction on uninteresting calls | ||
| 385 | - // made on this mock object BEFORE performing the action, | ||
| 386 | - // because the action may DELETE the mock object and make the | ||
| 387 | - // following expression meaningless. | ||
| 388 | - const CallReaction reaction = | ||
| 389 | - Mock::GetReactionOnUninterestingCalls(MockObject()); | ||
| 390 | - | ||
| 391 | - // True if and only if we need to print this call's arguments and return | ||
| 392 | - // value. This definition must be kept in sync with | ||
| 393 | - // the behavior of ReportUninterestingCall(). | ||
| 394 | - const bool need_to_report_uninteresting_call = | ||
| 395 | - // If the user allows this uninteresting call, we print it | ||
| 396 | - // only when they want informational messages. | ||
| 397 | - reaction == kAllow ? LogIsVisible(kInfo) : | ||
| 398 | - // If the user wants this to be a warning, we print | ||
| 399 | - // it only when they want to see warnings. | ||
| 400 | - reaction == kWarn | ||
| 401 | - ? LogIsVisible(kWarning) | ||
| 402 | - : | ||
| 403 | - // Otherwise, the user wants this to be an error, and we | ||
| 404 | - // should always print detailed information in the error. | ||
| 405 | - true; | ||
| 406 | - | ||
| 407 | - if (!need_to_report_uninteresting_call) { | ||
| 408 | - // Perform the action without printing the call information. | ||
| 409 | - return this->UntypedPerformDefaultAction( | ||
| 410 | - untyped_args, "Function call: " + std::string(Name())); | ||
| 411 | - } | ||
| 412 | - | ||
| 413 | - // Warns about the uninteresting call. | ||
| 414 | - ::std::stringstream ss; | ||
| 415 | - this->UntypedDescribeUninterestingCall(untyped_args, &ss); | ||
| 416 | - | ||
| 417 | - // Calculates the function result. | ||
| 418 | - UntypedActionResultHolderBase* const result = | ||
| 419 | - this->UntypedPerformDefaultAction(untyped_args, ss.str()); | ||
| 420 | - | ||
| 421 | - // Prints the function result. | ||
| 422 | - if (result != nullptr) result->PrintAsActionResult(&ss); | ||
| 423 | - | ||
| 424 | - ReportUninterestingCall(reaction, ss.str()); | ||
| 425 | - return result; | ||
| 426 | - } | ||
| 427 | - | ||
| 428 | - bool is_excessive = false; | ||
| 429 | - ::std::stringstream ss; | ||
| 430 | - ::std::stringstream why; | ||
| 431 | - ::std::stringstream loc; | ||
| 432 | - const void* untyped_action = nullptr; | ||
| 433 | - | ||
| 434 | - // The UntypedFindMatchingExpectation() function acquires and | ||
| 435 | - // releases g_gmock_mutex. | ||
| 436 | - | ||
| 437 | - const ExpectationBase* const untyped_expectation = | ||
| 438 | - this->UntypedFindMatchingExpectation(untyped_args, &untyped_action, | ||
| 439 | - &is_excessive, &ss, &why); | ||
| 440 | - const bool found = untyped_expectation != nullptr; | ||
| 441 | - | ||
| 442 | - // True if and only if we need to print the call's arguments | ||
| 443 | - // and return value. | ||
| 444 | - // This definition must be kept in sync with the uses of Expect() | ||
| 445 | - // and Log() in this function. | ||
| 446 | - const bool need_to_report_call = | ||
| 447 | - !found || is_excessive || LogIsVisible(kInfo); | ||
| 448 | - if (!need_to_report_call) { | ||
| 449 | - // Perform the action without printing the call information. | ||
| 450 | - return untyped_action == nullptr | ||
| 451 | - ? this->UntypedPerformDefaultAction(untyped_args, "") | ||
| 452 | - : this->UntypedPerformAction(untyped_action, untyped_args); | ||
| 453 | - } | ||
| 454 | - | ||
| 455 | - ss << " Function call: " << Name(); | ||
| 456 | - this->UntypedPrintArgs(untyped_args, &ss); | ||
| 457 | - | ||
| 458 | - // In case the action deletes a piece of the expectation, we | ||
| 459 | - // generate the message beforehand. | ||
| 460 | - if (found && !is_excessive) { | ||
| 461 | - untyped_expectation->DescribeLocationTo(&loc); | ||
| 462 | - } | ||
| 463 | - | ||
| 464 | - UntypedActionResultHolderBase* result = nullptr; | ||
| 465 | - | ||
| 466 | - auto perform_action = [&] { | ||
| 467 | - return untyped_action == nullptr | ||
| 468 | - ? this->UntypedPerformDefaultAction(untyped_args, ss.str()) | ||
| 469 | - : this->UntypedPerformAction(untyped_action, untyped_args); | ||
| 470 | - }; | ||
| 471 | - auto handle_failures = [&] { | ||
| 472 | - ss << "\n" << why.str(); | ||
| 473 | - | ||
| 474 | - if (!found) { | ||
| 475 | - // No expectation matches this call - reports a failure. | ||
| 476 | - Expect(false, nullptr, -1, ss.str()); | ||
| 477 | - } else if (is_excessive) { | ||
| 478 | - // We had an upper-bound violation and the failure message is in ss. | ||
| 479 | - Expect(false, untyped_expectation->file(), untyped_expectation->line(), | ||
| 480 | - ss.str()); | ||
| 481 | - } else { | ||
| 482 | - // We had an expected call and the matching expectation is | ||
| 483 | - // described in ss. | ||
| 484 | - Log(kInfo, loc.str() + ss.str(), 2); | ||
| 485 | - } | ||
| 486 | - }; | ||
| 487 | - | ||
| 488 | - try { | ||
| 489 | - result = perform_action(); | ||
| 490 | - } catch (...) { | ||
| 491 | - handle_failures(); | ||
| 492 | - throw; | ||
| 493 | - } | ||
| 494 | - | ||
| 495 | - result = perform_action(); | ||
| 496 | - | ||
| 497 | - | ||
| 498 | - if (result != nullptr) result->PrintAsActionResult(&ss); | ||
| 499 | - handle_failures(); | ||
| 500 | - return result; | ||
| 501 | -} | ||
| 502 | - | ||
| 503 | // Returns an Expectation object that references and co-owns exp, | 376 | // Returns an Expectation object that references and co-owns exp, |
| 504 | // which must be an expectation on this mock function. | 377 | // which must be an expectation on this mock function. |
| 505 | Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { | 378 | Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { |
| 506 | // See the definition of untyped_expectations_ for why access to it | 379 | // See the definition of untyped_expectations_ for why access to it |
| 507 | // is unprotected here. | 380 | // is unprotected here. |
| 508 | - for (UntypedExpectations::const_iterator it = | 381 | + for (UntypedExpectations::const_iterator it = untyped_expectations_.begin(); |
| 509 | - untyped_expectations_.begin(); | ||
| 510 | it != untyped_expectations_.end(); ++it) { | 382 | it != untyped_expectations_.end(); ++it) { |
| 511 | if (it->get() == exp) { | 383 | if (it->get() == exp) { |
| 512 | return Expectation(*it); | 384 | return Expectation(*it); |
| @@ -526,8 +398,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() | |||
| 526 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { | 398 | GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 527 | g_gmock_mutex.AssertHeld(); | 399 | g_gmock_mutex.AssertHeld(); |
| 528 | bool expectations_met = true; | 400 | bool expectations_met = true; |
| 529 | - for (UntypedExpectations::const_iterator it = | 401 | + for (UntypedExpectations::const_iterator it = untyped_expectations_.begin(); |
| 530 | - untyped_expectations_.begin(); | ||
| 531 | it != untyped_expectations_.end(); ++it) { | 402 | it != untyped_expectations_.end(); ++it) { |
| 532 | ExpectationBase* const untyped_expectation = it->get(); | 403 | ExpectationBase* const untyped_expectation = it->get(); |
| 533 | if (untyped_expectation->IsOverSaturated()) { | 404 | if (untyped_expectation->IsOverSaturated()) { |
| @@ -538,15 +409,22 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() | |||
| 538 | } else if (!untyped_expectation->IsSatisfied()) { | 409 | } else if (!untyped_expectation->IsSatisfied()) { |
| 539 | expectations_met = false; | 410 | expectations_met = false; |
| 540 | ::std::stringstream ss; | 411 | ::std::stringstream ss; |
| 541 | - ss << "Actual function call count doesn't match " | 412 | + |
| 542 | - << untyped_expectation->source_text() << "...\n"; | 413 | + const ::std::string& expectation_name = |
| 414 | + untyped_expectation->GetDescription(); | ||
| 415 | + ss << "Actual function "; | ||
| 416 | + if (!expectation_name.empty()) { | ||
| 417 | + ss << "\"" << expectation_name << "\" "; | ||
| 418 | + } | ||
| 419 | + ss << "call count doesn't match " << untyped_expectation->source_text() | ||
| 420 | + << "...\n"; | ||
| 543 | // No need to show the source file location of the expectation | 421 | // No need to show the source file location of the expectation |
| 544 | // in the description, as the Expect() call that follows already | 422 | // in the description, as the Expect() call that follows already |
| 545 | // takes care of it. | 423 | // takes care of it. |
| 546 | untyped_expectation->MaybeDescribeExtraMatcherTo(&ss); | 424 | untyped_expectation->MaybeDescribeExtraMatcherTo(&ss); |
| 547 | untyped_expectation->DescribeCallCountTo(&ss); | 425 | untyped_expectation->DescribeCallCountTo(&ss); |
| 548 | - Expect(false, untyped_expectation->file(), | 426 | + Expect(false, untyped_expectation->file(), untyped_expectation->line(), |
| 549 | - untyped_expectation->line(), ss.str()); | 427 | + ss.str()); |
| 550 | } | 428 | } |
| 551 | } | 429 | } |
| 552 | 430 | ||
| @@ -567,7 +445,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() | |||
| 567 | return expectations_met; | 445 | return expectations_met; |
| 568 | } | 446 | } |
| 569 | 447 | ||
| 570 | -CallReaction intToCallReaction(int mock_behavior) { | 448 | +static CallReaction intToCallReaction(int mock_behavior) { |
| 571 | if (mock_behavior >= kAllow && mock_behavior <= kFail) { | 449 | if (mock_behavior >= kAllow && mock_behavior <= kFail) { |
| 572 | return static_cast<internal::CallReaction>(mock_behavior); | 450 | return static_cast<internal::CallReaction>(mock_behavior); |
| 573 | } | 451 | } |
| @@ -613,8 +491,7 @@ class MockObjectRegistry { | |||
| 613 | // object alive. Therefore we report any living object as test | 491 | // object alive. Therefore we report any living object as test |
| 614 | // failure, unless the user explicitly asked us to ignore it. | 492 | // failure, unless the user explicitly asked us to ignore it. |
| 615 | ~MockObjectRegistry() { | 493 | ~MockObjectRegistry() { |
| 616 | - if (!GMOCK_FLAG(catch_leaked_mocks)) | 494 | + if (!GMOCK_FLAG_GET(catch_leaked_mocks)) return; |
| 617 | - return; | ||
| 618 | 495 | ||
| 619 | int leaked_count = 0; | 496 | int leaked_count = 0; |
| 620 | for (StateMap::const_iterator it = states_.begin(); it != states_.end(); | 497 | for (StateMap::const_iterator it = states_.begin(); it != states_.end(); |
| @@ -634,7 +511,7 @@ class MockObjectRegistry { | |||
| 634 | << state.first_used_test << ")"; | 511 | << state.first_used_test << ")"; |
| 635 | } | 512 | } |
| 636 | std::cout << " should be deleted but never is. Its address is @" | 513 | std::cout << " should be deleted but never is. Its address is @" |
| 637 | - << it->first << "."; | 514 | + << it->first << "."; |
| 638 | leaked_count++; | 515 | leaked_count++; |
| 639 | } | 516 | } |
| 640 | if (leaked_count > 0) { | 517 | if (leaked_count > 0) { |
| @@ -652,8 +529,12 @@ class MockObjectRegistry { | |||
| 652 | // RUN_ALL_TESTS() has already returned when this destructor is | 529 | // RUN_ALL_TESTS() has already returned when this destructor is |
| 653 | // called. Therefore we cannot use the normal Google Test | 530 | // called. Therefore we cannot use the normal Google Test |
| 654 | // failure reporting mechanism. | 531 | // failure reporting mechanism. |
| 532 | + | ||
| 533 | + qurt_exception_raise_fatal(); | ||
| 534 | + | ||
| 655 | _exit(1); // We cannot call exit() as it is not reentrant and | 535 | _exit(1); // We cannot call exit() as it is not reentrant and |
| 656 | // may already have been called. | 536 | // may already have been called. |
| 537 | + | ||
| 657 | } | 538 | } |
| 658 | } | 539 | } |
| 659 | 540 | ||
| @@ -668,57 +549,63 @@ MockObjectRegistry g_mock_object_registry; | |||
| 668 | 549 | ||
| 669 | // Maps a mock object to the reaction Google Mock should have when an | 550 | // Maps a mock object to the reaction Google Mock should have when an |
| 670 | // uninteresting method is called. Protected by g_gmock_mutex. | 551 | // uninteresting method is called. Protected by g_gmock_mutex. |
| 671 | -std::map<const void*, internal::CallReaction> g_uninteresting_call_reaction; | 552 | +std::unordered_map<uintptr_t, internal::CallReaction>& |
| 553 | +UninterestingCallReactionMap() { | ||
| 554 | + static auto* map = new std::unordered_map<uintptr_t, internal::CallReaction>; | ||
| 555 | + return *map; | ||
| 556 | +} | ||
| 672 | 557 | ||
| 673 | // Sets the reaction Google Mock should have when an uninteresting | 558 | // Sets the reaction Google Mock should have when an uninteresting |
| 674 | // method of the given mock object is called. | 559 | // method of the given mock object is called. |
| 675 | -void SetReactionOnUninterestingCalls(const void* mock_obj, | 560 | +void SetReactionOnUninterestingCalls(uintptr_t mock_obj, |
| 676 | internal::CallReaction reaction) | 561 | internal::CallReaction reaction) |
| 677 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | 562 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 678 | internal::MutexLock l(&internal::g_gmock_mutex); | 563 | internal::MutexLock l(&internal::g_gmock_mutex); |
| 679 | - g_uninteresting_call_reaction[mock_obj] = reaction; | 564 | + UninterestingCallReactionMap()[mock_obj] = reaction; |
| 680 | } | 565 | } |
| 681 | 566 | ||
| 682 | } // namespace | 567 | } // namespace |
| 683 | 568 | ||
| 684 | // Tells Google Mock to allow uninteresting calls on the given mock | 569 | // Tells Google Mock to allow uninteresting calls on the given mock |
| 685 | // object. | 570 | // object. |
| 686 | -void Mock::AllowUninterestingCalls(const void* mock_obj) | 571 | +void Mock::AllowUninterestingCalls(uintptr_t mock_obj) |
| 687 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | 572 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 688 | SetReactionOnUninterestingCalls(mock_obj, internal::kAllow); | 573 | SetReactionOnUninterestingCalls(mock_obj, internal::kAllow); |
| 689 | } | 574 | } |
| 690 | 575 | ||
| 691 | // Tells Google Mock to warn the user about uninteresting calls on the | 576 | // Tells Google Mock to warn the user about uninteresting calls on the |
| 692 | // given mock object. | 577 | // given mock object. |
| 693 | -void Mock::WarnUninterestingCalls(const void* mock_obj) | 578 | +void Mock::WarnUninterestingCalls(uintptr_t mock_obj) |
| 694 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | 579 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 695 | SetReactionOnUninterestingCalls(mock_obj, internal::kWarn); | 580 | SetReactionOnUninterestingCalls(mock_obj, internal::kWarn); |
| 696 | } | 581 | } |
| 697 | 582 | ||
| 698 | // Tells Google Mock to fail uninteresting calls on the given mock | 583 | // Tells Google Mock to fail uninteresting calls on the given mock |
| 699 | // object. | 584 | // object. |
| 700 | -void Mock::FailUninterestingCalls(const void* mock_obj) | 585 | +void Mock::FailUninterestingCalls(uintptr_t mock_obj) |
| 701 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | 586 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 702 | SetReactionOnUninterestingCalls(mock_obj, internal::kFail); | 587 | SetReactionOnUninterestingCalls(mock_obj, internal::kFail); |
| 703 | } | 588 | } |
| 704 | 589 | ||
| 705 | // Tells Google Mock the given mock object is being destroyed and its | 590 | // Tells Google Mock the given mock object is being destroyed and its |
| 706 | // entry in the call-reaction table should be removed. | 591 | // entry in the call-reaction table should be removed. |
| 707 | -void Mock::UnregisterCallReaction(const void* mock_obj) | 592 | +void Mock::UnregisterCallReaction(uintptr_t mock_obj) |
| 708 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | 593 | GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 709 | internal::MutexLock l(&internal::g_gmock_mutex); | 594 | internal::MutexLock l(&internal::g_gmock_mutex); |
| 710 | - g_uninteresting_call_reaction.erase(mock_obj); | 595 | + UninterestingCallReactionMap().erase(static_cast<uintptr_t>(mock_obj)); |
| 711 | } | 596 | } |
| 712 | 597 | ||
| 713 | // Returns the reaction Google Mock will have on uninteresting calls | 598 | // Returns the reaction Google Mock will have on uninteresting calls |
| 714 | // made on the given mock object. | 599 | // made on the given mock object. |
| 715 | internal::CallReaction Mock::GetReactionOnUninterestingCalls( | 600 | internal::CallReaction Mock::GetReactionOnUninterestingCalls( |
| 716 | - const void* mock_obj) | 601 | + const void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { |
| 717 | - GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { | ||
| 718 | internal::MutexLock l(&internal::g_gmock_mutex); | 602 | internal::MutexLock l(&internal::g_gmock_mutex); |
| 719 | - return (g_uninteresting_call_reaction.count(mock_obj) == 0) ? | 603 | + return (UninterestingCallReactionMap().count( |
| 720 | - internal::intToCallReaction(GMOCK_FLAG(default_mock_behavior)) : | 604 | + reinterpret_cast<uintptr_t>(mock_obj)) == 0) |
| 721 | - g_uninteresting_call_reaction[mock_obj]; | 605 | + ? internal::intToCallReaction( |
| 606 | + GMOCK_FLAG_GET(default_mock_behavior)) | ||
| 607 | + : UninterestingCallReactionMap()[reinterpret_cast<uintptr_t>( | ||
| 608 | + mock_obj)]; | ||
| 722 | } | 609 | } |
| 723 | 610 | ||
| 724 | // Tells Google Mock to ignore mock_obj when checking for leaked mock | 611 | // Tells Google Mock to ignore mock_obj when checking for leaked mock |
| @@ -873,8 +760,8 @@ Expectation::~Expectation() {} | |||
| 873 | void Sequence::AddExpectation(const Expectation& expectation) const { | 760 | void Sequence::AddExpectation(const Expectation& expectation) const { |
| 874 | if (*last_expectation_ != expectation) { | 761 | if (*last_expectation_ != expectation) { |
| 875 | if (last_expectation_->expectation_base() != nullptr) { | 762 | if (last_expectation_->expectation_base() != nullptr) { |
| 876 | - expectation.expectation_base()->immediate_prerequisites_ | 763 | + expectation.expectation_base()->immediate_prerequisites_ += |
| 877 | - += *last_expectation_; | 764 | + *last_expectation_; |
| 878 | } | 765 | } |
| 879 | *last_expectation_ = expectation; | 766 | *last_expectation_ = expectation; |
| 880 | } | 767 | } |
| @@ -903,6 +790,6 @@ InSequence::~InSequence() { | |||
| 903 | 790 | ||
| 904 | 791 | ||
| 905 | 792 | ||
| 906 | -# pragma warning(pop) | 793 | +#pragma warning(pop) |
| 907 | 794 | ||
| 908 | 795 | ||