diff --git a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp index 042beb6c4643ff9740449a6fc4f28da6279706cb..ddca36ad14699b3cb748468dfb1f8a1995144489 100644 --- a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp +++ b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp @@ -31,7 +31,7 @@ namespace DistributedKv { using namespace OHOS::EventFwk; using namespace OHOS::AAFwk; using namespace OHOS::DistributedData; -using namespace Security::AccessToken;6 +using namespace Security::AccessToken; //AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; AccountDelegate *AccountDelegateNormalImpl::GetBaseInstance() { diff --git a/googletest/.github/ISSUE_TEMPLATE/00-bug_report.md b/googletest/.github/ISSUE_TEMPLATE/00-bug_report.md deleted file mode 100644 index 0f7e8b532f92a563bbbdfbe1a2ad0257b36c0123..0000000000000000000000000000000000000000 --- a/googletest/.github/ISSUE_TEMPLATE/00-bug_report.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: 'bug' -assignees: '' ---- - -**Describe the bug** - -Include a clear and concise description of what the problem is, including what -you expected to happen, and what actually happened. - -**Steps to reproduce the bug** - -It's important that we are able to reproduce the problem that you are -experiencing. Please provide all code and relevant steps to reproduce the -problem, including your `BUILD`/`CMakeLists.txt` file and build commands. Links -to a GitHub branch or [godbolt.org](https://godbolt.org/) that demonstrate the -problem are also helpful. - -**Does the bug persist in the most recent commit?** - -We recommend using the latest commit in the master branch in your projects. - -**What operating system and version are you using?** - -If you are using a Linux distribution please include the name and version of the -distribution as well. - -**What compiler and version are you using?** - -Please include the output of `gcc -v` or `clang -v`, or the equivalent for your -compiler. - -**What build system are you using?** - -Please include the output of `bazel --version` or `cmake --version`, or the -equivalent for your build system. - -**Additional context** - -Add any other context about the problem here. diff --git a/googletest/.github/ISSUE_TEMPLATE/10-feature_request.md b/googletest/.github/ISSUE_TEMPLATE/10-feature_request.md deleted file mode 100644 index 70a3a2099c506c0255c3e3c6ab1d83f4b91015b8..0000000000000000000000000000000000000000 --- a/googletest/.github/ISSUE_TEMPLATE/10-feature_request.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: Feature request -about: Propose a new feature -title: '' -labels: 'enhancement' -assignees: '' ---- - -**Does the feature exist in the most recent commit?** - -We recommend using the latest commit from GitHub in your projects. - -**Why do we need this feature?** - -Ideally, explain why a combination of existing features cannot be used instead. - -**Describe the proposal** - -Include a detailed description of the feature, with usage examples. - -**Is the feature specific to an operating system, compiler, or build system version?** - -If it is, please specify which versions. - diff --git a/googletest/.github/ISSUE_TEMPLATE/config.yml b/googletest/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 3ba13e0cec6cbbfd462e9ebf529dd2093148cd69..0000000000000000000000000000000000000000 --- a/googletest/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1 +0,0 @@ -blank_issues_enabled: false diff --git a/googletest/BUILD.bazel b/googletest/BUILD.bazel index 1df5ff5f998e51f66c0bd5b244bf5e75ab6211f9..965c518d7a7c4e2a4f642706e8fc57a9542ca14f 100644 --- a/googletest/BUILD.bazel +++ b/googletest/BUILD.bazel @@ -30,32 +30,19 @@ # # Bazel Build for Google C++ Testing Framework(Google Test) +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) exports_files(["LICENSE"]) -config_setting( - name = "qnx", - constraint_values = ["@platforms//os:qnx"], -) - config_setting( name = "windows", constraint_values = ["@platforms//os:windows"], ) -config_setting( - name = "freebsd", - constraint_values = ["@platforms//os:freebsd"], -) - -config_setting( - name = "openbsd", - constraint_values = ["@platforms//os:openbsd"], -) - config_setting( name = "msvc_compiler", flag_values = { @@ -99,7 +86,6 @@ cc_library( "googlemock/include/gmock/*.h", ]), copts = select({ - ":qnx": [], ":windows": [], "//conditions:default": ["-pthread"], }), @@ -118,10 +104,7 @@ cc_library( "googletest/include", ], linkopts = select({ - ":qnx": ["-lregex"], ":windows": [], - ":freebsd": ["-lm", "-pthread"], - ":openbsd": ["-lm", "-pthread"], "//conditions:default": ["-pthread"], }), deps = select({ diff --git a/googletest/BUILD.gn b/googletest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f890da313f08df81408399e7c6388c94a640c8f6 --- /dev/null +++ b/googletest/BUILD.gn @@ -0,0 +1,137 @@ +# Copyright (C) 2018. Huawei Technologies Co., Ltd. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +config("gtest_private_config") { + visibility = [ ":*" ] + include_dirs = [ "googletest" ] +} + +config("gtest_config") { + include_dirs = [ "googletest/include" ] + if (is_mingw) { + cflags_cc = [ + "-Wno-unused-const-variable", + "-Wno-unused-private-field", + ] + } +} + +static_library("gtest") { + testonly = true + public = [ + "googletest/include/gtest/gtest-spi.h", + "googletest/include/gtest/gtest.h", + ] + sources = [ + "googletest/include/gtest/gtest-death-test.h", + "googletest/include/gtest/gtest-matchers.h", + "googletest/include/gtest/gtest-message.h", + "googletest/include/gtest/gtest-param-test.h", + "googletest/include/gtest/gtest-printers.h", + "googletest/include/gtest/gtest-test-part.h", + "googletest/include/gtest/gtest-typed-test.h", + "googletest/include/gtest/gtest_pred_impl.h", + "googletest/include/gtest/gtest_prod.h", + "googletest/include/gtest/hwext/gtest-ext.h", + "googletest/include/gtest/hwext/gtest-filter.h", + "googletest/include/gtest/hwext/gtest-tag.h", + "googletest/include/gtest/hwext/utils.h", + "googletest/include/gtest/internal/custom/gtest-port.h", + "googletest/include/gtest/internal/custom/gtest-printers.h", + "googletest/include/gtest/internal/custom/gtest.h", + "googletest/include/gtest/internal/gtest-death-test-internal.h", + "googletest/include/gtest/internal/gtest-filepath.h", + "googletest/include/gtest/internal/gtest-internal.h", + "googletest/include/gtest/internal/gtest-param-util.h", + "googletest/include/gtest/internal/gtest-port-arch.h", + "googletest/include/gtest/internal/gtest-port.h", + "googletest/include/gtest/internal/gtest-string.h", + "googletest/include/gtest/internal/gtest-type-util.h", + "googletest/src/gtest-all.cc", + "googletest/src/gtest-death-test.cc", + "googletest/src/gtest-filepath.cc", + "googletest/src/gtest-internal-inl.h", + "googletest/src/gtest-matchers.cc", + "googletest/src/gtest-port.cc", + "googletest/src/gtest-printers.cc", + "googletest/src/gtest-test-part.cc", + "googletest/src/gtest-typed-test.cc", + "googletest/src/gtest.cc", + "googletest/src/hwext/gtest-ext.cc", + "googletest/src/hwext/gtest-filter.cc", + "googletest/src/hwext/gtest-tag.cc", + "googletest/src/hwext/gtest-utils.cc", + ] + sources -= [ "googletest/src/gtest-all.cc" ] + public_configs = [ ":gtest_config" ] + configs += [ ":gtest_private_config" ] + configs -= [ "//build/config/coverage:default_coverage" ] +} + +static_library("gtest_main") { + testonly = true + sources = [ "googletest/src/gtest_main.cc" ] + public_deps = [ ":gtest" ] + configs -= [ "//build/config/coverage:default_coverage" ] +} + +config("gmock_private_config") { + visibility = [ ":*" ] + include_dirs = [ "googlemock" ] +} + +config("gmock_config") { + include_dirs = [ "googlemock/include" ] + + cflags_cc = [ + # The MOCK_METHODn() macros do not specify "override", which triggers this + # warning in users: "error: 'Method' overrides a member function but is not + # marked 'override' [-Werror,-Winconsistent-missing-override]". Suppress + # these warnings until https://github.com/google/googletest/issues/533 is + # fixed. + "-Wno-inconsistent-missing-override", + ] +} + +static_library("gmock") { + testonly = true + public = [ "googlemock/include/gmock/gmock.h" ] + sources = [ + "googlemock/include/gmock/gmock-actions.h", + "googlemock/include/gmock/gmock-cardinalities.h", + "googlemock/include/gmock/gmock-function-mocker.h", + "googlemock/include/gmock/gmock-matchers.h", + "googlemock/include/gmock/gmock-more-actions.h", + "googlemock/include/gmock/gmock-more-matchers.h", + "googlemock/include/gmock/gmock-nice-strict.h", + "googlemock/include/gmock/gmock-spec-builders.h", + "googlemock/include/gmock/internal/custom/gmock-generated-actions.h", + "googlemock/include/gmock/internal/custom/gmock-matchers.h", + "googlemock/include/gmock/internal/custom/gmock-port.h", + "googlemock/include/gmock/internal/gmock-internal-utils.h", + "googlemock/include/gmock/internal/gmock-port.h", + "googlemock/include/gmock/internal/gmock-pp.h", + "googlemock/src/gmock-all.cc", + "googlemock/src/gmock-cardinalities.cc", + "googlemock/src/gmock-internal-utils.cc", + "googlemock/src/gmock-matchers.cc", + "googlemock/src/gmock-spec-builders.cc", + "googlemock/src/gmock.cc", + ] + sources -= [ "googlemock/src/gmock-all.cc" ] + public_configs = [ ":gmock_config" ] + configs += [ ":gmock_private_config" ] + configs -= [ "//build/config/coverage:default_coverage" ] + deps = [ ":gtest" ] +} + +static_library("gmock_main") { + testonly = true + sources = [ "googlemock/src/gmock_main.cc" ] + public_deps = [ + ":gmock", + ":gtest", + ] + configs -= [ "//build/config/coverage:default_coverage" ] +} diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 7d2eb810282b11df34331d554dd616af14e2549a..ea81ab1292d0b9099ac389b6c71885b0e6a1d034 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -1,7 +1,7 @@ # Note: CMake support is community-based. The maintainers do not use CMake # internally. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 2.8.12) if (POLICY CMP0048) cmake_policy(SET CMP0048 NEW) @@ -10,8 +10,10 @@ endif (POLICY CMP0048) project(googletest-distribution) set(GOOGLETEST_VERSION 1.11.0) -if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) - set(CMAKE_CXX_EXTENSIONS OFF) +if (CMAKE_VERSION VERSION_GREATER "3.0.2") + if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) + set(CMAKE_CXX_EXTENSIONS OFF) + endif() endif() enable_testing() diff --git a/googletest/CONTRIBUTING.md b/googletest/CONTRIBUTING.md index 5bdead5389581d85216bb3ae7dac32ba06a92487..da45e4450ce7f155f809f058b6f8a9d05d7642ce 100644 --- a/googletest/CONTRIBUTING.md +++ b/googletest/CONTRIBUTING.md @@ -36,8 +36,7 @@ PR is acceptable as an alternative. This ensures that work isn't being duplicated and communicating your plan early also generally leads to better patches. 4. If your proposed change is accepted, and you haven't already done so, sign a - Contributor License Agreement - ([see details above](#contributor-license-agreements)). + Contributor License Agreement (see details above). 5. Fork the desired repo, develop and test your code changes. 6. Ensure that your code adheres to the existing style in the sample to which you are contributing. diff --git a/googletest/CONTRIBUTORS b/googletest/CONTRIBUTORS index d9bc587b1bd8deaceb1864f97d9da3fd57c4fccb..76db0b40ffb3fe70d5f321d78eade1d1e226fc43 100644 --- a/googletest/CONTRIBUTORS +++ b/googletest/CONTRIBUTORS @@ -34,7 +34,6 @@ Manuel Klimek Mario Tanev Mark Paskin Markus Heule -Martijn Vels Matthew Simmons Mika Raento Mike Bland diff --git a/googletest/OAT.xml b/googletest/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..79905db41139117bf9c6e76cc3557747e7b42163 --- /dev/null +++ b/googletest/OAT.xml @@ -0,0 +1,75 @@ + + + + + + LICENSE + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/googletest/README.OpenSource b/googletest/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..b7b7997fbd79b7af2c19d8428b4e8999613cc9cc --- /dev/null +++ b/googletest/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "googletest", + "License": "BSD 3-Clause License", + "License File": "LICENSE", + "Version Number": "1.11.0", + "Owner": "zhangchunbao@huawei.com", + "Upstream URL": "https://github.com/google/googletest/releases/tag/release-1.11.0", + "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" + } +] diff --git a/googletest/README.md b/googletest/README.md index 29e5a4ea72be29e89aad1eaae682f3d89a96a7f0..7d872a57ed456934329d0872d42fb5e6c30def7e 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -6,7 +6,7 @@ GoogleTest now follows the [Abseil Live at Head philosophy](https://abseil.io/about/philosophy#upgrade-support). -We recommend using the latest commit in the `main` branch in your projects. +We recommend using the latest commit in the `master` branch in your projects. #### Documentation Updates @@ -14,9 +14,9 @@ Our documentation is now live on GitHub Pages at https://google.github.io/googletest/. We recommend browsing the documentation on GitHub Pages rather than directly in the repository. -#### Release 1.11.0 +#### Release 1.10.x -[Release 1.11.0](https://github.com/google/googletest/releases/tag/release-1.11.0) +[Release 1.10.x](https://github.com/google/googletest/releases/tag/release-1.10.0) is now available. #### Coming Soon @@ -109,8 +109,8 @@ Windows and Linux platforms. [GoogleTest UI](https://github.com/ospector/gtest-gbar) is a test runner that runs your test binary, allows you to track its progress via a progress bar, and -displays a list of test failures. Clicking on one shows failure text. GoogleTest -UI is written in C#. +displays a list of test failures. Clicking on one shows failure text. Google +Test UI is written in C#. [GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event listener for GoogleTest that implements the diff --git a/googletest/WORKSPACE b/googletest/WORKSPACE index 7eb18eb984229e836b01781426242a00f888c32d..614f55778e6e1f33235300fe60cbe167c2c34845 100644 --- a/googletest/WORKSPACE +++ b/googletest/WORKSPACE @@ -4,14 +4,21 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "com_google_absl", - sha256 = "aeba534f7307e36fe084b452299e49b97420667a8d28102cf9a0daeed340b859", - strip_prefix = "abseil-cpp-7971fb358ae376e016d2d4fc9327aad95659b25e", urls = ["https://github.com/abseil/abseil-cpp/archive/7971fb358ae376e016d2d4fc9327aad95659b25e.zip"], # 2021-05-20T02:59:16Z + strip_prefix = "abseil-cpp-7971fb358ae376e016d2d4fc9327aad95659b25e", + sha256 = "aeba534f7307e36fe084b452299e49b97420667a8d28102cf9a0daeed340b859", +) + +http_archive( + name = "rules_cc", + urls = ["https://github.com/bazelbuild/rules_cc/archive/68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9.zip"], # 2021-05-14T14:51:14Z + strip_prefix = "rules_cc-68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9", + sha256 = "1e19e9a3bc3d4ee91d7fcad00653485ee6c798efbbf9588d40b34cbfbded143d", ) http_archive( - name = "rules_python", - sha256 = "98b3c592faea9636ac8444bfd9de7f3fb4c60590932d6e6ac5946e3f8dbd5ff6", - strip_prefix = "rules_python-ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2", - urls = ["https://github.com/bazelbuild/rules_python/archive/ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2.zip"], # 2021-05-17T00:24:16Z + name = "rules_python", + urls = ["https://github.com/bazelbuild/rules_python/archive/ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2.zip"], # 2021-05-17T00:24:16Z + strip_prefix = "rules_python-ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2", + sha256 = "98b3c592faea9636ac8444bfd9de7f3fb4c60590932d6e6ac5946e3f8dbd5ff6", ) diff --git a/googletest/bundle.json b/googletest/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..002bd1d6bb09afb58f073424096e63f5464793d5 --- /dev/null +++ b/googletest/bundle.json @@ -0,0 +1,30 @@ +{ + "name": "@ohos/googletest", + "description": "The 1.8.x is the last release supporting pre-C++11 compilers. The 1.8.x will not accept any requests for any new features and any bugfix requests will only be accepted if proven critical", + "version": "3.1", + "license": "BSD 3-Clause", + "publishAs": "code-segment", + "segment": { + "destPath": "third_party/googletest" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "thirdparty_googletest", + "subsystem": "", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/googletest/ci/linux-presubmit.sh b/googletest/ci/linux-presubmit.sh index 003664e50996a1d128bcaebb5902674efbb98072..6bea1cde26aff516d6b7a3780fcdecacb5376388 100644 --- a/googletest/ci/linux-presubmit.sh +++ b/googletest/ci/linux-presubmit.sh @@ -31,8 +31,8 @@ set -euox pipefail -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20210617" -readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20210617" +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20210525" +readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20201015" if [[ -z ${GTEST_ROOT:-} ]]; then GTEST_ROOT="$(realpath $(dirname ${0})/..)" diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index f2f8854bf322e71863444f1e5c9a8cf5947215ab..8dff5ba1508085ae5b26a2716985eb669a90ebd8 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -157,11 +157,8 @@ that can be used in the predicate assertion macro example: ```c++ -using ::testing::FloatLE; -using ::testing::DoubleLE; -... -EXPECT_PRED_FORMAT2(FloatLE, val1, val2); -EXPECT_PRED_FORMAT2(DoubleLE, val1, val2); +EXPECT_PRED_FORMAT2(testing::FloatLE, val1, val2); +EXPECT_PRED_FORMAT2(testing::DoubleLE, val1, val2); ``` The above code verifies that `val1` is less than, or approximately equal to, @@ -205,9 +202,10 @@ You can call the function to assert that types `T1` and `T2` are the same. The function does nothing if the assertion is satisfied. If the types are different, the function call will -fail to compile, the compiler error message will say that `T1 and T2 are not the -same type` and most likely (depending on the compiler) show you the actual -values of `T1` and `T2`. This is mainly useful inside template code. +fail to compile, the compiler error message will say that +`T1 and T2 are not the same type` and most likely (depending on the compiler) +show you the actual values of `T1` and `T2`. This is mainly useful inside +template code. **Caveat**: When used inside a member function of a class template or a function template, `StaticAssertTypeEq()` is effective only if the function is @@ -385,10 +383,10 @@ EXPECT_TRUE(IsCorrectBarIntVector(bar_ints)) ## Death Tests In many applications, there are assertions that can cause application failure if -a condition is not met. These consistency checks, which ensure that the program -is in a known good state, are there to fail at the earliest possible time after -some program state is corrupted. If the assertion checks the wrong condition, -then the program may proceed in an erroneous state, which could lead to memory +a condition is not met. These sanity checks, which ensure that the program is in +a known good state, are there to fail at the earliest possible time after some +program state is corrupted. If the assertion checks the wrong condition, then +the program may proceed in an erroneous state, which could lead to memory corruption, security holes, or worse. Hence it is vitally important to test that such assertion statements work as expected. @@ -560,7 +558,7 @@ The automated testing framework does not set the style flag. You can choose a particular style of death tests by setting the flag programmatically: ```c++ -GTEST_FLAG_SET(death_test_style, "threadsafe") +testing::FLAGS_gtest_death_test_style="threadsafe" ``` You can do this in `main()` to set the style for all death tests in the binary, @@ -570,12 +568,12 @@ restored afterwards, so you need not do that yourself. For example: ```c++ int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); - GTEST_FLAG_SET(death_test_style, "fast"); + testing::FLAGS_gtest_death_test_style = "fast"; return RUN_ALL_TESTS(); } TEST(MyDeathTest, TestOne) { - GTEST_FLAG_SET(death_test_style, "threadsafe"); + testing::FLAGS_gtest_death_test_style = "threadsafe"; // This test is run in the "threadsafe" style: ASSERT_DEATH(ThisShouldDie(), ""); } @@ -612,14 +610,15 @@ Despite the improved thread safety afforded by the "threadsafe" style of death test, thread problems such as deadlock are still possible in the presence of handlers registered with `pthread_atfork(3)`. + ## Using Assertions in Sub-routines {: .callout .note} Note: If you want to put a series of test assertions in a subroutine to check for a complex condition, consider using -[a custom GMock matcher](gmock_cook_book.md#NewMatchers) instead. This lets you -provide a more readable error message in case of failure and avoid all of the -issues described below. +[a custom GMock matcher](gmock_cook_book.md#NewMatchers) +instead. This lets you provide a more readable error message in case of failure +and avoid all of the issues described below. ### Adding Traces to Assertions @@ -632,7 +631,6 @@ the `SCOPED_TRACE` macro or the `ScopedTrace` utility: ```c++ SCOPED_TRACE(message); ``` - ```c++ ScopedTrace trace("file_path", line_number, message); ``` @@ -890,12 +888,6 @@ preceding or following another. Also, the tests must either not modify the state of any shared resource, or, if they do modify the state, they must restore the state to its original value before passing control to the next test. -Note that `SetUpTestSuite()` may be called multiple times for a test fixture -class that has derived classes, so you should not expect code in the function -body to be run only once. Also, derived classes still have access to shared -resources defined as static members, so careful consideration is needed when -managing shared resources to avoid memory leaks. - Here's an example of per-test-suite set-up and tear-down: ```c++ @@ -905,10 +897,7 @@ class FooTest : public testing::Test { // Called before the first test in this test suite. // Can be omitted if not needed. static void SetUpTestSuite() { - // Avoid reallocating static objects if called in subclasses of FooTest. - if (shared_resource_ == nullptr) { - shared_resource_ = new ...; - } + shared_resource_ = new ...; } // Per-test-suite tear-down. @@ -1492,8 +1481,8 @@ In frameworks that report a failure by throwing an exception, you could catch the exception and assert on it. But googletest doesn't use exceptions, so how do we test that a piece of code generates an expected failure? -`"gtest/gtest-spi.h"` contains some constructs to do this. -After #including this header, you can use +`"gtest/gtest-spi.h"` contains some constructs to do this. After #including this header, +you can use ```c++ EXPECT_FATAL_FAILURE(statement, substring); @@ -1597,14 +1586,12 @@ void RegisterMyTests(const std::vector& values) { } ... int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); std::vector values_to_test = LoadValuesFromConfig(); RegisterMyTests(values_to_test); ... return RUN_ALL_TESTS(); } ``` - ## Getting the Current Test's Name Sometimes a function may need to know the name of the currently running test. @@ -1829,7 +1816,8 @@ By default, a googletest program runs all tests the user has defined. In some cases (e.g. iterative test development & execution) it may be desirable stop test execution upon first failure (trading improved latency for completeness). If `GTEST_FAIL_FAST` environment variable or `--gtest_fail_fast` flag is set, -the test runner will stop execution as soon as the first test failure is found. +the test runner will stop execution as soon as the first test failure is +found. #### Temporarily Disabling Tests @@ -1923,58 +1911,6 @@ time. If you combine this with `--gtest_repeat=N`, googletest will pick a different random seed and re-shuffle the tests in each iteration. -### Distributing Test Functions to Multiple Machines - -If you have more than one machine you can use to run a test program, you might -want to run the test functions in parallel and get the result faster. We call -this technique *sharding*, where each machine is called a *shard*. - -GoogleTest is compatible with test sharding. To take advantage of this feature, -your test runner (not part of GoogleTest) needs to do the following: - -1. Allocate a number of machines (shards) to run the tests. -1. On each shard, set the `GTEST_TOTAL_SHARDS` environment variable to the total - number of shards. It must be the same for all shards. -1. On each shard, set the `GTEST_SHARD_INDEX` environment variable to the index - of the shard. Different shards must be assigned different indices, which - must be in the range `[0, GTEST_TOTAL_SHARDS - 1]`. -1. Run the same test program on all shards. When GoogleTest sees the above two - environment variables, it will select a subset of the test functions to run. - Across all shards, each test function in the program will be run exactly - once. -1. Wait for all shards to finish, then collect and report the results. - -Your project may have tests that were written without GoogleTest and thus don't -understand this protocol. In order for your test runner to figure out which test -supports sharding, it can set the environment variable `GTEST_SHARD_STATUS_FILE` -to a non-existent file path. If a test program supports sharding, it will create -this file to acknowledge that fact; otherwise it will not create it. The actual -contents of the file are not important at this time, although we may put some -useful information in it in the future. - -Here's an example to make it clear. Suppose you have a test program `foo_test` -that contains the following 5 test functions: - -``` -TEST(A, V) -TEST(A, W) -TEST(B, X) -TEST(B, Y) -TEST(B, Z) -``` - -Suppose you have 3 machines at your disposal. To run the test functions in -parallel, you would set `GTEST_TOTAL_SHARDS` to 3 on all machines, and set -`GTEST_SHARD_INDEX` to 0, 1, and 2 on the machines respectively. Then you would -run the same `foo_test` on each machine. - -GoogleTest reserves the right to change how the work is distributed across the -shards, but here's one possible scenario: - -* Machine #0 runs `A.V` and `B.X`. -* Machine #1 runs `A.W` and `B.Y`. -* Machine #2 runs `B.Z`. - ### Controlling Test Output #### Colored Terminal Output @@ -2029,6 +1965,8 @@ text because, for example, you don't have an UTF-8 compatible output medium, run the test program with `--gtest_print_utf8=0` or set the `GTEST_PRINT_UTF8` environment variable to `0`. + + #### Generating an XML Report googletest can emit a detailed XML report to a file in addition to its normal @@ -2315,11 +2253,12 @@ IMPORTANT: The exact format of the JSON document is subject to change. #### Detecting Test Premature Exit -Google Test implements the _premature-exit-file_ protocol for test runners to -catch any kind of unexpected exits of test programs. Upon start, Google Test -creates the file which will be automatically deleted after all work has been -finished. Then, the test runner can check if this file exists. In case the file -remains undeleted, the inspected test has exited prematurely. +Google Test implements the _premature-exit-file_ protocol for test runners +to catch any kind of unexpected exits of test programs. Upon start, +Google Test creates the file which will be automatically deleted after +all work has been finished. Then, the test runner can check if this file +exists. In case the file remains undeleted, the inspected test has exited +prematurely. This feature is enabled only if the `TEST_PREMATURE_EXIT_FILE` environment variable has been set. diff --git a/googletest/docs/faq.md b/googletest/docs/faq.md index 8e4fd5eca288a07bf7916bc2b84150375f69b63a..9042da1efb43a6bf0893275bb8c84e544c01c2a1 100644 --- a/googletest/docs/faq.md +++ b/googletest/docs/faq.md @@ -410,6 +410,7 @@ C++ is case-sensitive. Did you spell it as `Setup()`? Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and wonder why it's never called. + ## I have several test suites which share the same test fixture logic, do I have to define a new test fixture class for each of them? This seems pretty tedious. You don't have to. Instead of diff --git a/googletest/docs/gmock_cheat_sheet.md b/googletest/docs/gmock_cheat_sheet.md index 3d164ad629df42a769fa8049317bbe0cb16928dd..17ed7a54d80933ec8fce9a0691c958809c2dedb5 100644 --- a/googletest/docs/gmock_cheat_sheet.md +++ b/googletest/docs/gmock_cheat_sheet.md @@ -230,7 +230,7 @@ class MockFunction { }; ``` -See this [recipe](gmock_cook_book.md#UsingCheckPoints) for one application of +See this [recipe](gmock_cook_book.md#using-check-points) for one application of it. ## Flags diff --git a/googletest/docs/gmock_cook_book.md b/googletest/docs/gmock_cook_book.md index b41c5b98b9881c0cfc2aed6fc1548b30b969a712..c08958eb16ab892787db493ac667b83736b1a369 100644 --- a/googletest/docs/gmock_cook_book.md +++ b/googletest/docs/gmock_cook_book.md @@ -1452,7 +1452,7 @@ the pointer is copied. When the last matcher that references the implementation object dies, the implementation object will be deleted. Therefore, if you have some complex matcher that you want to use again and -again, there is no need to build it every time. Just assign it to a matcher +again, there is no need to build it everytime. Just assign it to a matcher variable and use that variable repeatedly! For example, ```cpp @@ -1754,7 +1754,7 @@ specifies the following DAG (where `s1` is `A -> B`, and `s2` is `A -> C -> D`): | A ---| | - +---> C ---> D + +---> C ---> D ``` This means that A must occur before B and C, and C must occur before D. There's @@ -1980,7 +1980,6 @@ If the mock method also needs to return a value as well, you can chain ```cpp using ::testing::_; -using ::testing::DoAll; using ::testing::Return; using ::testing::SetArgPointee; @@ -2034,7 +2033,10 @@ class MockRolodex : public Rolodex { } ... MockRolodex rolodex; - vector names = {"George", "John", "Thomas"}; + vector names; + names.push_back("George"); + names.push_back("John"); + names.push_back("Thomas"); EXPECT_CALL(rolodex, GetNames(_)) .WillOnce(SetArrayArgument<0>(names.begin(), names.end())); ``` @@ -2602,7 +2604,7 @@ efficient. When the last action that references the implementation object dies, the implementation object will be deleted. If you have some complex action that you want to use again and again, you may -not have to build it from scratch every time. If the action doesn't have an +not have to build it from scratch everytime. If the action doesn't have an internal state (i.e. if it always does the same thing no matter how many times it has been called), you can assign it to an action variable and use that variable repeatedly. For example: @@ -4189,7 +4191,7 @@ This implementation class does *not* need to inherit from any particular class. What matters is that it must have a `Perform()` method template. This method template takes the mock function's arguments as a tuple in a **single** argument, and returns the result of the action. It can be either `const` or not, -but must be invocable with exactly one template argument, which is the result +but must be invokable with exactly one template argument, which is the result type. In other words, you must be able to call `Perform(args)` where `R` is the mock function's return type and `args` is its arguments in a tuple. diff --git a/googletest/docs/gmock_for_dummies.md b/googletest/docs/gmock_for_dummies.md index 0392b5de3da7b089bb7ee6672ac51dc0a1a3ce31..1f4cc246c483109a494adc7c0b3d0981e061c77b 100644 --- a/googletest/docs/gmock_for_dummies.md +++ b/googletest/docs/gmock_for_dummies.md @@ -480,8 +480,8 @@ the *default* action for the function every time (unless, of course, you have a `WillRepeatedly()`.). What can we do inside `WillOnce()` besides `Return()`? You can return a -reference using `ReturnRef(`*`variable`*`)`, or invoke a pre-defined function, -among [others](gmock_cook_book.md#using-actions). +reference using `ReturnRef(*variable*)`, or invoke a pre-defined function, among +[others](gmock_cook_book.md#using-actions). **Important note:** The `EXPECT_CALL()` statement evaluates the action clause only once, even though the action may be performed many times. Therefore you diff --git a/googletest/docs/pkgconfig.md b/googletest/docs/pkgconfig.md index 18a2546a3846acde26b930a5ee30a00cce96a570..768e9b4c2673977f4f459dbd76c569ad490978ee 100644 --- a/googletest/docs/pkgconfig.md +++ b/googletest/docs/pkgconfig.md @@ -105,7 +105,7 @@ includedir=/usr/include Name: gtest Description: GoogleTest (without main() function) -Version: 1.11.0 +Version: 1.10.0 URL: https://github.com/google/googletest Libs: -L${libdir} -lgtest -lpthread Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread diff --git a/googletest/docs/primer.md b/googletest/docs/primer.md index aecc368b08fe5db5ba00b2d94e2940d6af098d43..6d8fdf443923cacc83425cf45d5102d9889f6241 100644 --- a/googletest/docs/primer.md +++ b/googletest/docs/primer.md @@ -162,9 +162,9 @@ TEST(TestSuiteName, TestName) { `TEST()` arguments go from general to specific. The *first* argument is the name of the test suite, and the *second* argument is the test's name within the test -suite. Both names must be valid C++ identifiers, and they should not contain any -underscores (`_`). A test's *full name* consists of its containing test suite -and its individual name. Tests from different test suites can have the same +suite. Both names must be valid C++ identifiers, and they should not contain +any underscores (`_`). A test's *full name* consists of its containing test suite and +its individual name. Tests from different test suites can have the same individual name. For example, let's take a simple integer function: @@ -245,8 +245,8 @@ Also, you must first define a test fixture class before using it in a declaration`". For each test defined with `TEST_F()`, googletest will create a *fresh* test -fixture at runtime, immediately initialize it via `SetUp()`, run the test, clean -up by calling `TearDown()`, and then delete the test fixture. Note that +fixture at runtime, immediately initialize it via `SetUp()`, run the test, +clean up by calling `TearDown()`, and then delete the test fixture. Note that different tests in the same test suite have different test fixture objects, and googletest always deletes a test fixture before it creates the next one. googletest does **not** reuse the same test fixture for multiple tests. Any @@ -342,8 +342,8 @@ your defined tests in order to run them. After defining your tests, you can run them with `RUN_ALL_TESTS()`, which returns `0` if all the tests are successful, or `1` otherwise. Note that -`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from different -test suites, or even different source files. +`RUN_ALL_TESTS()` runs *all tests* in your link unit--they can be from +different test suites, or even different source files. When invoked, the `RUN_ALL_TESTS()` macro: @@ -456,8 +456,8 @@ int main(int argc, char **argv) { The `::testing::InitGoogleTest()` function parses the command line for googletest flags, and removes all recognized flags. This allows the user to -control a test program's behavior via various flags, which we'll cover in the -[AdvancedGuide](advanced.md). You **must** call this function before calling +control a test program's behavior via various flags, which we'll cover in +the [AdvancedGuide](advanced.md). You **must** call this function before calling `RUN_ALL_TESTS()`, or the flags won't be properly initialized. On Windows, `InitGoogleTest()` also works with wide strings, so it can be used diff --git a/googletest/docs/quickstart-bazel.md b/googletest/docs/quickstart-bazel.md index 5d6e9c68adb0e6ad15e73660b0102611e9ad5538..362ee6d0506eb04b85fa1b40e57db3ef1c38c09a 100644 --- a/googletest/docs/quickstart-bazel.md +++ b/googletest/docs/quickstart-bazel.md @@ -17,7 +17,7 @@ See [Supported Platforms](platforms.md) for more information about platforms compatible with GoogleTest. If you don't already have Bazel installed, see the -[Bazel installation guide](https://docs.bazel.build/versions/main/install.html). +[Bazel installation guide](https://docs.bazel.build/versions/master/install.html). {: .callout .note} Note: The terminal commands in this tutorial show a Unix shell prompt, but the @@ -26,7 +26,7 @@ commands work on the Windows command line as well. ## Set up a Bazel workspace A -[Bazel workspace](https://docs.bazel.build/versions/main/build-ref.html#workspace) +[Bazel workspace](https://docs.bazel.build/versions/master/build-ref.html#workspace) is a directory on your filesystem that you use to manage source files for the software you want to build. Each workspace directory has a text file named `WORKSPACE` which may be empty, or may contain references to external @@ -40,9 +40,9 @@ $ mkdir my_workspace && cd my_workspace Next, you’ll create the `WORKSPACE` file to specify dependencies. A common and recommended way to depend on GoogleTest is to use a -[Bazel external dependency](https://docs.bazel.build/versions/main/external.html) +[Bazel external dependency](https://docs.bazel.build/versions/master/external.html) via the -[`http_archive` rule](https://docs.bazel.build/versions/main/repo/http.html#http_archive). +[`http_archive` rule](https://docs.bazel.build/versions/master/repo/http.html#http_archive). To do this, in the root directory of your workspace (`my_workspace/`), create a file named `WORKSPACE` with the following contents: @@ -62,6 +62,18 @@ as a ZIP archive from GitHub. In the above example, GoogleTest version to use; we recommend updating the hash often to point to the latest version. +Bazel also needs a dependency on the +[`rules_cc` repository](https://github.com/bazelbuild/rules_cc) to build C++ +code, so add the following to the `WORKSPACE` file: + +``` +http_archive( + name = "rules_cc", + urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"], + strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556", +) +``` + Now you're ready to build C++ code that uses GoogleTest. ## Create and run a binary @@ -92,6 +104,8 @@ To build the code, create a file named `BUILD` in the same directory with the following contents: ``` +load("@rules_cc//cc:defs.bzl", "cc_test") + cc_test( name = "hello_test", size = "small", @@ -104,7 +118,7 @@ This `cc_test` rule declares the C++ test binary you want to build, and links to GoogleTest (`//:gtest_main`) using the prefix you specified in the `WORKSPACE` file (`@com_google_googletest`). For more information about Bazel `BUILD` files, see the -[Bazel C++ Tutorial](https://docs.bazel.build/versions/main/tutorial/cpp.html). +[Bazel C++ Tutorial](https://docs.bazel.build/versions/master/tutorial/cpp.html). Now you can build and run your test: diff --git a/googletest/docs/reference/actions.md b/googletest/docs/reference/actions.md index ab81a129eff692d513b27c155abed96dd30f8db6..166d2a897a44465c75a2f3fb9ad34025c8fc98d1 100644 --- a/googletest/docs/reference/actions.md +++ b/googletest/docs/reference/actions.md @@ -6,7 +6,7 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace. ## Returning a Value -| Action | Description | +| | | | :-------------------------------- | :-------------------------------------------- | | `Return()` | Return from a `void` mock function. | | `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type at the time the expectation is set, not when the action is executed. | @@ -20,7 +20,7 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace. ## Side Effects -| Action | Description | +| | | | :--------------------------------- | :-------------------------------------- | | `Assign(&variable, value)` | Assign `value` to variable. | | `DeleteArg()` | Delete the `N`-th (0-based) argument, which must be a pointer. | @@ -38,9 +38,9 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace. In the following, by "callable" we mean a free function, `std::function`, functor, or lambda. -| Action | Description | +| | | | :---------------------------------- | :------------------------------------- | -| `f` | Invoke `f` with the arguments passed to the mock function, where `f` is a callable. | +| `f` | Invoke f with the arguments passed to the mock function, where f is a callable. | | `Invoke(f)` | Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor. | | `Invoke(object_pointer, &class::method)` | Invoke the method on the object with the arguments passed to the mock function. | | `InvokeWithoutArgs(f)` | Invoke `f`, which can be a global/static function or a functor. `f` must take no arguments. | @@ -86,7 +86,7 @@ value, and `foo` by reference. ## Default Action -| Action | Description | +| Matcher | Description | | :------------ | :----------------------------------------------------- | | `DoDefault()` | Do the default action (specified by `ON_CALL()` or the built-in one). | @@ -96,7 +96,7 @@ composite action - trying to do so will result in a run-time error. ## Composite Actions -| Action | Description | +| | | | :----------------------------- | :------------------------------------------ | | `DoAll(a1, a2, ..., an)` | Do all actions `a1` to `an` and return the result of `an` in each invocation. The first `n - 1` sub-actions must return void and will receive a readonly view of the arguments. | | `IgnoreResult(a)` | Perform action `a` and ignore its result. `a` must not return void. | @@ -106,7 +106,7 @@ composite action - trying to do so will result in a run-time error. ## Defining Actions -| Macro | Description | +| | | | :--------------------------------- | :-------------------------------------- | | `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. | | `ACTION_P(Plus, n) { return arg0 + n; }` | Defines an action `Plus(n)` to return the sum of the mock function's argument #0 and `n`. | diff --git a/googletest/docs/reference/matchers.md b/googletest/docs/reference/matchers.md index 47d2808c3baf3e2f9e2cfe32eaae504343a99a5c..9e40cab70454a68fa8a9d708b6fa2fe87e498a76 100644 --- a/googletest/docs/reference/matchers.md +++ b/googletest/docs/reference/matchers.md @@ -88,17 +88,16 @@ The `argument` can be either a C string or a C++ string object: | Matcher | Description | | :---------------------- | :------------------------------------------------- | -| `ContainsRegex(string)` | `argument` matches the given regular expression. | -| `EndsWith(suffix)` | `argument` ends with string `suffix`. | -| `HasSubstr(string)` | `argument` contains `string` as a sub-string. | -| `IsEmpty()` | `argument` is an empty string. | -| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. | -| `StartsWith(prefix)` | `argument` starts with string `prefix`. | -| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. | -| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. | -| `StrEq(string)` | `argument` is equal to `string`. | -| `StrNe(string)` | `argument` is not equal to `string`. | -| `WhenBase64Unescaped(m)` | `argument` is a base-64 escaped string whose unescaped string matches `m`. | +| `ContainsRegex(string)` | `argument` matches the given regular expression. | +| `EndsWith(suffix)` | `argument` ends with string `suffix`. | +| `HasSubstr(string)` | `argument` contains `string` as a sub-string. | +| `IsEmpty()` | `argument` is an empty string. | +| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. | +| `StartsWith(prefix)` | `argument` starts with string `prefix`. | +| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. | +| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. | +| `StrEq(string)` | `argument` is equal to `string`. | +| `StrNe(string)` | `argument` is not equal to `string`. | `ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They use the regular expression syntax defined @@ -117,7 +116,6 @@ messages, you can use: | `BeginEndDistanceIs(m)` | `argument` is a container whose `begin()` and `end()` iterators are separated by a number of increments matching `m`. E.g. `BeginEndDistanceIs(2)` or `BeginEndDistanceIs(Lt(2))`. For containers that define a `size()` method, `SizeIs(m)` may be more efficient. | | `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. | | `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. | -| `Contains(e).Times(n)` | `argument` contains elements that match `e`, which can be either a value or a matcher, and the number of matches is `n`, which can be either a value or a matcher. Unlike the plain `Contains` and `Each` this allows to check for arbitrary occurrences including testing for absence with `Contains(e).Times(0)`. | | `Each(e)` | `argument` is a container where *every* element matches `e`, which can be either a value or a matcher. | | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. | | `ElementsAreArray({e0, e1, ..., en})`, `ElementsAreArray(a_container)`, `ElementsAreArray(begin, end)`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. | @@ -148,6 +146,7 @@ messages, you can use: one might write: ```cpp + using ::std::get; MATCHER(FooEq, "") { return std::get<0>(arg).Equals(std::get<1>(arg)); } @@ -238,7 +237,6 @@ You can make a matcher from one or more other matchers: | `AnyOf(m1, m2, ..., mn)` | `argument` matches at least one of the matchers `m1` to `mn`. | | `AnyOfArray({m0, m1, ..., mn})`, `AnyOfArray(a_container)`, `AnyOfArray(begin, end)`, `AnyOfArray(array)`, or `AnyOfArray(array, count)` | The same as `AnyOf()` except that the matchers come from an initializer list, STL-style container, iterator range, or C-style array. | | `Not(m)` | `argument` doesn't match matcher `m`. | -| `Conditional(cond, m1, m2)` | Matches matcher `m1` if `cond` evaluates to true, else matches `m2`.| ## Adapters for Matchers @@ -261,7 +259,7 @@ which must be a permanent callback. ## Defining Matchers -| Macro | Description | +| Matcher | Description | | :----------------------------------- | :------------------------------------ | | `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. | | `MATCHER_P(IsDivisibleBy, n, "") { *result_listener << "where the remainder is " << (arg % n); return (arg % n) == 0; }` | Defines a matcher `IsDivisibleBy(n)` to match a number divisible by `n`. | diff --git a/googletest/googlemock/README.md b/googletest/googlemock/README.md index 7da60655dba8b8e91ec66a9a65f97139af03ee9b..ead688325d2c603575148543bd0f1b136412c207 100644 --- a/googletest/googlemock/README.md +++ b/googletest/googlemock/README.md @@ -35,6 +35,10 @@ Details and examples can be found here: * [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) * [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) +Please note that code under scripts/generator/ is from the +[cppclean project](http://code.google.com/p/cppclean/) and under the Apache +License, which is different from GoogleMock's license. + GoogleMock is a part of [GoogleTest C++ testing framework](http://github.com/google/googletest/) and a subject to the same requirements. diff --git a/googletest/googlemock/include/gmock/gmock-actions.h b/googletest/googlemock/include/gmock/gmock-actions.h index 0046aaf6f6b6fdf5906aff3b09d769116da5fd11..f2393bd3afadaba8506261b18a32040395a28267 100644 --- a/googletest/googlemock/include/gmock/gmock-actions.h +++ b/googletest/googlemock/include/gmock/gmock-actions.h @@ -125,6 +125,8 @@ // To learn more about using these macros, please search for 'ACTION' on // https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/googletest/googlemock/include/gmock/gmock-cardinalities.h b/googletest/googlemock/include/gmock/gmock-cardinalities.h index c45fd641f3a59ab4cf18bcfd79fb241a72f3e057..fc7f803a7a6515c21e3fbf9b505b0a76e8b9c670 100644 --- a/googletest/googlemock/include/gmock/gmock-cardinalities.h +++ b/googletest/googlemock/include/gmock/gmock-cardinalities.h @@ -34,6 +34,8 @@ // cardinalities can be defined by the user implementing the // CardinalityInterface interface if necessary. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ diff --git a/googletest/googlemock/include/gmock/gmock-function-mocker.h b/googletest/googlemock/include/gmock/gmock-function-mocker.h index e6913e5834cfc2963c36e50b3fbe81547a9b8ee4..0fc6f6f3f13ccdaf94a4d055783879a57dcf8dc5 100644 --- a/googletest/googlemock/include/gmock/gmock-function-mocker.h +++ b/googletest/googlemock/include/gmock/gmock-function-mocker.h @@ -31,6 +31,8 @@ // // This file implements MOCK_METHOD. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT @@ -62,39 +64,6 @@ struct ThisRefAdjuster { } }; -constexpr bool PrefixOf(const char* a, const char* b) { - return *a == 0 || (*a == *b && internal::PrefixOf(a + 1, b + 1)); -} - -template -constexpr bool StartsWith(const char (&prefix)[N], const char (&str)[M]) { - return N <= M && internal::PrefixOf(prefix, str); -} - -template -constexpr bool EndsWith(const char (&suffix)[N], const char (&str)[M]) { - return N <= M && internal::PrefixOf(suffix, str + M - N); -} - -template -constexpr bool Equals(const char (&a)[N], const char (&b)[M]) { - return N == M && internal::PrefixOf(a, b); -} - -template -constexpr bool ValidateSpec(const char (&spec)[N]) { - return internal::Equals("const", spec) || - internal::Equals("override", spec) || - internal::Equals("final", spec) || - internal::Equals("noexcept", spec) || - (internal::StartsWith("noexcept(", spec) && - internal::EndsWith(")", spec)) || - internal::Equals("ref(&)", spec) || - internal::Equals("ref(&&)", spec) || - (internal::StartsWith("Calltype(", spec) && - internal::EndsWith(")", spec)); -} - } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -117,18 +86,17 @@ using internal::FunctionMocker; #define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ - GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ - GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ - GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ - GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ - GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ - GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ - GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ - GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Spec), \ - GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ +#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ + GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ + GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ + GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ + GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ + GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ + GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ + GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ + GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ + GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) #define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ @@ -202,7 +170,7 @@ using internal::FunctionMocker; #define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ -// Valid modifiers. +// Five Valid modifiers. #define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) @@ -221,14 +189,6 @@ using internal::FunctionMocker; GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ _elem, ) -#define GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Tuple) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE, ~, _Tuple) - -#define GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE(_i, _, _elem) \ - GMOCK_PP_IF( \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem)), \ - GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) - #define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) @@ -236,25 +196,19 @@ using internal::FunctionMocker; GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) -#ifdef GMOCK_INTERNAL_STRICT_SPEC_ASSERT -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ - static_assert( \ - ::testing::internal::ValidateSpec(GMOCK_PP_STRINGIZE(_elem)), \ - "Token \'" GMOCK_PP_STRINGIZE( \ - _elem) "\' cannot be recognized as a valid specification " \ - "modifier. Is a ',' missing?"); -#else -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ - static_assert( \ - (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem))) == 1, \ - GMOCK_PP_STRINGIZE( \ +#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) + +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ + static_assert( \ + (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ + GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ + GMOCK_PP_STRINGIZE( \ _elem) " cannot be recognized as a valid specification modifier."); -#endif // GMOCK_INTERNAL_STRICT_SPEC_ASSERT // Modifiers implementation. #define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ @@ -284,12 +238,26 @@ using internal::FunctionMocker; #define GMOCK_INTERNAL_UNPACK_ref(x) x -#define GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CALLTYPE_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_CALLTYPE_I_Calltype , +#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ + GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ + GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ + (_elem) -#define GMOCK_INTERNAL_UNPACK_Calltype(...) __VA_ARGS__ +// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and +// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows +// maybe they can be simplified somehow. +#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \ + GMOCK_INTERNAL_IS_CALLTYPE_I( \ + GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) +#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg) + +#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ + GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ + GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) +#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ + GMOCK_PP_IDENTITY _arg + +#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype // Note: The use of `identity_t` here allows _Ret to represent return types that // would normally need to be specified in a different way. For example, a method diff --git a/googletest/googlemock/include/gmock/gmock-matchers.h b/googletest/googlemock/include/gmock/gmock-matchers.h index d9523695311e0df9a36da23793bc00d6a599ba70..86be9c176ebcaf8e8e373626d851f4be2f4687c9 100644 --- a/googletest/googlemock/include/gmock/gmock-matchers.h +++ b/googletest/googlemock/include/gmock/gmock-matchers.h @@ -250,6 +250,8 @@ // See googletest/include/gtest/gtest-matchers.h for the definition of class // Matcher, class MatcherInterface, and others. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ @@ -1122,45 +1124,6 @@ class EndsWithMatcher { const StringType suffix_; }; -// Implements the polymorphic WhenBase64Unescaped(matcher) matcher, which can be -// used as a Matcher as long as T can be converted to a string. -class WhenBase64UnescapedMatcher { - public: - using is_gtest_matcher = void; - - explicit WhenBase64UnescapedMatcher( - const Matcher& internal_matcher) - : internal_matcher_(internal_matcher) {} - - // Matches anything that can convert to std::string. - template - bool MatchAndExplain(const MatcheeStringType& s, - MatchResultListener* listener) const { - const std::string s2(s); // NOLINT (needed for working with string_view). - std::string unescaped; - if (!internal::Base64Unescape(s2, &unescaped)) { - if (listener != nullptr) { - *listener << "is not a valid base64 escaped string"; - } - return false; - } - return MatchPrintAndExplain(unescaped, internal_matcher_, listener); - } - - void DescribeTo(::std::ostream* os) const { - *os << "matches after Base64Unescape "; - internal_matcher_.DescribeTo(os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "does not match after Base64Unescape "; - internal_matcher_.DescribeTo(os); - } - - private: - const Matcher internal_matcher_; -}; - // Implements a matcher that compares the two fields of a 2-tuple // using one of the ==, <=, <, etc, operators. The two fields being // compared don't have to have the same type. @@ -1442,30 +1405,6 @@ class AnyOfMatcherImpl : public MatcherInterface { template using AnyOfMatcher = VariadicMatcher; -// ConditionalMatcher is the implementation of Conditional(cond, m1, m2) -template -class ConditionalMatcher { - public: - ConditionalMatcher(bool condition, MatcherTrue matcher_true, - MatcherFalse matcher_false) - : condition_(condition), - matcher_true_(std::move(matcher_true)), - matcher_false_(std::move(matcher_false)) {} - - template - operator Matcher() const { // NOLINT(runtime/explicit) - return condition_ ? SafeMatcherCast(matcher_true_) - : SafeMatcherCast(matcher_false_); - } - - private: - bool condition_; - MatcherTrue matcher_true_; - MatcherFalse matcher_false_; - - GTEST_DISALLOW_ASSIGN_(ConditionalMatcher); -}; - // Wrapper for implementation of Any/AllOfArray(). template