├── .gitignore ├── tests ├── gtest │ ├── CMakeLists.txt │ ├── internal │ │ ├── custom │ │ │ ├── README.md │ │ │ ├── gtest.h │ │ │ ├── gtest-port.h │ │ │ └── gtest-printers.h │ │ ├── gtest-port-arch.h │ │ ├── gtest-type-util.h │ │ ├── gtest-string.h │ │ └── gtest-filepath.h │ ├── gmock-all.cc │ ├── gtest-all.cc │ ├── gtest_prod.h │ ├── gmock.h │ ├── gtest-test-part.h │ ├── gtest-message.h │ ├── gtest-assertion-result.h │ └── gtest-spi.h ├── testmain.cc ├── gmock │ ├── internal │ │ ├── custom │ │ │ ├── gmock-generated-actions.h │ │ │ ├── README.md │ │ │ ├── gmock-matchers.h │ │ │ └── gmock-port.h │ │ └── gmock-port.h │ ├── gmock-more-matchers.h │ ├── gmock.h │ ├── gmock-cardinalities.h │ └── gmock-nice-strict.h ├── dense_hash_map_unittests.cc ├── CMakeLists.txt ├── dense_hash_set_unittests.cc ├── src │ ├── gtest_main.cc │ ├── gtest-all.cc │ ├── gmock_main.cc │ ├── gtest-assertion-result.cc │ ├── gtest-matchers.cc │ ├── gtest-typed-test.cc │ ├── gtest-test-part.cc │ ├── gmock-cardinalities.cc │ ├── gmock.cc │ └── gmock-internal-utils.cc ├── simple_unittests.cc ├── fixture_unittests.cc └── allocator_unittests.cc ├── .github └── workflows │ ├── build_nix.yml │ ├── build_osx.yml │ └── build_win.yml ├── CMakeLists.txt ├── README.md ├── LICENSE ├── Makefile ├── docs ├── index.html ├── designstyle.css └── performance.html ├── sparsehash ├── traits └── internal │ └── libc_allocator_with_realloc.h └── README /.gitignore: -------------------------------------------------------------------------------- 1 | sparsehash/.DS_Store 2 | .DS_Store 3 | *.o 4 | *_unittests -------------------------------------------------------------------------------- /tests/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(gtest gtest-all.cc gmock-all.cc) 2 | -------------------------------------------------------------------------------- /tests/testmain.cc: -------------------------------------------------------------------------------- 1 | #include "gmock/gmock.h" 2 | #include "gtest/gtest.h" 3 | 4 | int main(int argc, char** argv) { 5 | // The following line must be executed to initialize Google Mock 6 | // (and Google Test) before running the tests. 7 | ::testing::InitGoogleMock(&argc, argv); 8 | return RUN_ALL_TESTS(); 9 | } -------------------------------------------------------------------------------- /tests/gmock/internal/custom/gmock-generated-actions.h: -------------------------------------------------------------------------------- 1 | // IWYU pragma: private, include "gmock/gmock.h" 2 | // IWYU pragma: friend gmock/.* 3 | 4 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 5 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 6 | 7 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ 8 | -------------------------------------------------------------------------------- /.github/workflows/build_nix.yml: -------------------------------------------------------------------------------- 1 | name: ubuntu-latest 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: test 16 | run: mkdir build && cd build && cmake .. -DCMAKE_CXX_FLAGS="-D_SPARSEHASH_CI_TESTING_=1" 17 | 18 | -------------------------------------------------------------------------------- /.github/workflows/build_osx.yml: -------------------------------------------------------------------------------- 1 | name: macos-latest 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: macos-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: test 16 | run: mkdir build && cd build && cmake .. -DCMAKE_CXX_FLAGS="-D_SPARSEHASH_CI_TESTING_=1" 17 | 18 | -------------------------------------------------------------------------------- /.github/workflows/build_win.yml: -------------------------------------------------------------------------------- 1 | name: windows-latest 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: windows-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - uses: ilammy/msvc-dev-cmd@v1 16 | with: 17 | arch: amd64 18 | 19 | - shell: cmd 20 | name: test 21 | run: mkdir build && cd build && cmake .. -DCMAKE_CXX_FLAGS="-D_SPARSEHASH_CI_TESTING_=1" 22 | 23 | -------------------------------------------------------------------------------- /tests/dense_hash_map_unittests.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Lukas Barth on 17.04.18. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "sparsehash/dense_hash_map" 7 | 8 | using google::dense_hash_map; 9 | 10 | TEST(DenseHashMap, TestEmplaceHint) { 11 | dense_hash_map map; 12 | map.set_empty_key(0); 13 | 14 | const char * str1 = "Hello"; 15 | 16 | map.insert({42, str1}); 17 | auto it = map.begin(); 18 | map.emplace_hint(it, 1701, "World"); 19 | 20 | ASSERT_EQ(map.size(), 2u); 21 | } -------------------------------------------------------------------------------- /tests/gmock/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gmock-port.h` 6 | 7 | The following macros can be defined: 8 | 9 | ### Flag related macros: 10 | 11 | * `GMOCK_DECLARE_bool_(name)` 12 | * `GMOCK_DECLARE_int32_(name)` 13 | * `GMOCK_DECLARE_string_(name)` 14 | * `GMOCK_DEFINE_bool_(name, default_val, doc)` 15 | * `GMOCK_DEFINE_int32_(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)` 19 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.3) 2 | 3 | set(CMAKE_BUILD_TYPE Release) 4 | project (sparsehash 5 | VERSION 2.11.1) 6 | 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") 8 | if(NOT MSVC) 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wpedantic -Wno-missing-field-initializers") 10 | endif() 11 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") 12 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") 13 | 14 | include_directories(.) 15 | 16 | enable_testing() 17 | add_subdirectory(tests) 18 | 19 | install(DIRECTORY sparsehash DESTINATION include/google) 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Experimental C++11 version of sparsehash 2 | 3 | [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) 4 | 5 | | Operating system | Build Status | 6 | | ------------- | ------------- | 7 | | Linux/Mac | [![Linux/Mac Build](https://travis-ci.org/sparsehash/sparsehash-c11.svg?branch=master)](https://travis-ci.org/sparsehash/sparsehash-c11) | 8 | | Windows | [![Windows Build](https://ci.appveyor.com/api/projects/status/i2eikr5a5d6wf9u8/branch/master?svg=true)](https://ci.appveyor.com/project/Dekken/sparsehash-c11) | 9 | 10 | [Original README](https://github.com/sparsehash/sparsehash-c11/raw/master/README) -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | add_subdirectory(gtest) 4 | 5 | add_executable(sparsehash_unittests 6 | testmain.cc 7 | sparsetable_unittests.cc 8 | simple_unittests.cc 9 | hashtable_unittests.cc 10 | hashtable_c11_unittests.cc 11 | fixture_unittests.cc 12 | allocator_unittests.cc 13 | dense_hash_set_unittests.cc 14 | dense_hash_map_unittests.cc) 15 | 16 | add_executable(bench bench.cc) 17 | 18 | add_test(sparsehash_unittests sparsehash_unittests) 19 | 20 | set(_THREAD_LIB "") 21 | if(NOT WIN32) 22 | set(_THREAD_LIB pthread) 23 | endif() 24 | 25 | target_link_libraries(sparsehash_unittests gtest ${_THREAD_LIB}) 26 | target_link_libraries(bench ${_THREAD_LIB}) 27 | -------------------------------------------------------------------------------- /tests/dense_hash_set_unittests.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Lukas Barth on 17.04.18. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "sparsehash/dense_hash_set" 7 | 8 | using google::dense_hash_set; 9 | 10 | TEST(DenseHashSet, TestEmplaceHint) { 11 | dense_hash_set set; 12 | set.set_empty_key(nullptr); 13 | 14 | const char * str1 = "Hello"; 15 | const char * str2 = "World"; 16 | 17 | set.insert(str1); 18 | auto it = set.begin(); 19 | set.emplace_hint(it, str2); 20 | 21 | ASSERT_EQ(set.size(), 2ul); 22 | } 23 | 24 | TEST(DenseHashSet, TestEmplaceHintAfterDelete) { 25 | dense_hash_set set; 26 | 27 | const char * deleted_ptr = ""; 28 | const char * str1 = "Hello"; 29 | 30 | set.set_empty_key(nullptr); 31 | set.set_deleted_key(deleted_ptr); 32 | 33 | auto insertion_result = set.insert(str1); 34 | auto str1_inserted_it = insertion_result.first; 35 | 36 | auto deleted_iterator = set.erase(str1_inserted_it); 37 | set.emplace_hint(deleted_iterator, str1); 38 | } -------------------------------------------------------------------------------- /tests/gtest/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gtest.h` 6 | 7 | ### The following macros can be defined: 8 | 9 | * `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of 10 | `OsStackTraceGetterInterface`. 11 | * `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See 12 | `testing::TempDir` for semantics and signature. 13 | 14 | ## Header `gtest-port.h` 15 | 16 | The following macros can be defined: 17 | 18 | ### Logging: 19 | 20 | * `GTEST_LOG_(severity)` 21 | * `GTEST_CHECK_(condition)` 22 | * Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. 23 | 24 | ### Threading: 25 | 26 | * `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. 27 | * `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` 28 | are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` 29 | and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` 30 | * `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` 31 | * `GTEST_LOCK_EXCLUDED_(locks)` 32 | 33 | ### Underlying library support features 34 | 35 | * `GTEST_HAS_CXXABI_H_` 36 | 37 | ### Exporting API symbols: 38 | 39 | * `GTEST_API_` - Specifier for exported symbols. 40 | 41 | ## Header `gtest-printers.h` 42 | 43 | * See documentation at `gtest/gtest-printers.h` for details on how to define a 44 | custom printer. 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TEST_DIR = tests 2 | 3 | CPPFLAGS += -I$(TEST_DIR) -I. -isystem $(TEST_DIR)/gtest 4 | CXXFLAGS += -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -std=c++11 -O3 -D_SPARSEHASH_CI_TESTING_ ${_CXXFLAGS} 5 | LDFLAGS += -lpthread 6 | 7 | all : sparsehash_unittests bench 8 | 9 | check : all 10 | ./sparsehash_unittests 11 | 12 | clean : 13 | rm -rf sparsehash_unittests *.o 14 | 15 | bench.o : $(TEST_DIR)/bench.cc 16 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/bench.cc 17 | 18 | bench: bench.o 19 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) 20 | 21 | gmock-gtest-all.o : 22 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/gtest/gmock-gtest-all.cc 23 | 24 | fixture_unittests.o : $(TEST_DIR)/fixture_unittests.cc 25 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/fixture_unittests.cc 26 | 27 | simple_unittests.o : $(TEST_DIR)/simple_unittests.cc 28 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/simple_unittests.cc 29 | 30 | sparsetable_unittests.o : $(TEST_DIR)/sparsetable_unittests.cc 31 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/sparsetable_unittests.cc 32 | 33 | allocator_unittests.o : $(TEST_DIR)/allocator_unittests.cc 34 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/allocator_unittests.cc 35 | 36 | hashtable_unittests.o: $(TEST_DIR)/hashtable_unittests.cc 37 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/hashtable_unittests.cc 38 | 39 | hashtable_c11_unittests.o: $(TEST_DIR)/hashtable_c11_unittests.cc 40 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/hashtable_c11_unittests.cc 41 | 42 | testmain.o : $(TEST_DIR)/*.cc 43 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/testmain.cc 44 | 45 | sparsehash_unittests : simple_unittests.o sparsetable_unittests.o allocator_unittests.o hashtable_unittests.o hashtable_c11_unittests.o fixture_unittests.o testmain.o gmock-gtest-all.o 46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) 47 | 48 | -------------------------------------------------------------------------------- /tests/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 38 | -------------------------------------------------------------------------------- /tests/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 38 | -------------------------------------------------------------------------------- /tests/gmock/internal/custom/gmock-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Injection point for custom user configurations. See README for details 31 | 32 | // IWYU pragma: private, include "gmock/gmock.h" 33 | // IWYU pragma: friend gmock/.* 34 | 35 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 36 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 37 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ 38 | -------------------------------------------------------------------------------- /tests/gmock/internal/custom/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | // IWYU pragma: private, include "gmock/gmock.h" 35 | // IWYU pragma: friend gmock/.* 36 | 37 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 38 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 39 | 40 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ 41 | -------------------------------------------------------------------------------- /tests/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 35 | #if GTEST_OS_ESP8266 36 | extern "C" { 37 | #endif 38 | void setup() { testing::InitGoogleTest(); } 39 | 40 | void loop() { RUN_ALL_TESTS(); } 41 | 42 | #if GTEST_OS_ESP8266 43 | } 44 | #endif 45 | 46 | #else 47 | 48 | GTEST_API_ int main(int argc, char **argv) { 49 | printf("Running main() from %s\n", __FILE__); 50 | testing::InitGoogleTest(&argc, argv); 51 | return RUN_ALL_TESTS(); 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /tests/gtest/internal/custom/gtest-printers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | // 30 | // This file provides an injection point for custom printers in a local 31 | // installation of gTest. 32 | // It will be included from gtest-printers.h and the overrides in this file 33 | // will be visible to everyone. 34 | // 35 | // Injection point for custom user configurations. See README for details 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /tests/gtest/gmock-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // 31 | // Google C++ Mocking Framework (Google Mock) 32 | // 33 | // This file #includes all Google Mock implementation .cc files. The 34 | // purpose is to allow a user to build Google Mock by compiling this 35 | // file alone. 36 | 37 | // This line ensures that gmock.h can be compiled on its own, even 38 | // when it's fused. 39 | #include "gmock/gmock.h" 40 | 41 | // The following lines pull in the real gmock *.cc files. 42 | #include "src/gmock-cardinalities.cc" 43 | #include "src/gmock-internal-utils.cc" 44 | #include "src/gmock-matchers.cc" 45 | #include "src/gmock-spec-builders.cc" 46 | #include "src/gmock.cc" 47 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Sparsehash Package (formerly Google Sparsehash) 5 | 6 | 7 | 8 | 24 | 25 | 26 | 27 |

Sparsehash Package (formerly 28 | Google Sparsehash)

29 |
30 | 31 |

The sparsehash package consists of two hashtable 32 | implementations: sparse, which is designed to be very space 33 | efficient, and dense, which is designed to be very time 34 | efficient. For each one, the package provides both a hash-map and a 35 | hash-set, to mirror the classes in the common STL implementation.

36 | 37 |

Documentation on how to use these classes:

38 | 44 | 45 |

In addition to the hash-map (and hash-set) classes, there's also a 46 | lower-level class that implements a "sparse" array. This class can be 47 | useful in its own right; consider using it when you'd normally use a 48 | sparse_hash_map, but your keys are all small-ish 49 | integers.

50 | 53 | 54 |

There is also a doc explaining the implementation details of these 56 | classes, for those who are curious. And finally, you can see some 57 | performance comparisons, both between 58 | the various classes here, but also between these implementations and 59 | other standard hashtable implementations.

60 | 61 |
62 |
63 | Craig Silverstein
64 | Last modified: Thu Jan 25 17:58:02 PST 2007 65 |
66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /tests/gtest/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // 31 | // Google C++ Testing and Mocking Framework (Google Test) 32 | // 33 | // Sometimes it's desirable to build Google Test by compiling a single file. 34 | // This file serves this purpose. 35 | 36 | // This line ensures that gtest.h can be compiled on its own, even 37 | // when it's fused. 38 | #include "gtest/gtest.h" 39 | 40 | // The following lines pull in the real gtest *.cc files. 41 | #include "src/gtest-assertion-result.cc" 42 | #include "src/gtest-death-test.cc" 43 | #include "src/gtest-filepath.cc" 44 | #include "src/gtest-matchers.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | #include "src/gtest.cc" 50 | -------------------------------------------------------------------------------- /tests/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // 31 | // Google C++ Testing and Mocking Framework (Google Test) 32 | // 33 | // Sometimes it's desirable to build Google Test by compiling a single file. 34 | // This file serves this purpose. 35 | 36 | // This line ensures that gtest.h can be compiled on its own, even 37 | // when it's fused. 38 | #include "gtest/gtest.h" 39 | 40 | // The following lines pull in the real gtest *.cc files. 41 | #include "src/gtest-assertion-result.cc" 42 | #include "src/gtest-death-test.cc" 43 | #include "src/gtest-filepath.cc" 44 | #include "src/gtest-matchers.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | #include "src/gtest.cc" 50 | -------------------------------------------------------------------------------- /sparsehash/traits: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | #pragma once 31 | #include 32 | #include // For pair 33 | 34 | namespace google { 35 | 36 | // trait which can be added to user types to enable use of memcpy in sparsetable 37 | // Example: 38 | // namespace google{ 39 | // template <> 40 | // struct is_relocatable : std::true_type {}; 41 | // } 42 | 43 | template 44 | struct is_relocatable 45 | : std::integral_constant::value && 47 | std::is_trivially_destructible::value)> {}; 48 | template 49 | struct is_relocatable> 50 | : std::integral_constant::value && 51 | is_relocatable::value)> {}; 52 | 53 | template 54 | struct is_relocatable : is_relocatable {}; 55 | } -------------------------------------------------------------------------------- /docs/designstyle.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #ffffff; 3 | color: black; 4 | margin-right: 1in; 5 | margin-left: 1in; 6 | } 7 | 8 | 9 | h1, h2, h3, h4, h5, h6 { 10 | color: #3366ff; 11 | font-family: sans-serif; 12 | } 13 | @media print { 14 | /* Darker version for printing */ 15 | h1, h2, h3, h4, h5, h6 { 16 | color: #000080; 17 | font-family: helvetica, sans-serif; 18 | } 19 | } 20 | 21 | h1 { 22 | text-align: center; 23 | font-size: 18pt; 24 | } 25 | h2 { 26 | margin-left: -0.5in; 27 | } 28 | h3 { 29 | margin-left: -0.25in; 30 | } 31 | h4 { 32 | margin-left: -0.125in; 33 | } 34 | hr { 35 | margin-left: -1in; 36 | } 37 | 38 | /* Definition lists: definition term bold */ 39 | dt { 40 | font-weight: bold; 41 | } 42 | 43 | address { 44 | text-align: right; 45 | } 46 | /* Use the tag for bits of code and for variables and objects. */ 47 | code,pre,samp,var { 48 | color: #006000; 49 | } 50 | /* Use the tag for file and directory paths and names. */ 51 | file { 52 | color: #905050; 53 | font-family: monospace; 54 | } 55 | /* Use the tag for stuff the user should type. */ 56 | kbd { 57 | color: #600000; 58 | } 59 | div.note p { 60 | float: right; 61 | width: 3in; 62 | margin-right: 0%; 63 | padding: 1px; 64 | border: 2px solid #6060a0; 65 | background-color: #fffff0; 66 | } 67 | 68 | UL.nobullets { 69 | list-style-type: none; 70 | list-style-image: none; 71 | margin-left: -1em; 72 | } 73 | 74 | /* pretty printing styles. See prettify.js */ 75 | .str { color: #080; } 76 | .kwd { color: #008; } 77 | .com { color: #800; } 78 | .typ { color: #606; } 79 | .lit { color: #066; } 80 | .pun { color: #660; } 81 | .pln { color: #000; } 82 | .tag { color: #008; } 83 | .atn { color: #606; } 84 | .atv { color: #080; } 85 | pre.prettyprint { padding: 2px; border: 1px solid #888; } 86 | 87 | .embsrc { background: #eee; } 88 | 89 | @media print { 90 | .str { color: #060; } 91 | .kwd { color: #006; font-weight: bold; } 92 | .com { color: #600; font-style: italic; } 93 | .typ { color: #404; font-weight: bold; } 94 | .lit { color: #044; } 95 | .pun { color: #440; } 96 | .pln { color: #000; } 97 | .tag { color: #006; font-weight: bold; } 98 | .atn { color: #404; } 99 | .atv { color: #060; } 100 | } 101 | 102 | /* Table Column Headers */ 103 | .hdr { 104 | color: #006; 105 | font-weight: bold; 106 | background-color: #dddddd; } 107 | .hdr2 { 108 | color: #006; 109 | background-color: #eeeeee; } -------------------------------------------------------------------------------- /tests/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google C++ Testing and Mocking Framework definitions useful in production 31 | // code. 32 | 33 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 34 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | 36 | // When you need to test the private or protected members of a class, 37 | // use the FRIEND_TEST macro to declare your tests as friends of the 38 | // class. For example: 39 | // 40 | // class MyClass { 41 | // private: 42 | // void PrivateMethod(); 43 | // FRIEND_TEST(MyClassTest, PrivateMethodWorks); 44 | // }; 45 | // 46 | // class MyClassTest : public testing::Test { 47 | // // ... 48 | // }; 49 | // 50 | // TEST_F(MyClassTest, PrivateMethodWorks) { 51 | // // Can call MyClass::PrivateMethod() here. 52 | // } 53 | // 54 | // Note: The test class must be in the same namespace as the class being tested. 55 | // For example, putting MyClassTest in an anonymous namespace will not work. 56 | 57 | #define FRIEND_TEST(test_case_name, test_name) \ 58 | friend class test_case_name##_##test_name##_Test 59 | 60 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 61 | -------------------------------------------------------------------------------- /tests/simple_unittests.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // --- 31 | // 32 | // This tests mostly that we can #include the files correctly 33 | // and have them work. It's meant to emulate what a 'regular 34 | // install' of sparsehash would be able to see. 35 | 36 | #include "gtest/gtest.h" 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | using namespace testing; 43 | 44 | TEST(Simple, All) { 45 | google::sparse_hash_set sset; 46 | google::sparse_hash_map smap; 47 | google::dense_hash_set dset; 48 | google::dense_hash_map dmap; 49 | dset.set_empty_key(-1); 50 | dmap.set_empty_key(-1); 51 | 52 | for (int i = 0; i < 100; i += 10) { // go by tens 53 | sset.insert(i); 54 | smap[i] = i + 1; 55 | dset.insert(i + 5); 56 | dmap[i + 5] = i + 6; 57 | } 58 | 59 | for (int i = 0; i < 100; i++) { 60 | ASSERT_EQ(sset.find(i) != sset.end(), (i % 10) == 0); 61 | ASSERT_EQ(smap.find(i) != smap.end(), (i % 10) == 0); 62 | ASSERT_EQ(smap.find(i) != smap.end() && smap.find(i)->second == i + 1, 63 | (i % 10) == 0); 64 | ASSERT_EQ(dset.find(i) != dset.end(), (i % 10) == 5); 65 | ASSERT_EQ(dmap.find(i) != dmap.end(), (i % 10) == 5); 66 | ASSERT_EQ(dmap.find(i) != dmap.end() && dmap.find(i)->second == i + 1, 67 | (i % 10) == 5); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/fixture_unittests.cc: -------------------------------------------------------------------------------- 1 | #include "fixture_unittests.h" 2 | 3 | 4 | // This is just to avoid memory leaks -- it's a global pointer to 5 | // all the memory allocated by UniqueObjectHelper. We'll use it 6 | // to semi-test sparsetable as well. :-) 7 | sparsetable g_unique_charstar_objects = sparsetable(16); 8 | 9 | // These are used to specify the empty key and deleted key in some 10 | // contexts. They can't be in the unnamed namespace, or static, 11 | // because the template code requires external linkage. 12 | const string kEmptyString("--empty string--"); 13 | const string kDeletedString("--deleted string--"); 14 | const int kEmptyInt = 0; 15 | const int kDeletedInt = -1234676543; // an unlikely-to-pick int 16 | const char* const kEmptyCharStar = "--empty char*--"; 17 | const char* const kDeletedCharStar = "--deleted char*--"; 18 | const pair kEmptyIntPair = {0, 0}; 19 | const pair kDeletedIntPair = {-1234676543, -1234676543}; 20 | 21 | const char* const ValueType::kDefault = "hi"; 22 | 23 | template <> 24 | int UniqueObjectHelper(int index) { 25 | return index; 26 | } 27 | 28 | template <> 29 | string UniqueObjectHelper(int index) { 30 | char buffer[64]; 31 | snprintf(buffer, sizeof(buffer), "%d", index); 32 | return buffer; 33 | } 34 | 35 | template <> 36 | char* UniqueObjectHelper(int index) { 37 | // First grow the table if need be. 38 | sparsetable::size_type table_size = g_unique_charstar_objects.size(); 39 | while (index >= static_cast(table_size)) { 40 | assert(table_size * 2 > table_size); // avoid overflow problems 41 | table_size *= 2; 42 | } 43 | if (table_size > g_unique_charstar_objects.size()) 44 | g_unique_charstar_objects.resize(table_size); 45 | 46 | if (!g_unique_charstar_objects.test(index)) { 47 | char buffer[64]; 48 | snprintf(buffer, sizeof(buffer), "%d", index); 49 | g_unique_charstar_objects[index] = strdup(buffer); 50 | } 51 | return g_unique_charstar_objects.get(index); 52 | } 53 | 54 | template <> 55 | const char* UniqueObjectHelper(int index) { 56 | return UniqueObjectHelper(index); 57 | } 58 | 59 | template <> 60 | ValueType UniqueObjectHelper(int index) { 61 | return ValueType(UniqueObjectHelper(index).c_str()); 62 | } 63 | 64 | template <> 65 | pair UniqueObjectHelper(int index) { 66 | return pair(index, index + 1); 67 | } 68 | 69 | template <> 70 | pair UniqueObjectHelper(int index) { 71 | return pair(UniqueObjectHelper(index), 72 | UniqueObjectHelper(index + 1)); 73 | } 74 | 75 | template <> 76 | pair UniqueObjectHelper(int index) { 77 | return pair( 78 | UniqueObjectHelper(index), 79 | UniqueObjectHelper(index + 1)); 80 | } 81 | 82 | template <> 83 | pair UniqueObjectHelper(int index) { 84 | return pair(index, index + 1); 85 | } 86 | 87 | template <> 88 | pair, int> UniqueObjectHelper(int index) { 89 | return pair, int>( 90 | UniqueObjectHelper>(index), 91 | index + 2); 92 | } 93 | -------------------------------------------------------------------------------- /tests/src/gmock_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | #include 31 | 32 | #include "gmock/gmock.h" 33 | #include "gtest/gtest.h" 34 | 35 | #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 36 | #if GTEST_OS_ESP8266 37 | extern "C" { 38 | #endif 39 | void setup() { 40 | // Since Google Mock depends on Google Test, InitGoogleMock() is 41 | // also responsible for initializing Google Test. Therefore there's 42 | // no need for calling testing::InitGoogleTest() separately. 43 | testing::InitGoogleMock(); 44 | } 45 | void loop() { RUN_ALL_TESTS(); } 46 | #if GTEST_OS_ESP8266 47 | } 48 | #endif 49 | 50 | #else 51 | 52 | // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which 53 | // causes a link error when _tmain is defined in a static library and UNICODE 54 | // is enabled. For this reason instead of _tmain, main function is used on 55 | // Windows. See the following link to track the current status of this bug: 56 | // https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library 57 | // // NOLINT 58 | #if GTEST_OS_WINDOWS_MOBILE 59 | #include // NOLINT 60 | 61 | GTEST_API_ int _tmain(int argc, TCHAR** argv) { 62 | #else 63 | GTEST_API_ int main(int argc, char** argv) { 64 | #endif // GTEST_OS_WINDOWS_MOBILE 65 | std::cout << "Running main() from gmock_main.cc\n"; 66 | // Since Google Mock depends on Google Test, InitGoogleMock() is 67 | // also responsible for initializing Google Test. Therefore there's 68 | // no need for calling testing::InitGoogleTest() separately. 69 | testing::InitGoogleMock(&argc, argv); 70 | return RUN_ALL_TESTS(); 71 | } 72 | #endif 73 | -------------------------------------------------------------------------------- /tests/src/gtest-assertion-result.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This file defines the AssertionResult type. 33 | 34 | #include "gtest/gtest-assertion-result.h" 35 | 36 | #include 37 | #include 38 | 39 | #include "gtest/gtest-message.h" 40 | 41 | namespace testing { 42 | 43 | // AssertionResult constructors. 44 | // Used in EXPECT_TRUE/FALSE(assertion_result). 45 | AssertionResult::AssertionResult(const AssertionResult& other) 46 | : success_(other.success_), 47 | message_(other.message_.get() != nullptr 48 | ? new ::std::string(*other.message_) 49 | : static_cast< ::std::string*>(nullptr)) {} 50 | 51 | // Swaps two AssertionResults. 52 | void AssertionResult::swap(AssertionResult& other) { 53 | using std::swap; 54 | swap(success_, other.success_); 55 | swap(message_, other.message_); 56 | } 57 | 58 | // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. 59 | AssertionResult AssertionResult::operator!() const { 60 | AssertionResult negation(!success_); 61 | if (message_.get() != nullptr) negation << *message_; 62 | return negation; 63 | } 64 | 65 | // Makes a successful assertion result. 66 | AssertionResult AssertionSuccess() { return AssertionResult(true); } 67 | 68 | // Makes a failed assertion result. 69 | AssertionResult AssertionFailure() { return AssertionResult(false); } 70 | 71 | // Makes a failed assertion result with the given failure message. 72 | // Deprecated; use AssertionFailure() << message. 73 | AssertionResult AssertionFailure(const Message& message) { 74 | return AssertionFailure() << message; 75 | } 76 | 77 | } // namespace testing 78 | -------------------------------------------------------------------------------- /tests/gmock/gmock-more-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file implements some matchers that depend on gmock-matchers.h. 33 | // 34 | // Note that tests are implemented in gmock-matchers_test.cc rather than 35 | // gmock-more-matchers-test.cc. 36 | 37 | // IWYU pragma: private, include "gmock/gmock.h" 38 | // IWYU pragma: friend gmock/.* 39 | 40 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 41 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 42 | 43 | #include "gmock/gmock-matchers.h" 44 | 45 | namespace testing { 46 | 47 | // Silence C4100 (unreferenced formal 48 | // parameter) for MSVC 49 | #ifdef _MSC_VER 50 | #pragma warning(push) 51 | #pragma warning(disable : 4100) 52 | #if (_MSC_VER == 1900) 53 | // and silence C4800 (C4800: 'int *const ': forcing value 54 | // to bool 'true' or 'false') for MSVC 14 55 | #pragma warning(disable : 4800) 56 | #endif 57 | #endif 58 | 59 | // Defines a matcher that matches an empty container. The container must 60 | // support both size() and empty(), which all STL-like containers provide. 61 | MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { 62 | if (arg.empty()) { 63 | return true; 64 | } 65 | *result_listener << "whose size is " << arg.size(); 66 | return false; 67 | } 68 | 69 | // Define a matcher that matches a value that evaluates in boolean 70 | // context to true. Useful for types that define "explicit operator 71 | // bool" operators and so can't be compared for equality with true 72 | // and false. 73 | MATCHER(IsTrue, negation ? "is false" : "is true") { 74 | return static_cast(arg); 75 | } 76 | 77 | // Define a matcher that matches a value that evaluates in boolean 78 | // context to false. Useful for types that define "explicit operator 79 | // bool" operators and so can't be compared for equality with true 80 | // and false. 81 | MATCHER(IsFalse, negation ? "is true" : "is false") { 82 | return !static_cast(arg); 83 | } 84 | 85 | #ifdef _MSC_VER 86 | #pragma warning(pop) 87 | #endif 88 | 89 | } // namespace testing 90 | 91 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ 92 | -------------------------------------------------------------------------------- /docs/performance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Performance notes: sparse_hash, dense_hash, sparsetable 5 | 6 | 7 | 8 | 9 |

Performance Numbers

10 | 11 |

Here are some performance numbers from an example desktop machine, 12 | taken from a version of time_hash_map that was instrumented to also 13 | report memory allocation information (this modification is not 14 | included by default because it required a big hack to do, including 15 | modifying the STL code to not try to do its own freelist management).

16 | 17 |

Note there are lots of caveats on these numbers: they may differ from 18 | machine to machine and compiler to compiler, and they only test a very 19 | particular usage pattern that may not match how you use hashtables -- 20 | for instance, they test hashtables with very small keys. However, 21 | they're still useful for a baseline comparison of the various 22 | hashtable implementations.

23 | 24 |

These figures are from a 2.80GHz Pentium 4 with 2G of memory. The 25 | 'standard' hash_map and map implementations are the SGI STL code 26 | included with gcc2. Compiled with gcc2.95.3 -g 27 | -O2

28 | 29 |
30 | ======
31 | Average over 10000000 iterations
32 | Wed Dec  8 14:56:38 PST 2004
33 | 
34 | SPARSE_HASH_MAP:
35 | map_grow                  665 ns
36 | map_predict/grow          303 ns
37 | map_replace               177 ns
38 | map_fetch                 117 ns
39 | map_remove                192 ns
40 | memory used in map_grow    84.3956 Mbytes
41 | 
42 | DENSE_HASH_MAP:
43 | map_grow                   84 ns
44 | map_predict/grow           22 ns
45 | map_replace                18 ns
46 | map_fetch                  13 ns
47 | map_remove                 23 ns
48 | memory used in map_grow   256.0000 Mbytes
49 | 
50 | STANDARD HASH_MAP:
51 | map_grow                  162 ns
52 | map_predict/grow          107 ns
53 | map_replace                44 ns
54 | map_fetch                  22 ns
55 | map_remove                124 ns
56 | memory used in map_grow   204.1643 Mbytes
57 | 
58 | STANDARD MAP:
59 | map_grow                  297 ns
60 | map_predict/grow          282 ns
61 | map_replace               113 ns
62 | map_fetch                 113 ns
63 | map_remove                238 ns
64 | memory used in map_grow   236.8081 Mbytes
65 | 
66 | 67 | 68 |

A Note on Hash Functions

69 | 70 |

For good performance, the sparsehash hash routines depend on a good 71 | hash function: one that distributes data evenly. Many hashtable 72 | implementations come with sub-optimal hash functions that can degrade 73 | performance. For instance, the hash function given in Knuth's _Art of 74 | Computer Programming_, and the default string hash function in SGI's 75 | STL implementation, both distribute certain data sets unevenly, 76 | leading to poor performance.

77 | 78 |

As an example, in one test of the default SGI STL string hash 79 | function against the Hsieh hash function (see below), for a particular 80 | set of string keys, the Hsieh function resulted in hashtable lookups 81 | that were 20 times as fast as the STLPort hash function. The string 82 | keys were chosen to be "hard" to hash well, so these results may not 83 | be typical, but they are suggestive.

84 | 85 |

There has been much research over the years into good hash 86 | functions. Here are some hash functions of note.

87 | 88 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /tests/gmock/gmock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This is the main header file a user should include. 33 | 34 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 35 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 36 | 37 | // This file implements the following syntax: 38 | // 39 | // ON_CALL(mock_object, Method(...)) 40 | // .With(...) ? 41 | // .WillByDefault(...); 42 | // 43 | // where With() is optional and WillByDefault() must appear exactly 44 | // once. 45 | // 46 | // EXPECT_CALL(mock_object, Method(...)) 47 | // .With(...) ? 48 | // .Times(...) ? 49 | // .InSequence(...) * 50 | // .WillOnce(...) * 51 | // .WillRepeatedly(...) ? 52 | // .RetiresOnSaturation() ? ; 53 | // 54 | // where all clauses are optional and WillOnce() can be repeated. 55 | 56 | #include "gmock/gmock-actions.h" 57 | #include "gmock/gmock-cardinalities.h" 58 | #include "gmock/gmock-function-mocker.h" 59 | #include "gmock/gmock-matchers.h" 60 | #include "gmock/gmock-more-actions.h" 61 | #include "gmock/gmock-more-matchers.h" 62 | #include "gmock/gmock-nice-strict.h" 63 | #include "gmock/internal/gmock-internal-utils.h" 64 | #include "gmock/internal/gmock-port.h" 65 | 66 | // Declares Google Mock flags that we want a user to use programmatically. 67 | GMOCK_DECLARE_bool_(catch_leaked_mocks); 68 | GMOCK_DECLARE_string_(verbose); 69 | GMOCK_DECLARE_int32_(default_mock_behavior); 70 | 71 | namespace testing { 72 | 73 | // Initializes Google Mock. This must be called before running the 74 | // tests. In particular, it parses the command line for the flags 75 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, 76 | // it is removed from argv, and *argc is decremented. 77 | // 78 | // No value is returned. Instead, the Google Mock flag variables are 79 | // updated. 80 | // 81 | // Since Google Test is needed for Google Mock to work, this function 82 | // also initializes Google Test and parses its flags, if that hasn't 83 | // been done. 84 | GTEST_API_ void InitGoogleMock(int* argc, char** argv); 85 | 86 | // This overloaded version can be used in Windows programs compiled in 87 | // UNICODE mode. 88 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 89 | 90 | // This overloaded version can be used on Arduino/embedded platforms where 91 | // there is no argc/argv. 92 | GTEST_API_ void InitGoogleMock(); 93 | 94 | } // namespace testing 95 | 96 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 97 | -------------------------------------------------------------------------------- /tests/gtest/gmock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This is the main header file a user should include. 33 | 34 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 35 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 36 | 37 | // This file implements the following syntax: 38 | // 39 | // ON_CALL(mock_object, Method(...)) 40 | // .With(...) ? 41 | // .WillByDefault(...); 42 | // 43 | // where With() is optional and WillByDefault() must appear exactly 44 | // once. 45 | // 46 | // EXPECT_CALL(mock_object, Method(...)) 47 | // .With(...) ? 48 | // .Times(...) ? 49 | // .InSequence(...) * 50 | // .WillOnce(...) * 51 | // .WillRepeatedly(...) ? 52 | // .RetiresOnSaturation() ? ; 53 | // 54 | // where all clauses are optional and WillOnce() can be repeated. 55 | 56 | #include "gmock/gmock-actions.h" 57 | #include "gmock/gmock-cardinalities.h" 58 | #include "gmock/gmock-function-mocker.h" 59 | #include "gmock/gmock-matchers.h" 60 | #include "gmock/gmock-more-actions.h" 61 | #include "gmock/gmock-more-matchers.h" 62 | #include "gmock/gmock-nice-strict.h" 63 | #include "gmock/internal/gmock-internal-utils.h" 64 | #include "gmock/internal/gmock-port.h" 65 | 66 | // Declares Google Mock flags that we want a user to use programmatically. 67 | GMOCK_DECLARE_bool_(catch_leaked_mocks); 68 | GMOCK_DECLARE_string_(verbose); 69 | GMOCK_DECLARE_int32_(default_mock_behavior); 70 | 71 | namespace testing { 72 | 73 | // Initializes Google Mock. This must be called before running the 74 | // tests. In particular, it parses the command line for the flags 75 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, 76 | // it is removed from argv, and *argc is decremented. 77 | // 78 | // No value is returned. Instead, the Google Mock flag variables are 79 | // updated. 80 | // 81 | // Since Google Test is needed for Google Mock to work, this function 82 | // also initializes Google Test and parses its flags, if that hasn't 83 | // been done. 84 | GTEST_API_ void InitGoogleMock(int* argc, char** argv); 85 | 86 | // This overloaded version can be used in Windows programs compiled in 87 | // UNICODE mode. 88 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 89 | 90 | // This overloaded version can be used on Arduino/embedded platforms where 91 | // there is no argc/argv. 92 | GTEST_API_ void InitGoogleMock(); 93 | 94 | } // namespace testing 95 | 96 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_ 97 | -------------------------------------------------------------------------------- /tests/src/gtest-matchers.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This file implements just enough of the matcher interface to allow 33 | // EXPECT_DEATH and friends to accept a matcher argument. 34 | 35 | #include "gtest/gtest-matchers.h" 36 | 37 | #include 38 | 39 | #include "gtest/internal/gtest-internal.h" 40 | #include "gtest/internal/gtest-port.h" 41 | 42 | namespace testing { 43 | 44 | // Constructs a matcher that matches a const std::string& whose value is 45 | // equal to s. 46 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 47 | 48 | // Constructs a matcher that matches a const std::string& whose value is 49 | // equal to s. 50 | Matcher::Matcher(const char* s) { 51 | *this = Eq(std::string(s)); 52 | } 53 | 54 | // Constructs a matcher that matches a std::string whose value is equal to 55 | // s. 56 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 57 | 58 | // Constructs a matcher that matches a std::string whose value is equal to 59 | // s. 60 | Matcher::Matcher(const char* s) { *this = Eq(std::string(s)); } 61 | 62 | #if GTEST_INTERNAL_HAS_STRING_VIEW 63 | // Constructs a matcher that matches a const StringView& whose value is 64 | // equal to s. 65 | Matcher::Matcher(const std::string& s) { 66 | *this = Eq(s); 67 | } 68 | 69 | // Constructs a matcher that matches a const StringView& whose value is 70 | // equal to s. 71 | Matcher::Matcher(const char* s) { 72 | *this = Eq(std::string(s)); 73 | } 74 | 75 | // Constructs a matcher that matches a const StringView& whose value is 76 | // equal to s. 77 | Matcher::Matcher(internal::StringView s) { 78 | *this = Eq(std::string(s)); 79 | } 80 | 81 | // Constructs a matcher that matches a StringView whose value is equal to 82 | // s. 83 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 84 | 85 | // Constructs a matcher that matches a StringView whose value is equal to 86 | // s. 87 | Matcher::Matcher(const char* s) { 88 | *this = Eq(std::string(s)); 89 | } 90 | 91 | // Constructs a matcher that matches a StringView whose value is equal to 92 | // s. 93 | Matcher::Matcher(internal::StringView s) { 94 | *this = Eq(std::string(s)); 95 | } 96 | #endif // GTEST_INTERNAL_HAS_STRING_VIEW 97 | 98 | } // namespace testing 99 | -------------------------------------------------------------------------------- /tests/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | #include "gtest/gtest-typed-test.h" 31 | 32 | #include "gtest/gtest.h" 33 | 34 | namespace testing { 35 | namespace internal { 36 | 37 | // Skips to the first non-space char in str. Returns an empty string if str 38 | // contains only whitespace characters. 39 | static const char* SkipSpaces(const char* str) { 40 | while (IsSpace(*str)) str++; 41 | return str; 42 | } 43 | 44 | static std::vector SplitIntoTestNames(const char* src) { 45 | std::vector name_vec; 46 | src = SkipSpaces(src); 47 | for (; src != nullptr; src = SkipComma(src)) { 48 | name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); 49 | } 50 | return name_vec; 51 | } 52 | 53 | // Verifies that registered_tests match the test names in 54 | // registered_tests_; returns registered_tests if successful, or 55 | // aborts the program otherwise. 56 | const char* TypedTestSuitePState::VerifyRegisteredTestNames( 57 | const char* test_suite_name, const char* file, int line, 58 | const char* registered_tests) { 59 | RegisterTypeParameterizedTestSuite(test_suite_name, CodeLocation(file, line)); 60 | 61 | typedef RegisteredTestsMap::const_iterator RegisteredTestIter; 62 | registered_ = true; 63 | 64 | std::vector name_vec = SplitIntoTestNames(registered_tests); 65 | 66 | Message errors; 67 | 68 | std::set tests; 69 | for (std::vector::const_iterator name_it = name_vec.begin(); 70 | name_it != name_vec.end(); ++name_it) { 71 | const std::string& name = *name_it; 72 | if (tests.count(name) != 0) { 73 | errors << "Test " << name << " is listed more than once.\n"; 74 | continue; 75 | } 76 | 77 | if (registered_tests_.count(name) != 0) { 78 | tests.insert(name); 79 | } else { 80 | errors << "No test named " << name 81 | << " can be found in this test suite.\n"; 82 | } 83 | } 84 | 85 | for (RegisteredTestIter it = registered_tests_.begin(); 86 | it != registered_tests_.end(); ++it) { 87 | if (tests.count(it->first) == 0) { 88 | errors << "You forgot to list test " << it->first << ".\n"; 89 | } 90 | } 91 | 92 | const std::string& errors_str = errors.GetString(); 93 | if (errors_str != "") { 94 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 95 | errors_str.c_str()); 96 | fflush(stderr); 97 | posix::Abort(); 98 | } 99 | 100 | return registered_tests; 101 | } 102 | 103 | } // namespace internal 104 | } // namespace testing 105 | -------------------------------------------------------------------------------- /sparsehash/internal/libc_allocator_with_realloc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // --- 31 | 32 | #pragma once 33 | 34 | #include // for malloc/realloc/free 35 | #include // for ptrdiff_t 36 | #include // for placement new 37 | 38 | namespace google { 39 | template 40 | class libc_allocator_with_realloc { 41 | public: 42 | typedef T value_type; 43 | typedef size_t size_type; 44 | typedef ptrdiff_t difference_type; 45 | 46 | typedef T* pointer; 47 | typedef const T* const_pointer; 48 | typedef T& reference; 49 | typedef const T& const_reference; 50 | 51 | libc_allocator_with_realloc() {} 52 | libc_allocator_with_realloc(const libc_allocator_with_realloc&) {} 53 | ~libc_allocator_with_realloc() {} 54 | 55 | pointer address(reference r) const { return &r; } 56 | const_pointer address(const_reference r) const { return &r; } 57 | 58 | pointer allocate(size_type n, const_pointer = 0) { 59 | return static_cast(malloc(n * sizeof(value_type))); 60 | } 61 | void deallocate(pointer p, size_type) { free(p); } 62 | pointer reallocate(pointer p, size_type n) { 63 | // p points to a storage array whose objects have already been destroyed 64 | // cast to void* to prevent compiler warnings about calling realloc() on 65 | // an object which cannot be relocated in memory 66 | return static_cast(realloc(static_cast(p), n * sizeof(value_type))); 67 | } 68 | 69 | size_type max_size() const { 70 | return static_cast(-1) / sizeof(value_type); 71 | } 72 | 73 | void construct(pointer p, const value_type& val) { new (p) value_type(val); } 74 | void destroy(pointer p) { p->~value_type(); } 75 | 76 | template 77 | libc_allocator_with_realloc(const libc_allocator_with_realloc&) {} 78 | 79 | template 80 | struct rebind { 81 | typedef libc_allocator_with_realloc other; 82 | }; 83 | }; 84 | 85 | // libc_allocator_with_realloc specialization. 86 | template <> 87 | class libc_allocator_with_realloc { 88 | public: 89 | typedef void value_type; 90 | typedef size_t size_type; 91 | typedef ptrdiff_t difference_type; 92 | typedef void* pointer; 93 | typedef const void* const_pointer; 94 | 95 | template 96 | struct rebind { 97 | typedef libc_allocator_with_realloc other; 98 | }; 99 | }; 100 | 101 | template 102 | inline bool operator==(const libc_allocator_with_realloc&, 103 | const libc_allocator_with_realloc&) { 104 | return true; 105 | } 106 | 107 | template 108 | inline bool operator!=(const libc_allocator_with_realloc&, 109 | const libc_allocator_with_realloc&) { 110 | return false; 111 | } 112 | 113 | } // namespace google 114 | -------------------------------------------------------------------------------- /tests/src/gtest-test-part.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // 31 | // The Google C++ Testing and Mocking Framework (Google Test) 32 | 33 | #include "gtest/gtest-test-part.h" 34 | 35 | #include "gtest/internal/gtest-port.h" 36 | #include "src/gtest-internal-inl.h" 37 | 38 | namespace testing { 39 | 40 | using internal::GetUnitTestImpl; 41 | 42 | // Gets the summary of the failure message by omitting the stack trace 43 | // in it. 44 | std::string TestPartResult::ExtractSummary(const char* message) { 45 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 46 | return stack_trace == nullptr ? message : std::string(message, stack_trace); 47 | } 48 | 49 | // Prints a TestPartResult object. 50 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 51 | return os << internal::FormatFileLocation(result.file_name(), 52 | result.line_number()) 53 | << " " 54 | << (result.type() == TestPartResult::kSuccess ? "Success" 55 | : result.type() == TestPartResult::kSkip ? "Skipped" 56 | : result.type() == TestPartResult::kFatalFailure 57 | ? "Fatal failure" 58 | : "Non-fatal failure") 59 | << ":\n" 60 | << result.message() << std::endl; 61 | } 62 | 63 | // Appends a TestPartResult to the array. 64 | void TestPartResultArray::Append(const TestPartResult& result) { 65 | array_.push_back(result); 66 | } 67 | 68 | // Returns the TestPartResult at the given index (0-based). 69 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 70 | if (index < 0 || index >= size()) { 71 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 72 | internal::posix::Abort(); 73 | } 74 | 75 | return array_[static_cast(index)]; 76 | } 77 | 78 | // Returns the number of TestPartResult objects in the array. 79 | int TestPartResultArray::size() const { 80 | return static_cast(array_.size()); 81 | } 82 | 83 | namespace internal { 84 | 85 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 86 | : has_new_fatal_failure_(false), 87 | original_reporter_( 88 | GetUnitTestImpl()->GetTestPartResultReporterForCurrentThread()) { 89 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 90 | } 91 | 92 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 93 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 94 | original_reporter_); 95 | } 96 | 97 | void HasNewFatalFailureHelper::ReportTestPartResult( 98 | const TestPartResult& result) { 99 | if (result.fatally_failed()) has_new_fatal_failure_ = true; 100 | original_reporter_->ReportTestPartResult(result); 101 | } 102 | 103 | } // namespace internal 104 | 105 | } // namespace testing 106 | -------------------------------------------------------------------------------- /tests/gtest/internal/gtest-port-arch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This header file defines the GTEST_OS_* macro. 33 | // It is separate from gtest-port.h so that custom/gtest-port.h can include it. 34 | 35 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 36 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 37 | 38 | // Determines the platform on which Google Test is compiled. 39 | #ifdef __CYGWIN__ 40 | #define GTEST_OS_CYGWIN 1 41 | #elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) 42 | #define GTEST_OS_WINDOWS_MINGW 1 43 | #define GTEST_OS_WINDOWS 1 44 | #elif defined _WIN32 45 | #define GTEST_OS_WINDOWS 1 46 | #ifdef _WIN32_WCE 47 | #define GTEST_OS_WINDOWS_MOBILE 1 48 | #elif defined(WINAPI_FAMILY) 49 | #include 50 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 51 | #define GTEST_OS_WINDOWS_DESKTOP 1 52 | #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) 53 | #define GTEST_OS_WINDOWS_PHONE 1 54 | #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 55 | #define GTEST_OS_WINDOWS_RT 1 56 | #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) 57 | #define GTEST_OS_WINDOWS_PHONE 1 58 | #define GTEST_OS_WINDOWS_TV_TITLE 1 59 | #else 60 | // WINAPI_FAMILY defined but no known partition matched. 61 | // Default to desktop. 62 | #define GTEST_OS_WINDOWS_DESKTOP 1 63 | #endif 64 | #else 65 | #define GTEST_OS_WINDOWS_DESKTOP 1 66 | #endif // _WIN32_WCE 67 | #elif defined __OS2__ 68 | #define GTEST_OS_OS2 1 69 | #elif defined __APPLE__ 70 | #define GTEST_OS_MAC 1 71 | #include 72 | #if TARGET_OS_IPHONE 73 | #define GTEST_OS_IOS 1 74 | #endif 75 | #elif defined __DragonFly__ 76 | #define GTEST_OS_DRAGONFLY 1 77 | #elif defined __FreeBSD__ 78 | #define GTEST_OS_FREEBSD 1 79 | #elif defined __Fuchsia__ 80 | #define GTEST_OS_FUCHSIA 1 81 | #elif defined(__GNU__) 82 | #define GTEST_OS_GNU_HURD 1 83 | #elif defined(__GLIBC__) && defined(__FreeBSD_kernel__) 84 | #define GTEST_OS_GNU_KFREEBSD 1 85 | #elif defined __linux__ 86 | #define GTEST_OS_LINUX 1 87 | #if defined __ANDROID__ 88 | #define GTEST_OS_LINUX_ANDROID 1 89 | #endif 90 | #elif defined __MVS__ 91 | #define GTEST_OS_ZOS 1 92 | #elif defined(__sun) && defined(__SVR4) 93 | #define GTEST_OS_SOLARIS 1 94 | #elif defined(_AIX) 95 | #define GTEST_OS_AIX 1 96 | #elif defined(__hpux) 97 | #define GTEST_OS_HPUX 1 98 | #elif defined __native_client__ 99 | #define GTEST_OS_NACL 1 100 | #elif defined __NetBSD__ 101 | #define GTEST_OS_NETBSD 1 102 | #elif defined __OpenBSD__ 103 | #define GTEST_OS_OPENBSD 1 104 | #elif defined __QNX__ 105 | #define GTEST_OS_QNX 1 106 | #elif defined(__HAIKU__) 107 | #define GTEST_OS_HAIKU 1 108 | #elif defined ESP8266 109 | #define GTEST_OS_ESP8266 1 110 | #elif defined ESP32 111 | #define GTEST_OS_ESP32 1 112 | #elif defined(__XTENSA__) 113 | #define GTEST_OS_XTENSA 1 114 | #endif // __CYGWIN__ 115 | 116 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 117 | -------------------------------------------------------------------------------- /tests/allocator_unittests.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // --- 31 | 32 | #include 33 | #include 34 | #include 35 | #include "gtest/gtest.h" 36 | #include 37 | 38 | using std::string; 39 | using std::basic_string; 40 | using std::char_traits; 41 | using std::vector; 42 | using google::libc_allocator_with_realloc; 43 | 44 | using namespace testing; 45 | 46 | #define arraysize(a) (sizeof(a) / sizeof(*(a))) 47 | 48 | typedef libc_allocator_with_realloc int_alloc; 49 | typedef int_alloc::rebind::other intp_alloc; 50 | 51 | // cstring allocates from libc_allocator_with_realloc. 52 | typedef basic_string, 53 | libc_allocator_with_realloc > cstring; 54 | typedef vector > cstring_vector; 55 | 56 | TEST(LibcAllocatorWithRealloc, Allocate) { 57 | int_alloc alloc; 58 | intp_alloc palloc; 59 | 60 | int** parray = palloc.allocate(1024); 61 | for (int i = 0; i < 16; ++i) { 62 | parray[i] = alloc.allocate(i * 1024 + 1); 63 | } 64 | for (int i = 0; i < 16; ++i) { 65 | alloc.deallocate(parray[i], i * 1024 + 1); 66 | } 67 | palloc.deallocate(parray, 1024); 68 | 69 | int* p = alloc.allocate(4096); 70 | p[0] = 1; 71 | p[1023] = 2; 72 | p[4095] = 3; 73 | p = alloc.reallocate(p, 8192); 74 | ASSERT_EQ(1, p[0]); 75 | ASSERT_EQ(2, p[1023]); 76 | ASSERT_EQ(3, p[4095]); 77 | p = alloc.reallocate(p, 1024); 78 | ASSERT_EQ(1, p[0]); 79 | ASSERT_EQ(2, p[1023]); 80 | alloc.deallocate(p, 1024); 81 | } 82 | 83 | TEST(LibcAllocatorWithRealloc, TestSTL) { 84 | // Test strings copied from base/arena_unittest.cc 85 | static const char* test_strings[] = { 86 | "aback", "abaft", "abandon", "abandoned", 87 | "abandoning", "abandonment", "abandons", "abase", 88 | "abased", "abasement", "abasements", "abases", 89 | "abash", "abashed", "abashes", "abashing", 90 | "abasing", "abate", "abated", "abatement", 91 | "abatements", "abater", "abates", "abating", 92 | "abbe", "abbey", "abbeys", "abbot", 93 | "abbots", "abbreviate", "abbreviated", "abbreviates", 94 | "abbreviating", "abbreviation", "abbreviations", "abdomen", 95 | "abdomens", "abdominal", "abduct", "abducted", 96 | "abduction", "abductions", "abductor", "abductors", 97 | "abducts", "Abe", "abed", "Abel", 98 | "Abelian", "Abelson", "Aberdeen", "Abernathy", 99 | "aberrant", "aberration", "aberrations", "abet", 100 | "abets", "abetted", "abetter", "abetting", 101 | "abeyance", "abhor", "abhorred", "abhorrent", 102 | "abhorrer", "abhorring", "abhors", "abide", 103 | "abided", "abides", "abiding"}; 104 | cstring_vector v; 105 | for (size_t i = 0; i < arraysize(test_strings); ++i) { 106 | v.push_back(test_strings[i]); 107 | } 108 | for (size_t i = arraysize(test_strings); i > 0; --i) { 109 | ASSERT_EQ(cstring(test_strings[i - 1]), v.back()); 110 | v.pop_back(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /tests/src/gmock-cardinalities.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file implements cardinalities. 33 | 34 | #include "gmock/gmock-cardinalities.h" 35 | 36 | #include 37 | 38 | #include // NOLINT 39 | #include 40 | #include 41 | 42 | #include "gmock/internal/gmock-internal-utils.h" 43 | #include "gtest/gtest.h" 44 | 45 | namespace testing { 46 | 47 | namespace { 48 | 49 | // Implements the Between(m, n) cardinality. 50 | class BetweenCardinalityImpl : public CardinalityInterface { 51 | public: 52 | BetweenCardinalityImpl(int min, int max) 53 | : min_(min >= 0 ? min : 0), max_(max >= min_ ? max : min_) { 54 | std::stringstream ss; 55 | if (min < 0) { 56 | ss << "The invocation lower bound must be >= 0, " 57 | << "but is actually " << min << "."; 58 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 59 | } else if (max < 0) { 60 | ss << "The invocation upper bound must be >= 0, " 61 | << "but is actually " << max << "."; 62 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 63 | } else if (min > max) { 64 | ss << "The invocation upper bound (" << max 65 | << ") must be >= the invocation lower bound (" << min << ")."; 66 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 67 | } 68 | } 69 | 70 | // Conservative estimate on the lower/upper bound of the number of 71 | // calls allowed. 72 | int ConservativeLowerBound() const override { return min_; } 73 | int ConservativeUpperBound() const override { return max_; } 74 | 75 | bool IsSatisfiedByCallCount(int call_count) const override { 76 | return min_ <= call_count && call_count <= max_; 77 | } 78 | 79 | bool IsSaturatedByCallCount(int call_count) const override { 80 | return call_count >= max_; 81 | } 82 | 83 | void DescribeTo(::std::ostream* os) const override; 84 | 85 | private: 86 | const int min_; 87 | const int max_; 88 | 89 | BetweenCardinalityImpl(const BetweenCardinalityImpl&) = delete; 90 | BetweenCardinalityImpl& operator=(const BetweenCardinalityImpl&) = delete; 91 | }; 92 | 93 | // Formats "n times" in a human-friendly way. 94 | inline std::string FormatTimes(int n) { 95 | if (n == 1) { 96 | return "once"; 97 | } else if (n == 2) { 98 | return "twice"; 99 | } else { 100 | std::stringstream ss; 101 | ss << n << " times"; 102 | return ss.str(); 103 | } 104 | } 105 | 106 | // Describes the Between(m, n) cardinality in human-friendly text. 107 | void BetweenCardinalityImpl::DescribeTo(::std::ostream* os) const { 108 | if (min_ == 0) { 109 | if (max_ == 0) { 110 | *os << "never called"; 111 | } else if (max_ == INT_MAX) { 112 | *os << "called any number of times"; 113 | } else { 114 | *os << "called at most " << FormatTimes(max_); 115 | } 116 | } else if (min_ == max_) { 117 | *os << "called " << FormatTimes(min_); 118 | } else if (max_ == INT_MAX) { 119 | *os << "called at least " << FormatTimes(min_); 120 | } else { 121 | // 0 < min_ < max_ < INT_MAX 122 | *os << "called between " << min_ << " and " << max_ << " times"; 123 | } 124 | } 125 | 126 | } // Unnamed namespace 127 | 128 | // Describes the given call count to an ostream. 129 | void Cardinality::DescribeActualCallCountTo(int actual_call_count, 130 | ::std::ostream* os) { 131 | if (actual_call_count > 0) { 132 | *os << "called " << FormatTimes(actual_call_count); 133 | } else { 134 | *os << "never called"; 135 | } 136 | } 137 | 138 | // Creates a cardinality that allows at least n calls. 139 | GTEST_API_ Cardinality AtLeast(int n) { return Between(n, INT_MAX); } 140 | 141 | // Creates a cardinality that allows at most n calls. 142 | GTEST_API_ Cardinality AtMost(int n) { return Between(0, n); } 143 | 144 | // Creates a cardinality that allows any number of calls. 145 | GTEST_API_ Cardinality AnyNumber() { return AtLeast(0); } 146 | 147 | // Creates a cardinality that allows between min and max calls. 148 | GTEST_API_ Cardinality Between(int min, int max) { 149 | return Cardinality(new BetweenCardinalityImpl(min, max)); 150 | } 151 | 152 | // Creates a cardinality that allows exactly n calls. 153 | GTEST_API_ Cardinality Exactly(int n) { return Between(n, n); } 154 | 155 | } // namespace testing 156 | -------------------------------------------------------------------------------- /tests/gmock/internal/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Low-level types and utilities for porting Google Mock to various 31 | // platforms. All macros ending with _ and symbols defined in an 32 | // internal namespace are subject to change without notice. Code 33 | // outside Google Mock MUST NOT USE THEM DIRECTLY. Macros that don't 34 | // end with _ are part of Google Mock's public API and can be used by 35 | // code outside Google Mock. 36 | 37 | // IWYU pragma: private, include "gmock/gmock.h" 38 | // IWYU pragma: friend gmock/.* 39 | 40 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 41 | #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | // Most of the utilities needed for porting Google Mock are also 49 | // required for Google Test and are defined in gtest-port.h. 50 | // 51 | // Note to maintainers: to reduce code duplication, prefer adding 52 | // portability utilities to Google Test's gtest-port.h instead of 53 | // here, as Google Mock depends on Google Test. Only add a utility 54 | // here if it's truly specific to Google Mock. 55 | 56 | #include "gmock/internal/custom/gmock-port.h" 57 | #include "gtest/internal/gtest-port.h" 58 | 59 | #if GTEST_HAS_ABSL 60 | #include "absl/flags/declare.h" 61 | #include "absl/flags/flag.h" 62 | #endif 63 | 64 | // For MS Visual C++, check the compiler version. At least VS 2015 is 65 | // required to compile Google Mock. 66 | #if defined(_MSC_VER) && _MSC_VER < 1900 67 | #error "At least Visual C++ 2015 (14.0) is required to compile Google Mock." 68 | #endif 69 | 70 | // Macro for referencing flags. This is public as we want the user to 71 | // use this syntax to reference Google Mock flags. 72 | #define GMOCK_FLAG_NAME_(name) gmock_##name 73 | #define GMOCK_FLAG(name) FLAGS_gmock_##name 74 | 75 | // Pick a command line flags implementation. 76 | #if GTEST_HAS_ABSL 77 | 78 | // Macros for defining flags. 79 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 80 | ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc) 81 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 82 | ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc) 83 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ 84 | ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc) 85 | 86 | // Macros for declaring flags. 87 | #define GMOCK_DECLARE_bool_(name) \ 88 | ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name)) 89 | #define GMOCK_DECLARE_int32_(name) \ 90 | ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name)) 91 | #define GMOCK_DECLARE_string_(name) \ 92 | ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name)) 93 | 94 | #define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name)) 95 | #define GMOCK_FLAG_SET(name, value) \ 96 | (void)(::absl::SetFlag(&GMOCK_FLAG(name), value)) 97 | 98 | #else // GTEST_HAS_ABSL 99 | 100 | // Macros for defining flags. 101 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 102 | namespace testing { \ 103 | GTEST_API_ bool GMOCK_FLAG(name) = (default_val); \ 104 | } \ 105 | static_assert(true, "no-op to require trailing semicolon") 106 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 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 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ 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 | #define GMOCK_DECLARE_bool_(name) \ 119 | namespace testing { \ 120 | GTEST_API_ extern bool GMOCK_FLAG(name); \ 121 | } \ 122 | static_assert(true, "no-op to require trailing semicolon") 123 | #define GMOCK_DECLARE_int32_(name) \ 124 | namespace testing { \ 125 | GTEST_API_ extern int32_t GMOCK_FLAG(name); \ 126 | } \ 127 | static_assert(true, "no-op to require trailing semicolon") 128 | #define GMOCK_DECLARE_string_(name) \ 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 | #define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name) 135 | #define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value) 136 | 137 | #endif // GTEST_HAS_ABSL 138 | 139 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 140 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This directory contains several hash-map implementations, similar in 2 | API to SGI's hash_map class, but with different performance 3 | characteristics. sparse_hash_map uses very little space overhead, 1-2 4 | bits per entry. dense_hash_map is very fast, particulary on lookup. 5 | (sparse_hash_set and dense_hash_set are the set versions of these 6 | routines.) On the other hand, these classes have requirements that 7 | may not make them appropriate for all applications. 8 | 9 | All these implementation use a hashtable with internal quadratic 10 | probing. This method is space-efficient -- there is no pointer 11 | overhead -- and time-efficient for good hash functions. 12 | 13 | COMPILING 14 | --------- 15 | To compile test applications with these classes, run ./configure 16 | followed by make. To install these header files on your system, run 17 | 'make install'. (On Windows, the instructions are different; see 18 | README_windows.txt.) See INSTALL for more details. 19 | 20 | This code should work on any modern C++ system. It has been tested on 21 | Linux (Ubuntu, Fedora, RedHat, Debian), Solaris 10 x86, FreeBSD 6.0, 22 | OS X 10.3 and 10.4, and Windows under both VC++7 and VC++8. 23 | 24 | USING 25 | ----- 26 | See the html files in the doc directory for small example programs 27 | that use these classes. It's enough to just include the header file: 28 | 29 | #include // or sparse_hash_set, dense_hash_map, ... 30 | google::sparse_hash_set number_mapper; 31 | 32 | and use the class the way you would other hash-map implementations. 33 | (Though see "API" below for caveats.) 34 | 35 | By default (you can change it via a flag to ./configure), these hash 36 | implementations are defined in the google namespace. 37 | 38 | API 39 | --- 40 | The API for sparse_hash_map, dense_hash_map, sparse_hash_set, and 41 | dense_hash_set, are a superset of the API of SGI's hash_map class. 42 | See doc/sparse_hash_map.html, et al., for more information about the 43 | API. 44 | 45 | The usage of these classes differ from SGI's hash_map, and other 46 | hashtable implementations, in the following major ways: 47 | 48 | 1) dense_hash_map requires you to set aside one key value as the 49 | 'empty bucket' value, set via the set_empty_key() method. This 50 | *MUST* be called before you can use the dense_hash_map. It is 51 | illegal to insert any elements into a dense_hash_map whose key is 52 | equal to the empty-key. 53 | 54 | 2) For both dense_hash_map and sparse_hash_map, if you wish to delete 55 | elements from the hashtable, you must set aside a key value as the 56 | 'deleted bucket' value, set via the set_deleted_key() method. If 57 | your hash-map is insert-only, there is no need to call this 58 | method. If you call set_deleted_key(), it is illegal to insert any 59 | elements into a dense_hash_map or sparse_hash_map whose key is 60 | equal to the deleted-key. 61 | 62 | 3) These hash-map implementation support I/O. See below. 63 | 64 | There are also some smaller differences: 65 | 66 | 1) The constructor takes an optional argument that specifies the 67 | number of elements you expect to insert into the hashtable. This 68 | differs from SGI's hash_map implementation, which takes an optional 69 | number of buckets. 70 | 71 | 2) erase() does not immediately reclaim memory. As a consequence, 72 | erase() does not invalidate any iterators, making loops like this 73 | correct: 74 | for (it = ht.begin(); it != ht.end(); ++it) 75 | if (...) ht.erase(it); 76 | As another consequence, a series of erase() calls can leave your 77 | hashtable using more memory than it needs to. The hashtable will 78 | automatically compact at the next call to insert(), but to 79 | manually compact a hashtable, you can call 80 | ht.resize(0) 81 | 82 | I/O 83 | --- 84 | In addition to the normal hash-map operations, sparse_hash_map can 85 | read and write hashtables to disk. (dense_hash_map also has the API, 86 | but it has not yet been implemented, and writes will always fail.) 87 | 88 | In the simplest case, writing a hashtable is as easy as calling two 89 | methods on the hashtable: 90 | ht.write_metadata(fp); 91 | ht.write_nopointer_data(fp); 92 | 93 | Reading in this data is equally simple: 94 | google::sparse_hash_map<...> ht; 95 | ht.read_metadata(fp); 96 | ht.read_nopointer_data(fp); 97 | 98 | The above is sufficient if the key and value do not contain any 99 | pointers: they are basic C types or agglomorations of basic C types. 100 | If the key and/or value do contain pointers, you can still store the 101 | hashtable by replacing write_nopointer_data() with a custom writing 102 | routine. See sparse_hash_map.html et al. for more information. 103 | 104 | SPARSETABLE 105 | ----------- 106 | In addition to the hash-map and hash-set classes, this package also 107 | provides sparsetable.h, an array implementation that uses space 108 | proportional to the number of elements in the array, rather than the 109 | maximum element index. It uses very little space overhead: 2 to 5 110 | bits per entry. See doc/sparsetable.html for the API. 111 | 112 | RESOURCE USAGE 113 | -------------- 114 | * sparse_hash_map has memory overhead of about 4 to 10 bits per 115 | hash-map entry, assuming a typical average occupancy of 50%. 116 | * dense_hash_map has a factor of 2-3 memory overhead: if your 117 | hashtable data takes X bytes, dense_hash_map will use 3X-4X memory 118 | total. 119 | 120 | Hashtables tend to double in size when resizing, creating an 121 | additional 50% space overhead. dense_hash_map does in fact have a 122 | significant "high water mark" memory use requirement, which is 6 times 123 | the size of hash entries in the table when resizing (when reaching 124 | 50% occupancy, the table resizes to double the previous size, and the 125 | old table (2x) is copied to the new table (4x)). 126 | 127 | sparse_hash_map, however, is written to need very little space 128 | overhead when resizing: only a few bits per hashtable entry. 129 | 130 | PERFORMANCE 131 | ----------- 132 | You can compile and run the included file time_hash_map.cc to examine 133 | the performance of sparse_hash_map, dense_hash_map, and your native 134 | hash_map implementation on your system. One test against the 135 | SGI hash_map implementation gave the following timing information for 136 | a simple find() call: 137 | SGI hash_map: 22 ns 138 | dense_hash_map: 13 ns 139 | sparse_hash_map: 117 ns 140 | SGI map: 113 ns 141 | 142 | See doc/performance.html for more detailed charts on resource usage 143 | and performance data. 144 | 145 | --- 146 | 16 March 2005 147 | (Last updated: 12 September 2010) 148 | -------------------------------------------------------------------------------- /tests/gmock/gmock-cardinalities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file implements some commonly used cardinalities. More 33 | // cardinalities can be defined by the user implementing the 34 | // CardinalityInterface interface if necessary. 35 | 36 | // IWYU pragma: private, include "gmock/gmock.h" 37 | // IWYU pragma: friend gmock/.* 38 | 39 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 40 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 41 | 42 | #include 43 | 44 | #include 45 | #include // NOLINT 46 | 47 | #include "gmock/internal/gmock-port.h" 48 | #include "gtest/gtest.h" 49 | 50 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 51 | /* class A needs to have dll-interface to be used by clients of class B */) 52 | 53 | namespace testing { 54 | 55 | // To implement a cardinality Foo, define: 56 | // 1. a class FooCardinality that implements the 57 | // CardinalityInterface interface, and 58 | // 2. a factory function that creates a Cardinality object from a 59 | // const FooCardinality*. 60 | // 61 | // The two-level delegation design follows that of Matcher, providing 62 | // consistency for extension developers. It also eases ownership 63 | // management as Cardinality objects can now be copied like plain values. 64 | 65 | // The implementation of a cardinality. 66 | class CardinalityInterface { 67 | public: 68 | virtual ~CardinalityInterface() {} 69 | 70 | // Conservative estimate on the lower/upper bound of the number of 71 | // calls allowed. 72 | virtual int ConservativeLowerBound() const { return 0; } 73 | virtual int ConservativeUpperBound() const { return INT_MAX; } 74 | 75 | // Returns true if and only if call_count calls will satisfy this 76 | // cardinality. 77 | virtual bool IsSatisfiedByCallCount(int call_count) const = 0; 78 | 79 | // Returns true if and only if call_count calls will saturate this 80 | // cardinality. 81 | virtual bool IsSaturatedByCallCount(int call_count) const = 0; 82 | 83 | // Describes self to an ostream. 84 | virtual void DescribeTo(::std::ostream* os) const = 0; 85 | }; 86 | 87 | // A Cardinality is a copyable and IMMUTABLE (except by assignment) 88 | // object that specifies how many times a mock function is expected to 89 | // be called. The implementation of Cardinality is just a std::shared_ptr 90 | // to const CardinalityInterface. Don't inherit from Cardinality! 91 | class GTEST_API_ Cardinality { 92 | public: 93 | // Constructs a null cardinality. Needed for storing Cardinality 94 | // objects in STL containers. 95 | Cardinality() {} 96 | 97 | // Constructs a Cardinality from its implementation. 98 | explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} 99 | 100 | // Conservative estimate on the lower/upper bound of the number of 101 | // calls allowed. 102 | int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } 103 | int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } 104 | 105 | // Returns true if and only if call_count calls will satisfy this 106 | // cardinality. 107 | bool IsSatisfiedByCallCount(int call_count) const { 108 | return impl_->IsSatisfiedByCallCount(call_count); 109 | } 110 | 111 | // Returns true if and only if call_count calls will saturate this 112 | // cardinality. 113 | bool IsSaturatedByCallCount(int call_count) const { 114 | return impl_->IsSaturatedByCallCount(call_count); 115 | } 116 | 117 | // Returns true if and only if call_count calls will over-saturate this 118 | // cardinality, i.e. exceed the maximum number of allowed calls. 119 | bool IsOverSaturatedByCallCount(int call_count) const { 120 | return impl_->IsSaturatedByCallCount(call_count) && 121 | !impl_->IsSatisfiedByCallCount(call_count); 122 | } 123 | 124 | // Describes self to an ostream 125 | void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } 126 | 127 | // Describes the given actual call count to an ostream. 128 | static void DescribeActualCallCountTo(int actual_call_count, 129 | ::std::ostream* os); 130 | 131 | private: 132 | std::shared_ptr impl_; 133 | }; 134 | 135 | // Creates a cardinality that allows at least n calls. 136 | GTEST_API_ Cardinality AtLeast(int n); 137 | 138 | // Creates a cardinality that allows at most n calls. 139 | GTEST_API_ Cardinality AtMost(int n); 140 | 141 | // Creates a cardinality that allows any number of calls. 142 | GTEST_API_ Cardinality AnyNumber(); 143 | 144 | // Creates a cardinality that allows between min and max calls. 145 | GTEST_API_ Cardinality Between(int min, int max); 146 | 147 | // Creates a cardinality that allows exactly n calls. 148 | GTEST_API_ Cardinality Exactly(int n); 149 | 150 | // Creates a cardinality from its implementation. 151 | inline Cardinality MakeCardinality(const CardinalityInterface* c) { 152 | return Cardinality(c); 153 | } 154 | 155 | } // namespace testing 156 | 157 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 158 | 159 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 160 | -------------------------------------------------------------------------------- /tests/gtest/internal/gtest-type-util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Type utilities needed for implementing typed and type-parameterized 31 | // tests. 32 | 33 | // IWYU pragma: private, include "gtest/gtest.h" 34 | // IWYU pragma: friend gtest/.* 35 | // IWYU pragma: friend gmock/.* 36 | 37 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 38 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 39 | 40 | #include "gtest/internal/gtest-port.h" 41 | 42 | // #ifdef __GNUC__ is too general here. It is possible to use gcc without using 43 | // libstdc++ (which is where cxxabi.h comes from). 44 | #if GTEST_HAS_CXXABI_H_ 45 | #include 46 | #elif defined(__HP_aCC) 47 | #include 48 | #endif // GTEST_HASH_CXXABI_H_ 49 | 50 | namespace testing { 51 | namespace internal { 52 | 53 | // Canonicalizes a given name with respect to the Standard C++ Library. 54 | // This handles removing the inline namespace within `std` that is 55 | // used by various standard libraries (e.g., `std::__1`). Names outside 56 | // of namespace std are returned unmodified. 57 | inline std::string CanonicalizeForStdLibVersioning(std::string s) { 58 | static const char prefix[] = "std::__"; 59 | if (s.compare(0, strlen(prefix), prefix) == 0) { 60 | std::string::size_type end = s.find("::", strlen(prefix)); 61 | if (end != s.npos) { 62 | // Erase everything between the initial `std` and the second `::`. 63 | s.erase(strlen("std"), end - strlen("std")); 64 | } 65 | } 66 | return s; 67 | } 68 | 69 | #if GTEST_HAS_RTTI 70 | // GetTypeName(const std::type_info&) returns a human-readable name of type T. 71 | inline std::string GetTypeName(const std::type_info& type) { 72 | const char* const name = type.name(); 73 | #if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) 74 | int status = 0; 75 | // gcc's implementation of typeid(T).name() mangles the type name, 76 | // so we have to demangle it. 77 | #if GTEST_HAS_CXXABI_H_ 78 | using abi::__cxa_demangle; 79 | #endif // GTEST_HAS_CXXABI_H_ 80 | char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status); 81 | const std::string name_str(status == 0 ? readable_name : name); 82 | free(readable_name); 83 | return CanonicalizeForStdLibVersioning(name_str); 84 | #else 85 | return name; 86 | #endif // GTEST_HAS_CXXABI_H_ || __HP_aCC 87 | } 88 | #endif // GTEST_HAS_RTTI 89 | 90 | // GetTypeName() returns a human-readable name of type T if and only if 91 | // RTTI is enabled, otherwise it returns a dummy type name. 92 | // NB: This function is also used in Google Mock, so don't move it inside of 93 | // the typed-test-only section below. 94 | template 95 | std::string GetTypeName() { 96 | #if GTEST_HAS_RTTI 97 | return GetTypeName(typeid(T)); 98 | #else 99 | return ""; 100 | #endif // GTEST_HAS_RTTI 101 | } 102 | 103 | // A unique type indicating an empty node 104 | struct None {}; 105 | 106 | #define GTEST_TEMPLATE_ \ 107 | template \ 108 | class 109 | 110 | // The template "selector" struct TemplateSel is used to 111 | // represent Tmpl, which must be a class template with one type 112 | // parameter, as a type. TemplateSel::Bind::type is defined 113 | // as the type Tmpl. This allows us to actually instantiate the 114 | // template "selected" by TemplateSel. 115 | // 116 | // This trick is necessary for simulating typedef for class templates, 117 | // which C++ doesn't support directly. 118 | template 119 | struct TemplateSel { 120 | template 121 | struct Bind { 122 | typedef Tmpl type; 123 | }; 124 | }; 125 | 126 | #define GTEST_BIND_(TmplSel, T) TmplSel::template Bind::type 127 | 128 | template 129 | struct Templates { 130 | using Head = TemplateSel; 131 | using Tail = Templates; 132 | }; 133 | 134 | template 135 | struct Templates { 136 | using Head = TemplateSel; 137 | using Tail = None; 138 | }; 139 | 140 | // Tuple-like type lists 141 | template 142 | struct Types { 143 | using Head = Head_; 144 | using Tail = Types; 145 | }; 146 | 147 | template 148 | struct Types { 149 | using Head = Head_; 150 | using Tail = None; 151 | }; 152 | 153 | // Helper metafunctions to tell apart a single type from types 154 | // generated by ::testing::Types 155 | template 156 | struct ProxyTypeList { 157 | using type = Types; 158 | }; 159 | 160 | template 161 | struct is_proxy_type_list : std::false_type {}; 162 | 163 | template 164 | struct is_proxy_type_list> : std::true_type {}; 165 | 166 | // Generator which conditionally creates type lists. 167 | // It recognizes if a requested type list should be created 168 | // and prevents creating a new type list nested within another one. 169 | template 170 | struct GenerateTypeList { 171 | private: 172 | using proxy = typename std::conditional::value, T, 173 | ProxyTypeList>::type; 174 | 175 | public: 176 | using type = typename proxy::type; 177 | }; 178 | 179 | } // namespace internal 180 | 181 | template 182 | using Types = internal::ProxyTypeList; 183 | 184 | } // namespace testing 185 | 186 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 187 | -------------------------------------------------------------------------------- /tests/gtest/gtest-test-part.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // IWYU pragma: private, include "gtest/gtest.h" 31 | // IWYU pragma: friend gtest/.* 32 | // IWYU pragma: friend gmock/.* 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 36 | 37 | #include 38 | #include 39 | 40 | #include "gtest/internal/gtest-internal.h" 41 | #include "gtest/internal/gtest-string.h" 42 | 43 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 44 | /* class A needs to have dll-interface to be used by clients of class B */) 45 | 46 | namespace testing { 47 | 48 | // A copyable object representing the result of a test part (i.e. an 49 | // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). 50 | // 51 | // Don't inherit from TestPartResult as its destructor is not virtual. 52 | class GTEST_API_ TestPartResult { 53 | public: 54 | // The possible outcomes of a test part (i.e. an assertion or an 55 | // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). 56 | enum Type { 57 | kSuccess, // Succeeded. 58 | kNonFatalFailure, // Failed but the test can continue. 59 | kFatalFailure, // Failed and the test should be terminated. 60 | kSkip // Skipped. 61 | }; 62 | 63 | // C'tor. TestPartResult does NOT have a default constructor. 64 | // Always use this constructor (with parameters) to create a 65 | // TestPartResult object. 66 | TestPartResult(Type a_type, const char* a_file_name, int a_line_number, 67 | const char* a_message) 68 | : type_(a_type), 69 | file_name_(a_file_name == nullptr ? "" : a_file_name), 70 | line_number_(a_line_number), 71 | summary_(ExtractSummary(a_message)), 72 | message_(a_message) {} 73 | 74 | // Gets the outcome of the test part. 75 | Type type() const { return type_; } 76 | 77 | // Gets the name of the source file where the test part took place, or 78 | // NULL if it's unknown. 79 | const char* file_name() const { 80 | return file_name_.empty() ? nullptr : file_name_.c_str(); 81 | } 82 | 83 | // Gets the line in the source file where the test part took place, 84 | // or -1 if it's unknown. 85 | int line_number() const { return line_number_; } 86 | 87 | // Gets the summary of the failure message. 88 | const char* summary() const { return summary_.c_str(); } 89 | 90 | // Gets the message associated with the test part. 91 | const char* message() const { return message_.c_str(); } 92 | 93 | // Returns true if and only if the test part was skipped. 94 | bool skipped() const { return type_ == kSkip; } 95 | 96 | // Returns true if and only if the test part passed. 97 | bool passed() const { return type_ == kSuccess; } 98 | 99 | // Returns true if and only if the test part non-fatally failed. 100 | bool nonfatally_failed() const { return type_ == kNonFatalFailure; } 101 | 102 | // Returns true if and only if the test part fatally failed. 103 | bool fatally_failed() const { return type_ == kFatalFailure; } 104 | 105 | // Returns true if and only if the test part failed. 106 | bool failed() const { return fatally_failed() || nonfatally_failed(); } 107 | 108 | private: 109 | Type type_; 110 | 111 | // Gets the summary of the failure message by omitting the stack 112 | // trace in it. 113 | static std::string ExtractSummary(const char* message); 114 | 115 | // The name of the source file where the test part took place, or 116 | // "" if the source file is unknown. 117 | std::string file_name_; 118 | // The line in the source file where the test part took place, or -1 119 | // if the line number is unknown. 120 | int line_number_; 121 | std::string summary_; // The test failure summary. 122 | std::string message_; // The test failure message. 123 | }; 124 | 125 | // Prints a TestPartResult object. 126 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result); 127 | 128 | // An array of TestPartResult objects. 129 | // 130 | // Don't inherit from TestPartResultArray as its destructor is not 131 | // virtual. 132 | class GTEST_API_ TestPartResultArray { 133 | public: 134 | TestPartResultArray() {} 135 | 136 | // Appends the given TestPartResult to the array. 137 | void Append(const TestPartResult& result); 138 | 139 | // Returns the TestPartResult at the given index (0-based). 140 | const TestPartResult& GetTestPartResult(int index) const; 141 | 142 | // Returns the number of TestPartResult objects in the array. 143 | int size() const; 144 | 145 | private: 146 | std::vector array_; 147 | 148 | TestPartResultArray(const TestPartResultArray&) = delete; 149 | TestPartResultArray& operator=(const TestPartResultArray&) = delete; 150 | }; 151 | 152 | // This interface knows how to report a test part result. 153 | class GTEST_API_ TestPartResultReporterInterface { 154 | public: 155 | virtual ~TestPartResultReporterInterface() {} 156 | 157 | virtual void ReportTestPartResult(const TestPartResult& result) = 0; 158 | }; 159 | 160 | namespace internal { 161 | 162 | // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a 163 | // statement generates new fatal failures. To do so it registers itself as the 164 | // current test part result reporter. Besides checking if fatal failures were 165 | // reported, it only delegates the reporting to the former result reporter. 166 | // The original result reporter is restored in the destructor. 167 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 168 | class GTEST_API_ HasNewFatalFailureHelper 169 | : public TestPartResultReporterInterface { 170 | public: 171 | HasNewFatalFailureHelper(); 172 | ~HasNewFatalFailureHelper() override; 173 | void ReportTestPartResult(const TestPartResult& result) override; 174 | bool has_new_fatal_failure() const { return has_new_fatal_failure_; } 175 | 176 | private: 177 | bool has_new_fatal_failure_; 178 | TestPartResultReporterInterface* original_reporter_; 179 | 180 | HasNewFatalFailureHelper(const HasNewFatalFailureHelper&) = delete; 181 | HasNewFatalFailureHelper& operator=(const HasNewFatalFailureHelper&) = delete; 182 | }; 183 | 184 | } // namespace internal 185 | 186 | } // namespace testing 187 | 188 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 189 | 190 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 191 | -------------------------------------------------------------------------------- /tests/gtest/internal/gtest-string.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This header file declares the String class and functions used internally by 33 | // Google Test. They are subject to change without notice. They should not used 34 | // by code external to Google Test. 35 | // 36 | // This header file is #included by gtest-internal.h. 37 | // It should not be #included by other files. 38 | 39 | // IWYU pragma: private, include "gtest/gtest.h" 40 | // IWYU pragma: friend gtest/.* 41 | // IWYU pragma: friend gmock/.* 42 | 43 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 44 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 45 | 46 | #ifdef __BORLANDC__ 47 | // string.h is not guaranteed to provide strcpy on C++ Builder. 48 | #include 49 | #endif 50 | 51 | #include 52 | 53 | #include 54 | #include 55 | 56 | #include "gtest/internal/gtest-port.h" 57 | 58 | namespace testing { 59 | namespace internal { 60 | 61 | // String - an abstract class holding static string utilities. 62 | class GTEST_API_ String { 63 | public: 64 | // Static utility methods 65 | 66 | // Clones a 0-terminated C string, allocating memory using new. The 67 | // caller is responsible for deleting the return value using 68 | // delete[]. Returns the cloned string, or NULL if the input is 69 | // NULL. 70 | // 71 | // This is different from strdup() in string.h, which allocates 72 | // memory using malloc(). 73 | static const char* CloneCString(const char* c_str); 74 | 75 | #if GTEST_OS_WINDOWS_MOBILE 76 | // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be 77 | // able to pass strings to Win32 APIs on CE we need to convert them 78 | // to 'Unicode', UTF-16. 79 | 80 | // Creates a UTF-16 wide string from the given ANSI string, allocating 81 | // memory using new. The caller is responsible for deleting the return 82 | // value using delete[]. Returns the wide string, or NULL if the 83 | // input is NULL. 84 | // 85 | // The wide string is created using the ANSI codepage (CP_ACP) to 86 | // match the behaviour of the ANSI versions of Win32 calls and the 87 | // C runtime. 88 | static LPCWSTR AnsiToUtf16(const char* c_str); 89 | 90 | // Creates an ANSI string from the given wide string, allocating 91 | // memory using new. The caller is responsible for deleting the return 92 | // value using delete[]. Returns the ANSI string, or NULL if the 93 | // input is NULL. 94 | // 95 | // The returned string is created using the ANSI codepage (CP_ACP) to 96 | // match the behaviour of the ANSI versions of Win32 calls and the 97 | // C runtime. 98 | static const char* Utf16ToAnsi(LPCWSTR utf16_str); 99 | #endif 100 | 101 | // Compares two C strings. Returns true if and only if they have the same 102 | // content. 103 | // 104 | // Unlike strcmp(), this function can handle NULL argument(s). A 105 | // NULL C string is considered different to any non-NULL C string, 106 | // including the empty string. 107 | static bool CStringEquals(const char* lhs, const char* rhs); 108 | 109 | // Converts a wide C string to a String using the UTF-8 encoding. 110 | // NULL will be converted to "(null)". If an error occurred during 111 | // the conversion, "(failed to convert from wide string)" is 112 | // returned. 113 | static std::string ShowWideCString(const wchar_t* wide_c_str); 114 | 115 | // Compares two wide C strings. Returns true if and only if they have the 116 | // same content. 117 | // 118 | // Unlike wcscmp(), this function can handle NULL argument(s). A 119 | // NULL C string is considered different to any non-NULL C string, 120 | // including the empty string. 121 | static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); 122 | 123 | // Compares two C strings, ignoring case. Returns true if and only if 124 | // they have the same content. 125 | // 126 | // Unlike strcasecmp(), this function can handle NULL argument(s). 127 | // A NULL C string is considered different to any non-NULL C string, 128 | // including the empty string. 129 | static bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs); 130 | 131 | // Compares two wide C strings, ignoring case. Returns true if and only if 132 | // they have the same content. 133 | // 134 | // Unlike wcscasecmp(), this function can handle NULL argument(s). 135 | // A NULL C string is considered different to any non-NULL wide C string, 136 | // including the empty string. 137 | // NB: The implementations on different platforms slightly differ. 138 | // On windows, this method uses _wcsicmp which compares according to LC_CTYPE 139 | // environment variable. On GNU platform this method uses wcscasecmp 140 | // which compares according to LC_CTYPE category of the current locale. 141 | // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the 142 | // current locale. 143 | static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, 144 | const wchar_t* rhs); 145 | 146 | // Returns true if and only if the given string ends with the given suffix, 147 | // ignoring case. Any string is considered to end with an empty suffix. 148 | static bool EndsWithCaseInsensitive(const std::string& str, 149 | const std::string& suffix); 150 | 151 | // Formats an int value as "%02d". 152 | static std::string FormatIntWidth2(int value); // "%02d" for width == 2 153 | 154 | // Formats an int value to given width with leading zeros. 155 | static std::string FormatIntWidthN(int value, int width); 156 | 157 | // Formats an int value as "%X". 158 | static std::string FormatHexInt(int value); 159 | 160 | // Formats an int value as "%X". 161 | static std::string FormatHexUInt32(uint32_t value); 162 | 163 | // Formats a byte as "%02X". 164 | static std::string FormatByte(unsigned char value); 165 | 166 | private: 167 | String(); // Not meant to be instantiated. 168 | }; // class String 169 | 170 | // Gets the content of the stringstream's buffer as an std::string. Each '\0' 171 | // character in the buffer is replaced with "\\0". 172 | GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); 173 | 174 | } // namespace internal 175 | } // namespace testing 176 | 177 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 178 | -------------------------------------------------------------------------------- /tests/gtest/gtest-message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This header file defines the Message class. 33 | // 34 | // IMPORTANT NOTE: Due to limitation of the C++ language, we have to 35 | // leave some internal implementation details in this header file. 36 | // They are clearly marked by comments like this: 37 | // 38 | // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 39 | // 40 | // Such code is NOT meant to be used by a user directly, and is subject 41 | // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user 42 | // program! 43 | 44 | // IWYU pragma: private, include "gtest/gtest.h" 45 | // IWYU pragma: friend gtest/.* 46 | // IWYU pragma: friend gmock/.* 47 | 48 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 49 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 50 | 51 | #include 52 | #include 53 | #include 54 | 55 | #include "gtest/internal/gtest-port.h" 56 | 57 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 58 | /* class A needs to have dll-interface to be used by clients of class B */) 59 | 60 | // Ensures that there is at least one operator<< in the global namespace. 61 | // See Message& operator<<(...) below for why. 62 | void operator<<(const testing::internal::Secret&, int); 63 | 64 | namespace testing { 65 | 66 | // The Message class works like an ostream repeater. 67 | // 68 | // Typical usage: 69 | // 70 | // 1. You stream a bunch of values to a Message object. 71 | // It will remember the text in a stringstream. 72 | // 2. Then you stream the Message object to an ostream. 73 | // This causes the text in the Message to be streamed 74 | // to the ostream. 75 | // 76 | // For example; 77 | // 78 | // testing::Message foo; 79 | // foo << 1 << " != " << 2; 80 | // std::cout << foo; 81 | // 82 | // will print "1 != 2". 83 | // 84 | // Message is not intended to be inherited from. In particular, its 85 | // destructor is not virtual. 86 | // 87 | // Note that stringstream behaves differently in gcc and in MSVC. You 88 | // can stream a NULL char pointer to it in the former, but not in the 89 | // latter (it causes an access violation if you do). The Message 90 | // class hides this difference by treating a NULL char pointer as 91 | // "(null)". 92 | class GTEST_API_ Message { 93 | private: 94 | // The type of basic IO manipulators (endl, ends, and flush) for 95 | // narrow streams. 96 | typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); 97 | 98 | public: 99 | // Constructs an empty Message. 100 | Message(); 101 | 102 | // Copy constructor. 103 | Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT 104 | *ss_ << msg.GetString(); 105 | } 106 | 107 | // Constructs a Message from a C-string. 108 | explicit Message(const char* str) : ss_(new ::std::stringstream) { 109 | *ss_ << str; 110 | } 111 | 112 | // Streams a non-pointer value to this object. 113 | template 114 | inline Message& operator<<(const T& val) { 115 | // Some libraries overload << for STL containers. These 116 | // overloads are defined in the global namespace instead of ::std. 117 | // 118 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these 119 | // overloads are visible in either the std namespace or the global 120 | // namespace, but not other namespaces, including the testing 121 | // namespace which Google Test's Message class is in. 122 | // 123 | // To allow STL containers (and other types that has a << operator 124 | // defined in the global namespace) to be used in Google Test 125 | // assertions, testing::Message must access the custom << operator 126 | // from the global namespace. With this using declaration, 127 | // overloads of << defined in the global namespace and those 128 | // visible via Koenig lookup are both exposed in this function. 129 | using ::operator<<; 130 | *ss_ << val; 131 | return *this; 132 | } 133 | 134 | // Streams a pointer value to this object. 135 | // 136 | // This function is an overload of the previous one. When you 137 | // stream a pointer to a Message, this definition will be used as it 138 | // is more specialized. (The C++ Standard, section 139 | // [temp.func.order].) If you stream a non-pointer, then the 140 | // previous definition will be used. 141 | // 142 | // The reason for this overload is that streaming a NULL pointer to 143 | // ostream is undefined behavior. Depending on the compiler, you 144 | // may get "0", "(nil)", "(null)", or an access violation. To 145 | // ensure consistent result across compilers, we always treat NULL 146 | // as "(null)". 147 | template 148 | inline Message& operator<<(T* const& pointer) { // NOLINT 149 | if (pointer == nullptr) { 150 | *ss_ << "(null)"; 151 | } else { 152 | *ss_ << pointer; 153 | } 154 | return *this; 155 | } 156 | 157 | // Since the basic IO manipulators are overloaded for both narrow 158 | // and wide streams, we have to provide this specialized definition 159 | // of operator <<, even though its body is the same as the 160 | // templatized version above. Without this definition, streaming 161 | // endl or other basic IO manipulators to Message will confuse the 162 | // compiler. 163 | Message& operator<<(BasicNarrowIoManip val) { 164 | *ss_ << val; 165 | return *this; 166 | } 167 | 168 | // Instead of 1/0, we want to see true/false for bool values. 169 | Message& operator<<(bool b) { return *this << (b ? "true" : "false"); } 170 | 171 | // These two overloads allow streaming a wide C string to a Message 172 | // using the UTF-8 encoding. 173 | Message& operator<<(const wchar_t* wide_c_str); 174 | Message& operator<<(wchar_t* wide_c_str); 175 | 176 | #if GTEST_HAS_STD_WSTRING 177 | // Converts the given wide string to a narrow string using the UTF-8 178 | // encoding, and streams the result to this Message object. 179 | Message& operator<<(const ::std::wstring& wstr); 180 | #endif // GTEST_HAS_STD_WSTRING 181 | 182 | // Gets the text streamed to this object so far as an std::string. 183 | // Each '\0' character in the buffer is replaced with "\\0". 184 | // 185 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 186 | std::string GetString() const; 187 | 188 | private: 189 | // We'll hold the text streamed to this object here. 190 | const std::unique_ptr< ::std::stringstream> ss_; 191 | 192 | // We declare (but don't implement) this to prevent the compiler 193 | // from implementing the assignment operator. 194 | void operator=(const Message&); 195 | }; 196 | 197 | // Streams a Message to an ostream. 198 | inline std::ostream& operator<<(std::ostream& os, const Message& sb) { 199 | return os << sb.GetString(); 200 | } 201 | 202 | namespace internal { 203 | 204 | // Converts a streamable value to an std::string. A NULL pointer is 205 | // converted to "(null)". When the input value is a ::string, 206 | // ::std::string, ::wstring, or ::std::wstring object, each NUL 207 | // character in it is replaced with "\\0". 208 | template 209 | std::string StreamableToString(const T& streamable) { 210 | return (Message() << streamable).GetString(); 211 | } 212 | 213 | } // namespace internal 214 | } // namespace testing 215 | 216 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 217 | 218 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 219 | -------------------------------------------------------------------------------- /tests/src/gmock.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | #include "gmock/gmock.h" 31 | 32 | #include "gmock/internal/gmock-port.h" 33 | 34 | GMOCK_DEFINE_bool_(catch_leaked_mocks, true, 35 | "true if and only if Google Mock should report leaked " 36 | "mock objects as failures."); 37 | 38 | GMOCK_DEFINE_string_(verbose, testing::internal::kWarningVerbosity, 39 | "Controls how verbose Google Mock's output is." 40 | " Valid values:\n" 41 | " info - prints all messages.\n" 42 | " warning - prints warnings and errors.\n" 43 | " error - prints errors only."); 44 | 45 | GMOCK_DEFINE_int32_(default_mock_behavior, 1, 46 | "Controls the default behavior of mocks." 47 | " Valid values:\n" 48 | " 0 - by default, mocks act as NiceMocks.\n" 49 | " 1 - by default, mocks act as NaggyMocks.\n" 50 | " 2 - by default, mocks act as StrictMocks."); 51 | 52 | namespace testing { 53 | namespace internal { 54 | 55 | // Parses a string as a command line flag. The string should have the 56 | // format "--gmock_flag=value". When def_optional is true, the 57 | // "=value" part can be omitted. 58 | // 59 | // Returns the value of the flag, or NULL if the parsing failed. 60 | static const char* ParseGoogleMockFlagValue(const char* str, 61 | const char* flag_name, 62 | bool def_optional) { 63 | // str and flag must not be NULL. 64 | if (str == nullptr || flag_name == nullptr) return nullptr; 65 | 66 | // The flag must start with "--gmock_". 67 | const std::string flag_name_str = std::string("--gmock_") + flag_name; 68 | const size_t flag_name_len = flag_name_str.length(); 69 | if (strncmp(str, flag_name_str.c_str(), flag_name_len) != 0) return nullptr; 70 | 71 | // Skips the flag name. 72 | const char* flag_end = str + flag_name_len; 73 | 74 | // When def_optional is true, it's OK to not have a "=value" part. 75 | if (def_optional && (flag_end[0] == '\0')) { 76 | return flag_end; 77 | } 78 | 79 | // If def_optional is true and there are more characters after the 80 | // flag name, or if def_optional is false, there must be a '=' after 81 | // the flag name. 82 | if (flag_end[0] != '=') return nullptr; 83 | 84 | // Returns the string after "=". 85 | return flag_end + 1; 86 | } 87 | 88 | // Parses a string for a Google Mock bool flag, in the form of 89 | // "--gmock_flag=value". 90 | // 91 | // On success, stores the value of the flag in *value, and returns 92 | // true. On failure, returns false without changing *value. 93 | static bool ParseGoogleMockFlag(const char* str, const char* flag_name, 94 | bool* value) { 95 | // Gets the value of the flag as a string. 96 | const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, true); 97 | 98 | // Aborts if the parsing failed. 99 | if (value_str == nullptr) return false; 100 | 101 | // Converts the string value to a bool. 102 | *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); 103 | return true; 104 | } 105 | 106 | // Parses a string for a Google Mock string flag, in the form of 107 | // "--gmock_flag=value". 108 | // 109 | // On success, stores the value of the flag in *value, and returns 110 | // true. On failure, returns false without changing *value. 111 | template 112 | static bool ParseGoogleMockFlag(const char* str, const char* flag_name, 113 | String* value) { 114 | // Gets the value of the flag as a string. 115 | const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, false); 116 | 117 | // Aborts if the parsing failed. 118 | if (value_str == nullptr) return false; 119 | 120 | // Sets *value to the value of the flag. 121 | *value = value_str; 122 | return true; 123 | } 124 | 125 | static bool ParseGoogleMockFlag(const char* str, const char* flag_name, 126 | int32_t* value) { 127 | // Gets the value of the flag as a string. 128 | const char* const value_str = ParseGoogleMockFlagValue(str, flag_name, true); 129 | 130 | // Aborts if the parsing failed. 131 | if (value_str == nullptr) return false; 132 | 133 | // Sets *value to the value of the flag. 134 | return ParseInt32(Message() << "The value of flag --" << flag_name, value_str, 135 | value); 136 | } 137 | 138 | // The internal implementation of InitGoogleMock(). 139 | // 140 | // The type parameter CharType can be instantiated to either char or 141 | // wchar_t. 142 | template 143 | void InitGoogleMockImpl(int* argc, CharType** argv) { 144 | // Makes sure Google Test is initialized. InitGoogleTest() is 145 | // idempotent, so it's fine if the user has already called it. 146 | InitGoogleTest(argc, argv); 147 | if (*argc <= 0) return; 148 | 149 | for (int i = 1; i != *argc; i++) { 150 | const std::string arg_string = StreamableToString(argv[i]); 151 | const char* const arg = arg_string.c_str(); 152 | 153 | // Do we see a Google Mock flag? 154 | bool found_gmock_flag = false; 155 | 156 | #define GMOCK_INTERNAL_PARSE_FLAG(flag_name) \ 157 | if (!found_gmock_flag) { \ 158 | auto value = GMOCK_FLAG_GET(flag_name); \ 159 | if (ParseGoogleMockFlag(arg, #flag_name, &value)) { \ 160 | GMOCK_FLAG_SET(flag_name, value); \ 161 | found_gmock_flag = true; \ 162 | } \ 163 | } 164 | 165 | GMOCK_INTERNAL_PARSE_FLAG(catch_leaked_mocks) 166 | GMOCK_INTERNAL_PARSE_FLAG(verbose) 167 | GMOCK_INTERNAL_PARSE_FLAG(default_mock_behavior) 168 | 169 | if (found_gmock_flag) { 170 | // Yes. Shift the remainder of the argv list left by one. Note 171 | // that argv has (*argc + 1) elements, the last one always being 172 | // NULL. The following loop moves the trailing NULL element as 173 | // well. 174 | for (int j = i; j != *argc; j++) { 175 | argv[j] = argv[j + 1]; 176 | } 177 | 178 | // Decrements the argument count. 179 | (*argc)--; 180 | 181 | // We also need to decrement the iterator as we just removed 182 | // an element. 183 | i--; 184 | } 185 | } 186 | } 187 | 188 | } // namespace internal 189 | 190 | // Initializes Google Mock. This must be called before running the 191 | // tests. In particular, it parses a command line for the flags that 192 | // Google Mock recognizes. Whenever a Google Mock flag is seen, it is 193 | // removed from argv, and *argc is decremented. 194 | // 195 | // No value is returned. Instead, the Google Mock flag variables are 196 | // updated. 197 | // 198 | // Since Google Test is needed for Google Mock to work, this function 199 | // also initializes Google Test and parses its flags, if that hasn't 200 | // been done. 201 | GTEST_API_ void InitGoogleMock(int* argc, char** argv) { 202 | internal::InitGoogleMockImpl(argc, argv); 203 | } 204 | 205 | // This overloaded version can be used in Windows programs compiled in 206 | // UNICODE mode. 207 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv) { 208 | internal::InitGoogleMockImpl(argc, argv); 209 | } 210 | 211 | // This overloaded version can be used on Arduino/embedded platforms where 212 | // there is no argc/argv. 213 | GTEST_API_ void InitGoogleMock() { 214 | // Since Arduino doesn't have a command line, fake out the argc/argv arguments 215 | int argc = 1; 216 | const auto arg0 = "dummy"; 217 | char* argv0 = const_cast(arg0); 218 | char** argv = &argv0; 219 | 220 | internal::InitGoogleMockImpl(&argc, argv); 221 | } 222 | 223 | } // namespace testing 224 | -------------------------------------------------------------------------------- /tests/gtest/gtest-assertion-result.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This file implements the AssertionResult type. 33 | 34 | // IWYU pragma: private, include "gtest/gtest.h" 35 | // IWYU pragma: friend gtest/.* 36 | // IWYU pragma: friend gmock/.* 37 | 38 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ 39 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "gtest/gtest-message.h" 47 | #include "gtest/internal/gtest-port.h" 48 | 49 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 50 | /* class A needs to have dll-interface to be used by clients of class B */) 51 | 52 | namespace testing { 53 | 54 | // A class for indicating whether an assertion was successful. When 55 | // the assertion wasn't successful, the AssertionResult object 56 | // remembers a non-empty message that describes how it failed. 57 | // 58 | // To create an instance of this class, use one of the factory functions 59 | // (AssertionSuccess() and AssertionFailure()). 60 | // 61 | // This class is useful for two purposes: 62 | // 1. Defining predicate functions to be used with Boolean test assertions 63 | // EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts 64 | // 2. Defining predicate-format functions to be 65 | // used with predicate assertions (ASSERT_PRED_FORMAT*, etc). 66 | // 67 | // For example, if you define IsEven predicate: 68 | // 69 | // testing::AssertionResult IsEven(int n) { 70 | // if ((n % 2) == 0) 71 | // return testing::AssertionSuccess(); 72 | // else 73 | // return testing::AssertionFailure() << n << " is odd"; 74 | // } 75 | // 76 | // Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) 77 | // will print the message 78 | // 79 | // Value of: IsEven(Fib(5)) 80 | // Actual: false (5 is odd) 81 | // Expected: true 82 | // 83 | // instead of a more opaque 84 | // 85 | // Value of: IsEven(Fib(5)) 86 | // Actual: false 87 | // Expected: true 88 | // 89 | // in case IsEven is a simple Boolean predicate. 90 | // 91 | // If you expect your predicate to be reused and want to support informative 92 | // messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up 93 | // about half as often as positive ones in our tests), supply messages for 94 | // both success and failure cases: 95 | // 96 | // testing::AssertionResult IsEven(int n) { 97 | // if ((n % 2) == 0) 98 | // return testing::AssertionSuccess() << n << " is even"; 99 | // else 100 | // return testing::AssertionFailure() << n << " is odd"; 101 | // } 102 | // 103 | // Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print 104 | // 105 | // Value of: IsEven(Fib(6)) 106 | // Actual: true (8 is even) 107 | // Expected: false 108 | // 109 | // NB: Predicates that support negative Boolean assertions have reduced 110 | // performance in positive ones so be careful not to use them in tests 111 | // that have lots (tens of thousands) of positive Boolean assertions. 112 | // 113 | // To use this class with EXPECT_PRED_FORMAT assertions such as: 114 | // 115 | // // Verifies that Foo() returns an even number. 116 | // EXPECT_PRED_FORMAT1(IsEven, Foo()); 117 | // 118 | // you need to define: 119 | // 120 | // testing::AssertionResult IsEven(const char* expr, int n) { 121 | // if ((n % 2) == 0) 122 | // return testing::AssertionSuccess(); 123 | // else 124 | // return testing::AssertionFailure() 125 | // << "Expected: " << expr << " is even\n Actual: it's " << n; 126 | // } 127 | // 128 | // If Foo() returns 5, you will see the following message: 129 | // 130 | // Expected: Foo() is even 131 | // Actual: it's 5 132 | // 133 | class GTEST_API_ AssertionResult { 134 | public: 135 | // Copy constructor. 136 | // Used in EXPECT_TRUE/FALSE(assertion_result). 137 | AssertionResult(const AssertionResult& other); 138 | 139 | // C4800 is a level 3 warning in Visual Studio 2015 and earlier. 140 | // This warning is not emitted in Visual Studio 2017. 141 | // This warning is off by default starting in Visual Studio 2019 but can be 142 | // enabled with command-line options. 143 | #if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) 144 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) 145 | #endif 146 | 147 | // Used in the EXPECT_TRUE/FALSE(bool_expression). 148 | // 149 | // T must be contextually convertible to bool. 150 | // 151 | // The second parameter prevents this overload from being considered if 152 | // the argument is implicitly convertible to AssertionResult. In that case 153 | // we want AssertionResult's copy constructor to be used. 154 | template 155 | explicit AssertionResult( 156 | const T& success, 157 | typename std::enable_if< 158 | !std::is_convertible::value>::type* 159 | /*enabler*/ 160 | = nullptr) 161 | : success_(success) {} 162 | 163 | #if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) 164 | GTEST_DISABLE_MSC_WARNINGS_POP_() 165 | #endif 166 | 167 | // Assignment operator. 168 | AssertionResult& operator=(AssertionResult other) { 169 | swap(other); 170 | return *this; 171 | } 172 | 173 | // Returns true if and only if the assertion succeeded. 174 | operator bool() const { return success_; } // NOLINT 175 | 176 | // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. 177 | AssertionResult operator!() const; 178 | 179 | // Returns the text streamed into this AssertionResult. Test assertions 180 | // use it when they fail (i.e., the predicate's outcome doesn't match the 181 | // assertion's expectation). When nothing has been streamed into the 182 | // object, returns an empty string. 183 | const char* message() const { 184 | return message_.get() != nullptr ? message_->c_str() : ""; 185 | } 186 | // Deprecated; please use message() instead. 187 | const char* failure_message() const { return message(); } 188 | 189 | // Streams a custom failure message into this object. 190 | template 191 | AssertionResult& operator<<(const T& value) { 192 | AppendMessage(Message() << value); 193 | return *this; 194 | } 195 | 196 | // Allows streaming basic output manipulators such as endl or flush into 197 | // this object. 198 | AssertionResult& operator<<( 199 | ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { 200 | AppendMessage(Message() << basic_manipulator); 201 | return *this; 202 | } 203 | 204 | private: 205 | // Appends the contents of message to message_. 206 | void AppendMessage(const Message& a_message) { 207 | if (message_.get() == nullptr) message_.reset(new ::std::string); 208 | message_->append(a_message.GetString().c_str()); 209 | } 210 | 211 | // Swap the contents of this AssertionResult with other. 212 | void swap(AssertionResult& other); 213 | 214 | // Stores result of the assertion predicate. 215 | bool success_; 216 | // Stores the message describing the condition in case the expectation 217 | // construct is not satisfied with the predicate's outcome. 218 | // Referenced via a pointer to avoid taking too much stack frame space 219 | // with test assertions. 220 | std::unique_ptr< ::std::string> message_; 221 | }; 222 | 223 | // Makes a successful assertion result. 224 | GTEST_API_ AssertionResult AssertionSuccess(); 225 | 226 | // Makes a failed assertion result. 227 | GTEST_API_ AssertionResult AssertionFailure(); 228 | 229 | // Makes a failed assertion result with the given failure message. 230 | // Deprecated; use AssertionFailure() << msg. 231 | GTEST_API_ AssertionResult AssertionFailure(const Message& msg); 232 | 233 | } // namespace testing 234 | 235 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 236 | 237 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ 238 | -------------------------------------------------------------------------------- /tests/src/gmock-internal-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Mock - a framework for writing C++ mock classes. 31 | // 32 | // This file defines some utilities useful for implementing Google 33 | // Mock. They are subject to change without notice, so please DO NOT 34 | // USE THEM IN USER CODE. 35 | 36 | #include "gmock/internal/gmock-internal-utils.h" 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include // NOLINT 45 | #include 46 | #include 47 | 48 | #include "gmock/gmock.h" 49 | #include "gmock/internal/gmock-port.h" 50 | #include "gtest/gtest.h" 51 | 52 | namespace testing { 53 | namespace internal { 54 | 55 | // Joins a vector of strings as if they are fields of a tuple; returns 56 | // the joined string. 57 | GTEST_API_ std::string JoinAsKeyValueTuple( 58 | const std::vector& names, const Strings& values) { 59 | GTEST_CHECK_(names.size() == values.size()); 60 | if (values.empty()) { 61 | return ""; 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; 73 | } 74 | 75 | // Converts an identifier name to a space-separated list of lower-case 76 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is 77 | // treated as one word. For example, both "FooBar123" and 78 | // "foo_bar_123" are converted to "foo bar 123". 79 | GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) { 80 | std::string result; 81 | char prev_char = '\0'; 82 | for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { 83 | // We don't care about the current locale as the input is 84 | // guaranteed to be a valid C++ identifier name. 85 | const bool starts_new_word = IsUpper(*p) || 86 | (!IsAlpha(prev_char) && IsLower(*p)) || 87 | (!IsDigit(prev_char) && IsDigit(*p)); 88 | 89 | if (IsAlNum(*p)) { 90 | if (starts_new_word && result != "") result += ' '; 91 | result += ToLower(*p); 92 | } 93 | } 94 | return result; 95 | } 96 | 97 | // This class reports Google Mock failures as Google Test failures. A 98 | // user can define another class in a similar fashion if they intend to 99 | // use Google Mock with a testing framework other than Google Test. 100 | class GoogleTestFailureReporter : public FailureReporterInterface { 101 | public: 102 | void ReportFailure(FailureType type, const char* file, int line, 103 | const std::string& message) override { 104 | AssertHelper(type == kFatal ? TestPartResult::kFatalFailure 105 | : TestPartResult::kNonFatalFailure, 106 | file, line, message.c_str()) = Message(); 107 | if (type == kFatal) { 108 | posix::Abort(); 109 | } 110 | } 111 | }; 112 | 113 | // Returns the global failure reporter. Will create a 114 | // GoogleTestFailureReporter and return it the first time called. 115 | GTEST_API_ FailureReporterInterface* GetFailureReporter() { 116 | // Points to the global failure reporter used by Google Mock. gcc 117 | // guarantees that the following use of failure_reporter is 118 | // thread-safe. We may need to add additional synchronization to 119 | // protect failure_reporter if we port Google Mock to other 120 | // compilers. 121 | static FailureReporterInterface* const failure_reporter = 122 | new GoogleTestFailureReporter(); 123 | return failure_reporter; 124 | } 125 | 126 | // Protects global resources (stdout in particular) used by Log(). 127 | static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex); 128 | 129 | // Returns true if and only if a log with the given severity is visible 130 | // according to the --gmock_verbose flag. 131 | GTEST_API_ bool LogIsVisible(LogSeverity severity) { 132 | if (GMOCK_FLAG_GET(verbose) == kInfoVerbosity) { 133 | // Always show the log if --gmock_verbose=info. 134 | return true; 135 | } else if (GMOCK_FLAG_GET(verbose) == kErrorVerbosity) { 136 | // Always hide it if --gmock_verbose=error. 137 | return false; 138 | } else { 139 | // If --gmock_verbose is neither "info" nor "error", we treat it 140 | // as "warning" (its default value). 141 | return severity == kWarning; 142 | } 143 | } 144 | 145 | // Prints the given message to stdout if and only if 'severity' >= the level 146 | // specified by the --gmock_verbose flag. If stack_frames_to_skip >= 147 | // 0, also prints the stack trace excluding the top 148 | // stack_frames_to_skip frames. In opt mode, any positive 149 | // stack_frames_to_skip is treated as 0, since we don't know which 150 | // function calls will be inlined by the compiler and need to be 151 | // conservative. 152 | GTEST_API_ void Log(LogSeverity severity, const std::string& message, 153 | int stack_frames_to_skip) { 154 | if (!LogIsVisible(severity)) return; 155 | 156 | // Ensures that logs from different threads don't interleave. 157 | MutexLock l(&g_log_mutex); 158 | 159 | if (severity == kWarning) { 160 | // Prints a GMOCK WARNING marker to make the warnings easily searchable. 161 | std::cout << "\nGMOCK WARNING:"; 162 | } 163 | // Pre-pends a new-line to message if it doesn't start with one. 164 | if (message.empty() || message[0] != '\n') { 165 | std::cout << "\n"; 166 | } 167 | std::cout << message; 168 | if (stack_frames_to_skip >= 0) { 169 | #ifdef NDEBUG 170 | // In opt mode, we have to be conservative and skip no stack frame. 171 | const int actual_to_skip = 0; 172 | #else 173 | // In dbg mode, we can do what the caller tell us to do (plus one 174 | // for skipping this function's stack frame). 175 | const int actual_to_skip = stack_frames_to_skip + 1; 176 | #endif // NDEBUG 177 | 178 | // Appends a new-line to message if it doesn't end with one. 179 | if (!message.empty() && *message.rbegin() != '\n') { 180 | std::cout << "\n"; 181 | } 182 | std::cout << "Stack trace:\n" 183 | << ::testing::internal::GetCurrentOsStackTraceExceptTop( 184 | ::testing::UnitTest::GetInstance(), actual_to_skip); 185 | } 186 | std::cout << ::std::flush; 187 | } 188 | 189 | GTEST_API_ WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); } 190 | 191 | GTEST_API_ void IllegalDoDefault(const char* file, int line) { 192 | internal::Assert( 193 | false, file, line, 194 | "You are using DoDefault() inside a composite action like " 195 | "DoAll() or WithArgs(). This is not supported for technical " 196 | "reasons. Please instead spell out the default action, or " 197 | "assign the default action to an Action variable and use " 198 | "the variable in various places."); 199 | } 200 | 201 | constexpr char UnBase64Impl(char c, const char* const base64, char carry) { 202 | return *base64 == 0 ? static_cast(65) 203 | : *base64 == c ? carry 204 | : UnBase64Impl(c, base64 + 1, carry + 1); 205 | } 206 | 207 | template 208 | constexpr std::array UnBase64Impl(IndexSequence, 209 | const char* const base64) { 210 | return {{UnBase64Impl(static_cast(I), base64, 0)...}}; 211 | } 212 | 213 | constexpr std::array UnBase64(const char* const base64) { 214 | return UnBase64Impl(MakeIndexSequence<256>{}, base64); 215 | } 216 | 217 | static constexpr char kBase64[] = 218 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 219 | static constexpr std::array kUnBase64 = UnBase64(kBase64); 220 | 221 | bool Base64Unescape(const std::string& encoded, std::string* decoded) { 222 | decoded->clear(); 223 | size_t encoded_len = encoded.size(); 224 | decoded->reserve(3 * (encoded_len / 4) + (encoded_len % 4)); 225 | int bit_pos = 0; 226 | char dst = 0; 227 | for (int src : encoded) { 228 | if (std::isspace(src) || src == '=') { 229 | continue; 230 | } 231 | char src_bin = kUnBase64[static_cast(src)]; 232 | if (src_bin >= 64) { 233 | decoded->clear(); 234 | return false; 235 | } 236 | if (bit_pos == 0) { 237 | dst |= static_cast(src_bin << 2); 238 | bit_pos = 6; 239 | } else { 240 | dst |= static_cast(src_bin >> (bit_pos - 2)); 241 | decoded->push_back(dst); 242 | dst = static_cast(src_bin << (10 - bit_pos)); 243 | bit_pos = (bit_pos + 6) % 8; 244 | } 245 | } 246 | return true; 247 | } 248 | 249 | } // namespace internal 250 | } // namespace testing 251 | -------------------------------------------------------------------------------- /tests/gtest/internal/gtest-filepath.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Google Test filepath utilities 31 | // 32 | // This header file declares classes and functions used internally by 33 | // Google Test. They are subject to change without notice. 34 | // 35 | // This file is #included in gtest/internal/gtest-internal.h. 36 | // Do not include this header file separately! 37 | 38 | // IWYU pragma: private, include "gtest/gtest.h" 39 | // IWYU pragma: friend gtest/.* 40 | // IWYU pragma: friend gmock/.* 41 | 42 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 43 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 44 | 45 | #include "gtest/internal/gtest-string.h" 46 | 47 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 48 | /* class A needs to have dll-interface to be used by clients of class B */) 49 | 50 | namespace testing { 51 | namespace internal { 52 | 53 | // FilePath - a class for file and directory pathname manipulation which 54 | // handles platform-specific conventions (like the pathname separator). 55 | // Used for helper functions for naming files in a directory for xml output. 56 | // Except for Set methods, all methods are const or static, which provides an 57 | // "immutable value object" -- useful for peace of mind. 58 | // A FilePath with a value ending in a path separator ("like/this/") represents 59 | // a directory, otherwise it is assumed to represent a file. In either case, 60 | // it may or may not represent an actual file or directory in the file system. 61 | // Names are NOT checked for syntax correctness -- no checking for illegal 62 | // characters, malformed paths, etc. 63 | 64 | class GTEST_API_ FilePath { 65 | public: 66 | FilePath() : pathname_("") {} 67 | FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {} 68 | 69 | explicit FilePath(const std::string& pathname) : pathname_(pathname) { 70 | Normalize(); 71 | } 72 | 73 | FilePath& operator=(const FilePath& rhs) { 74 | Set(rhs); 75 | return *this; 76 | } 77 | 78 | void Set(const FilePath& rhs) { pathname_ = rhs.pathname_; } 79 | 80 | const std::string& string() const { return pathname_; } 81 | const char* c_str() const { return pathname_.c_str(); } 82 | 83 | // Returns the current working directory, or "" if unsuccessful. 84 | static FilePath GetCurrentDir(); 85 | 86 | // Given directory = "dir", base_name = "test", number = 0, 87 | // extension = "xml", returns "dir/test.xml". If number is greater 88 | // than zero (e.g., 12), returns "dir/test_12.xml". 89 | // On Windows platform, uses \ as the separator rather than /. 90 | static FilePath MakeFileName(const FilePath& directory, 91 | const FilePath& base_name, int number, 92 | const char* extension); 93 | 94 | // Given directory = "dir", relative_path = "test.xml", 95 | // returns "dir/test.xml". 96 | // On Windows, uses \ as the separator rather than /. 97 | static FilePath ConcatPaths(const FilePath& directory, 98 | const FilePath& relative_path); 99 | 100 | // Returns a pathname for a file that does not currently exist. The pathname 101 | // will be directory/base_name.extension or 102 | // directory/base_name_.extension if directory/base_name.extension 103 | // already exists. The number will be incremented until a pathname is found 104 | // that does not already exist. 105 | // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. 106 | // There could be a race condition if two or more processes are calling this 107 | // function at the same time -- they could both pick the same filename. 108 | static FilePath GenerateUniqueFileName(const FilePath& directory, 109 | const FilePath& base_name, 110 | const char* extension); 111 | 112 | // Returns true if and only if the path is "". 113 | bool IsEmpty() const { return pathname_.empty(); } 114 | 115 | // If input name has a trailing separator character, removes it and returns 116 | // the name, otherwise return the name string unmodified. 117 | // On Windows platform, uses \ as the separator, other platforms use /. 118 | FilePath RemoveTrailingPathSeparator() const; 119 | 120 | // Returns a copy of the FilePath with the directory part removed. 121 | // Example: FilePath("path/to/file").RemoveDirectoryName() returns 122 | // FilePath("file"). If there is no directory part ("just_a_file"), it returns 123 | // the FilePath unmodified. If there is no file part ("just_a_dir/") it 124 | // returns an empty FilePath (""). 125 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 126 | FilePath RemoveDirectoryName() const; 127 | 128 | // RemoveFileName returns the directory path with the filename removed. 129 | // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". 130 | // If the FilePath is "a_file" or "/a_file", RemoveFileName returns 131 | // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does 132 | // not have a file, like "just/a/dir/", it returns the FilePath unmodified. 133 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 134 | FilePath RemoveFileName() const; 135 | 136 | // Returns a copy of the FilePath with the case-insensitive extension removed. 137 | // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns 138 | // FilePath("dir/file"). If a case-insensitive extension is not 139 | // found, returns a copy of the original FilePath. 140 | FilePath RemoveExtension(const char* extension) const; 141 | 142 | // Creates directories so that path exists. Returns true if successful or if 143 | // the directories already exist; returns false if unable to create 144 | // directories for any reason. Will also return false if the FilePath does 145 | // not represent a directory (that is, it doesn't end with a path separator). 146 | bool CreateDirectoriesRecursively() const; 147 | 148 | // Create the directory so that path exists. Returns true if successful or 149 | // if the directory already exists; returns false if unable to create the 150 | // directory for any reason, including if the parent directory does not 151 | // exist. Not named "CreateDirectory" because that's a macro on Windows. 152 | bool CreateFolder() const; 153 | 154 | // Returns true if FilePath describes something in the file-system, 155 | // either a file, directory, or whatever, and that something exists. 156 | bool FileOrDirectoryExists() const; 157 | 158 | // Returns true if pathname describes a directory in the file-system 159 | // that exists. 160 | bool DirectoryExists() const; 161 | 162 | // Returns true if FilePath ends with a path separator, which indicates that 163 | // it is intended to represent a directory. Returns false otherwise. 164 | // This does NOT check that a directory (or file) actually exists. 165 | bool IsDirectory() const; 166 | 167 | // Returns true if pathname describes a root directory. (Windows has one 168 | // root directory per disk drive.) 169 | bool IsRootDirectory() const; 170 | 171 | // Returns true if pathname describes an absolute path. 172 | bool IsAbsolutePath() const; 173 | 174 | private: 175 | // Replaces multiple consecutive separators with a single separator. 176 | // For example, "bar///foo" becomes "bar/foo". Does not eliminate other 177 | // redundancies that might be in a pathname involving "." or "..". 178 | // 179 | // A pathname with multiple consecutive separators may occur either through 180 | // user error or as a result of some scripts or APIs that generate a pathname 181 | // with a trailing separator. On other platforms the same API or script 182 | // may NOT generate a pathname with a trailing "/". Then elsewhere that 183 | // pathname may have another "/" and pathname components added to it, 184 | // without checking for the separator already being there. 185 | // The script language and operating system may allow paths like "foo//bar" 186 | // but some of the functions in FilePath will not handle that correctly. In 187 | // particular, RemoveTrailingPathSeparator() only removes one separator, and 188 | // it is called in CreateDirectoriesRecursively() assuming that it will change 189 | // a pathname from directory syntax (trailing separator) to filename syntax. 190 | // 191 | // On Windows this method also replaces the alternate path separator '/' with 192 | // the primary path separator '\\', so that for example "bar\\/\\foo" becomes 193 | // "bar\\foo". 194 | 195 | void Normalize(); 196 | 197 | // Returns a pointer to the last occurrence of a valid path separator in 198 | // the FilePath. On Windows, for example, both '/' and '\' are valid path 199 | // separators. Returns NULL if no path separator was found. 200 | const char* FindLastPathSeparator() const; 201 | 202 | std::string pathname_; 203 | }; // class FilePath 204 | 205 | } // namespace internal 206 | } // namespace testing 207 | 208 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 209 | 210 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 211 | -------------------------------------------------------------------------------- /tests/gmock/gmock-nice-strict.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Implements class templates NiceMock, NaggyMock, and StrictMock. 31 | // 32 | // Given a mock class MockFoo that is created using Google Mock, 33 | // NiceMock is a subclass of MockFoo that allows 34 | // uninteresting calls (i.e. calls to mock methods that have no 35 | // EXPECT_CALL specs), NaggyMock is a subclass of MockFoo 36 | // that prints a warning when an uninteresting call occurs, and 37 | // StrictMock is a subclass of MockFoo that treats all 38 | // uninteresting calls as errors. 39 | // 40 | // Currently a mock is naggy by default, so MockFoo and 41 | // NaggyMock behave like the same. However, we will soon 42 | // switch the default behavior of mocks to be nice, as that in general 43 | // leads to more maintainable tests. When that happens, MockFoo will 44 | // stop behaving like NaggyMock and start behaving like 45 | // NiceMock. 46 | // 47 | // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of 48 | // their respective base class. Therefore you can write 49 | // NiceMock(5, "a") to construct a nice mock where MockFoo 50 | // has a constructor that accepts (int, const char*), for example. 51 | // 52 | // A known limitation is that NiceMock, NaggyMock, 53 | // and StrictMock only works for mock methods defined using 54 | // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. 55 | // If a mock method is defined in a base class of MockFoo, the "nice" 56 | // or "strict" modifier may not affect it, depending on the compiler. 57 | // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT 58 | // supported. 59 | 60 | // IWYU pragma: private, include "gmock/gmock.h" 61 | // IWYU pragma: friend gmock/.* 62 | 63 | #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 64 | #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 65 | 66 | #include 67 | #include 68 | 69 | #include "gmock/gmock-spec-builders.h" 70 | #include "gmock/internal/gmock-port.h" 71 | 72 | namespace testing { 73 | template 74 | class NiceMock; 75 | template 76 | class NaggyMock; 77 | template 78 | class StrictMock; 79 | 80 | namespace internal { 81 | template 82 | std::true_type StrictnessModifierProbe(const NiceMock&); 83 | template 84 | std::true_type StrictnessModifierProbe(const NaggyMock&); 85 | template 86 | std::true_type StrictnessModifierProbe(const StrictMock&); 87 | std::false_type StrictnessModifierProbe(...); 88 | 89 | template 90 | constexpr bool HasStrictnessModifier() { 91 | return decltype(StrictnessModifierProbe(std::declval()))::value; 92 | } 93 | 94 | // Base classes that register and deregister with testing::Mock to alter the 95 | // default behavior around uninteresting calls. Inheriting from one of these 96 | // classes first and then MockClass ensures the MockClass constructor is run 97 | // after registration, and that the MockClass destructor runs before 98 | // deregistration. This guarantees that MockClass's constructor and destructor 99 | // run with the same level of strictness as its instance methods. 100 | 101 | #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ 102 | (defined(_MSC_VER) || defined(__clang__)) 103 | // We need to mark these classes with this declspec to ensure that 104 | // the empty base class optimization is performed. 105 | #define GTEST_INTERNAL_EMPTY_BASE_CLASS __declspec(empty_bases) 106 | #else 107 | #define GTEST_INTERNAL_EMPTY_BASE_CLASS 108 | #endif 109 | 110 | template 111 | class NiceMockImpl { 112 | public: 113 | NiceMockImpl() { 114 | ::testing::Mock::AllowUninterestingCalls(reinterpret_cast(this)); 115 | } 116 | 117 | ~NiceMockImpl() { 118 | ::testing::Mock::UnregisterCallReaction(reinterpret_cast(this)); 119 | } 120 | }; 121 | 122 | template 123 | class NaggyMockImpl { 124 | public: 125 | NaggyMockImpl() { 126 | ::testing::Mock::WarnUninterestingCalls(reinterpret_cast(this)); 127 | } 128 | 129 | ~NaggyMockImpl() { 130 | ::testing::Mock::UnregisterCallReaction(reinterpret_cast(this)); 131 | } 132 | }; 133 | 134 | template 135 | class StrictMockImpl { 136 | public: 137 | StrictMockImpl() { 138 | ::testing::Mock::FailUninterestingCalls(reinterpret_cast(this)); 139 | } 140 | 141 | ~StrictMockImpl() { 142 | ::testing::Mock::UnregisterCallReaction(reinterpret_cast(this)); 143 | } 144 | }; 145 | 146 | } // namespace internal 147 | 148 | template 149 | class GTEST_INTERNAL_EMPTY_BASE_CLASS NiceMock 150 | : private internal::NiceMockImpl, 151 | public MockClass { 152 | public: 153 | static_assert(!internal::HasStrictnessModifier(), 154 | "Can't apply NiceMock to a class hierarchy that already has a " 155 | "strictness modifier. See " 156 | "https://google.github.io/googletest/" 157 | "gmock_cook_book.html#NiceStrictNaggy"); 158 | NiceMock() : MockClass() { 159 | static_assert(sizeof(*this) == sizeof(MockClass), 160 | "The impl subclass shouldn't introduce any padding"); 161 | } 162 | 163 | // Ideally, we would inherit base class's constructors through a using 164 | // declaration, which would preserve their visibility. However, many existing 165 | // tests rely on the fact that current implementation reexports protected 166 | // constructors as public. These tests would need to be cleaned up first. 167 | 168 | // Single argument constructor is special-cased so that it can be 169 | // made explicit. 170 | template 171 | explicit NiceMock(A&& arg) : MockClass(std::forward(arg)) { 172 | static_assert(sizeof(*this) == sizeof(MockClass), 173 | "The impl subclass shouldn't introduce any padding"); 174 | } 175 | 176 | template 177 | NiceMock(TArg1&& arg1, TArg2&& arg2, An&&... args) 178 | : MockClass(std::forward(arg1), std::forward(arg2), 179 | std::forward(args)...) { 180 | static_assert(sizeof(*this) == sizeof(MockClass), 181 | "The impl subclass shouldn't introduce any padding"); 182 | } 183 | 184 | private: 185 | NiceMock(const NiceMock&) = delete; 186 | NiceMock& operator=(const NiceMock&) = delete; 187 | }; 188 | 189 | template 190 | class GTEST_INTERNAL_EMPTY_BASE_CLASS NaggyMock 191 | : private internal::NaggyMockImpl, 192 | public MockClass { 193 | static_assert(!internal::HasStrictnessModifier(), 194 | "Can't apply NaggyMock to a class hierarchy that already has a " 195 | "strictness modifier. See " 196 | "https://google.github.io/googletest/" 197 | "gmock_cook_book.html#NiceStrictNaggy"); 198 | 199 | public: 200 | NaggyMock() : MockClass() { 201 | static_assert(sizeof(*this) == sizeof(MockClass), 202 | "The impl subclass shouldn't introduce any padding"); 203 | } 204 | 205 | // Ideally, we would inherit base class's constructors through a using 206 | // declaration, which would preserve their visibility. However, many existing 207 | // tests rely on the fact that current implementation reexports protected 208 | // constructors as public. These tests would need to be cleaned up first. 209 | 210 | // Single argument constructor is special-cased so that it can be 211 | // made explicit. 212 | template 213 | explicit NaggyMock(A&& arg) : MockClass(std::forward(arg)) { 214 | static_assert(sizeof(*this) == sizeof(MockClass), 215 | "The impl subclass shouldn't introduce any padding"); 216 | } 217 | 218 | template 219 | NaggyMock(TArg1&& arg1, TArg2&& arg2, An&&... args) 220 | : MockClass(std::forward(arg1), std::forward(arg2), 221 | std::forward(args)...) { 222 | static_assert(sizeof(*this) == sizeof(MockClass), 223 | "The impl subclass shouldn't introduce any padding"); 224 | } 225 | 226 | private: 227 | NaggyMock(const NaggyMock&) = delete; 228 | NaggyMock& operator=(const NaggyMock&) = delete; 229 | }; 230 | 231 | template 232 | class GTEST_INTERNAL_EMPTY_BASE_CLASS StrictMock 233 | : private internal::StrictMockImpl, 234 | public MockClass { 235 | public: 236 | static_assert( 237 | !internal::HasStrictnessModifier(), 238 | "Can't apply StrictMock to a class hierarchy that already has a " 239 | "strictness modifier. See " 240 | "https://google.github.io/googletest/" 241 | "gmock_cook_book.html#NiceStrictNaggy"); 242 | StrictMock() : MockClass() { 243 | static_assert(sizeof(*this) == sizeof(MockClass), 244 | "The impl subclass shouldn't introduce any padding"); 245 | } 246 | 247 | // Ideally, we would inherit base class's constructors through a using 248 | // declaration, which would preserve their visibility. However, many existing 249 | // tests rely on the fact that current implementation reexports protected 250 | // constructors as public. These tests would need to be cleaned up first. 251 | 252 | // Single argument constructor is special-cased so that it can be 253 | // made explicit. 254 | template 255 | explicit StrictMock(A&& arg) : MockClass(std::forward(arg)) { 256 | static_assert(sizeof(*this) == sizeof(MockClass), 257 | "The impl subclass shouldn't introduce any padding"); 258 | } 259 | 260 | template 261 | StrictMock(TArg1&& arg1, TArg2&& arg2, An&&... args) 262 | : MockClass(std::forward(arg1), std::forward(arg2), 263 | std::forward(args)...) { 264 | static_assert(sizeof(*this) == sizeof(MockClass), 265 | "The impl subclass shouldn't introduce any padding"); 266 | } 267 | 268 | private: 269 | StrictMock(const StrictMock&) = delete; 270 | StrictMock& operator=(const StrictMock&) = delete; 271 | }; 272 | 273 | #undef GTEST_INTERNAL_EMPTY_BASE_CLASS 274 | 275 | } // namespace testing 276 | 277 | #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_NICE_STRICT_H_ 278 | -------------------------------------------------------------------------------- /tests/gtest/gtest-spi.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 | 30 | // Utilities for testing Google Test itself and code that uses Google Test 31 | // (e.g. frameworks built on top of Google Test). 32 | 33 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ 34 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ 35 | 36 | #include "gtest/gtest.h" 37 | 38 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ 39 | /* class A needs to have dll-interface to be used by clients of class B */) 40 | 41 | namespace testing { 42 | 43 | // This helper class can be used to mock out Google Test failure reporting 44 | // so that we can test Google Test or code that builds on Google Test. 45 | // 46 | // An object of this class appends a TestPartResult object to the 47 | // TestPartResultArray object given in the constructor whenever a Google Test 48 | // failure is reported. It can either intercept only failures that are 49 | // generated in the same thread that created this object or it can intercept 50 | // all generated failures. The scope of this mock object can be controlled with 51 | // the second argument to the two arguments constructor. 52 | class GTEST_API_ ScopedFakeTestPartResultReporter 53 | : public TestPartResultReporterInterface { 54 | public: 55 | // The two possible mocking modes of this object. 56 | enum InterceptMode { 57 | INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures. 58 | INTERCEPT_ALL_THREADS // Intercepts all failures. 59 | }; 60 | 61 | // The c'tor sets this object as the test part result reporter used 62 | // by Google Test. The 'result' parameter specifies where to report the 63 | // results. This reporter will only catch failures generated in the current 64 | // thread. DEPRECATED 65 | explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result); 66 | 67 | // Same as above, but you can choose the interception scope of this object. 68 | ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, 69 | TestPartResultArray* result); 70 | 71 | // The d'tor restores the previous test part result reporter. 72 | ~ScopedFakeTestPartResultReporter() override; 73 | 74 | // Appends the TestPartResult object to the TestPartResultArray 75 | // received in the constructor. 76 | // 77 | // This method is from the TestPartResultReporterInterface 78 | // interface. 79 | void ReportTestPartResult(const TestPartResult& result) override; 80 | 81 | private: 82 | void Init(); 83 | 84 | const InterceptMode intercept_mode_; 85 | TestPartResultReporterInterface* old_reporter_; 86 | TestPartResultArray* const result_; 87 | 88 | ScopedFakeTestPartResultReporter(const ScopedFakeTestPartResultReporter&) = 89 | delete; 90 | ScopedFakeTestPartResultReporter& operator=( 91 | const ScopedFakeTestPartResultReporter&) = delete; 92 | }; 93 | 94 | namespace internal { 95 | 96 | // A helper class for implementing EXPECT_FATAL_FAILURE() and 97 | // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given 98 | // TestPartResultArray contains exactly one failure that has the given 99 | // type and contains the given substring. If that's not the case, a 100 | // non-fatal failure will be generated. 101 | class GTEST_API_ SingleFailureChecker { 102 | public: 103 | // The constructor remembers the arguments. 104 | SingleFailureChecker(const TestPartResultArray* results, 105 | TestPartResult::Type type, const std::string& substr); 106 | ~SingleFailureChecker(); 107 | 108 | private: 109 | const TestPartResultArray* const results_; 110 | const TestPartResult::Type type_; 111 | const std::string substr_; 112 | 113 | SingleFailureChecker(const SingleFailureChecker&) = delete; 114 | SingleFailureChecker& operator=(const SingleFailureChecker&) = delete; 115 | }; 116 | 117 | } // namespace internal 118 | 119 | } // namespace testing 120 | 121 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 122 | 123 | // A set of macros for testing Google Test assertions or code that's expected 124 | // to generate Google Test fatal failures (e.g. a failure from an ASSERT_EQ, but 125 | // not a non-fatal failure, as from EXPECT_EQ). It verifies that the given 126 | // statement will cause exactly one fatal Google Test failure with 'substr' 127 | // being part of the failure message. 128 | // 129 | // There are two different versions of this macro. EXPECT_FATAL_FAILURE only 130 | // affects and considers failures generated in the current thread and 131 | // EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 132 | // 133 | // The verification of the assertion is done correctly even when the statement 134 | // throws an exception or aborts the current function. 135 | // 136 | // Known restrictions: 137 | // - 'statement' cannot reference local non-static variables or 138 | // non-static members of the current object. 139 | // - 'statement' cannot return a value. 140 | // - You cannot stream a failure message to this macro. 141 | // 142 | // Note that even though the implementations of the following two 143 | // macros are much alike, we cannot refactor them to use a common 144 | // helper macro, due to some peculiarity in how the preprocessor 145 | // works. The AcceptsMacroThatExpandsToUnprotectedComma test in 146 | // gtest_unittest.cc will fail to compile if we do that. 147 | #define EXPECT_FATAL_FAILURE(statement, substr) \ 148 | do { \ 149 | class GTestExpectFatalFailureHelper { \ 150 | public: \ 151 | static void Execute() { statement; } \ 152 | }; \ 153 | ::testing::TestPartResultArray gtest_failures; \ 154 | ::testing::internal::SingleFailureChecker gtest_checker( \ 155 | >est_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \ 156 | { \ 157 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ 158 | ::testing::ScopedFakeTestPartResultReporter:: \ 159 | INTERCEPT_ONLY_CURRENT_THREAD, \ 160 | >est_failures); \ 161 | GTestExpectFatalFailureHelper::Execute(); \ 162 | } \ 163 | } while (::testing::internal::AlwaysFalse()) 164 | 165 | #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 166 | do { \ 167 | class GTestExpectFatalFailureHelper { \ 168 | public: \ 169 | static void Execute() { statement; } \ 170 | }; \ 171 | ::testing::TestPartResultArray gtest_failures; \ 172 | ::testing::internal::SingleFailureChecker gtest_checker( \ 173 | >est_failures, ::testing::TestPartResult::kFatalFailure, (substr)); \ 174 | { \ 175 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ 176 | ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ 177 | >est_failures); \ 178 | GTestExpectFatalFailureHelper::Execute(); \ 179 | } \ 180 | } while (::testing::internal::AlwaysFalse()) 181 | 182 | // A macro for testing Google Test assertions or code that's expected to 183 | // generate Google Test non-fatal failures (e.g. a failure from an EXPECT_EQ, 184 | // but not from an ASSERT_EQ). It asserts that the given statement will cause 185 | // exactly one non-fatal Google Test failure with 'substr' being part of the 186 | // failure message. 187 | // 188 | // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only 189 | // affects and considers failures generated in the current thread and 190 | // EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 191 | // 192 | // 'statement' is allowed to reference local variables and members of 193 | // the current object. 194 | // 195 | // The verification of the assertion is done correctly even when the statement 196 | // throws an exception or aborts the current function. 197 | // 198 | // Known restrictions: 199 | // - You cannot stream a failure message to this macro. 200 | // 201 | // Note that even though the implementations of the following two 202 | // macros are much alike, we cannot refactor them to use a common 203 | // helper macro, due to some peculiarity in how the preprocessor 204 | // works. If we do that, the code won't compile when the user gives 205 | // EXPECT_NONFATAL_FAILURE() a statement that contains a macro that 206 | // expands to code containing an unprotected comma. The 207 | // AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc 208 | // catches that. 209 | // 210 | // For the same reason, we have to write 211 | // if (::testing::internal::AlwaysTrue()) { statement; } 212 | // instead of 213 | // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 214 | // to avoid an MSVC warning on unreachable code. 215 | #define EXPECT_NONFATAL_FAILURE(statement, substr) \ 216 | do { \ 217 | ::testing::TestPartResultArray gtest_failures; \ 218 | ::testing::internal::SingleFailureChecker gtest_checker( \ 219 | >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 220 | (substr)); \ 221 | { \ 222 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ 223 | ::testing::ScopedFakeTestPartResultReporter:: \ 224 | INTERCEPT_ONLY_CURRENT_THREAD, \ 225 | >est_failures); \ 226 | if (::testing::internal::AlwaysTrue()) { \ 227 | statement; \ 228 | } \ 229 | } \ 230 | } while (::testing::internal::AlwaysFalse()) 231 | 232 | #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 233 | do { \ 234 | ::testing::TestPartResultArray gtest_failures; \ 235 | ::testing::internal::SingleFailureChecker gtest_checker( \ 236 | >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 237 | (substr)); \ 238 | { \ 239 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter( \ 240 | ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ 241 | >est_failures); \ 242 | if (::testing::internal::AlwaysTrue()) { \ 243 | statement; \ 244 | } \ 245 | } \ 246 | } while (::testing::internal::AlwaysFalse()) 247 | 248 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ 249 | --------------------------------------------------------------------------------