├── .github └── workflows │ └── doxygen.yml ├── .travis.yml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Doxyfile ├── LICENSE ├── QUALITY_DECLARATION.md ├── README.md ├── appveyor.yml ├── console_bridge-config.cmake.in ├── console_bridge.pc.in ├── include └── console_bridge │ └── console.h ├── src └── console.cpp └── test ├── CMakeLists.txt ├── console_TEST.cc └── gtest ├── CHANGES ├── CMakeLists.txt ├── CONTRIBUTORS ├── LICENSE ├── cmake └── internal_utils.cmake ├── gtest-1.7.0.diff ├── include └── gtest │ ├── gtest-death-test.h │ ├── gtest-message.h │ ├── gtest-param-test.h │ ├── gtest-param-test.h.pump │ ├── gtest-printers.h │ ├── gtest-spi.h │ ├── gtest-test-part.h │ ├── gtest-typed-test.h │ ├── gtest.h │ ├── gtest_pred_impl.h │ ├── gtest_prod.h │ └── internal │ ├── custom │ ├── gtest-port.h │ ├── gtest-printers.h │ └── gtest.h │ ├── gtest-death-test-internal.h │ ├── gtest-filepath.h │ ├── gtest-internal.h │ ├── gtest-linked_ptr.h │ ├── gtest-param-util-generated.h │ ├── gtest-param-util-generated.h.pump │ ├── gtest-param-util.h │ ├── gtest-port-arch.h │ ├── gtest-port.h │ ├── gtest-string.h │ ├── gtest-tuple.h │ ├── gtest-tuple.h.pump │ ├── gtest-type-util.h │ └── gtest-type-util.h.pump └── src ├── gtest-all.cc ├── gtest-death-test.cc ├── gtest-filepath.cc ├── gtest-internal-inl.h ├── gtest-port.cc ├── gtest-printers.cc ├── gtest-test-part.cc ├── gtest-typed-test.cc ├── gtest.cc └── gtest_main.cc /.github/workflows/doxygen.yml: -------------------------------------------------------------------------------- 1 | name: Doxygen 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-20.04 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Install base dependencies 13 | run: | 14 | sudo apt update; 15 | sudo apt -y install doxygen graphviz 16 | - name: doxygen Doxyfile 17 | run: doxygen Doxyfile 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | dist: trusty 3 | language: cpp 4 | addons: 5 | apt: 6 | update: true 7 | packages: lcov python3 cppcheck 8 | compiler: 9 | - gcc 10 | - clang 11 | env: 12 | - BUILD_TYPE=Debug 13 | - BUILD_TYPE=RelWithDebInfo 14 | - BUILD_TYPE=Debug COVERAGE=true CXXFLAGS="--coverage" 15 | jobs: 16 | exclude: 17 | - compiler: clang 18 | env: BUILD_TYPE=Debug COVERAGE=true CXXFLAGS="--coverage" 19 | script: 20 | - mkdir build 21 | - cd build 22 | - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" -DBUILD_TESTING=True .. 23 | - make 24 | - make test ARGS="-VV" 25 | after_script: 26 | - sudo make install 27 | - pkg-config --modversion console_bridge 28 | - | 29 | if [[ $COVERAGE == true ]]; then 30 | lcov --capture --directory . --output-file coverage.info 31 | lcov --remove coverage.info */test/* --output-file coverage.info 32 | lcov --list coverage.info 33 | bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" 34 | fi 35 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | project(console_bridge) 3 | 4 | set (CONSOLE_BRIDGE_MAJOR_VERSION 1) 5 | set (CONSOLE_BRIDGE_MINOR_VERSION 0) 6 | set (CONSOLE_BRIDGE_PATCH_VERSION 2) 7 | 8 | set (CONSOLE_BRIDGE_VERSION ${CONSOLE_BRIDGE_MAJOR_VERSION}.${CONSOLE_BRIDGE_MINOR_VERSION}.${CONSOLE_BRIDGE_PATCH_VERSION}) 9 | message (STATUS "${PROJECT_NAME} version ${CONSOLE_BRIDGE_VERSION}") 10 | 11 | include(GNUInstallDirs) 12 | include(GenerateExportHeader) 13 | 14 | if (NOT CMAKE_BUILD_TYPE) 15 | set(CMAKE_BUILD_TYPE Release) 16 | endif() 17 | 18 | if(POLICY CMP0042) 19 | cmake_policy(SET CMP0042 NEW) 20 | endif() 21 | 22 | # If compiler support symbol visibility, enable it. 23 | include(CheckCCompilerFlag) 24 | check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY) 25 | if (HAS_VISIBILITY) 26 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") 27 | endif() 28 | 29 | if(NOT WIN32) 30 | # Use c++11 compiler flag, since it's needed for console.cpp 31 | # It isn't in a header file, so it doesn't need to be exported 32 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra") 33 | endif() 34 | 35 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CMAKE_CXX_FLAGS}") 36 | 37 | if(MSVC OR MSVC90 OR MSVC10) 38 | set(MSVC ON) 39 | endif (MSVC OR MSVC90 OR MSVC10) 40 | 41 | 42 | if(NOT DEFINED BUILD_SHARED_LIBS) 43 | option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON) 44 | endif() 45 | 46 | # Control where libraries and executables are placed during the build 47 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") 48 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") 49 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") 50 | 51 | add_library(${PROJECT_NAME} src/console.cpp) 52 | set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 53 | ${CONSOLE_BRIDGE_MAJOR_VERSION}.${CONSOLE_BRIDGE_MINOR_VERSION}) 54 | target_include_directories(${PROJECT_NAME} PUBLIC 55 | $ 56 | $ 57 | $) 58 | generate_export_header(${PROJECT_NAME} 59 | EXPORT_MACRO_NAME CONSOLE_BRIDGE_DLLAPI) 60 | 61 | install(TARGETS ${PROJECT_NAME} 62 | EXPORT ${PROJECT_NAME}-targets 63 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 64 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 65 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 66 | ) 67 | 68 | install(DIRECTORY include/ 69 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 70 | FILES_MATCHING PATTERN "*.h") 71 | 72 | install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h 73 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) 74 | 75 | if(WIN32 AND NOT CYGWIN) 76 | set(CMAKE_CONFIG_INSTALL_DIR CMake) 77 | else() 78 | set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/) 79 | endif() 80 | 81 | include(CMakePackageConfigHelpers) 82 | set(PKG_NAME ${PROJECT_NAME}) 83 | set(PKG_LIBRARIES ${PROJECT_NAME}) 84 | set(cmake_conf_file "${PROJECT_NAME}-config.cmake") 85 | configure_package_config_file("${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" 86 | INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} 87 | PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR 88 | NO_SET_AND_CHECK_MACRO 89 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) 90 | set(cmake_conf_version_file "${PROJECT_NAME}-config-version.cmake") 91 | # Use write_basic_package_version_file to generate a ConfigVersion file that 92 | # allow users of gazebo to specify the API or version to depend on 93 | # TODO: keep this instruction until deprecate Ubuntu/Precise and update with 94 | # https://github.com/Kitware/CMake/blob/v2.8.8/Modules/CMakePackageConfigHelpers.cmake 95 | include(WriteBasicConfigVersionFile) 96 | write_basic_config_version_file( 97 | ${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_version_file} 98 | VERSION "${CONSOLE_BRIDGE_VERSION}" 99 | COMPATIBILITY SameMajorVersion) 100 | 101 | install(EXPORT ${PROJECT_NAME}-targets 102 | FILE ${PROJECT_NAME}-targets.cmake 103 | NAMESPACE ${PROJECT_NAME}:: 104 | DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}) 105 | install(FILES 106 | "${CMAKE_BINARY_DIR}/${cmake_conf_file}" 107 | "${CMAKE_BINARY_DIR}/${cmake_conf_version_file}" 108 | DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} COMPONENT cmake) 109 | 110 | string(REGEX REPLACE "[^/]+" ".." RELATIVE_PATH_LIBDIR_TO_PREFIX "${CMAKE_INSTALL_LIBDIR}") 111 | 112 | set(PKG_DESC "Console Bridge") 113 | set(PKG_CB_LIBS "-l${PROJECT_NAME}") 114 | set(pkg_conf_file "console_bridge.pc") 115 | configure_file("${pkg_conf_file}.in" "${CMAKE_BINARY_DIR}/${pkg_conf_file}" @ONLY) 116 | install(FILES "${CMAKE_BINARY_DIR}/${pkg_conf_file}" 117 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig) 118 | 119 | SET_DIRECTORY_PROPERTIES(PROPERTIES 120 | ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/console_bridge-config.cmake 121 | ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/console_bridge.pc) 122 | 123 | if(BUILD_TESTING) 124 | enable_testing() 125 | add_subdirectory(test) 126 | endif() 127 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Any contribution that you make to this repository will 2 | be under the [BSD-3-Clause](./LICENSE). 3 | 4 | Contributors must sign-off each commit by adding a `Signed-off-by: ...` 5 | line to commit messages to certify that they have the right to submit 6 | the code they are contributing to the project according to the 7 | [Developer Certificate of Origin (DCO)](https://developercertificate.org/). 8 | -------------------------------------------------------------------------------- /Doxyfile: -------------------------------------------------------------------------------- 1 | # All settings not listed here will use the Doxygen default values. 2 | 3 | PROJECT_NAME = "console_bridge_dev" 4 | PROJECT_NUMBER = master 5 | PROJECT_BRIEF = "It is a ROS-independent, pure CMake (i.e. non-catkin and non-rosbuild package)\ 6 | that provides logging calls that mirror those found in rosconsole, but for applications that are \ 7 | not necessarily using ROS." 8 | 9 | INPUT = README.md ./include ./QUALITY_DECLARATION.md 10 | USE_MDFILE_AS_MAINPAGE = README.md 11 | RECURSIVE = YES 12 | OUTPUT_DIRECTORY = doc_output 13 | 14 | EXTRACT_ALL = YES 15 | SORT_MEMBER_DOCS = NO 16 | 17 | GENERATE_LATEX = NO 18 | 19 | ENABLE_PREPROCESSING = YES 20 | MACRO_EXPANSION = YES 21 | EXPAND_ONLY_PREDEF = YES 22 | 23 | # Tag files that do not exist will produce a warning and cross-project linking will not work. 24 | GENERATE_TAGFILE = "../../../doxygen_tag_files/console_bridge_dev.tag" 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions are met: 3 | 4 | * Redistributions of source code must retain the above copyright 5 | notice, this list of conditions and the following disclaimer. 6 | 7 | * Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 11 | * Neither the name of the copyright holder nor the names of its 12 | contributors may be used to endorse or promote products derived from 13 | this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /QUALITY_DECLARATION.md: -------------------------------------------------------------------------------- 1 | This document is a declaration of software quality for the `libconsole-bridge-dev` ROS external dependency, based on the guidelines in [REP-2004](https://www.ros.org/reps/rep-2004.html). 2 | 3 | # libconsole-bridge-dev Quality Declaration 4 | 5 | The ROS external dependency `libconsole-bridge-dev` claims to be in the **Quality Level 1** category. 6 | 7 | Below are the rationales, notes, and caveats for this claim, organized by each requirement listed in the [Package Quality Categories in REP-2004](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#package-quality-categories) of the ROS2 developer guide. 8 | 9 | ## Version Policy [1] 10 | 11 | ### Version Scheme [1.i] 12 | 13 | `libconsole-bridge-dev` uses `semver` according to the recommendation for ROS Core packages in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#versioning). 14 | 15 | ### Version Stability [1.ii] 16 | 17 | `libconsole-bridge-dev` is at a stable version, i.e. `>= 1.0.0`. 18 | 19 | ### Public API Declaration [1.iii] 20 | 21 | All symbols in the installed headers are considered part of the public API. 22 | 23 | ### API Stability Policy [1.iv] 24 | 25 | `libconsole-bridge-dev` is used as an upstream package within the ROS2 ecosystem and has been API/ABI stable for several years. If a breaking change is introduced, ROS2 distributions will pin to a specific major version. 26 | 27 | ### ABI Stability Policy [1.v] 28 | 29 | `libconsole-bridge-dev` is used as an upstream package within the ROS2 ecosystem and has been API/ABI stable for several years. If a breaking change is introduced, ROS2 distributions will pin to a specific major version. 30 | 31 | ### ABI and ABI Stability Within a Released ROS Distribution [1.vi] 32 | 33 | If a breaking change is introduced, ROS2 distributions will pin `libconsole-bridge-dev` to a specific major version. 34 | 35 | ## Change Control Process [2] 36 | 37 | `libconsole-bridge-dev` follows the recommended guidelines for ROS Core packages in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process). 38 | 39 | ### Change Requests [2.i] 40 | 41 | All changes will occur through a pull request, check [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process) for additional information. 42 | 43 | ### Contributor Origin [2.ii] 44 | 45 | This package uses DCO as its confirmation of contributor origin policy. More info can be seen under the [contributing file](./CONTRIBUTING.md) of this repository. 46 | 47 | ### Peer Review Policy [2.iii] 48 | 49 | All pull requests will be peer-reviewed, check [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process) for additional information. 50 | 51 | ### Continuous Integration [2.iv] 52 | 53 | Pull requests must pass CI under Linux and Windows environments set in with AppVeyor and Travis-CI. Jobs are automatically trigered with each PR and the results shown in the Github repository. 54 | 55 | Current test results are shown here: 56 | 57 | [Linux (Travis CI)](https://travis-ci.org/github/ros/console_bridge) 58 | [Windows (Appveyor)](https://ci.appveyor.com/project/tfoote/console-bridge) 59 | 60 | ### Documentation Policy [2.v] 61 | 62 | All pull requests must resolve related documentation changes before merging. 63 | 64 | ## Documentation [3] 65 | 66 | ### Feature Documentation [3.i] 67 | 68 | `libconsole-bridge-dev` lists its features in the README file of its GitHub repository, [here](https://github.com/ros/console_bridge/#features). Also its [wiki](http://wiki.ros.org/console_bridge) provides additional documentation over its usage. 69 | 70 | ### Public API Documentation [3.ii] 71 | 72 | All functions and classes in the public API of `libconsole-bridge-dev` include docblocks explaining their functionality or describing its usage. 73 | 74 | ### License [3.iii] 75 | 76 | The license for `libconsole-bridge-dev` is 3-Clause BSD, and a summary is in each source file and a full copy of the license is in the [`LICENSE`](./LICENSE) file. 77 | 78 | ### Copyright Statements [3.iv] 79 | 80 | The copyright holders each provide a statement of copyright in each source code file in `libconsole-bridge-dev`. 81 | 82 | New source files added to this library will require having a copyright statement. 83 | 84 | ## Testing [4] 85 | 86 | ### Feature Testing [4.i] 87 | 88 | `libconsole-bridge-dev` provides testing of its [features](https://github.com/ros/console_bridge/#features) under the [test folder](./test/). 89 | 90 | ### Public API Testing [4.ii] 91 | 92 | `libconsole-bridge-dev` includes public API tests and new additions or changes to the public API require tests before being added. 93 | 94 | The tests aim to cover both typical usage and corner cases, but are quantified by contributing to code coverage. Currently, the complete API of the package is not fully tested. 95 | 96 | Current test results are shown here: 97 | 98 | [Linux (Travis CI)](https://travis-ci.org/github/ros/console_bridge) 99 | [Windows (Appveyor)](https://ci.appveyor.com/project/tfoote/console-bridge) 100 | 101 | ### Coverage [4.iii] 102 | 103 | `libconsole-bridge-dev` provides coverage testing under its configured Travis-CI. 104 | 105 | Current test results are shown here: 106 | 107 | [Linux Coverage results(codecov)](https://codecov.io/gh/ros/console_bridge). 108 | 109 | ### Performance [4.iv] 110 | 111 | The performance tests of this package are located in the [vendored library](https://github.com/ros2/console_bridge_vendor/tree/master/test/benchmark). The most recent test results can be found [here](http://build.ros2.org/view/Rci/job/Rci__benchmark_ubuntu_focal_amd64/BenchmarkTable/). 112 | 113 | `libconsole-bridge-dev` doe s not provide performance testing. 114 | 115 | ### Linters and Static Analysis [4.v] 116 | 117 | `libconsole-bridge-dev` is being tested with `cppcheck` and `cpplint`. 118 | 119 | ## Dependencies [5] 120 | 121 | `libconsole-bridge-dev` has no run-time or build-time dependencies that need to be considered for this declaration. 122 | 123 | ## Platform Support [6] 124 | 125 | `libconsole-bridge-dev` officially supports Ubuntu, Windows and MacOS systems. CI tests PRs with Ubuntu Trusty (Travis CI) and Windows Server 2019 (Appveyor). 126 | 127 | ## Security 128 | 129 | ### Vulnerability Disclosure Policy [7.i] 130 | 131 | This package conforms to the Vulnerability Disclosure Policy in [REP-2006](https://www.ros.org/reps/rep-2006.html). 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # console_bridge 2 | 3 | `console_bridge` is a ROS-independent, pure CMake (i.e. non-catkin and non-rosbuild package) that provides logging calls that mirror those found in rosconsole, but for applications that are not necessarily using ROS. 4 | 5 | ## Quality Declaration 6 | 7 | This package claims to be in the **Quality Level 1** category, see the [Quality Declaration](./QUALITY_DECLARATION.md) for more details. 8 | 9 | ## Features 10 | 11 | This library allows to log messages in the standard output and the standard output error based on the log level: 12 | 13 | - CONSOLE_BRIDGE_LOG_DEBUG 14 | - CONSOLE_BRIDGE_LOG_INFO 15 | - CONSOLE_BRIDGE_LOG_WARN 16 | - CONSOLE_BRIDGE_LOG_ERROR 17 | - CONSOLE_BRIDGE_LOG_NONE 18 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - Visual Studio 2019 3 | - Visual Studio 2017 4 | - Visual Studio 2015 5 | 6 | configuration: 7 | - Debug 8 | - Release 9 | 10 | build_script: 11 | - md build 12 | - cd build 13 | - cmake .. -DEXTRA_CMAKE_CXX_FLAGS="-WX" -DBUILD_TESTING=True 14 | - cmake --build . --config %CONFIGURATION% 15 | 16 | install: 17 | # Prepend newly installed Python to the PATH of this build (this cannot be 18 | # done from inside the powershell script as it would require to restart 19 | # the parent CMD process). 20 | - "SET PATH=C:\\Python35;C:\\Python35\\Scripts;%PATH%" 21 | 22 | test_script: 23 | - cmake --build . --config %CONFIGURATION% --target RUN_TESTS 24 | 25 | after_build: 26 | - cmake --build . --config %CONFIGURATION% --target INSTALL 27 | -------------------------------------------------------------------------------- /console_bridge-config.cmake.in: -------------------------------------------------------------------------------- 1 | if (@PKG_NAME@_CONFIG_INCLUDED) 2 | return() 3 | endif() 4 | set(@PKG_NAME@_CONFIG_INCLUDED TRUE) 5 | 6 | @PACKAGE_INIT@ 7 | 8 | set(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@") 9 | 10 | include("${CMAKE_CURRENT_LIST_DIR}/@PKG_NAME@-targets.cmake") 11 | set(@PKG_NAME@_LIBRARIES @PKG_NAME@::@PKG_NAME@) 12 | set(@PKG_NAME@_TARGETS @PKG_NAME@::@PKG_NAME@) 13 | -------------------------------------------------------------------------------- /console_bridge.pc.in: -------------------------------------------------------------------------------- 1 | # This file was generated by CMake for @PROJECT_NAME@ 2 | prefix=${pcfiledir}/../@RELATIVE_PATH_LIBDIR_TO_PREFIX@ 3 | exec_prefix=${prefix} 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 6 | 7 | Name: @PKG_NAME@ 8 | Description: @PKG_DESC@ 9 | Version: @CONSOLE_BRIDGE_VERSION@ 10 | Requires: @PKG_EXTERNAL_DEPS@ 11 | Libs: -L${libdir} @PKG_CB_LIBS@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /include/console_bridge/console.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright (c) 2008, Willow Garage, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * * Neither the name of the Willow Garage nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | *********************************************************************/ 34 | 35 | /* Author: Ryan Luna, Ioan Sucan */ 36 | 37 | #ifndef INCLUDE_CONSOLE_BRIDGE_CONSOLE_H_ 38 | #define INCLUDE_CONSOLE_BRIDGE_CONSOLE_H_ 39 | 40 | #include 41 | 42 | #include "./console_bridge_export.h" 43 | 44 | /** \file console.h 45 | \defgroup logging Logging Macros 46 | \{ 47 | 48 | \def CONSOLE_BRIDGE_logError(fmt, ...) 49 | \brief Log a formatted error string. 50 | \remarks This macro takes the same arguments as printf. 51 | 52 | \def CONSOLE_BRIDGE_logWarn(fmt, ...) 53 | \brief Log a formatted warning string. 54 | \remarks This macro takes the same arguments as printf. 55 | 56 | \def CONSOLE_BRIDGE_logInform(fmt, ...) 57 | \brief Log a formatted information string. 58 | \remarks This macro takes the same arguments as printf. 59 | 60 | \def CONSOLE_BRIDGE_logDebug(fmt, ...) 61 | \brief Log a formatted debugging string. 62 | \remarks This macro takes the same arguments as printf. 63 | 64 | \} 65 | */ 66 | #define CONSOLE_BRIDGE_logError(...) \ 67 | console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, __VA_ARGS__) 68 | 69 | #define CONSOLE_BRIDGE_logWarn(...) \ 70 | console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_WARN, __VA_ARGS__) 71 | 72 | #define CONSOLE_BRIDGE_logInform(...) \ 73 | console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_INFO, __VA_ARGS__) 74 | 75 | #define CONSOLE_BRIDGE_logDebug(...) \ 76 | console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_DEBUG, __VA_ARGS__) 77 | 78 | /** 79 | * \brief Message namespace. This contains classes needed to output error messages (or logging) 80 | * from within the library. Message logging can be performed with \ref logging "logging macros" 81 | */ 82 | namespace console_bridge 83 | { 84 | /** \brief The set of priorities for message logging */ 85 | enum CONSOLE_BRIDGE_DLLAPI LogLevel 86 | { 87 | CONSOLE_BRIDGE_LOG_DEBUG = 0, 88 | CONSOLE_BRIDGE_LOG_INFO, 89 | CONSOLE_BRIDGE_LOG_WARN, 90 | CONSOLE_BRIDGE_LOG_ERROR, 91 | CONSOLE_BRIDGE_LOG_NONE 92 | }; 93 | 94 | /** 95 | * \brief Generic class to handle output from a piece of code. 96 | * 97 | * In order to handle output from the library in different ways, an implementation of this class 98 | * needs to be provided. This instance can be set with the useOutputHandler function. 99 | */ 100 | class CONSOLE_BRIDGE_DLLAPI OutputHandler 101 | { 102 | public: 103 | OutputHandler(void){} 104 | 105 | virtual ~OutputHandler(void){} 106 | 107 | /** 108 | * \brief log a message to the output handler with the given text and logging level from a 109 | * specific file and line number 110 | * \param text to log 111 | * \param level console_bridge log level 112 | * \param filename of the output log 113 | * \param line 114 | */ 115 | virtual void log(const std::string &text, LogLevel level, const char *filename, int line) = 0; 116 | }; 117 | 118 | /** 119 | * \brief Default implementation of OutputHandler. This sends the information to the console. 120 | */ 121 | class CONSOLE_BRIDGE_DLLAPI OutputHandlerSTD : public OutputHandler 122 | { 123 | public: 124 | OutputHandlerSTD(void) : OutputHandler(){} 125 | 126 | virtual void log(const std::string &text, LogLevel level, const char *filename, int line); 127 | }; 128 | 129 | /** \brief Implementation of OutputHandler that saves messages in a file. */ 130 | class CONSOLE_BRIDGE_DLLAPI OutputHandlerFile : public OutputHandler 131 | { 132 | public: 133 | /** \brief The name of the file in which to save the message data */ 134 | explicit OutputHandlerFile(const char *filename); 135 | 136 | virtual ~OutputHandlerFile(void); 137 | 138 | virtual void log(const std::string &text, LogLevel level, const char *filename, int line); 139 | 140 | private: 141 | /** \brief The file to save to */ 142 | FILE *file_; 143 | }; 144 | 145 | /** 146 | * \brief This function instructs console bridge that no messages should be outputted. 147 | * Equivalent to useOutputHandler(NULL) 148 | */ 149 | CONSOLE_BRIDGE_DLLAPI void noOutputHandler(void); 150 | 151 | /** 152 | * \brief Restore the output handler that was previously in use (if any) 153 | */ 154 | CONSOLE_BRIDGE_DLLAPI void restorePreviousOutputHandler(void); 155 | 156 | /** 157 | * \brief Specify the instance of the OutputHandler to use. 158 | * By default, this is OutputHandlerSTD 159 | */ 160 | CONSOLE_BRIDGE_DLLAPI void useOutputHandler(OutputHandler *oh); 161 | 162 | /** 163 | * \brief Get the instance of the OutputHandler currently used. 164 | * This is NULL in case there is no output handler. 165 | */ 166 | CONSOLE_BRIDGE_DLLAPI OutputHandler* getOutputHandler(void); 167 | 168 | /** 169 | * \brief Set the minimum level of logging data to output. Messages with lower logging levels will 170 | * not be recorded. 171 | */ 172 | CONSOLE_BRIDGE_DLLAPI void setLogLevel(LogLevel level); 173 | 174 | /** 175 | * \brief Retrieve the current level of logging data. Messages with lower logging levels will not be 176 | * recorded. 177 | */ 178 | CONSOLE_BRIDGE_DLLAPI LogLevel getLogLevel(void); 179 | 180 | /** 181 | * \brief Root level logging function. This should not be invoked directly, but rather used via a 182 | * \ref logging "logging macro". Formats the message string given the arguments and forwards the 183 | * string to the output handler 184 | */ 185 | CONSOLE_BRIDGE_DLLAPI void log(const char *file, 186 | int line, 187 | LogLevel level, 188 | const char* m, 189 | ...); 190 | } // namespace console_bridge 191 | 192 | #endif // INCLUDE_CONSOLE_BRIDGE_CONSOLE_H_ 193 | -------------------------------------------------------------------------------- /src/console.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright (c) 2008, Willow Garage, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * * Neither the name of the Willow Garage nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | *********************************************************************/ 34 | 35 | /* Author: Ryan Luna, Ioan Sucan */ 36 | 37 | #include "console_bridge/console.h" 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | /// @cond IGNORE 48 | 49 | struct DefaultOutputHandler 50 | { 51 | DefaultOutputHandler(void) 52 | { 53 | output_handler_ = static_cast(&std_output_handler_); 54 | previous_output_handler_ = output_handler_; 55 | logLevel_ = console_bridge::CONSOLE_BRIDGE_LOG_WARN; 56 | } 57 | 58 | console_bridge::OutputHandlerSTD std_output_handler_; 59 | console_bridge::OutputHandler *output_handler_; 60 | console_bridge::OutputHandler *previous_output_handler_; 61 | console_bridge::LogLevel logLevel_; 62 | // it is likely the outputhandler does some I/O, so we serialize it 63 | std::mutex lock_; 64 | }; 65 | 66 | // we use this function because we want to handle static initialization correctly 67 | // however, the first run of this function is not thread safe, due to the use of a static 68 | // variable inside the function. For this reason, we ensure the first call happens during 69 | // static initialization using a proxy class 70 | static DefaultOutputHandler* getDOH(void) 71 | { 72 | static DefaultOutputHandler DOH; 73 | return &DOH; 74 | } 75 | 76 | #define USE_DOH \ 77 | DefaultOutputHandler *doh = getDOH(); \ 78 | std::lock_guard lock_guard(doh->lock_) 79 | 80 | #define MAX_BUFFER_SIZE 1024 81 | 82 | /// @endcond 83 | 84 | void console_bridge::noOutputHandler(void) 85 | { 86 | USE_DOH; 87 | doh->previous_output_handler_ = doh->output_handler_; 88 | doh->output_handler_ = NULL; 89 | } 90 | 91 | void console_bridge::restorePreviousOutputHandler(void) 92 | { 93 | USE_DOH; 94 | std::swap(doh->previous_output_handler_, doh->output_handler_); 95 | } 96 | 97 | void console_bridge::useOutputHandler(OutputHandler *oh) 98 | { 99 | USE_DOH; 100 | doh->previous_output_handler_ = doh->output_handler_; 101 | doh->output_handler_ = oh; 102 | } 103 | 104 | console_bridge::OutputHandler* console_bridge::getOutputHandler(void) 105 | { 106 | return getDOH()->output_handler_; 107 | } 108 | 109 | void console_bridge::log(const char *file, int line, LogLevel level, const char* m, ...) 110 | { 111 | USE_DOH; 112 | if (doh->output_handler_ && level >= doh->logLevel_) 113 | { 114 | va_list __ap; 115 | va_start(__ap, m); 116 | char buf[MAX_BUFFER_SIZE]; 117 | #ifdef _MSC_VER 118 | vsnprintf_s(buf, sizeof(buf), _TRUNCATE, m, __ap); 119 | #else 120 | vsnprintf(buf, sizeof(buf), m, __ap); 121 | #endif 122 | va_end(__ap); 123 | buf[MAX_BUFFER_SIZE - 1] = '\0'; 124 | 125 | doh->output_handler_->log(buf, level, file, line); 126 | } 127 | } 128 | 129 | void console_bridge::setLogLevel(LogLevel level) 130 | { 131 | USE_DOH; 132 | doh->logLevel_ = level; 133 | } 134 | 135 | console_bridge::LogLevel console_bridge::getLogLevel(void) 136 | { 137 | USE_DOH; 138 | return doh->logLevel_; 139 | } 140 | 141 | static const char* LogLevelString[4] = {"Debug: ", "Info: ", "Warning: ", "Error: "}; 142 | 143 | void console_bridge::OutputHandlerSTD::log(const std::string &text, 144 | LogLevel level, 145 | const char *filename, 146 | int line) 147 | { 148 | if (level >= CONSOLE_BRIDGE_LOG_WARN) 149 | { 150 | std::cerr << LogLevelString[level] << text << std::endl; 151 | std::cerr << " at line " << line << " in " << filename << std::endl; 152 | std::cerr.flush(); 153 | } else { 154 | std::cout << LogLevelString[level] << text << std::endl; 155 | std::cout.flush(); 156 | } 157 | } 158 | 159 | console_bridge::OutputHandlerFile::OutputHandlerFile(const char *filename) : OutputHandler() 160 | { 161 | #ifdef _MSC_VER 162 | errno_t err = fopen_s(&file_, filename, "a"); 163 | if (err != 0 || !file_) 164 | #else 165 | file_ = fopen(filename, "a"); 166 | if (!file_) 167 | #endif 168 | std::cerr << "Unable to open log file: '" << filename << "'" << std::endl; 169 | } 170 | 171 | console_bridge::OutputHandlerFile::~OutputHandlerFile(void) 172 | { 173 | if (file_) 174 | if (fclose(file_) != 0) 175 | std::cerr << "Error closing logfile" << std::endl; 176 | } 177 | 178 | void console_bridge::OutputHandlerFile::log(const std::string &text, 179 | LogLevel level, 180 | const char *filename, 181 | int line) 182 | { 183 | if (file_) 184 | { 185 | fprintf(file_, "%s%s\n", LogLevelString[level], text.c_str()); 186 | if(level >= CONSOLE_BRIDGE_LOG_WARN) 187 | fprintf(file_, " at line %d in %s\n", line, filename); 188 | fflush(file_); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | link_directories( 2 | ${PROJECT_BINARY_DIR}/test 3 | ) 4 | 5 | 6 | # Build gtest 7 | add_library(gtest STATIC gtest/src/gtest-all.cc) 8 | target_include_directories(gtest 9 | PUBLIC 10 | ${PROJECT_SOURCE_DIR}/test/gtest/include 11 | ${PROJECT_SOURCE_DIR}/test/gtest 12 | ${PROJECT_SOURCE_DIR}/test 13 | ) 14 | 15 | add_library(gtest_main STATIC gtest/src/gtest_main.cc) 16 | target_link_libraries(gtest_main gtest) 17 | 18 | execute_process(COMMAND cmake -E remove_directory ${CMAKE_BINARY_DIR}/test_results) 19 | execute_process(COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test_results) 20 | 21 | set(tests 22 | console_TEST.cc) 23 | 24 | ################################################# 25 | # Build all the tests 26 | foreach(GTEST_SOURCE_file ${tests}) 27 | string(REGEX REPLACE ".cc" "" BINARY_NAME ${GTEST_SOURCE_file}) 28 | add_executable(${BINARY_NAME} ${GTEST_SOURCE_file}) 29 | 30 | add_dependencies(${BINARY_NAME} 31 | console_bridge 32 | gtest 33 | gtest_main) 34 | 35 | target_link_libraries(${BINARY_NAME} 36 | gtest_main 37 | gtest 38 | console_bridge) 39 | if (UNIX AND NOT ANDROID AND NOT QNX) 40 | target_link_libraries(${BINARY_NAME} pthread) 41 | endif() 42 | 43 | add_test(NAME ${BINARY_NAME} 44 | COMMAND ${BINARY_NAME} 45 | --gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${BINARY_NAME}.xml) 46 | 47 | set_tests_properties(${BINARY_NAME} PROPERTIES TIMEOUT 240) 48 | endforeach() 49 | 50 | find_package(PythonInterp 3 REQUIRED) 51 | 52 | if(NOT PYTHONINTERP_FOUND) 53 | message(WARNING "No PythonInterp found. Linters will not be executed") 54 | return() 55 | endif() 56 | 57 | find_program(WGET_EXE wget) 58 | if(WGET_EXE) 59 | message(STATUS "Found WGet: ${WGET_EXE}") 60 | add_custom_target(wget_cppcheck 61 | COMMAND ${WGET_EXE} -q -O cppcheck.py https://raw.githubusercontent.com/ament/ament_lint/master/ament_cppcheck/ament_cppcheck/main.py 62 | ) 63 | 64 | add_test(NAME console_bridge_cppcheck 65 | COMMAND "${PYTHON_EXECUTABLE}" 66 | "cppcheck.py" 67 | "--language=c++" "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/include" 68 | ) 69 | 70 | add_custom_target(wget_cpplint 71 | COMMAND wget -q -O cpplint.py https://raw.githubusercontent.com/ament/ament_lint/master/ament_cpplint/ament_cpplint/cpplint.py 72 | ) 73 | 74 | add_test(NAME console_bridge_cpplint 75 | COMMAND "${PYTHON_EXECUTABLE}" 76 | "cpplint.py" 77 | "--counting=detailed" 78 | "--extensions=cpp,h" 79 | "--linelength=100" 80 | "--repository=${PROJECT_SOURCE_DIR}" 81 | "--filter=-build/c++11,-runtime/references,-whitespace/braces,-whitespace/indent,-whitespace/parens,-whitespace/semicolon" 82 | "${PROJECT_SOURCE_DIR}/include/console_bridge/console.h" 83 | "${PROJECT_SOURCE_DIR}/src/console.cpp" 84 | ) 85 | 86 | add_dependencies(console_bridge wget_cppcheck wget_cpplint) 87 | 88 | else() 89 | message(WARNING "wget not found. Linters will not be executed") 90 | endif() 91 | -------------------------------------------------------------------------------- /test/console_TEST.cc: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * Software License Agreement (BSD License) 3 | * 4 | * Copyright (c) 2020, Open Source Robotics Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following 15 | * disclaimer in the documentation and/or other materials provided 16 | * with the distribution. 17 | * * Neither the name of the Willow Garage nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | *********************************************************************/ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | class OutputHandlerString : public console_bridge::OutputHandler 43 | { 44 | public: 45 | OutputHandlerString() 46 | { 47 | } 48 | 49 | ~OutputHandlerString() override 50 | { 51 | } 52 | 53 | void log(const std::string & text, console_bridge::LogLevel level, const char *filename, int line) override 54 | { 55 | (void)line; 56 | (void)filename; 57 | text_ = text; 58 | log_level_ = level; 59 | } 60 | 61 | std::string text_; 62 | console_bridge::LogLevel log_level_{console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_NONE}; 63 | }; 64 | 65 | ////////////////////////////////////////////////// 66 | TEST(ConsoleTest, MacroExpansionTest_ItShouldCompile) 67 | { 68 | if (true) 69 | CONSOLE_BRIDGE_logDebug("Testing Log"); 70 | 71 | if (true) 72 | CONSOLE_BRIDGE_logDebug("Testing Log"); 73 | else 74 | { 75 | assert(true); 76 | } 77 | 78 | if (true) 79 | { 80 | CONSOLE_BRIDGE_logDebug("Testing Log"); 81 | } 82 | else 83 | { 84 | CONSOLE_BRIDGE_logDebug("Testing Log"); 85 | } 86 | } 87 | 88 | ////////////////////////////////////////////////// 89 | TEST(ConsoleTest, StdoutStderrOutput) 90 | { 91 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 92 | EXPECT_NO_THROW( 93 | CONSOLE_BRIDGE_logDebug("Testing Log")); 94 | EXPECT_NO_THROW( 95 | CONSOLE_BRIDGE_logInform("Testing Log")); 96 | EXPECT_NO_THROW( 97 | CONSOLE_BRIDGE_logWarn("Testing Log")); 98 | EXPECT_NO_THROW( 99 | CONSOLE_BRIDGE_logError("Testing Log")); 100 | } 101 | 102 | ////////////////////////////////////////////////// 103 | TEST(ConsoleTest, MultipleArguments) 104 | { 105 | // This tests that multiple arguments to the CONSOLE_BRIDGE_* macros get 106 | // formatted and output properly. 107 | 108 | OutputHandlerString string_oh; 109 | console_bridge::useOutputHandler(&string_oh); 110 | EXPECT_EQ(&string_oh, console_bridge::getOutputHandler()); 111 | 112 | CONSOLE_BRIDGE_logError("no extra parameters"); 113 | EXPECT_EQ(string_oh.text_, "no extra parameters"); 114 | 115 | CONSOLE_BRIDGE_logError("one integer: %d", 42); 116 | EXPECT_EQ(string_oh.text_, "one integer: 42"); 117 | 118 | CONSOLE_BRIDGE_logError("two floats: %.2f, %.2f", 42.01, 1/3.0); 119 | EXPECT_EQ(string_oh.text_, "two floats: 42.01, 0.33"); 120 | } 121 | 122 | TEST(ConsoleTest, BasicOutputHandler) 123 | { 124 | // This tests that we can install a custom OutputHandler and log to it. 125 | 126 | OutputHandlerString string_oh; 127 | console_bridge::useOutputHandler(&string_oh); 128 | EXPECT_EQ(&string_oh, console_bridge::getOutputHandler()); 129 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 130 | 131 | CONSOLE_BRIDGE_logDebug("Debug"); 132 | 133 | EXPECT_EQ(string_oh.text_, "Debug"); 134 | EXPECT_EQ(string_oh.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 135 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 136 | } 137 | 138 | TEST(ConsoleTest, LogLevelTooLow) 139 | { 140 | // This tests that the custom OutputHandler log() method is *not* invoked if 141 | // the log level set in console_bridge is higher than the message log level. 142 | OutputHandlerString string_oh; 143 | console_bridge::useOutputHandler(&string_oh); 144 | EXPECT_EQ(&string_oh, console_bridge::getOutputHandler()); 145 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 146 | 147 | CONSOLE_BRIDGE_logDebug("Debug"); 148 | 149 | EXPECT_EQ(string_oh.text_, ""); 150 | EXPECT_EQ(string_oh.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_NONE); 151 | } 152 | 153 | TEST(ConsoleTest, SwapHandlers) 154 | { 155 | // This tests the ability to swap output handlers from one to another. 156 | 157 | OutputHandlerString string_oh1; 158 | OutputHandlerString string_oh2; 159 | 160 | console_bridge::useOutputHandler(&string_oh1); 161 | EXPECT_EQ(&string_oh1, console_bridge::getOutputHandler()); 162 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 163 | 164 | CONSOLE_BRIDGE_logInform("Info1"); 165 | 166 | console_bridge::useOutputHandler(&string_oh2); 167 | EXPECT_EQ(&string_oh2, console_bridge::getOutputHandler()); 168 | 169 | CONSOLE_BRIDGE_logInform("Info2"); 170 | 171 | EXPECT_EQ(string_oh1.text_, "Info1"); 172 | EXPECT_EQ(string_oh1.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 173 | 174 | EXPECT_EQ(string_oh2.text_, "Info2"); 175 | EXPECT_EQ(string_oh2.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 176 | } 177 | 178 | TEST(ConsoleTest, RestoreHandler) 179 | { 180 | // This tests the console_bridge::restorePreviousOutputHandler() function. 181 | 182 | OutputHandlerString string_oh1; 183 | OutputHandlerString string_oh2; 184 | 185 | console_bridge::useOutputHandler(&string_oh1); 186 | EXPECT_EQ(&string_oh1, console_bridge::getOutputHandler()); 187 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 188 | 189 | console_bridge::useOutputHandler(&string_oh2); 190 | EXPECT_EQ(&string_oh2, console_bridge::getOutputHandler()); 191 | 192 | CONSOLE_BRIDGE_logInform("Info2"); 193 | 194 | console_bridge::restorePreviousOutputHandler(); 195 | 196 | CONSOLE_BRIDGE_logInform("Info1"); 197 | 198 | EXPECT_EQ(string_oh1.text_, "Info1"); 199 | EXPECT_EQ(string_oh1.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 200 | 201 | EXPECT_EQ(string_oh2.text_, "Info2"); 202 | EXPECT_EQ(string_oh2.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_INFO); 203 | } 204 | 205 | TEST(ConsoleTest, NoOutputHandler) 206 | { 207 | // This tests that calling console_bridge::noOutputHandler() results in 208 | // no output, even when our custom OutputHandler is "installed". 209 | 210 | OutputHandlerString string_oh; 211 | console_bridge::useOutputHandler(&string_oh); 212 | EXPECT_EQ(&string_oh, console_bridge::getOutputHandler()); 213 | console_bridge::setLogLevel(console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 214 | 215 | CONSOLE_BRIDGE_logDebug("Debug"); 216 | EXPECT_EQ(string_oh.text_, "Debug"); 217 | EXPECT_EQ(string_oh.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 218 | 219 | string_oh.text_ = ""; 220 | string_oh.log_level_ = console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_NONE; 221 | 222 | console_bridge::noOutputHandler(); 223 | EXPECT_EQ(nullptr, console_bridge::getOutputHandler()); 224 | 225 | CONSOLE_BRIDGE_logDebug("Debug"); 226 | EXPECT_EQ(string_oh.text_, ""); 227 | EXPECT_EQ(string_oh.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_NONE); 228 | 229 | console_bridge::restorePreviousOutputHandler(); 230 | CONSOLE_BRIDGE_logDebug("Debug2"); 231 | 232 | EXPECT_EQ(string_oh.text_, "Debug2"); 233 | EXPECT_EQ(string_oh.log_level_, console_bridge::LogLevel::CONSOLE_BRIDGE_LOG_DEBUG); 234 | } 235 | 236 | TEST(ConsoleTest, TestLogLevel) 237 | { 238 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_DEBUG); 239 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::CONSOLE_BRIDGE_LOG_DEBUG); 240 | 241 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_INFO); 242 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::CONSOLE_BRIDGE_LOG_INFO); 243 | 244 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_WARN); 245 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::CONSOLE_BRIDGE_LOG_WARN); 246 | 247 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_ERROR); 248 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::CONSOLE_BRIDGE_LOG_ERROR); 249 | 250 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_NONE); 251 | EXPECT_EQ(console_bridge::getLogLevel(), console_bridge::CONSOLE_BRIDGE_LOG_NONE); 252 | } 253 | 254 | TEST(ConsoleTest, TestOutputHandlerFileBadFilename) { 255 | console_bridge::OutputHandlerFile handler("/really/hoping/this/path/doesnt/exist.txt"); 256 | EXPECT_NO_THROW( 257 | handler.log("This should not crash", console_bridge::CONSOLE_BRIDGE_LOG_WARN, "file.cpp", 42)); 258 | 259 | console_bridge::useOutputHandler(&handler); 260 | EXPECT_NO_THROW( 261 | CONSOLE_BRIDGE_logError("This also should not crash, nor actually log anything")); 262 | // ~OutputHandlerFile() should not fail to close a non-existent file handle 263 | } 264 | 265 | class FileHandlerTest : public ::testing::Test { 266 | public: 267 | FileHandlerTest() : log_filename_("tmp.txt") {} 268 | 269 | virtual void SetUp() 270 | { 271 | // Needs to be reset to avoid side effects from other tests 272 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_WARN); 273 | } 274 | 275 | virtual void TearDown() 276 | { 277 | remove(log_filename()); 278 | } 279 | 280 | std::string getTextFromLogFile() { 281 | std::ifstream f(log_filename_); 282 | std::stringstream result; 283 | result << f.rdbuf(); 284 | return result.str(); 285 | } 286 | 287 | const char * log_filename() { return log_filename_.c_str(); } 288 | 289 | private: 290 | std::string log_filename_; 291 | }; 292 | 293 | TEST_F(FileHandlerTest, TestInformDoesntLog) { 294 | // Use scoping to call ~OutputHandlerFile() and force in to flush contents and close file 295 | { 296 | const std::string text = "Some logging text"; 297 | console_bridge::OutputHandlerFile handler(log_filename()); 298 | console_bridge::useOutputHandler(&handler); 299 | CONSOLE_BRIDGE_logInform("This shouldn't log to file because it's only inform"); 300 | } 301 | 302 | const std::string result = getTextFromLogFile(); 303 | EXPECT_TRUE(result.empty()) << "Log file was not empty, it contained:\n\n" << result; 304 | } 305 | 306 | TEST_F(FileHandlerTest, TestErrorLogs) { 307 | const std::string text = "Some logging text"; 308 | 309 | // Use scoping to call ~OutputHandlerFile() and force in to flush contents and close file 310 | { 311 | console_bridge::OutputHandlerFile handler(log_filename()); 312 | console_bridge::useOutputHandler(&handler); 313 | CONSOLE_BRIDGE_logError(text.c_str()); 314 | } 315 | const std::string expected_text = "Error: " + text; 316 | const std::string result = getTextFromLogFile(); 317 | 318 | // Just checking that expected text is in the file, not checking full log statement. 319 | EXPECT_NE(result.find(expected_text), result.npos) 320 | << "Log file did not contain expected text, instead it contained:\n\n: " << result; 321 | } 322 | 323 | TEST_F(FileHandlerTest, TestInformLogsWithLogLevel) { 324 | const std::string text = "Some logging text"; 325 | console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_INFO); 326 | 327 | // Use scoping to call ~OutputHandlerFile() and force in to flush contents and close file 328 | { 329 | console_bridge::OutputHandlerFile handler(log_filename()); 330 | console_bridge::useOutputHandler(&handler); 331 | CONSOLE_BRIDGE_logInform(text.c_str()); 332 | } 333 | 334 | const std::string expected_text = "Info: " + text; 335 | const std::string result = getTextFromLogFile(); 336 | 337 | // Just checking that expected text is in the file, not checking full log statement. 338 | EXPECT_NE(result.find(expected_text), result.npos) 339 | << "Log file did not contain expected text, instead it contained:\n\n: " << result; 340 | } 341 | -------------------------------------------------------------------------------- /test/gtest/CHANGES: -------------------------------------------------------------------------------- 1 | Changes for 1.7.0: 2 | 3 | * New feature: death tests are supported on OpenBSD and in iOS 4 | simulator now. 5 | * New feature: Google Test now implements a protocol to allow 6 | a test runner to detect that a test program has exited 7 | prematurely and report it as a failure (before it would be 8 | falsely reported as a success if the exit code is 0). 9 | * New feature: Test::RecordProperty() can now be used outside of the 10 | lifespan of a test method, in which case it will be attributed to 11 | the current test case or the test program in the XML report. 12 | * New feature (potentially breaking): --gtest_list_tests now prints 13 | the type parameters and value parameters for each test. 14 | * Improvement: char pointers and char arrays are now escaped properly 15 | in failure messages. 16 | * Improvement: failure summary in XML reports now includes file and 17 | line information. 18 | * Improvement: the XML element now has a timestamp attribute. 19 | * Improvement: When --gtest_filter is specified, XML report now doesn't 20 | contain information about tests that are filtered out. 21 | * Fixed the bug where long --gtest_filter flag values are truncated in 22 | death tests. 23 | * Potentially breaking change: RUN_ALL_TESTS() is now implemented as a 24 | function instead of a macro in order to work better with Clang. 25 | * Compatibility fixes with C++ 11 and various platforms. 26 | * Bug/warning fixes. 27 | 28 | Changes for 1.6.0: 29 | 30 | * New feature: ADD_FAILURE_AT() for reporting a test failure at the 31 | given source location -- useful for writing testing utilities. 32 | * New feature: the universal value printer is moved from Google Mock 33 | to Google Test. 34 | * New feature: type parameters and value parameters are reported in 35 | the XML report now. 36 | * A gtest_disable_pthreads CMake option. 37 | * Colored output works in GNU Screen sessions now. 38 | * Parameters of value-parameterized tests are now printed in the 39 | textual output. 40 | * Failures from ad hoc test assertions run before RUN_ALL_TESTS() are 41 | now correctly reported. 42 | * Arguments of ASSERT_XY and EXPECT_XY no longer need to support << to 43 | ostream. 44 | * More complete handling of exceptions. 45 | * GTEST_ASSERT_XY can be used instead of ASSERT_XY in case the latter 46 | name is already used by another library. 47 | * --gtest_catch_exceptions is now true by default, allowing a test 48 | program to continue after an exception is thrown. 49 | * Value-parameterized test fixtures can now derive from Test and 50 | WithParamInterface separately, easing conversion of legacy tests. 51 | * Death test messages are clearly marked to make them more 52 | distinguishable from other messages. 53 | * Compatibility fixes for Android, Google Native Client, MinGW, HP UX, 54 | PowerPC, Lucid autotools, libCStd, Sun C++, Borland C++ Builder (Code Gear), 55 | IBM XL C++ (Visual Age C++), and C++0x. 56 | * Bug fixes and implementation clean-ups. 57 | * Potentially incompatible changes: disables the harmful 'make install' 58 | command in autotools. 59 | 60 | Changes for 1.5.0: 61 | 62 | * New feature: assertions can be safely called in multiple threads 63 | where the pthreads library is available. 64 | * New feature: predicates used inside EXPECT_TRUE() and friends 65 | can now generate custom failure messages. 66 | * New feature: Google Test can now be compiled as a DLL. 67 | * New feature: fused source files are included. 68 | * New feature: prints help when encountering unrecognized Google Test flags. 69 | * Experimental feature: CMake build script (requires CMake 2.6.4+). 70 | * Experimental feature: the Pump script for meta programming. 71 | * double values streamed to an assertion are printed with enough precision 72 | to differentiate any two different values. 73 | * Google Test now works on Solaris and AIX. 74 | * Build and test script improvements. 75 | * Bug fixes and implementation clean-ups. 76 | 77 | Potentially breaking changes: 78 | 79 | * Stopped supporting VC++ 7.1 with exceptions disabled. 80 | * Dropped support for 'make install'. 81 | 82 | Changes for 1.4.0: 83 | 84 | * New feature: the event listener API 85 | * New feature: test shuffling 86 | * New feature: the XML report format is closer to junitreport and can 87 | be parsed by Hudson now. 88 | * New feature: when a test runs under Visual Studio, its failures are 89 | integrated in the IDE. 90 | * New feature: /MD(d) versions of VC++ projects. 91 | * New feature: elapsed time for the tests is printed by default. 92 | * New feature: comes with a TR1 tuple implementation such that Boost 93 | is no longer needed for Combine(). 94 | * New feature: EXPECT_DEATH_IF_SUPPORTED macro and friends. 95 | * New feature: the Xcode project can now produce static gtest 96 | libraries in addition to a framework. 97 | * Compatibility fixes for Solaris, Cygwin, minGW, Windows Mobile, 98 | Symbian, gcc, and C++Builder. 99 | * Bug fixes and implementation clean-ups. 100 | 101 | Changes for 1.3.0: 102 | 103 | * New feature: death tests on Windows, Cygwin, and Mac. 104 | * New feature: ability to use Google Test assertions in other testing 105 | frameworks. 106 | * New feature: ability to run disabled test via 107 | --gtest_also_run_disabled_tests. 108 | * New feature: the --help flag for printing the usage. 109 | * New feature: access to Google Test flag values in user code. 110 | * New feature: a script that packs Google Test into one .h and one 111 | .cc file for easy deployment. 112 | * New feature: support for distributing test functions to multiple 113 | machines (requires support from the test runner). 114 | * Bug fixes and implementation clean-ups. 115 | 116 | Changes for 1.2.1: 117 | 118 | * Compatibility fixes for Linux IA-64 and IBM z/OS. 119 | * Added support for using Boost and other TR1 implementations. 120 | * Changes to the build scripts to support upcoming release of Google C++ 121 | Mocking Framework. 122 | * Added Makefile to the distribution package. 123 | * Improved build instructions in README. 124 | 125 | Changes for 1.2.0: 126 | 127 | * New feature: value-parameterized tests. 128 | * New feature: the ASSERT/EXPECT_(NON)FATAL_FAILURE(_ON_ALL_THREADS) 129 | macros. 130 | * Changed the XML report format to match JUnit/Ant's. 131 | * Added tests to the Xcode project. 132 | * Added scons/SConscript for building with SCons. 133 | * Added src/gtest-all.cc for building Google Test from a single file. 134 | * Fixed compatibility with Solaris and z/OS. 135 | * Enabled running Python tests on systems with python 2.3 installed, 136 | e.g. Mac OS X 10.4. 137 | * Bug fixes. 138 | 139 | Changes for 1.1.0: 140 | 141 | * New feature: type-parameterized tests. 142 | * New feature: exception assertions. 143 | * New feature: printing elapsed time of tests. 144 | * Improved the robustness of death tests. 145 | * Added an Xcode project and samples. 146 | * Adjusted the output format on Windows to be understandable by Visual Studio. 147 | * Minor bug fixes. 148 | 149 | Changes for 1.0.1: 150 | 151 | * Added project files for Visual Studio 7.1. 152 | * Fixed issues with compiling on Mac OS X. 153 | * Fixed issues with compiling on Cygwin. 154 | 155 | Changes for 1.0.0: 156 | 157 | * Initial Open Source release of Google Test 158 | -------------------------------------------------------------------------------- /test/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ros/console_bridge/122ed72b90bc9b69c68bafae901a78fcd43270a1/test/gtest/CMakeLists.txt -------------------------------------------------------------------------------- /test/gtest/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This file contains a list of people who've made non-trivial 2 | # contribution to the Google C++ Testing Framework project. People 3 | # who commit code to the project are encouraged to add their names 4 | # here. Please keep the list sorted by first names. 5 | 6 | Ajay Joshi 7 | Balázs Dán 8 | Bharat Mediratta 9 | Chandler Carruth 10 | Chris Prince 11 | Chris Taylor 12 | Dan Egnor 13 | Eric Roman 14 | Hady Zalek 15 | Jeffrey Yasskin 16 | Jói Sigurðsson 17 | Keir Mierle 18 | Keith Ray 19 | Kenton Varda 20 | Manuel Klimek 21 | Markus Heule 22 | Mika Raento 23 | Miklós Fazekas 24 | Pasi Valminen 25 | Patrick Hanna 26 | Patrick Riley 27 | Peter Kaminski 28 | Preston Jackson 29 | Rainer Klaffenboeck 30 | Russ Cox 31 | Russ Rufer 32 | Sean Mcafee 33 | Sigurður Ásgeirsson 34 | Tracy Bialik 35 | Vadim Berman 36 | Vlad Losev 37 | Zhanyong Wan 38 | -------------------------------------------------------------------------------- /test/gtest/LICENSE: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/gtest/cmake/internal_utils.cmake: -------------------------------------------------------------------------------- 1 | # Defines functions and macros useful for building Google Test and 2 | # Google Mock. 3 | # 4 | # Note: 5 | # 6 | # - This file will be run twice when building Google Mock (once via 7 | # Google Test's CMakeLists.txt, and once via Google Mock's). 8 | # Therefore it shouldn't have any side effects other than defining 9 | # the functions and macros. 10 | # 11 | # - The functions/macros defined in this file may depend on Google 12 | # Test and Google Mock's option() definitions, and thus must be 13 | # called *after* the options have been defined. 14 | 15 | # Tweaks CMake's default compiler/linker settings to suit Google Test's needs. 16 | # 17 | # This must be a macro(), as inside a function string() can only 18 | # update variables in the function scope. 19 | macro(fix_default_compiler_settings_) 20 | if (MSVC) 21 | # For MSVC, CMake sets certain flags to defaults we want to override. 22 | # This replacement code is taken from sample in the CMake Wiki at 23 | # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace. 24 | foreach (flag_var 25 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 26 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 27 | if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt) 28 | # When Google Test is built as a shared library, it should also use 29 | # shared runtime libraries. Otherwise, it may end up with multiple 30 | # copies of runtime library data in different modules, resulting in 31 | # hard-to-find crashes. When it is built as a static library, it is 32 | # preferable to use CRT as static libraries, as we don't have to rely 33 | # on CRT DLLs being available. CMake always defaults to using shared 34 | # CRT libraries, so we override that default here. 35 | string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") 36 | endif() 37 | 38 | # We prefer more strict warning checking for building Google Test. 39 | # Replaces /W3 with /W4 in defaults. 40 | string(REPLACE "/W3" "-W4" ${flag_var} "${${flag_var}}") 41 | endforeach() 42 | endif() 43 | endmacro() 44 | 45 | # Defines the compiler/linker flags used to build Google Test and 46 | # Google Mock. You can tweak these definitions to suit your need. A 47 | # variable's value is empty before it's explicitly assigned to. 48 | macro(config_compiler_and_linker) 49 | if (NOT gtest_disable_pthreads) 50 | # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. 51 | find_package(Threads) 52 | endif() 53 | 54 | fix_default_compiler_settings_() 55 | if (MSVC) 56 | # Newlines inside flags variables break CMake's NMake generator. 57 | # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds. 58 | set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi") 59 | if (MSVC_VERSION LESS 1400) 60 | # Suppress spurious warnings MSVC 7.1 sometimes issues. 61 | # Forcing value to bool. 62 | set(cxx_base_flags "${cxx_base_flags} -wd4800") 63 | # Copy constructor and assignment operator could not be generated. 64 | set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512") 65 | # Compatibility warnings not applicable to Google Test. 66 | # Resolved overload was found by argument-dependent lookup. 67 | set(cxx_base_flags "${cxx_base_flags} -wd4675") 68 | endif() 69 | set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32") 70 | set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN") 71 | set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") 72 | set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0") 73 | set(cxx_no_rtti_flags "-GR-") 74 | elseif (CMAKE_COMPILER_IS_GNUCXX) 75 | set(cxx_base_flags "-Wall -Wshadow") 76 | set(cxx_exception_flags "-fexceptions") 77 | set(cxx_no_exception_flags "-fno-exceptions") 78 | # Until version 4.3.2, GCC doesn't define a macro to indicate 79 | # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI 80 | # explicitly. 81 | set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") 82 | set(cxx_strict_flags 83 | "-Wextra -Wno-unused-parameter -Wno-missing-field-initializers") 84 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") 85 | set(cxx_exception_flags "-features=except") 86 | # Sun Pro doesn't provide macros to indicate whether exceptions and 87 | # RTTI are enabled, so we define GTEST_HAS_* explicitly. 88 | set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0") 89 | set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0") 90 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR 91 | CMAKE_CXX_COMPILER_ID STREQUAL "XL") 92 | # CMake 2.8 changes Visual Age's compiler ID to "XL". 93 | set(cxx_exception_flags "-qeh") 94 | set(cxx_no_exception_flags "-qnoeh") 95 | # Until version 9.0, Visual Age doesn't define a macro to indicate 96 | # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI 97 | # explicitly. 98 | set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0") 99 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP") 100 | set(cxx_base_flags "-AA -mt") 101 | set(cxx_exception_flags "-DGTEST_HAS_EXCEPTIONS=1") 102 | set(cxx_no_exception_flags "+noeh -DGTEST_HAS_EXCEPTIONS=0") 103 | # RTTI can not be disabled in HP aCC compiler. 104 | set(cxx_no_rtti_flags "") 105 | endif() 106 | 107 | if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available and allowed. 108 | set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1") 109 | else() 110 | set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0") 111 | endif() 112 | 113 | # For building gtest's own tests and samples. 114 | set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}") 115 | set(cxx_no_exception 116 | "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}") 117 | set(cxx_default "${cxx_exception}") 118 | set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}") 119 | set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1") 120 | 121 | # For building the gtest libraries. 122 | set(cxx_strict "${cxx_default} ${cxx_strict_flags}") 123 | endmacro() 124 | 125 | # Defines the gtest & gtest_main libraries. User tests should link 126 | # with one of them. 127 | function(cxx_library_with_type name type cxx_flags) 128 | # type can be either STATIC or SHARED to denote a static or shared library. 129 | # ARGN refers to additional arguments after 'cxx_flags'. 130 | add_library(${name} ${type} ${ARGN}) 131 | set_target_properties(${name} 132 | PROPERTIES 133 | COMPILE_FLAGS "${cxx_flags}") 134 | if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED") 135 | set_target_properties(${name} 136 | PROPERTIES 137 | COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") 138 | endif() 139 | if (CMAKE_USE_PTHREADS_INIT) 140 | target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT}) 141 | endif() 142 | endfunction() 143 | 144 | ######################################################################## 145 | # 146 | # Helper functions for creating build targets. 147 | 148 | function(cxx_shared_library name cxx_flags) 149 | cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN}) 150 | endfunction() 151 | 152 | function(cxx_library name cxx_flags) 153 | cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN}) 154 | endfunction() 155 | 156 | # cxx_executable_with_flags(name cxx_flags libs srcs...) 157 | # 158 | # creates a named C++ executable that depends on the given libraries and 159 | # is built from the given source files with the given compiler flags. 160 | function(cxx_executable_with_flags name cxx_flags libs) 161 | add_executable(${name} ${ARGN}) 162 | if (cxx_flags) 163 | set_target_properties(${name} 164 | PROPERTIES 165 | COMPILE_FLAGS "${cxx_flags}") 166 | endif() 167 | if (BUILD_SHARED_LIBS) 168 | set_target_properties(${name} 169 | PROPERTIES 170 | COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") 171 | endif() 172 | # To support mixing linking in static and dynamic libraries, link each 173 | # library in with an extra call to target_link_libraries. 174 | foreach (lib "${libs}") 175 | target_link_libraries(${name} ${lib}) 176 | endforeach() 177 | endfunction() 178 | 179 | # cxx_executable(name dir lib srcs...) 180 | # 181 | # creates a named target that depends on the given libs and is built 182 | # from the given source files. dir/name.cc is implicitly included in 183 | # the source file list. 184 | function(cxx_executable name dir libs) 185 | cxx_executable_with_flags( 186 | ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) 187 | endfunction() 188 | 189 | # Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE. 190 | find_package(PythonInterp) 191 | 192 | # cxx_test_with_flags(name cxx_flags libs srcs...) 193 | # 194 | # creates a named C++ test that depends on the given libs and is built 195 | # from the given source files with the given compiler flags. 196 | function(cxx_test_with_flags name cxx_flags libs) 197 | cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) 198 | add_test(${name} ${name}) 199 | endfunction() 200 | 201 | # cxx_test(name libs srcs...) 202 | # 203 | # creates a named test target that depends on the given libs and is 204 | # built from the given source files. Unlike cxx_test_with_flags, 205 | # test/name.cc is already implicitly included in the source file list. 206 | function(cxx_test name libs) 207 | cxx_test_with_flags("${name}" "${cxx_default}" "${libs}" 208 | "test/${name}.cc" ${ARGN}) 209 | endfunction() 210 | 211 | # py_test(name) 212 | # 213 | # creates a Python test with the given name whose main module is in 214 | # test/name.py. It does nothing if Python is not installed. 215 | function(py_test name) 216 | # We are not supporting Python tests on Linux yet as they consider 217 | # all Linux environments to be google3 and try to use google3 features. 218 | if (PYTHONINTERP_FOUND) 219 | # ${CMAKE_BINARY_DIR} is known at configuration time, so we can 220 | # directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known 221 | # only at ctest runtime (by calling ctest -c ), so 222 | # we have to escape $ to delay variable substitution here. 223 | add_test(${name} 224 | ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py 225 | --build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE}) 226 | endif() 227 | endfunction() 228 | -------------------------------------------------------------------------------- /test/gtest/gtest-1.7.0.diff: -------------------------------------------------------------------------------- 1 | diff -r a5e72dd0ecf3 test/gtest/include/gtest/gtest-typed-test.h 2 | --- a/test/gtest/include/gtest/gtest-typed-test.h Mon Nov 04 11:47:43 2013 -0800 3 | +++ b/test/gtest/include/gtest/gtest-typed-test.h Mon Nov 04 11:49:12 2013 -0800 4 | @@ -31,6 +31,7 @@ 5 | 6 | #ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ 7 | #define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ 8 | +#pragma GCC system_header 9 | 10 | // This header implements typed tests and type-parameterized tests. 11 | 12 | diff -r a5e72dd0ecf3 test/gtest/src/gtest.cc 13 | --- a/test/gtest/src/gtest.cc Mon Nov 04 11:47:43 2013 -0800 14 | +++ b/test/gtest/src/gtest.cc Mon Nov 04 11:49:12 2013 -0800 15 | @@ -33,6 +33,7 @@ 16 | 17 | #include "gtest/gtest.h" 18 | #include "gtest/gtest-spi.h" 19 | +#pragma GCC system_header 20 | 21 | #include 22 | #include 23 | diff -r c33b44f8a9a1 test/gtest/include/gtest/internal/gtest-port.h 24 | --- a/test/gtest/include/gtest/internal/gtest-port.h Wed Nov 06 11:23:38 2013 -0800 25 | +++ b/test/gtest/include/gtest/internal/gtest-port.h Wed Nov 06 17:12:57 2013 -0800 26 | @@ -39,6 +39,7 @@ 27 | 28 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 29 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ 30 | +#pragma GCC system_header 31 | 32 | // The user can define the following macros in the build script to 33 | // control Google Test's behavior. If the user doesn't define a macro 34 | diff -r e980730656c1 test/gtest/include/gtest/gtest-printers.h 35 | --- a/test/gtest/include/gtest/gtest-printers.h Wed Nov 06 17:13:57 2013 -0800 36 | +++ b/test/gtest/include/gtest/gtest-printers.h Thu Nov 07 09:29:28 2013 -0800 37 | @@ -94,6 +94,7 @@ 38 | 39 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ 40 | #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ 41 | +#pragma GCC system_header 42 | 43 | #include // NOLINT 44 | #include 45 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest-death-test.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 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | // 34 | // This header file defines the public API for death tests. It is 35 | // #included by gtest.h so a user doesn't need to include this 36 | // directly. 37 | 38 | #ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 39 | #define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 40 | 41 | #include "gtest/internal/gtest-death-test-internal.h" 42 | 43 | namespace testing { 44 | 45 | // This flag controls the style of death tests. Valid values are "threadsafe", 46 | // meaning that the death test child process will re-execute the test binary 47 | // from the start, running only a single death test, or "fast", 48 | // meaning that the child process will execute the test logic immediately 49 | // after forking. 50 | GTEST_DECLARE_string_(death_test_style); 51 | 52 | #if GTEST_HAS_DEATH_TEST 53 | 54 | namespace internal { 55 | 56 | // Returns a Boolean value indicating whether the caller is currently 57 | // executing in the context of the death test child process. Tools such as 58 | // Valgrind heap checkers may need this to modify their behavior in death 59 | // tests. IMPORTANT: This is an internal utility. Using it may break the 60 | // implementation of death tests. User code MUST NOT use it. 61 | GTEST_API_ bool InDeathTestChild(); 62 | 63 | } // namespace internal 64 | 65 | // The following macros are useful for writing death tests. 66 | 67 | // Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is 68 | // executed: 69 | // 70 | // 1. It generates a warning if there is more than one active 71 | // thread. This is because it's safe to fork() or clone() only 72 | // when there is a single thread. 73 | // 74 | // 2. The parent process clone()s a sub-process and runs the death 75 | // test in it; the sub-process exits with code 0 at the end of the 76 | // death test, if it hasn't exited already. 77 | // 78 | // 3. The parent process waits for the sub-process to terminate. 79 | // 80 | // 4. The parent process checks the exit code and error message of 81 | // the sub-process. 82 | // 83 | // Examples: 84 | // 85 | // ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number"); 86 | // for (int i = 0; i < 5; i++) { 87 | // EXPECT_DEATH(server.ProcessRequest(i), 88 | // "Invalid request .* in ProcessRequest()") 89 | // << "Failed to die on request " << i; 90 | // } 91 | // 92 | // ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting"); 93 | // 94 | // bool KilledBySIGHUP(int exit_code) { 95 | // return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP; 96 | // } 97 | // 98 | // ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); 99 | // 100 | // On the regular expressions used in death tests: 101 | // 102 | // On POSIX-compliant systems (*nix), we use the library, 103 | // which uses the POSIX extended regex syntax. 104 | // 105 | // On other platforms (e.g. Windows or Mac), we only support a simple regex 106 | // syntax implemented as part of Google Test. This limited 107 | // implementation should be enough most of the time when writing 108 | // death tests; though it lacks many features you can find in PCRE 109 | // or POSIX extended regex syntax. For example, we don't support 110 | // union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and 111 | // repetition count ("x{5,7}"), among others. 112 | // 113 | // Below is the syntax that we do support. We chose it to be a 114 | // subset of both PCRE and POSIX extended regex, so it's easy to 115 | // learn wherever you come from. In the following: 'A' denotes a 116 | // literal character, period (.), or a single \\ escape sequence; 117 | // 'x' and 'y' denote regular expressions; 'm' and 'n' are for 118 | // natural numbers. 119 | // 120 | // c matches any literal character c 121 | // \\d matches any decimal digit 122 | // \\D matches any character that's not a decimal digit 123 | // \\f matches \f 124 | // \\n matches \n 125 | // \\r matches \r 126 | // \\s matches any ASCII whitespace, including \n 127 | // \\S matches any character that's not a whitespace 128 | // \\t matches \t 129 | // \\v matches \v 130 | // \\w matches any letter, _, or decimal digit 131 | // \\W matches any character that \\w doesn't match 132 | // \\c matches any literal character c, which must be a punctuation 133 | // . matches any single character except \n 134 | // A? matches 0 or 1 occurrences of A 135 | // A* matches 0 or many occurrences of A 136 | // A+ matches 1 or many occurrences of A 137 | // ^ matches the beginning of a string (not that of each line) 138 | // $ matches the end of a string (not that of each line) 139 | // xy matches x followed by y 140 | // 141 | // If you accidentally use PCRE or POSIX extended regex features 142 | // not implemented by us, you will get a run-time failure. In that 143 | // case, please try to rewrite your regular expression within the 144 | // above syntax. 145 | // 146 | // This implementation is *not* meant to be as highly tuned or robust 147 | // as a compiled regex library, but should perform well enough for a 148 | // death test, which already incurs significant overhead by launching 149 | // a child process. 150 | // 151 | // Known caveats: 152 | // 153 | // A "threadsafe" style death test obtains the path to the test 154 | // program from argv[0] and re-executes it in the sub-process. For 155 | // simplicity, the current implementation doesn't search the PATH 156 | // when launching the sub-process. This means that the user must 157 | // invoke the test program via a path that contains at least one 158 | // path separator (e.g. path/to/foo_test and 159 | // /absolute/path/to/bar_test are fine, but foo_test is not). This 160 | // is rarely a problem as people usually don't put the test binary 161 | // directory in PATH. 162 | // 163 | // TODO(wan@google.com): make thread-safe death tests search the PATH. 164 | 165 | // Asserts that a given statement causes the program to exit, with an 166 | // integer exit status that satisfies predicate, and emitting error output 167 | // that matches regex. 168 | # define ASSERT_EXIT(statement, predicate, regex) \ 169 | GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) 170 | 171 | // Like ASSERT_EXIT, but continues on to successive tests in the 172 | // test case, if any: 173 | # define EXPECT_EXIT(statement, predicate, regex) \ 174 | GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) 175 | 176 | // Asserts that a given statement causes the program to exit, either by 177 | // explicitly exiting with a nonzero exit code or being killed by a 178 | // signal, and emitting error output that matches regex. 179 | # define ASSERT_DEATH(statement, regex) \ 180 | ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) 181 | 182 | // Like ASSERT_DEATH, but continues on to successive tests in the 183 | // test case, if any: 184 | # define EXPECT_DEATH(statement, regex) \ 185 | EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) 186 | 187 | // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: 188 | 189 | // Tests that an exit code describes a normal exit with a given exit code. 190 | class GTEST_API_ ExitedWithCode { 191 | public: 192 | explicit ExitedWithCode(int exit_code); 193 | bool operator()(int exit_status) const; 194 | private: 195 | // No implementation - assignment is unsupported. 196 | void operator=(const ExitedWithCode& other); 197 | 198 | const int exit_code_; 199 | }; 200 | 201 | # if !GTEST_OS_WINDOWS 202 | // Tests that an exit code describes an exit due to termination by a 203 | // given signal. 204 | class GTEST_API_ KilledBySignal { 205 | public: 206 | explicit KilledBySignal(int signum); 207 | bool operator()(int exit_status) const; 208 | private: 209 | const int signum_; 210 | }; 211 | # endif // !GTEST_OS_WINDOWS 212 | 213 | // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. 214 | // The death testing framework causes this to have interesting semantics, 215 | // since the sideeffects of the call are only visible in opt mode, and not 216 | // in debug mode. 217 | // 218 | // In practice, this can be used to test functions that utilize the 219 | // LOG(DFATAL) macro using the following style: 220 | // 221 | // int DieInDebugOr12(int* sideeffect) { 222 | // if (sideeffect) { 223 | // *sideeffect = 12; 224 | // } 225 | // LOG(DFATAL) << "death"; 226 | // return 12; 227 | // } 228 | // 229 | // TEST(TestCase, TestDieOr12WorksInDgbAndOpt) { 230 | // int sideeffect = 0; 231 | // // Only asserts in dbg. 232 | // EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death"); 233 | // 234 | // #ifdef NDEBUG 235 | // // opt-mode has sideeffect visible. 236 | // EXPECT_EQ(12, sideeffect); 237 | // #else 238 | // // dbg-mode no visible sideeffect. 239 | // EXPECT_EQ(0, sideeffect); 240 | // #endif 241 | // } 242 | // 243 | // This will assert that DieInDebugReturn12InOpt() crashes in debug 244 | // mode, usually due to a DCHECK or LOG(DFATAL), but returns the 245 | // appropriate fallback value (12 in this case) in opt mode. If you 246 | // need to test that a function has appropriate side-effects in opt 247 | // mode, include assertions against the side-effects. A general 248 | // pattern for this is: 249 | // 250 | // EXPECT_DEBUG_DEATH({ 251 | // // Side-effects here will have an effect after this statement in 252 | // // opt mode, but none in debug mode. 253 | // EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); 254 | // }, "death"); 255 | // 256 | # ifdef NDEBUG 257 | 258 | # define EXPECT_DEBUG_DEATH(statement, regex) \ 259 | GTEST_EXECUTE_STATEMENT_(statement, regex) 260 | 261 | # define ASSERT_DEBUG_DEATH(statement, regex) \ 262 | GTEST_EXECUTE_STATEMENT_(statement, regex) 263 | 264 | # else 265 | 266 | # define EXPECT_DEBUG_DEATH(statement, regex) \ 267 | EXPECT_DEATH(statement, regex) 268 | 269 | # define ASSERT_DEBUG_DEATH(statement, regex) \ 270 | ASSERT_DEATH(statement, regex) 271 | 272 | # endif // NDEBUG for EXPECT_DEBUG_DEATH 273 | #endif // GTEST_HAS_DEATH_TEST 274 | 275 | // This macro is used for implementing macros such as 276 | // EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where 277 | // death tests are not supported. Those macros must compile on such systems 278 | // iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on 279 | // systems that support death tests. This allows one to write such a macro 280 | // on a system that does not support death tests and be sure that it will 281 | // compile on a death-test supporting system. It is exposed publicly so that 282 | // systems that have death-tests with stricter requirements than 283 | // GTEST_HAS_DEATH_TEST can write their own equivalent of 284 | // EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED. 285 | // 286 | // Parameters: 287 | // statement - A statement that a macro such as EXPECT_DEATH would test 288 | // for program termination. This macro has to make sure this 289 | // statement is compiled but not executed, to ensure that 290 | // EXPECT_DEATH_IF_SUPPORTED compiles with a certain 291 | // parameter iff EXPECT_DEATH compiles with it. 292 | // regex - A regex that a macro such as EXPECT_DEATH would use to test 293 | // the output of statement. This parameter has to be 294 | // compiled but not evaluated by this macro, to ensure that 295 | // this macro only accepts expressions that a macro such as 296 | // EXPECT_DEATH would accept. 297 | // terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED 298 | // and a return statement for ASSERT_DEATH_IF_SUPPORTED. 299 | // This ensures that ASSERT_DEATH_IF_SUPPORTED will not 300 | // compile inside functions where ASSERT_DEATH doesn't 301 | // compile. 302 | // 303 | // The branch that has an always false condition is used to ensure that 304 | // statement and regex are compiled (and thus syntactically correct) but 305 | // never executed. The unreachable code macro protects the terminator 306 | // statement from generating an 'unreachable code' warning in case 307 | // statement unconditionally returns or throws. The Message constructor at 308 | // the end allows the syntax of streaming additional messages into the 309 | // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. 310 | # define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ 311 | GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 312 | if (::testing::internal::AlwaysTrue()) { \ 313 | GTEST_LOG_(WARNING) \ 314 | << "Death tests are not supported on this platform.\n" \ 315 | << "Statement '" #statement "' cannot be verified."; \ 316 | } else if (::testing::internal::AlwaysFalse()) { \ 317 | ::testing::internal::RE::PartialMatch(".*", (regex)); \ 318 | GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 319 | terminator; \ 320 | } else \ 321 | ::testing::Message() 322 | 323 | // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and 324 | // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if 325 | // death tests are supported; otherwise they just issue a warning. This is 326 | // useful when you are combining death test assertions with normal test 327 | // assertions in one test. 328 | #if GTEST_HAS_DEATH_TEST 329 | # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ 330 | EXPECT_DEATH(statement, regex) 331 | # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ 332 | ASSERT_DEATH(statement, regex) 333 | #else 334 | # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ 335 | GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) 336 | # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ 337 | GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) 338 | #endif 339 | 340 | } // namespace testing 341 | 342 | #endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 343 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | // 34 | // This header file defines the Message class. 35 | // 36 | // IMPORTANT NOTE: Due to limitation of the C++ language, we have to 37 | // leave some internal implementation details in this header file. 38 | // They are clearly marked by comments like this: 39 | // 40 | // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 41 | // 42 | // Such code is NOT meant to be used by a user directly, and is subject 43 | // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user 44 | // program! 45 | 46 | #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 47 | #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 48 | 49 | #include 50 | 51 | #include "gtest/internal/gtest-port.h" 52 | 53 | // Ensures that there is at least one operator<< in the global namespace. 54 | // See Message& operator<<(...) below for why. 55 | void operator<<(const testing::internal::Secret&, int); 56 | 57 | namespace testing { 58 | 59 | // The Message class works like an ostream repeater. 60 | // 61 | // Typical usage: 62 | // 63 | // 1. You stream a bunch of values to a Message object. 64 | // It will remember the text in a stringstream. 65 | // 2. Then you stream the Message object to an ostream. 66 | // This causes the text in the Message to be streamed 67 | // to the ostream. 68 | // 69 | // For example; 70 | // 71 | // testing::Message foo; 72 | // foo << 1 << " != " << 2; 73 | // std::cout << foo; 74 | // 75 | // will print "1 != 2". 76 | // 77 | // Message is not intended to be inherited from. In particular, its 78 | // destructor is not virtual. 79 | // 80 | // Note that stringstream behaves differently in gcc and in MSVC. You 81 | // can stream a NULL char pointer to it in the former, but not in the 82 | // latter (it causes an access violation if you do). The Message 83 | // class hides this difference by treating a NULL char pointer as 84 | // "(null)". 85 | class GTEST_API_ Message { 86 | private: 87 | // The type of basic IO manipulators (endl, ends, and flush) for 88 | // narrow streams. 89 | typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); 90 | 91 | public: 92 | // Constructs an empty Message. 93 | Message(); 94 | 95 | // Copy constructor. 96 | Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT 97 | *ss_ << msg.GetString(); 98 | } 99 | 100 | // Constructs a Message from a C-string. 101 | explicit Message(const char* str) : ss_(new ::std::stringstream) { 102 | *ss_ << str; 103 | } 104 | 105 | #if GTEST_OS_SYMBIAN 106 | // Streams a value (either a pointer or not) to this object. 107 | template 108 | inline Message& operator <<(const T& value) { 109 | StreamHelper(typename internal::is_pointer::type(), value); 110 | return *this; 111 | } 112 | #else 113 | // Streams a non-pointer value to this object. 114 | template 115 | inline Message& operator <<(const T& val) { 116 | // Some libraries overload << for STL containers. These 117 | // overloads are defined in the global namespace instead of ::std. 118 | // 119 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these 120 | // overloads are visible in either the std namespace or the global 121 | // namespace, but not other namespaces, including the testing 122 | // namespace which Google Test's Message class is in. 123 | // 124 | // To allow STL containers (and other types that has a << operator 125 | // defined in the global namespace) to be used in Google Test 126 | // assertions, testing::Message must access the custom << operator 127 | // from the global namespace. With this using declaration, 128 | // overloads of << defined in the global namespace and those 129 | // visible via Koenig lookup are both exposed in this function. 130 | using ::operator <<; 131 | *ss_ << val; 132 | return *this; 133 | } 134 | 135 | // Streams a pointer value to this object. 136 | // 137 | // This function is an overload of the previous one. When you 138 | // stream a pointer to a Message, this definition will be used as it 139 | // is more specialized. (The C++ Standard, section 140 | // [temp.func.order].) If you stream a non-pointer, then the 141 | // previous definition will be used. 142 | // 143 | // The reason for this overload is that streaming a NULL pointer to 144 | // ostream is undefined behavior. Depending on the compiler, you 145 | // may get "0", "(nil)", "(null)", or an access violation. To 146 | // ensure consistent result across compilers, we always treat NULL 147 | // as "(null)". 148 | template 149 | inline Message& operator <<(T* const& pointer) { // NOLINT 150 | if (pointer == NULL) { 151 | *ss_ << "(null)"; 152 | } else { 153 | *ss_ << pointer; 154 | } 155 | return *this; 156 | } 157 | #endif // GTEST_OS_SYMBIAN 158 | 159 | // Since the basic IO manipulators are overloaded for both narrow 160 | // and wide streams, we have to provide this specialized definition 161 | // of operator <<, even though its body is the same as the 162 | // templatized version above. Without this definition, streaming 163 | // endl or other basic IO manipulators to Message will confuse the 164 | // compiler. 165 | Message& operator <<(BasicNarrowIoManip val) { 166 | *ss_ << val; 167 | return *this; 168 | } 169 | 170 | // Instead of 1/0, we want to see true/false for bool values. 171 | Message& operator <<(bool b) { 172 | return *this << (b ? "true" : "false"); 173 | } 174 | 175 | // These two overloads allow streaming a wide C string to a Message 176 | // using the UTF-8 encoding. 177 | Message& operator <<(const wchar_t* wide_c_str); 178 | Message& operator <<(wchar_t* wide_c_str); 179 | 180 | #if GTEST_HAS_STD_WSTRING 181 | // Converts the given wide string to a narrow string using the UTF-8 182 | // encoding, and streams the result to this Message object. 183 | Message& operator <<(const ::std::wstring& wstr); 184 | #endif // GTEST_HAS_STD_WSTRING 185 | 186 | #if GTEST_HAS_GLOBAL_WSTRING 187 | // Converts the given wide string to a narrow string using the UTF-8 188 | // encoding, and streams the result to this Message object. 189 | Message& operator <<(const ::wstring& wstr); 190 | #endif // GTEST_HAS_GLOBAL_WSTRING 191 | 192 | // Gets the text streamed to this object so far as an std::string. 193 | // Each '\0' character in the buffer is replaced with "\\0". 194 | // 195 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 196 | std::string GetString() const; 197 | 198 | private: 199 | #if GTEST_OS_SYMBIAN 200 | // These are needed as the Nokia Symbian Compiler cannot decide between 201 | // const T& and const T* in a function template. The Nokia compiler _can_ 202 | // decide between class template specializations for T and T*, so a 203 | // tr1::type_traits-like is_pointer works, and we can overload on that. 204 | template 205 | inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) { 206 | if (pointer == NULL) { 207 | *ss_ << "(null)"; 208 | } else { 209 | *ss_ << pointer; 210 | } 211 | } 212 | template 213 | inline void StreamHelper(internal::false_type /*is_pointer*/, 214 | const T& value) { 215 | // See the comments in Message& operator <<(const T&) above for why 216 | // we need this using statement. 217 | using ::operator <<; 218 | *ss_ << value; 219 | } 220 | #endif // GTEST_OS_SYMBIAN 221 | 222 | // We'll hold the text streamed to this object here. 223 | const internal::scoped_ptr< ::std::stringstream> ss_; 224 | 225 | // We declare (but don't implement) this to prevent the compiler 226 | // from implementing the assignment operator. 227 | void operator=(const Message&); 228 | }; 229 | 230 | // Streams a Message to an ostream. 231 | inline std::ostream& operator <<(std::ostream& os, const Message& sb) { 232 | return os << sb.GetString(); 233 | } 234 | 235 | namespace internal { 236 | 237 | // Converts a streamable value to an std::string. A NULL pointer is 238 | // converted to "(null)". When the input value is a ::string, 239 | // ::std::string, ::wstring, or ::std::wstring object, each NUL 240 | // character in it is replaced with "\\0". 241 | template 242 | std::string StreamableToString(const T& streamable) { 243 | return (Message() << streamable).GetString(); 244 | } 245 | 246 | } // namespace internal 247 | } // namespace testing 248 | 249 | #endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 250 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Utilities for testing Google Test itself and code that uses Google Test 33 | // (e.g. frameworks built on top of Google Test). 34 | 35 | #ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 36 | #define GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 37 | 38 | #include "gtest/gtest.h" 39 | 40 | namespace testing { 41 | 42 | // This helper class can be used to mock out Google Test failure reporting 43 | // so that we can test Google Test or code that builds on Google Test. 44 | // 45 | // An object of this class appends a TestPartResult object to the 46 | // TestPartResultArray object given in the constructor whenever a Google Test 47 | // failure is reported. It can either intercept only failures that are 48 | // generated in the same thread that created this object or it can intercept 49 | // all generated failures. The scope of this mock object can be controlled with 50 | // the second argument to the two arguments constructor. 51 | class GTEST_API_ ScopedFakeTestPartResultReporter 52 | : public TestPartResultReporterInterface { 53 | public: 54 | // The two possible mocking modes of this object. 55 | enum InterceptMode { 56 | INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures. 57 | INTERCEPT_ALL_THREADS // Intercepts all failures. 58 | }; 59 | 60 | // The c'tor sets this object as the test part result reporter used 61 | // by Google Test. The 'result' parameter specifies where to report the 62 | // results. This reporter will only catch failures generated in the current 63 | // thread. DEPRECATED 64 | explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result); 65 | 66 | // Same as above, but you can choose the interception scope of this object. 67 | ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, 68 | TestPartResultArray* result); 69 | 70 | // The d'tor restores the previous test part result reporter. 71 | virtual ~ScopedFakeTestPartResultReporter(); 72 | 73 | // Appends the TestPartResult object to the TestPartResultArray 74 | // received in the constructor. 75 | // 76 | // This method is from the TestPartResultReporterInterface 77 | // interface. 78 | virtual void ReportTestPartResult(const TestPartResult& result); 79 | private: 80 | void Init(); 81 | 82 | const InterceptMode intercept_mode_; 83 | TestPartResultReporterInterface* old_reporter_; 84 | TestPartResultArray* const result_; 85 | 86 | GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); 87 | }; 88 | 89 | namespace internal { 90 | 91 | // A helper class for implementing EXPECT_FATAL_FAILURE() and 92 | // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given 93 | // TestPartResultArray contains exactly one failure that has the given 94 | // type and contains the given substring. If that's not the case, a 95 | // non-fatal failure will be generated. 96 | class GTEST_API_ SingleFailureChecker { 97 | public: 98 | // The constructor remembers the arguments. 99 | SingleFailureChecker(const TestPartResultArray* results, 100 | TestPartResult::Type type, const std::string& substr); 101 | ~SingleFailureChecker(); 102 | private: 103 | const TestPartResultArray* const results_; 104 | const TestPartResult::Type type_; 105 | const std::string substr_; 106 | 107 | GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); 108 | }; 109 | 110 | } // namespace internal 111 | 112 | } // namespace testing 113 | 114 | // A set of macros for testing Google Test assertions or code that's expected 115 | // to generate Google Test fatal failures. It verifies that the given 116 | // statement will cause exactly one fatal Google Test failure with 'substr' 117 | // being part of the failure message. 118 | // 119 | // There are two different versions of this macro. EXPECT_FATAL_FAILURE only 120 | // affects and considers failures generated in the current thread and 121 | // EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 122 | // 123 | // The verification of the assertion is done correctly even when the statement 124 | // throws an exception or aborts the current function. 125 | // 126 | // Known restrictions: 127 | // - 'statement' cannot reference local non-static variables or 128 | // non-static members of the current object. 129 | // - 'statement' cannot return a value. 130 | // - You cannot stream a failure message to this macro. 131 | // 132 | // Note that even though the implementations of the following two 133 | // macros are much alike, we cannot refactor them to use a common 134 | // helper macro, due to some peculiarity in how the preprocessor 135 | // works. The AcceptsMacroThatExpandsToUnprotectedComma test in 136 | // gtest_unittest.cc will fail to compile if we do that. 137 | #define EXPECT_FATAL_FAILURE(statement, substr) \ 138 | do { \ 139 | class GTestExpectFatalFailureHelper {\ 140 | public:\ 141 | static void Execute() { statement; }\ 142 | };\ 143 | ::testing::TestPartResultArray gtest_failures;\ 144 | ::testing::internal::SingleFailureChecker gtest_checker(\ 145 | >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 146 | {\ 147 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 148 | ::testing::ScopedFakeTestPartResultReporter:: \ 149 | INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 150 | GTestExpectFatalFailureHelper::Execute();\ 151 | }\ 152 | } while (::testing::internal::AlwaysFalse()) 153 | 154 | #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 155 | do { \ 156 | class GTestExpectFatalFailureHelper {\ 157 | public:\ 158 | static void Execute() { statement; }\ 159 | };\ 160 | ::testing::TestPartResultArray gtest_failures;\ 161 | ::testing::internal::SingleFailureChecker gtest_checker(\ 162 | >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 163 | {\ 164 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 165 | ::testing::ScopedFakeTestPartResultReporter:: \ 166 | INTERCEPT_ALL_THREADS, >est_failures);\ 167 | GTestExpectFatalFailureHelper::Execute();\ 168 | }\ 169 | } while (::testing::internal::AlwaysFalse()) 170 | 171 | // A macro for testing Google Test assertions or code that's expected to 172 | // generate Google Test non-fatal failures. It asserts that the given 173 | // statement will cause exactly one non-fatal Google Test failure with 'substr' 174 | // being part of the failure message. 175 | // 176 | // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only 177 | // affects and considers failures generated in the current thread and 178 | // EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 179 | // 180 | // 'statement' is allowed to reference local variables and members of 181 | // the current object. 182 | // 183 | // The verification of the assertion is done correctly even when the statement 184 | // throws an exception or aborts the current function. 185 | // 186 | // Known restrictions: 187 | // - You cannot stream a failure message to this macro. 188 | // 189 | // Note that even though the implementations of the following two 190 | // macros are much alike, we cannot refactor them to use a common 191 | // helper macro, due to some peculiarity in how the preprocessor 192 | // works. If we do that, the code won't compile when the user gives 193 | // EXPECT_NONFATAL_FAILURE() a statement that contains a macro that 194 | // expands to code containing an unprotected comma. The 195 | // AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc 196 | // catches that. 197 | // 198 | // For the same reason, we have to write 199 | // if (::testing::internal::AlwaysTrue()) { statement; } 200 | // instead of 201 | // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 202 | // to avoid an MSVC warning on unreachable code. 203 | #define EXPECT_NONFATAL_FAILURE(statement, substr) \ 204 | do {\ 205 | ::testing::TestPartResultArray gtest_failures;\ 206 | ::testing::internal::SingleFailureChecker gtest_checker(\ 207 | >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 208 | (substr));\ 209 | {\ 210 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 211 | ::testing::ScopedFakeTestPartResultReporter:: \ 212 | INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 213 | if (::testing::internal::AlwaysTrue()) { statement; }\ 214 | }\ 215 | } while (::testing::internal::AlwaysFalse()) 216 | 217 | #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 218 | do {\ 219 | ::testing::TestPartResultArray gtest_failures;\ 220 | ::testing::internal::SingleFailureChecker gtest_checker(\ 221 | >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 222 | (substr));\ 223 | {\ 224 | ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 225 | ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ 226 | >est_failures);\ 227 | if (::testing::internal::AlwaysTrue()) { statement; }\ 228 | }\ 229 | } while (::testing::internal::AlwaysFalse()) 230 | 231 | #endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 232 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | 33 | #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 34 | #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 35 | 36 | #include 37 | #include 38 | #include "gtest/internal/gtest-internal.h" 39 | #include "gtest/internal/gtest-string.h" 40 | 41 | namespace testing { 42 | 43 | // A copyable object representing the result of a test part (i.e. an 44 | // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). 45 | // 46 | // Don't inherit from TestPartResult as its destructor is not virtual. 47 | class GTEST_API_ TestPartResult { 48 | public: 49 | // The possible outcomes of a test part (i.e. an assertion or an 50 | // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). 51 | enum Type { 52 | kSuccess, // Succeeded. 53 | kNonFatalFailure, // Failed but the test can continue. 54 | kFatalFailure // Failed and the test should be terminated. 55 | }; 56 | 57 | // C'tor. TestPartResult does NOT have a default constructor. 58 | // Always use this constructor (with parameters) to create a 59 | // TestPartResult object. 60 | TestPartResult(Type a_type, 61 | const char* a_file_name, 62 | int a_line_number, 63 | const char* a_message) 64 | : type_(a_type), 65 | file_name_(a_file_name == NULL ? "" : a_file_name), 66 | line_number_(a_line_number), 67 | summary_(ExtractSummary(a_message)), 68 | message_(a_message) { 69 | } 70 | 71 | // Gets the outcome of the test part. 72 | Type type() const { return type_; } 73 | 74 | // Gets the name of the source file where the test part took place, or 75 | // NULL if it's unknown. 76 | const char* file_name() const { 77 | return file_name_.empty() ? NULL : file_name_.c_str(); 78 | } 79 | 80 | // Gets the line in the source file where the test part took place, 81 | // or -1 if it's unknown. 82 | int line_number() const { return line_number_; } 83 | 84 | // Gets the summary of the failure message. 85 | const char* summary() const { return summary_.c_str(); } 86 | 87 | // Gets the message associated with the test part. 88 | const char* message() const { return message_.c_str(); } 89 | 90 | // Returns true iff the test part passed. 91 | bool passed() const { return type_ == kSuccess; } 92 | 93 | // Returns true iff the test part failed. 94 | bool failed() const { return type_ != kSuccess; } 95 | 96 | // Returns true iff the test part non-fatally failed. 97 | bool nonfatally_failed() const { return type_ == kNonFatalFailure; } 98 | 99 | // Returns true iff the test part fatally failed. 100 | bool fatally_failed() const { return type_ == kFatalFailure; } 101 | 102 | private: 103 | Type type_; 104 | 105 | // Gets the summary of the failure message by omitting the stack 106 | // trace in it. 107 | static std::string ExtractSummary(const char* message); 108 | 109 | // The name of the source file where the test part took place, or 110 | // "" if the source file is unknown. 111 | std::string file_name_; 112 | // The line in the source file where the test part took place, or -1 113 | // if the line number is unknown. 114 | int line_number_; 115 | std::string summary_; // The test failure summary. 116 | std::string message_; // The test failure message. 117 | }; 118 | 119 | // Prints a TestPartResult object. 120 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result); 121 | 122 | // An array of TestPartResult objects. 123 | // 124 | // Don't inherit from TestPartResultArray as its destructor is not 125 | // virtual. 126 | class GTEST_API_ TestPartResultArray { 127 | public: 128 | TestPartResultArray() {} 129 | 130 | // Appends the given TestPartResult to the array. 131 | void Append(const TestPartResult& result); 132 | 133 | // Returns the TestPartResult at the given index (0-based). 134 | const TestPartResult& GetTestPartResult(int index) const; 135 | 136 | // Returns the number of TestPartResult objects in the array. 137 | int size() const; 138 | 139 | private: 140 | std::vector array_; 141 | 142 | GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); 143 | }; 144 | 145 | // This interface knows how to report a test part result. 146 | class TestPartResultReporterInterface { 147 | public: 148 | virtual ~TestPartResultReporterInterface() {} 149 | 150 | virtual void ReportTestPartResult(const TestPartResult& result) = 0; 151 | }; 152 | 153 | namespace internal { 154 | 155 | // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a 156 | // statement generates new fatal failures. To do so it registers itself as the 157 | // current test part result reporter. Besides checking if fatal failures were 158 | // reported, it only delegates the reporting to the former result reporter. 159 | // The original result reporter is restored in the destructor. 160 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 161 | class GTEST_API_ HasNewFatalFailureHelper 162 | : public TestPartResultReporterInterface { 163 | public: 164 | HasNewFatalFailureHelper(); 165 | virtual ~HasNewFatalFailureHelper(); 166 | virtual void ReportTestPartResult(const TestPartResult& result); 167 | bool has_new_fatal_failure() const { return has_new_fatal_failure_; } 168 | private: 169 | bool has_new_fatal_failure_; 170 | TestPartResultReporterInterface* original_reporter_; 171 | 172 | GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); 173 | }; 174 | 175 | } // namespace internal 176 | 177 | } // namespace testing 178 | 179 | #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 180 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest-typed-test.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 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ 33 | #define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ 34 | 35 | // This header implements typed tests and type-parameterized tests. 36 | 37 | // Typed (aka type-driven) tests repeat the same test for types in a 38 | // list. You must know which types you want to test with when writing 39 | // typed tests. Here's how you do it: 40 | 41 | #if 0 42 | 43 | // First, define a fixture class template. It should be parameterized 44 | // by a type. Remember to derive it from testing::Test. 45 | template 46 | class FooTest : public testing::Test { 47 | public: 48 | ... 49 | typedef std::list List; 50 | static T shared_; 51 | T value_; 52 | }; 53 | 54 | // Next, associate a list of types with the test case, which will be 55 | // repeated for each type in the list. The typedef is necessary for 56 | // the macro to parse correctly. 57 | typedef testing::Types MyTypes; 58 | TYPED_TEST_CASE(FooTest, MyTypes); 59 | 60 | // If the type list contains only one type, you can write that type 61 | // directly without Types<...>: 62 | // TYPED_TEST_CASE(FooTest, int); 63 | 64 | // Then, use TYPED_TEST() instead of TEST_F() to define as many typed 65 | // tests for this test case as you want. 66 | TYPED_TEST(FooTest, DoesBlah) { 67 | // Inside a test, refer to TypeParam to get the type parameter. 68 | // Since we are inside a derived class template, C++ requires use to 69 | // visit the members of FooTest via 'this'. 70 | TypeParam n = this->value_; 71 | 72 | // To visit static members of the fixture, add the TestFixture:: 73 | // prefix. 74 | n += TestFixture::shared_; 75 | 76 | // To refer to typedefs in the fixture, add the "typename 77 | // TestFixture::" prefix. 78 | typename TestFixture::List values; 79 | values.push_back(n); 80 | ... 81 | } 82 | 83 | TYPED_TEST(FooTest, HasPropertyA) { ... } 84 | 85 | #endif // 0 86 | 87 | // Type-parameterized tests are abstract test patterns parameterized 88 | // by a type. Compared with typed tests, type-parameterized tests 89 | // allow you to define the test pattern without knowing what the type 90 | // parameters are. The defined pattern can be instantiated with 91 | // different types any number of times, in any number of translation 92 | // units. 93 | // 94 | // If you are designing an interface or concept, you can define a 95 | // suite of type-parameterized tests to verify properties that any 96 | // valid implementation of the interface/concept should have. Then, 97 | // each implementation can easily instantiate the test suite to verify 98 | // that it conforms to the requirements, without having to write 99 | // similar tests repeatedly. Here's an example: 100 | 101 | #if 0 102 | 103 | // First, define a fixture class template. It should be parameterized 104 | // by a type. Remember to derive it from testing::Test. 105 | template 106 | class FooTest : public testing::Test { 107 | ... 108 | }; 109 | 110 | // Next, declare that you will define a type-parameterized test case 111 | // (the _P suffix is for "parameterized" or "pattern", whichever you 112 | // prefer): 113 | TYPED_TEST_CASE_P(FooTest); 114 | 115 | // Then, use TYPED_TEST_P() to define as many type-parameterized tests 116 | // for this type-parameterized test case as you want. 117 | TYPED_TEST_P(FooTest, DoesBlah) { 118 | // Inside a test, refer to TypeParam to get the type parameter. 119 | TypeParam n = 0; 120 | ... 121 | } 122 | 123 | TYPED_TEST_P(FooTest, HasPropertyA) { ... } 124 | 125 | // Now the tricky part: you need to register all test patterns before 126 | // you can instantiate them. The first argument of the macro is the 127 | // test case name; the rest are the names of the tests in this test 128 | // case. 129 | REGISTER_TYPED_TEST_CASE_P(FooTest, 130 | DoesBlah, HasPropertyA); 131 | 132 | // Finally, you are free to instantiate the pattern with the types you 133 | // want. If you put the above code in a header file, you can #include 134 | // it in multiple C++ source files and instantiate it multiple times. 135 | // 136 | // To distinguish different instances of the pattern, the first 137 | // argument to the INSTANTIATE_* macro is a prefix that will be added 138 | // to the actual test case name. Remember to pick unique prefixes for 139 | // different instances. 140 | typedef testing::Types MyTypes; 141 | INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); 142 | 143 | // If the type list contains only one type, you can write that type 144 | // directly without Types<...>: 145 | // INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int); 146 | 147 | #endif // 0 148 | 149 | #include "gtest/internal/gtest-port.h" 150 | #include "gtest/internal/gtest-type-util.h" 151 | 152 | // Implements typed tests. 153 | 154 | #if GTEST_HAS_TYPED_TEST 155 | 156 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 157 | // 158 | // Expands to the name of the typedef for the type parameters of the 159 | // given test case. 160 | # define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_ 161 | 162 | // The 'Types' template argument below must have spaces around it 163 | // since some compilers may choke on '>>' when passing a template 164 | // instance (e.g. Types) 165 | # define TYPED_TEST_CASE(CaseName, Types) \ 166 | typedef ::testing::internal::TypeList< Types >::type \ 167 | GTEST_TYPE_PARAMS_(CaseName) 168 | 169 | # define TYPED_TEST(CaseName, TestName) \ 170 | template \ 171 | class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ 172 | : public CaseName { \ 173 | private: \ 174 | typedef CaseName TestFixture; \ 175 | typedef gtest_TypeParam_ TypeParam; \ 176 | virtual void TestBody(); \ 177 | }; \ 178 | bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \ 179 | ::testing::internal::TypeParameterizedTest< \ 180 | CaseName, \ 181 | ::testing::internal::TemplateSel< \ 182 | GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \ 183 | GTEST_TYPE_PARAMS_(CaseName)>::Register(\ 184 | "", ::testing::internal::CodeLocation(__FILE__, __LINE__), \ 185 | #CaseName, #TestName, 0); \ 186 | template \ 187 | void GTEST_TEST_CLASS_NAME_(CaseName, TestName)::TestBody() 188 | 189 | #endif // GTEST_HAS_TYPED_TEST 190 | 191 | // Implements type-parameterized tests. 192 | 193 | #if GTEST_HAS_TYPED_TEST_P 194 | 195 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 196 | // 197 | // Expands to the namespace name that the type-parameterized tests for 198 | // the given type-parameterized test case are defined in. The exact 199 | // name of the namespace is subject to change without notice. 200 | # define GTEST_CASE_NAMESPACE_(TestCaseName) \ 201 | gtest_case_##TestCaseName##_ 202 | 203 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 204 | // 205 | // Expands to the name of the variable used to remember the names of 206 | // the defined tests in the given test case. 207 | # define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \ 208 | gtest_typed_test_case_p_state_##TestCaseName##_ 209 | 210 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY. 211 | // 212 | // Expands to the name of the variable used to remember the names of 213 | // the registered tests in the given test case. 214 | # define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \ 215 | gtest_registered_test_names_##TestCaseName##_ 216 | 217 | // The variables defined in the type-parameterized test macros are 218 | // static as typically these macros are used in a .h file that can be 219 | // #included in multiple translation units linked together. 220 | # define TYPED_TEST_CASE_P(CaseName) \ 221 | static ::testing::internal::TypedTestCasePState \ 222 | GTEST_TYPED_TEST_CASE_P_STATE_(CaseName) 223 | 224 | # define TYPED_TEST_P(CaseName, TestName) \ 225 | namespace GTEST_CASE_NAMESPACE_(CaseName) { \ 226 | template \ 227 | class TestName : public CaseName { \ 228 | private: \ 229 | typedef CaseName TestFixture; \ 230 | typedef gtest_TypeParam_ TypeParam; \ 231 | virtual void TestBody(); \ 232 | }; \ 233 | static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ 234 | GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\ 235 | __FILE__, __LINE__, #CaseName, #TestName); \ 236 | } \ 237 | template \ 238 | void GTEST_CASE_NAMESPACE_(CaseName)::TestName::TestBody() 239 | 240 | # define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \ 241 | namespace GTEST_CASE_NAMESPACE_(CaseName) { \ 242 | typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \ 243 | } \ 244 | static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \ 245 | GTEST_ATTRIBUTE_UNUSED_ = \ 246 | GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames( \ 247 | __FILE__, __LINE__, #__VA_ARGS__) 248 | 249 | // The 'Types' template argument below must have spaces around it 250 | // since some compilers may choke on '>>' when passing a template 251 | // instance (e.g. Types) 252 | # define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ 253 | bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \ 254 | ::testing::internal::TypeParameterizedTestCase::type>::Register(\ 257 | #Prefix, \ 258 | ::testing::internal::CodeLocation(__FILE__, __LINE__), \ 259 | >EST_TYPED_TEST_CASE_P_STATE_(CaseName), \ 260 | #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName)) 261 | 262 | #endif // GTEST_HAS_TYPED_TEST_P 263 | 264 | #endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ 265 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /test/gtest/include/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. 31 | // The following macros can be defined: 32 | // 33 | // Flag related macros: 34 | // GTEST_FLAG(flag_name) 35 | // GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its 36 | // own flagfile flag parsing. 37 | // GTEST_DECLARE_bool_(name) 38 | // GTEST_DECLARE_int32_(name) 39 | // GTEST_DECLARE_string_(name) 40 | // GTEST_DEFINE_bool_(name, default_val, doc) 41 | // GTEST_DEFINE_int32_(name, default_val, doc) 42 | // GTEST_DEFINE_string_(name, default_val, doc) 43 | // 44 | // Test filtering: 45 | // GTEST_TEST_FILTER_ENV_VAR_ - The name of an environment variable that 46 | // will be used if --GTEST_FLAG(test_filter) 47 | // is not provided. 48 | // 49 | // Logging: 50 | // GTEST_LOG_(severity) 51 | // GTEST_CHECK_(condition) 52 | // Functions LogToStderr() and FlushInfoLog() have to be provided too. 53 | // 54 | // Threading: 55 | // GTEST_HAS_NOTIFICATION_ - Enabled if Notification is already provided. 56 | // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Enabled if Mutex and ThreadLocal are 57 | // already provided. 58 | // Must also provide GTEST_DECLARE_STATIC_MUTEX_(mutex) and 59 | // GTEST_DEFINE_STATIC_MUTEX_(mutex) 60 | // 61 | // GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) 62 | // GTEST_LOCK_EXCLUDED_(locks) 63 | // 64 | // Underlying library support features: 65 | // GTEST_HAS_CXXABI_H_ 66 | // 67 | // Exporting API symbols: 68 | // GTEST_API_ - Specifier for exported symbols. 69 | // 70 | // ** Custom implementation starts here ** 71 | 72 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 73 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 74 | 75 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 76 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // See documentation at gtest/gtest-printers.h for details on how to define a 35 | // custom printer. 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /test/gtest/include/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. 31 | // The following macros can be defined: 32 | // 33 | // GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of 34 | // OsStackTraceGetterInterface. 35 | // 36 | // GTEST_CUSTOM_TEMPDIR_FUNCTION_ - An override for testing::TempDir(). 37 | // See testing::TempDir for semantics and 38 | // signature. 39 | // 40 | // ** Custom implementation starts here ** 41 | 42 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 43 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 44 | 45 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 46 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-death-test-internal.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 | // 31 | // The Google C++ Testing Framework (Google Test) 32 | // 33 | // This header file defines internal utilities needed for implementing 34 | // death tests. They are subject to change without notice. 35 | 36 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 37 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 38 | 39 | #include "gtest/internal/gtest-internal.h" 40 | 41 | #include 42 | 43 | namespace testing { 44 | namespace internal { 45 | 46 | GTEST_DECLARE_string_(internal_run_death_test); 47 | 48 | // Names of the flags (needed for parsing Google Test flags). 49 | const char kDeathTestStyleFlag[] = "death_test_style"; 50 | const char kDeathTestUseFork[] = "death_test_use_fork"; 51 | const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; 52 | 53 | #if GTEST_HAS_DEATH_TEST 54 | 55 | // DeathTest is a class that hides much of the complexity of the 56 | // GTEST_DEATH_TEST_ macro. It is abstract; its static Create method 57 | // returns a concrete class that depends on the prevailing death test 58 | // style, as defined by the --gtest_death_test_style and/or 59 | // --gtest_internal_run_death_test flags. 60 | 61 | // In describing the results of death tests, these terms are used with 62 | // the corresponding definitions: 63 | // 64 | // exit status: The integer exit information in the format specified 65 | // by wait(2) 66 | // exit code: The integer code passed to exit(3), _exit(2), or 67 | // returned from main() 68 | class GTEST_API_ DeathTest { 69 | public: 70 | // Create returns false if there was an error determining the 71 | // appropriate action to take for the current death test; for example, 72 | // if the gtest_death_test_style flag is set to an invalid value. 73 | // The LastMessage method will return a more detailed message in that 74 | // case. Otherwise, the DeathTest pointer pointed to by the "test" 75 | // argument is set. If the death test should be skipped, the pointer 76 | // is set to NULL; otherwise, it is set to the address of a new concrete 77 | // DeathTest object that controls the execution of the current test. 78 | static bool Create(const char* statement, const RE* regex, 79 | const char* file, int line, DeathTest** test); 80 | DeathTest(); 81 | virtual ~DeathTest() { } 82 | 83 | // A helper class that aborts a death test when it's deleted. 84 | class ReturnSentinel { 85 | public: 86 | explicit ReturnSentinel(DeathTest* test) : test_(test) { } 87 | ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); } 88 | private: 89 | DeathTest* const test_; 90 | GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); 91 | } GTEST_ATTRIBUTE_UNUSED_; 92 | 93 | // An enumeration of possible roles that may be taken when a death 94 | // test is encountered. EXECUTE means that the death test logic should 95 | // be executed immediately. OVERSEE means that the program should prepare 96 | // the appropriate environment for a child process to execute the death 97 | // test, then wait for it to complete. 98 | enum TestRole { OVERSEE_TEST, EXECUTE_TEST }; 99 | 100 | // An enumeration of the three reasons that a test might be aborted. 101 | enum AbortReason { 102 | TEST_ENCOUNTERED_RETURN_STATEMENT, 103 | TEST_THREW_EXCEPTION, 104 | TEST_DID_NOT_DIE 105 | }; 106 | 107 | // Assumes one of the above roles. 108 | virtual TestRole AssumeRole() = 0; 109 | 110 | // Waits for the death test to finish and returns its status. 111 | virtual int Wait() = 0; 112 | 113 | // Returns true if the death test passed; that is, the test process 114 | // exited during the test, its exit status matches a user-supplied 115 | // predicate, and its stderr output matches a user-supplied regular 116 | // expression. 117 | // The user-supplied predicate may be a macro expression rather 118 | // than a function pointer or functor, or else Wait and Passed could 119 | // be combined. 120 | virtual bool Passed(bool exit_status_ok) = 0; 121 | 122 | // Signals that the death test did not die as expected. 123 | virtual void Abort(AbortReason reason) = 0; 124 | 125 | // Returns a human-readable outcome message regarding the outcome of 126 | // the last death test. 127 | static const char* LastMessage(); 128 | 129 | static void set_last_death_test_message(const std::string& message); 130 | 131 | private: 132 | // A string containing a description of the outcome of the last death test. 133 | static std::string last_death_test_message_; 134 | 135 | GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); 136 | }; 137 | 138 | // Factory interface for death tests. May be mocked out for testing. 139 | class DeathTestFactory { 140 | public: 141 | virtual ~DeathTestFactory() { } 142 | virtual bool Create(const char* statement, const RE* regex, 143 | const char* file, int line, DeathTest** test) = 0; 144 | }; 145 | 146 | // A concrete DeathTestFactory implementation for normal use. 147 | class DefaultDeathTestFactory : public DeathTestFactory { 148 | public: 149 | virtual bool Create(const char* statement, const RE* regex, 150 | const char* file, int line, DeathTest** test); 151 | }; 152 | 153 | // Returns true if exit_status describes a process that was terminated 154 | // by a signal, or exited normally with a nonzero exit code. 155 | GTEST_API_ bool ExitedUnsuccessfully(int exit_status); 156 | 157 | // Traps C++ exceptions escaping statement and reports them as test 158 | // failures. Note that trapping SEH exceptions is not implemented here. 159 | # if GTEST_HAS_EXCEPTIONS 160 | # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 161 | try { \ 162 | GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 163 | } catch (const ::std::exception& gtest_exception) { \ 164 | fprintf(\ 165 | stderr, \ 166 | "\n%s: Caught std::exception-derived exception escaping the " \ 167 | "death test statement. Exception message: %s\n", \ 168 | ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ 169 | gtest_exception.what()); \ 170 | fflush(stderr); \ 171 | death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 172 | } catch (...) { \ 173 | death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 174 | } 175 | 176 | # else 177 | # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 178 | GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 179 | 180 | # endif 181 | 182 | // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, 183 | // ASSERT_EXIT*, and EXPECT_EXIT*. 184 | # define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ 185 | GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 186 | if (::testing::internal::AlwaysTrue()) { \ 187 | const ::testing::internal::RE& gtest_regex = (regex); \ 188 | ::testing::internal::DeathTest* gtest_dt; \ 189 | if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ 190 | __FILE__, __LINE__, >est_dt)) { \ 191 | goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 192 | } \ 193 | if (gtest_dt != NULL) { \ 194 | ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ 195 | gtest_dt_ptr(gtest_dt); \ 196 | switch (gtest_dt->AssumeRole()) { \ 197 | case ::testing::internal::DeathTest::OVERSEE_TEST: \ 198 | if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ 199 | goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 200 | } \ 201 | break; \ 202 | case ::testing::internal::DeathTest::EXECUTE_TEST: { \ 203 | ::testing::internal::DeathTest::ReturnSentinel \ 204 | gtest_sentinel(gtest_dt); \ 205 | GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ 206 | gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ 207 | break; \ 208 | } \ 209 | default: \ 210 | break; \ 211 | } \ 212 | } \ 213 | } else \ 214 | GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ 215 | fail(::testing::internal::DeathTest::LastMessage()) 216 | // The symbol "fail" here expands to something into which a message 217 | // can be streamed. 218 | 219 | // This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in 220 | // NDEBUG mode. In this case we need the statements to be executed, the regex is 221 | // ignored, and the macro must accept a streamed message even though the message 222 | // is never printed. 223 | # define GTEST_EXECUTE_STATEMENT_(statement, regex) \ 224 | GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 225 | if (::testing::internal::AlwaysTrue()) { \ 226 | GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 227 | } else \ 228 | ::testing::Message() 229 | 230 | // A class representing the parsed contents of the 231 | // --gtest_internal_run_death_test flag, as it existed when 232 | // RUN_ALL_TESTS was called. 233 | class InternalRunDeathTestFlag { 234 | public: 235 | InternalRunDeathTestFlag(const std::string& a_file, 236 | int a_line, 237 | int an_index, 238 | int a_write_fd) 239 | : file_(a_file), line_(a_line), index_(an_index), 240 | write_fd_(a_write_fd) {} 241 | 242 | ~InternalRunDeathTestFlag() { 243 | if (write_fd_ >= 0) 244 | posix::Close(write_fd_); 245 | } 246 | 247 | const std::string& file() const { return file_; } 248 | int line() const { return line_; } 249 | int index() const { return index_; } 250 | int write_fd() const { return write_fd_; } 251 | 252 | private: 253 | std::string file_; 254 | int line_; 255 | int index_; 256 | int write_fd_; 257 | 258 | GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); 259 | }; 260 | 261 | // Returns a newly created InternalRunDeathTestFlag object with fields 262 | // initialized from the GTEST_FLAG(internal_run_death_test) flag if 263 | // the flag is specified; otherwise returns NULL. 264 | InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); 265 | 266 | #endif // GTEST_HAS_DEATH_TEST 267 | 268 | } // namespace internal 269 | } // namespace testing 270 | 271 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 272 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // 31 | // Google Test filepath utilities 32 | // 33 | // This header file declares classes and functions used internally by 34 | // Google Test. They are subject to change without notice. 35 | // 36 | // This file is #included in gtest/internal/gtest-internal.h. 37 | // Do not include this header file separately! 38 | 39 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 40 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 41 | 42 | #include "gtest/internal/gtest-string.h" 43 | 44 | namespace testing { 45 | namespace internal { 46 | 47 | // FilePath - a class for file and directory pathname manipulation which 48 | // handles platform-specific conventions (like the pathname separator). 49 | // Used for helper functions for naming files in a directory for xml output. 50 | // Except for Set methods, all methods are const or static, which provides an 51 | // "immutable value object" -- useful for peace of mind. 52 | // A FilePath with a value ending in a path separator ("like/this/") represents 53 | // a directory, otherwise it is assumed to represent a file. In either case, 54 | // it may or may not represent an actual file or directory in the file system. 55 | // Names are NOT checked for syntax correctness -- no checking for illegal 56 | // characters, malformed paths, etc. 57 | 58 | class GTEST_API_ FilePath { 59 | public: 60 | FilePath() : pathname_("") { } 61 | FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } 62 | 63 | explicit FilePath(const std::string& pathname) : pathname_(pathname) { 64 | Normalize(); 65 | } 66 | 67 | FilePath& operator=(const FilePath& rhs) { 68 | Set(rhs); 69 | return *this; 70 | } 71 | 72 | void Set(const FilePath& rhs) { 73 | pathname_ = rhs.pathname_; 74 | } 75 | 76 | const std::string& string() const { return pathname_; } 77 | const char* c_str() const { return pathname_.c_str(); } 78 | 79 | // Returns the current working directory, or "" if unsuccessful. 80 | static FilePath GetCurrentDir(); 81 | 82 | // Given directory = "dir", base_name = "test", number = 0, 83 | // extension = "xml", returns "dir/test.xml". If number is greater 84 | // than zero (e.g., 12), returns "dir/test_12.xml". 85 | // On Windows platform, uses \ as the separator rather than /. 86 | static FilePath MakeFileName(const FilePath& directory, 87 | const FilePath& base_name, 88 | int number, 89 | const char* extension); 90 | 91 | // Given directory = "dir", relative_path = "test.xml", 92 | // returns "dir/test.xml". 93 | // On Windows, uses \ as the separator rather than /. 94 | static FilePath ConcatPaths(const FilePath& directory, 95 | const FilePath& relative_path); 96 | 97 | // Returns a pathname for a file that does not currently exist. The pathname 98 | // will be directory/base_name.extension or 99 | // directory/base_name_.extension if directory/base_name.extension 100 | // already exists. The number will be incremented until a pathname is found 101 | // that does not already exist. 102 | // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. 103 | // There could be a race condition if two or more processes are calling this 104 | // function at the same time -- they could both pick the same filename. 105 | static FilePath GenerateUniqueFileName(const FilePath& directory, 106 | const FilePath& base_name, 107 | const char* extension); 108 | 109 | // Returns true iff the path is "". 110 | bool IsEmpty() const { return pathname_.empty(); } 111 | 112 | // If input name has a trailing separator character, removes it and returns 113 | // the name, otherwise return the name string unmodified. 114 | // On Windows platform, uses \ as the separator, other platforms use /. 115 | FilePath RemoveTrailingPathSeparator() const; 116 | 117 | // Returns a copy of the FilePath with the directory part removed. 118 | // Example: FilePath("path/to/file").RemoveDirectoryName() returns 119 | // FilePath("file"). If there is no directory part ("just_a_file"), it returns 120 | // the FilePath unmodified. If there is no file part ("just_a_dir/") it 121 | // returns an empty FilePath (""). 122 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 123 | FilePath RemoveDirectoryName() const; 124 | 125 | // RemoveFileName returns the directory path with the filename removed. 126 | // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". 127 | // If the FilePath is "a_file" or "/a_file", RemoveFileName returns 128 | // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does 129 | // not have a file, like "just/a/dir/", it returns the FilePath unmodified. 130 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 131 | FilePath RemoveFileName() const; 132 | 133 | // Returns a copy of the FilePath with the case-insensitive extension removed. 134 | // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns 135 | // FilePath("dir/file"). If a case-insensitive extension is not 136 | // found, returns a copy of the original FilePath. 137 | FilePath RemoveExtension(const char* extension) const; 138 | 139 | // Creates directories so that path exists. Returns true if successful or if 140 | // the directories already exist; returns false if unable to create 141 | // directories for any reason. Will also return false if the FilePath does 142 | // not represent a directory (that is, it doesn't end with a path separator). 143 | bool CreateDirectoriesRecursively() const; 144 | 145 | // Create the directory so that path exists. Returns true if successful or 146 | // if the directory already exists; returns false if unable to create the 147 | // directory for any reason, including if the parent directory does not 148 | // exist. Not named "CreateDirectory" because that's a macro on Windows. 149 | bool CreateFolder() const; 150 | 151 | // Returns true if FilePath describes something in the file-system, 152 | // either a file, directory, or whatever, and that something exists. 153 | bool FileOrDirectoryExists() const; 154 | 155 | // Returns true if pathname describes a directory in the file-system 156 | // that exists. 157 | bool DirectoryExists() const; 158 | 159 | // Returns true if FilePath ends with a path separator, which indicates that 160 | // it is intended to represent a directory. Returns false otherwise. 161 | // This does NOT check that a directory (or file) actually exists. 162 | bool IsDirectory() const; 163 | 164 | // Returns true if pathname describes a root directory. (Windows has one 165 | // root directory per disk drive.) 166 | bool IsRootDirectory() const; 167 | 168 | // Returns true if pathname describes an absolute path. 169 | bool IsAbsolutePath() const; 170 | 171 | private: 172 | // Replaces multiple consecutive separators with a single separator. 173 | // For example, "bar///foo" becomes "bar/foo". Does not eliminate other 174 | // redundancies that might be in a pathname involving "." or "..". 175 | // 176 | // A pathname with multiple consecutive separators may occur either through 177 | // user error or as a result of some scripts or APIs that generate a pathname 178 | // with a trailing separator. On other platforms the same API or script 179 | // may NOT generate a pathname with a trailing "/". Then elsewhere that 180 | // pathname may have another "/" and pathname components added to it, 181 | // without checking for the separator already being there. 182 | // The script language and operating system may allow paths like "foo//bar" 183 | // but some of the functions in FilePath will not handle that correctly. In 184 | // particular, RemoveTrailingPathSeparator() only removes one separator, and 185 | // it is called in CreateDirectoriesRecursively() assuming that it will change 186 | // a pathname from directory syntax (trailing separator) to filename syntax. 187 | // 188 | // On Windows this method also replaces the alternate path separator '/' with 189 | // the primary path separator '\\', so that for example "bar\\/\\foo" becomes 190 | // "bar\\foo". 191 | 192 | void Normalize(); 193 | 194 | // Returns a pointer to the last occurence of a valid path separator in 195 | // the FilePath. On Windows, for example, both '/' and '\' are valid path 196 | // separators. Returns NULL if no path separator was found. 197 | const char* FindLastPathSeparator() const; 198 | 199 | std::string pathname_; 200 | }; // class FilePath 201 | 202 | } // namespace internal 203 | } // namespace testing 204 | 205 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 206 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-linked_ptr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2003 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 | // Authors: Dan Egnor (egnor@google.com) 31 | // 32 | // A "smart" pointer type with reference tracking. Every pointer to a 33 | // particular object is kept on a circular linked list. When the last pointer 34 | // to an object is destroyed or reassigned, the object is deleted. 35 | // 36 | // Used properly, this deletes the object when the last reference goes away. 37 | // There are several caveats: 38 | // - Like all reference counting schemes, cycles lead to leaks. 39 | // - Each smart pointer is actually two pointers (8 bytes instead of 4). 40 | // - Every time a pointer is assigned, the entire list of pointers to that 41 | // object is traversed. This class is therefore NOT SUITABLE when there 42 | // will often be more than two or three pointers to a particular object. 43 | // - References are only tracked as long as linked_ptr<> objects are copied. 44 | // If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS 45 | // will happen (double deletion). 46 | // 47 | // A good use of this class is storing object references in STL containers. 48 | // You can safely put linked_ptr<> in a vector<>. 49 | // Other uses may not be as good. 50 | // 51 | // Note: If you use an incomplete type with linked_ptr<>, the class 52 | // *containing* linked_ptr<> must have a constructor and destructor (even 53 | // if they do nothing!). 54 | // 55 | // Bill Gibbons suggested we use something like this. 56 | // 57 | // Thread Safety: 58 | // Unlike other linked_ptr implementations, in this implementation 59 | // a linked_ptr object is thread-safe in the sense that: 60 | // - it's safe to copy linked_ptr objects concurrently, 61 | // - it's safe to copy *from* a linked_ptr and read its underlying 62 | // raw pointer (e.g. via get()) concurrently, and 63 | // - it's safe to write to two linked_ptrs that point to the same 64 | // shared object concurrently. 65 | // TODO(wan@google.com): rename this to safe_linked_ptr to avoid 66 | // confusion with normal linked_ptr. 67 | 68 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 69 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 70 | 71 | #include 72 | #include 73 | 74 | #include "gtest/internal/gtest-port.h" 75 | 76 | namespace testing { 77 | namespace internal { 78 | 79 | // Protects copying of all linked_ptr objects. 80 | GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex); 81 | 82 | // This is used internally by all instances of linked_ptr<>. It needs to be 83 | // a non-template class because different types of linked_ptr<> can refer to 84 | // the same object (linked_ptr(obj) vs linked_ptr(obj)). 85 | // So, it needs to be possible for different types of linked_ptr to participate 86 | // in the same circular linked list, so we need a single class type here. 87 | // 88 | // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr. 89 | class linked_ptr_internal { 90 | public: 91 | // Create a new circle that includes only this instance. 92 | void join_new() { 93 | next_ = this; 94 | } 95 | 96 | // Many linked_ptr operations may change p.link_ for some linked_ptr 97 | // variable p in the same circle as this object. Therefore we need 98 | // to prevent two such operations from occurring concurrently. 99 | // 100 | // Note that different types of linked_ptr objects can coexist in a 101 | // circle (e.g. linked_ptr, linked_ptr, and 102 | // linked_ptr). Therefore we must use a single mutex to 103 | // protect all linked_ptr objects. This can create serious 104 | // contention in production code, but is acceptable in a testing 105 | // framework. 106 | 107 | // Join an existing circle. 108 | void join(linked_ptr_internal const* ptr) 109 | GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { 110 | MutexLock lock(&g_linked_ptr_mutex); 111 | 112 | linked_ptr_internal const* p = ptr; 113 | while (p->next_ != ptr) { 114 | assert(p->next_ != this && 115 | "Trying to join() a linked ring we are already in. " 116 | "Is GMock thread safety enabled?"); 117 | p = p->next_; 118 | } 119 | p->next_ = this; 120 | next_ = ptr; 121 | } 122 | 123 | // Leave whatever circle we're part of. Returns true if we were the 124 | // last member of the circle. Once this is done, you can join() another. 125 | bool depart() 126 | GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { 127 | MutexLock lock(&g_linked_ptr_mutex); 128 | 129 | if (next_ == this) return true; 130 | linked_ptr_internal const* p = next_; 131 | while (p->next_ != this) { 132 | assert(p->next_ != next_ && 133 | "Trying to depart() a linked ring we are not in. " 134 | "Is GMock thread safety enabled?"); 135 | p = p->next_; 136 | } 137 | p->next_ = next_; 138 | return false; 139 | } 140 | 141 | private: 142 | mutable linked_ptr_internal const* next_; 143 | }; 144 | 145 | template 146 | class linked_ptr { 147 | public: 148 | typedef T element_type; 149 | 150 | // Take over ownership of a raw pointer. This should happen as soon as 151 | // possible after the object is created. 152 | explicit linked_ptr(T* ptr = NULL) { capture(ptr); } 153 | ~linked_ptr() { depart(); } 154 | 155 | // Copy an existing linked_ptr<>, adding ourselves to the list of references. 156 | template linked_ptr(linked_ptr const& ptr) { copy(&ptr); } 157 | linked_ptr(linked_ptr const& ptr) { // NOLINT 158 | assert(&ptr != this); 159 | copy(&ptr); 160 | } 161 | 162 | // Assignment releases the old value and acquires the new. 163 | template linked_ptr& operator=(linked_ptr const& ptr) { 164 | depart(); 165 | copy(&ptr); 166 | return *this; 167 | } 168 | 169 | linked_ptr& operator=(linked_ptr const& ptr) { 170 | if (&ptr != this) { 171 | depart(); 172 | copy(&ptr); 173 | } 174 | return *this; 175 | } 176 | 177 | // Smart pointer members. 178 | void reset(T* ptr = NULL) { 179 | depart(); 180 | capture(ptr); 181 | } 182 | T* get() const { return value_; } 183 | T* operator->() const { return value_; } 184 | T& operator*() const { return *value_; } 185 | 186 | bool operator==(T* p) const { return value_ == p; } 187 | bool operator!=(T* p) const { return value_ != p; } 188 | template 189 | bool operator==(linked_ptr const& ptr) const { 190 | return value_ == ptr.get(); 191 | } 192 | template 193 | bool operator!=(linked_ptr const& ptr) const { 194 | return value_ != ptr.get(); 195 | } 196 | 197 | private: 198 | template 199 | friend class linked_ptr; 200 | 201 | T* value_; 202 | linked_ptr_internal link_; 203 | 204 | void depart() { 205 | if (link_.depart()) delete value_; 206 | } 207 | 208 | void capture(T* ptr) { 209 | value_ = ptr; 210 | link_.join_new(); 211 | } 212 | 213 | template void copy(linked_ptr const* ptr) { 214 | value_ = ptr->get(); 215 | if (value_) 216 | link_.join(&ptr->link_); 217 | else 218 | link_.join_new(); 219 | } 220 | }; 221 | 222 | template inline 223 | bool operator==(T* ptr, const linked_ptr& x) { 224 | return ptr == x.get(); 225 | } 226 | 227 | template inline 228 | bool operator!=(T* ptr, const linked_ptr& x) { 229 | return ptr != x.get(); 230 | } 231 | 232 | // A function to convert T* into linked_ptr 233 | // Doing e.g. make_linked_ptr(new FooBarBaz(arg)) is a shorter notation 234 | // for linked_ptr >(new FooBarBaz(arg)) 235 | template 236 | linked_ptr make_linked_ptr(T* ptr) { 237 | return linked_ptr(ptr); 238 | } 239 | 240 | } // namespace internal 241 | } // namespace testing 242 | 243 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 244 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-param-util-generated.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 50 $$ Maximum length of Values arguments we want to support. 3 | $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. 4 | // Copyright 2008 Google Inc. 5 | // All Rights Reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following disclaimer 15 | // in the documentation and/or other materials provided with the 16 | // distribution. 17 | // * Neither the name of Google Inc. nor the names of its 18 | // contributors may be used to endorse or promote products derived from 19 | // this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // Author: vladl@google.com (Vlad Losev) 34 | 35 | // Type and function utilities for implementing parameterized tests. 36 | // This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 37 | // 38 | // Currently Google Test supports at most $n arguments in Values, 39 | // and at most $maxtuple arguments in Combine. Please contact 40 | // googletestframework@googlegroups.com if you need more. 41 | // Please note that the number of arguments to Combine is limited 42 | // by the maximum arity of the implementation of tuple which is 43 | // currently set at $maxtuple. 44 | 45 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 46 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 47 | 48 | #include "gtest/internal/gtest-param-util.h" 49 | #include "gtest/internal/gtest-port.h" 50 | 51 | namespace testing { 52 | 53 | // Forward declarations of ValuesIn(), which is implemented in 54 | // include/gtest/gtest-param-test.h. 55 | template 56 | internal::ParamGenerator< 57 | typename ::testing::internal::IteratorTraits::value_type> 58 | ValuesIn(ForwardIterator begin, ForwardIterator end); 59 | 60 | template 61 | internal::ParamGenerator ValuesIn(const T (&array)[N]); 62 | 63 | template 64 | internal::ParamGenerator ValuesIn( 65 | const Container& container); 66 | 67 | namespace internal { 68 | 69 | // Used in the Values() function to provide polymorphic capabilities. 70 | $range i 1..n 71 | $for i [[ 72 | $range j 1..i 73 | 74 | template <$for j, [[typename T$j]]> 75 | class ValueArray$i { 76 | public: 77 | $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {} 78 | 79 | template 80 | operator ParamGenerator() const { 81 | const T array[] = {$for j, [[static_cast(v$(j)_)]]}; 82 | return ValuesIn(array); 83 | } 84 | 85 | private: 86 | // No implementation - assignment is unsupported. 87 | void operator=(const ValueArray$i& other); 88 | 89 | $for j [[ 90 | 91 | const T$j v$(j)_; 92 | ]] 93 | 94 | }; 95 | 96 | ]] 97 | 98 | # if GTEST_HAS_COMBINE 99 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 100 | // 101 | // Generates values from the Cartesian product of values produced 102 | // by the argument generators. 103 | // 104 | $range i 2..maxtuple 105 | $for i [[ 106 | $range j 1..i 107 | $range k 2..i 108 | 109 | template <$for j, [[typename T$j]]> 110 | class CartesianProductGenerator$i 111 | : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > { 112 | public: 113 | typedef ::testing::tuple<$for j, [[T$j]]> ParamType; 114 | 115 | CartesianProductGenerator$i($for j, [[const ParamGenerator& g$j]]) 116 | : $for j, [[g$(j)_(g$j)]] {} 117 | virtual ~CartesianProductGenerator$i() {} 118 | 119 | virtual ParamIteratorInterface* Begin() const { 120 | return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]); 121 | } 122 | virtual ParamIteratorInterface* End() const { 123 | return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]); 124 | } 125 | 126 | private: 127 | class Iterator : public ParamIteratorInterface { 128 | public: 129 | Iterator(const ParamGeneratorInterface* base, $for j, [[ 130 | 131 | const ParamGenerator& g$j, 132 | const typename ParamGenerator::iterator& current$(j)]]) 133 | : base_(base), 134 | $for j, [[ 135 | 136 | begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j) 137 | ]] { 138 | ComputeCurrentValue(); 139 | } 140 | virtual ~Iterator() {} 141 | 142 | virtual const ParamGeneratorInterface* BaseGenerator() const { 143 | return base_; 144 | } 145 | // Advance should not be called on beyond-of-range iterators 146 | // so no component iterators must be beyond end of range, either. 147 | virtual void Advance() { 148 | assert(!AtEnd()); 149 | ++current$(i)_; 150 | 151 | $for k [[ 152 | if (current$(i+2-k)_ == end$(i+2-k)_) { 153 | current$(i+2-k)_ = begin$(i+2-k)_; 154 | ++current$(i+2-k-1)_; 155 | } 156 | 157 | ]] 158 | ComputeCurrentValue(); 159 | } 160 | virtual ParamIteratorInterface* Clone() const { 161 | return new Iterator(*this); 162 | } 163 | virtual const ParamType* Current() const { return current_value_.get(); } 164 | virtual bool Equals(const ParamIteratorInterface& other) const { 165 | // Having the same base generator guarantees that the other 166 | // iterator is of the same type and we can downcast. 167 | GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) 168 | << "The program attempted to compare iterators " 169 | << "from different generators." << std::endl; 170 | const Iterator* typed_other = 171 | CheckedDowncastToActualType(&other); 172 | // We must report iterators equal if they both point beyond their 173 | // respective ranges. That can happen in a variety of fashions, 174 | // so we have to consult AtEnd(). 175 | return (AtEnd() && typed_other->AtEnd()) || 176 | ($for j && [[ 177 | 178 | current$(j)_ == typed_other->current$(j)_ 179 | ]]); 180 | } 181 | 182 | private: 183 | Iterator(const Iterator& other) 184 | : base_(other.base_), $for j, [[ 185 | 186 | begin$(j)_(other.begin$(j)_), 187 | end$(j)_(other.end$(j)_), 188 | current$(j)_(other.current$(j)_) 189 | ]] { 190 | ComputeCurrentValue(); 191 | } 192 | 193 | void ComputeCurrentValue() { 194 | if (!AtEnd()) 195 | current_value_.reset(new ParamType($for j, [[*current$(j)_]])); 196 | } 197 | bool AtEnd() const { 198 | // We must report iterator past the end of the range when either of the 199 | // component iterators has reached the end of its range. 200 | return 201 | $for j || [[ 202 | 203 | current$(j)_ == end$(j)_ 204 | ]]; 205 | } 206 | 207 | // No implementation - assignment is unsupported. 208 | void operator=(const Iterator& other); 209 | 210 | const ParamGeneratorInterface* const base_; 211 | // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. 212 | // current[i]_ is the actual traversing iterator. 213 | $for j [[ 214 | 215 | const typename ParamGenerator::iterator begin$(j)_; 216 | const typename ParamGenerator::iterator end$(j)_; 217 | typename ParamGenerator::iterator current$(j)_; 218 | ]] 219 | 220 | linked_ptr current_value_; 221 | }; // class CartesianProductGenerator$i::Iterator 222 | 223 | // No implementation - assignment is unsupported. 224 | void operator=(const CartesianProductGenerator$i& other); 225 | 226 | 227 | $for j [[ 228 | const ParamGenerator g$(j)_; 229 | 230 | ]] 231 | }; // class CartesianProductGenerator$i 232 | 233 | 234 | ]] 235 | 236 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 237 | // 238 | // Helper classes providing Combine() with polymorphic features. They allow 239 | // casting CartesianProductGeneratorN to ParamGenerator if T is 240 | // convertible to U. 241 | // 242 | $range i 2..maxtuple 243 | $for i [[ 244 | $range j 1..i 245 | 246 | template <$for j, [[class Generator$j]]> 247 | class CartesianProductHolder$i { 248 | public: 249 | CartesianProductHolder$i($for j, [[const Generator$j& g$j]]) 250 | : $for j, [[g$(j)_(g$j)]] {} 251 | template <$for j, [[typename T$j]]> 252 | operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const { 253 | return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >( 254 | new CartesianProductGenerator$i<$for j, [[T$j]]>( 255 | $for j,[[ 256 | 257 | static_cast >(g$(j)_) 258 | ]])); 259 | } 260 | 261 | private: 262 | // No implementation - assignment is unsupported. 263 | void operator=(const CartesianProductHolder$i& other); 264 | 265 | 266 | $for j [[ 267 | const Generator$j g$(j)_; 268 | 269 | ]] 270 | }; // class CartesianProductHolder$i 271 | 272 | ]] 273 | 274 | # endif // GTEST_HAS_COMBINE 275 | 276 | } // namespace internal 277 | } // namespace testing 278 | 279 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 280 | -------------------------------------------------------------------------------- /test/gtest/include/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 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 GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 36 | #define GTEST_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 __SYMBIAN32__ 42 | # define GTEST_OS_SYMBIAN 1 43 | #elif defined _WIN32 44 | # define GTEST_OS_WINDOWS 1 45 | # ifdef _WIN32_WCE 46 | # define GTEST_OS_WINDOWS_MOBILE 1 47 | # elif defined(__MINGW__) || defined(__MINGW32__) 48 | # define GTEST_OS_WINDOWS_MINGW 1 49 | # elif defined(WINAPI_FAMILY) 50 | # include 51 | # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 52 | # define GTEST_OS_WINDOWS_DESKTOP 1 53 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) 54 | # define GTEST_OS_WINDOWS_PHONE 1 55 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 56 | # define GTEST_OS_WINDOWS_RT 1 57 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) 58 | # define GTEST_OS_WINDOWS_PHONE 1 59 | # define GTEST_OS_WINDOWS_TV_TITLE 1 60 | # else 61 | // WINAPI_FAMILY defined but no known partition matched. 62 | // Default to desktop. 63 | # define GTEST_OS_WINDOWS_DESKTOP 1 64 | # endif 65 | # else 66 | # define GTEST_OS_WINDOWS_DESKTOP 1 67 | # endif // _WIN32_WCE 68 | #elif defined __APPLE__ 69 | # define GTEST_OS_MAC 1 70 | # if TARGET_OS_IPHONE 71 | # define GTEST_OS_IOS 1 72 | # endif 73 | #elif defined __FreeBSD__ 74 | # define GTEST_OS_FREEBSD 1 75 | #elif defined __Fuchsia__ 76 | # define GTEST_OS_FUCHSIA 1 77 | #elif defined __linux__ 78 | # define GTEST_OS_LINUX 1 79 | # if defined __ANDROID__ 80 | # define GTEST_OS_LINUX_ANDROID 1 81 | # endif 82 | #elif defined __MVS__ 83 | # define GTEST_OS_ZOS 1 84 | #elif defined(__sun) && defined(__SVR4) 85 | # define GTEST_OS_SOLARIS 1 86 | #elif defined(_AIX) 87 | # define GTEST_OS_AIX 1 88 | #elif defined(__hpux) 89 | # define GTEST_OS_HPUX 1 90 | #elif defined __native_client__ 91 | # define GTEST_OS_NACL 1 92 | #elif defined __NetBSD__ 93 | # define GTEST_OS_NETBSD 1 94 | #elif defined __OpenBSD__ 95 | # define GTEST_OS_OPENBSD 1 96 | #elif defined __QNX__ 97 | # define GTEST_OS_QNX 1 98 | #endif // __CYGWIN__ 99 | 100 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 101 | -------------------------------------------------------------------------------- /test/gtest/include/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 | // 31 | // The Google C++ Testing Framework (Google Test) 32 | // 33 | // This header file declares the String class and functions used internally by 34 | // Google Test. They are subject to change without notice. They should not used 35 | // by code external to Google Test. 36 | // 37 | // This header file is #included by 38 | // gtest/internal/gtest-internal.h. 39 | // It should not be #included by other files. 40 | 41 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 42 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 43 | 44 | #ifdef __BORLANDC__ 45 | // string.h is not guaranteed to provide strcpy on C++ Builder. 46 | # include 47 | #endif 48 | 49 | #include 50 | #include 51 | 52 | #include "gtest/internal/gtest-port.h" 53 | 54 | namespace testing { 55 | namespace internal { 56 | 57 | // String - an abstract class holding static string utilities. 58 | class GTEST_API_ String { 59 | public: 60 | // Static utility methods 61 | 62 | // Clones a 0-terminated C string, allocating memory using new. The 63 | // caller is responsible for deleting the return value using 64 | // delete[]. Returns the cloned string, or NULL if the input is 65 | // NULL. 66 | // 67 | // This is different from strdup() in string.h, which allocates 68 | // memory using malloc(). 69 | static const char* CloneCString(const char* c_str); 70 | 71 | #if GTEST_OS_WINDOWS_MOBILE 72 | // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be 73 | // able to pass strings to Win32 APIs on CE we need to convert them 74 | // to 'Unicode', UTF-16. 75 | 76 | // Creates a UTF-16 wide string from the given ANSI string, allocating 77 | // memory using new. The caller is responsible for deleting the return 78 | // value using delete[]. Returns the wide string, or NULL if the 79 | // input is NULL. 80 | // 81 | // The wide string is created using the ANSI codepage (CP_ACP) to 82 | // match the behaviour of the ANSI versions of Win32 calls and the 83 | // C runtime. 84 | static LPCWSTR AnsiToUtf16(const char* c_str); 85 | 86 | // Creates an ANSI string from the given wide string, allocating 87 | // memory using new. The caller is responsible for deleting the return 88 | // value using delete[]. Returns the ANSI string, or NULL if the 89 | // input is NULL. 90 | // 91 | // The returned string is created using the ANSI codepage (CP_ACP) to 92 | // match the behaviour of the ANSI versions of Win32 calls and the 93 | // C runtime. 94 | static const char* Utf16ToAnsi(LPCWSTR utf16_str); 95 | #endif 96 | 97 | // Compares two C strings. Returns true iff they have the same content. 98 | // 99 | // Unlike strcmp(), this function can handle NULL argument(s). A 100 | // NULL C string is considered different to any non-NULL C string, 101 | // including the empty string. 102 | static bool CStringEquals(const char* lhs, const char* rhs); 103 | 104 | // Converts a wide C string to a String using the UTF-8 encoding. 105 | // NULL will be converted to "(null)". If an error occurred during 106 | // the conversion, "(failed to convert from wide string)" is 107 | // returned. 108 | static std::string ShowWideCString(const wchar_t* wide_c_str); 109 | 110 | // Compares two wide C strings. Returns true iff they have the same 111 | // content. 112 | // 113 | // Unlike wcscmp(), this function can handle NULL argument(s). A 114 | // NULL C string is considered different to any non-NULL C string, 115 | // including the empty string. 116 | static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); 117 | 118 | // Compares two C strings, ignoring case. Returns true iff they 119 | // have the same content. 120 | // 121 | // Unlike strcasecmp(), this function can handle NULL argument(s). 122 | // A NULL C string is considered different to any non-NULL C string, 123 | // including the empty string. 124 | static bool CaseInsensitiveCStringEquals(const char* lhs, 125 | const char* rhs); 126 | 127 | // Compares two wide C strings, ignoring case. Returns true iff they 128 | // have the same content. 129 | // 130 | // Unlike wcscasecmp(), this function can handle NULL argument(s). 131 | // A NULL C string is considered different to any non-NULL wide C string, 132 | // including the empty string. 133 | // NB: The implementations on different platforms slightly differ. 134 | // On windows, this method uses _wcsicmp which compares according to LC_CTYPE 135 | // environment variable. On GNU platform this method uses wcscasecmp 136 | // which compares according to LC_CTYPE category of the current locale. 137 | // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the 138 | // current locale. 139 | static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, 140 | const wchar_t* rhs); 141 | 142 | // Returns true iff the given string ends with the given suffix, ignoring 143 | // case. Any string is considered to end with an empty suffix. 144 | static bool EndsWithCaseInsensitive( 145 | const std::string& str, const std::string& suffix); 146 | 147 | // Formats an int value as "%02d". 148 | static std::string FormatIntWidth2(int value); // "%02d" for width == 2 149 | 150 | // Formats an int value as "%X". 151 | static std::string FormatHexInt(int value); 152 | 153 | // Formats a byte as "%02X". 154 | static std::string FormatByte(unsigned char value); 155 | 156 | private: 157 | String(); // Not meant to be instantiated. 158 | }; // class String 159 | 160 | // Gets the content of the stringstream's buffer as an std::string. Each '\0' 161 | // character in the buffer is replaced with "\\0". 162 | GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); 163 | 164 | } // namespace internal 165 | } // namespace testing 166 | 167 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 168 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-tuple.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 10 $$ Maximum number of tuple fields we want to support. 3 | $$ This meta comment fixes auto-indentation in Emacs. }} 4 | // Copyright 2009 Google Inc. 5 | // All Rights Reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following disclaimer 15 | // in the documentation and/or other materials provided with the 16 | // distribution. 17 | // * Neither the name of Google Inc. nor the names of its 18 | // contributors may be used to endorse or promote products derived from 19 | // this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // Author: wan@google.com (Zhanyong Wan) 34 | 35 | // Implements a subset of TR1 tuple needed by Google Test and Google Mock. 36 | 37 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 38 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 39 | 40 | #include // For ::std::pair. 41 | 42 | // The compiler used in Symbian has a bug that prevents us from declaring the 43 | // tuple template as a friend (it complains that tuple is redefined). This 44 | // hack bypasses the bug by declaring the members that should otherwise be 45 | // private as public. 46 | // Sun Studio versions < 12 also have the above bug. 47 | #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 48 | # define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: 49 | #else 50 | # define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ 51 | template friend class tuple; \ 52 | private: 53 | #endif 54 | 55 | // Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict 56 | // with our own definitions. Therefore using our own tuple does not work on 57 | // those compilers. 58 | #if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */ 59 | # error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \ 60 | GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers." 61 | #endif 62 | 63 | 64 | $range i 0..n-1 65 | $range j 0..n 66 | $range k 1..n 67 | // GTEST_n_TUPLE_(T) is the type of an n-tuple. 68 | #define GTEST_0_TUPLE_(T) tuple<> 69 | 70 | $for k [[ 71 | $range m 0..k-1 72 | $range m2 k..n-1 73 | #define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]> 74 | 75 | ]] 76 | 77 | // GTEST_n_TYPENAMES_(T) declares a list of n typenames. 78 | 79 | $for j [[ 80 | $range m 0..j-1 81 | #define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]] 82 | 83 | 84 | ]] 85 | 86 | // In theory, defining stuff in the ::std namespace is undefined 87 | // behavior. We can do this as we are playing the role of a standard 88 | // library vendor. 89 | namespace std { 90 | namespace tr1 { 91 | 92 | template <$for i, [[typename T$i = void]]> 93 | class tuple; 94 | 95 | // Anything in namespace gtest_internal is Google Test's INTERNAL 96 | // IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code. 97 | namespace gtest_internal { 98 | 99 | // ByRef::type is T if T is a reference; otherwise it's const T&. 100 | template 101 | struct ByRef { typedef const T& type; }; // NOLINT 102 | template 103 | struct ByRef { typedef T& type; }; // NOLINT 104 | 105 | // A handy wrapper for ByRef. 106 | #define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef::type 107 | 108 | // AddRef::type is T if T is a reference; otherwise it's T&. This 109 | // is the same as tr1::add_reference::type. 110 | template 111 | struct AddRef { typedef T& type; }; // NOLINT 112 | template 113 | struct AddRef { typedef T& type; }; // NOLINT 114 | 115 | // A handy wrapper for AddRef. 116 | #define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef::type 117 | 118 | // A helper for implementing get(). 119 | template class Get; 120 | 121 | // A helper for implementing tuple_element. kIndexValid is true 122 | // iff k < the number of fields in tuple type T. 123 | template 124 | struct TupleElement; 125 | 126 | 127 | $for i [[ 128 | template 129 | struct TupleElement { 130 | typedef T$i type; 131 | }; 132 | 133 | 134 | ]] 135 | } // namespace gtest_internal 136 | 137 | template <> 138 | class tuple<> { 139 | public: 140 | tuple() {} 141 | tuple(const tuple& /* t */) {} 142 | tuple& operator=(const tuple& /* t */) { return *this; } 143 | }; 144 | 145 | 146 | $for k [[ 147 | $range m 0..k-1 148 | template 149 | class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] { 150 | public: 151 | template friend class gtest_internal::Get; 152 | 153 | tuple() : $for m, [[f$(m)_()]] {} 154 | 155 | explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]] 156 | $for m, [[f$(m)_(f$m)]] {} 157 | 158 | tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} 159 | 160 | template 161 | tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} 162 | 163 | $if k == 2 [[ 164 | template 165 | tuple(const ::std::pair& p) : f0_(p.first), f1_(p.second) {} 166 | 167 | ]] 168 | 169 | tuple& operator=(const tuple& t) { return CopyFrom(t); } 170 | 171 | template 172 | tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) { 173 | return CopyFrom(t); 174 | } 175 | 176 | $if k == 2 [[ 177 | template 178 | tuple& operator=(const ::std::pair& p) { 179 | f0_ = p.first; 180 | f1_ = p.second; 181 | return *this; 182 | } 183 | 184 | ]] 185 | 186 | GTEST_DECLARE_TUPLE_AS_FRIEND_ 187 | 188 | template 189 | tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) { 190 | 191 | $for m [[ 192 | f$(m)_ = t.f$(m)_; 193 | 194 | ]] 195 | return *this; 196 | } 197 | 198 | 199 | $for m [[ 200 | T$m f$(m)_; 201 | 202 | ]] 203 | }; 204 | 205 | 206 | ]] 207 | // 6.1.3.2 Tuple creation functions. 208 | 209 | // Known limitations: we don't support passing an 210 | // std::tr1::reference_wrapper to make_tuple(). And we don't 211 | // implement tie(). 212 | 213 | inline tuple<> make_tuple() { return tuple<>(); } 214 | 215 | $for k [[ 216 | $range m 0..k-1 217 | 218 | template 219 | inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) { 220 | return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]); 221 | } 222 | 223 | ]] 224 | 225 | // 6.1.3.3 Tuple helper classes. 226 | 227 | template struct tuple_size; 228 | 229 | 230 | $for j [[ 231 | template 232 | struct tuple_size { 233 | static const int value = $j; 234 | }; 235 | 236 | 237 | ]] 238 | template 239 | struct tuple_element { 240 | typedef typename gtest_internal::TupleElement< 241 | k < (tuple_size::value), k, Tuple>::type type; 242 | }; 243 | 244 | #define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element::type 245 | 246 | // 6.1.3.4 Element access. 247 | 248 | namespace gtest_internal { 249 | 250 | 251 | $for i [[ 252 | template <> 253 | class Get<$i> { 254 | public: 255 | template 256 | static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) 257 | Field(Tuple& t) { return t.f$(i)_; } // NOLINT 258 | 259 | template 260 | static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) 261 | ConstField(const Tuple& t) { return t.f$(i)_; } 262 | }; 263 | 264 | 265 | ]] 266 | } // namespace gtest_internal 267 | 268 | template 269 | GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) 270 | get(GTEST_$(n)_TUPLE_(T)& t) { 271 | return gtest_internal::Get::Field(t); 272 | } 273 | 274 | template 275 | GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) 276 | get(const GTEST_$(n)_TUPLE_(T)& t) { 277 | return gtest_internal::Get::ConstField(t); 278 | } 279 | 280 | // 6.1.3.5 Relational operators 281 | 282 | // We only implement == and !=, as we don't have a need for the rest yet. 283 | 284 | namespace gtest_internal { 285 | 286 | // SameSizeTuplePrefixComparator::Eq(t1, t2) returns true if the 287 | // first k fields of t1 equals the first k fields of t2. 288 | // SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if 289 | // k1 != k2. 290 | template 291 | struct SameSizeTuplePrefixComparator; 292 | 293 | template <> 294 | struct SameSizeTuplePrefixComparator<0, 0> { 295 | template 296 | static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) { 297 | return true; 298 | } 299 | }; 300 | 301 | template 302 | struct SameSizeTuplePrefixComparator { 303 | template 304 | static bool Eq(const Tuple1& t1, const Tuple2& t2) { 305 | return SameSizeTuplePrefixComparator::Eq(t1, t2) && 306 | ::std::tr1::get(t1) == ::std::tr1::get(t2); 307 | } 308 | }; 309 | 310 | } // namespace gtest_internal 311 | 312 | template 313 | inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t, 314 | const GTEST_$(n)_TUPLE_(U)& u) { 315 | return gtest_internal::SameSizeTuplePrefixComparator< 316 | tuple_size::value, 317 | tuple_size::value>::Eq(t, u); 318 | } 319 | 320 | template 321 | inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t, 322 | const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); } 323 | 324 | // 6.1.4 Pairs. 325 | // Unimplemented. 326 | 327 | } // namespace tr1 328 | } // namespace std 329 | 330 | 331 | $for j [[ 332 | #undef GTEST_$(j)_TUPLE_ 333 | 334 | ]] 335 | 336 | 337 | $for j [[ 338 | #undef GTEST_$(j)_TYPENAMES_ 339 | 340 | ]] 341 | 342 | #undef GTEST_DECLARE_TUPLE_AS_FRIEND_ 343 | #undef GTEST_BY_REF_ 344 | #undef GTEST_ADD_REF_ 345 | #undef GTEST_TUPLE_ELEMENT_ 346 | 347 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 348 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-type-util.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 50 $$ Maximum length of type lists we want to support. 3 | // Copyright 2008 Google Inc. 4 | // All Rights Reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | // Type utilities needed for implementing typed and type-parameterized 35 | // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 36 | // 37 | // Currently we support at most $n types in a list, and at most $n 38 | // type-parameterized tests in one type-parameterized test case. 39 | // Please contact googletestframework@googlegroups.com if you need 40 | // more. 41 | 42 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 43 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 44 | 45 | #include "gtest/internal/gtest-port.h" 46 | 47 | // #ifdef __GNUC__ is too general here. It is possible to use gcc without using 48 | // libstdc++ (which is where cxxabi.h comes from). 49 | # if GTEST_HAS_CXXABI_H_ 50 | # include 51 | # elif defined(__HP_aCC) 52 | # include 53 | # endif // GTEST_HASH_CXXABI_H_ 54 | 55 | namespace testing { 56 | namespace internal { 57 | 58 | // GetTypeName() returns a human-readable name of type T. 59 | // NB: This function is also used in Google Mock, so don't move it inside of 60 | // the typed-test-only section below. 61 | template 62 | std::string GetTypeName() { 63 | # if GTEST_HAS_RTTI 64 | 65 | const char* const name = typeid(T).name(); 66 | # if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) 67 | int status = 0; 68 | // gcc's implementation of typeid(T).name() mangles the type name, 69 | // so we have to demangle it. 70 | # if GTEST_HAS_CXXABI_H_ 71 | using abi::__cxa_demangle; 72 | # endif // GTEST_HAS_CXXABI_H_ 73 | char* const readable_name = __cxa_demangle(name, 0, 0, &status); 74 | const std::string name_str(status == 0 ? readable_name : name); 75 | free(readable_name); 76 | return name_str; 77 | # else 78 | return name; 79 | # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC 80 | 81 | # else 82 | 83 | return ""; 84 | 85 | # endif // GTEST_HAS_RTTI 86 | } 87 | 88 | #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 89 | 90 | // AssertyTypeEq::type is defined iff T1 and T2 are the same 91 | // type. This can be used as a compile-time assertion to ensure that 92 | // two types are equal. 93 | 94 | template 95 | struct AssertTypeEq; 96 | 97 | template 98 | struct AssertTypeEq { 99 | typedef bool type; 100 | }; 101 | 102 | // A unique type used as the default value for the arguments of class 103 | // template Types. This allows us to simulate variadic templates 104 | // (e.g. Types, Type, and etc), which C++ doesn't 105 | // support directly. 106 | struct None {}; 107 | 108 | // The following family of struct and struct templates are used to 109 | // represent type lists. In particular, TypesN 110 | // represents a type list with N types (T1, T2, ..., and TN) in it. 111 | // Except for Types0, every struct in the family has two member types: 112 | // Head for the first type in the list, and Tail for the rest of the 113 | // list. 114 | 115 | // The empty type list. 116 | struct Types0 {}; 117 | 118 | // Type lists of length 1, 2, 3, and so on. 119 | 120 | template 121 | struct Types1 { 122 | typedef T1 Head; 123 | typedef Types0 Tail; 124 | }; 125 | 126 | $range i 2..n 127 | 128 | $for i [[ 129 | $range j 1..i 130 | $range k 2..i 131 | template <$for j, [[typename T$j]]> 132 | struct Types$i { 133 | typedef T1 Head; 134 | typedef Types$(i-1)<$for k, [[T$k]]> Tail; 135 | }; 136 | 137 | 138 | ]] 139 | 140 | } // namespace internal 141 | 142 | // We don't want to require the users to write TypesN<...> directly, 143 | // as that would require them to count the length. Types<...> is much 144 | // easier to write, but generates horrible messages when there is a 145 | // compiler error, as gcc insists on printing out each template 146 | // argument, even if it has the default value (this means Types 147 | // will appear as Types in the compiler 148 | // errors). 149 | // 150 | // Our solution is to combine the best part of the two approaches: a 151 | // user would write Types, and Google Test will translate 152 | // that to TypesN internally to make error messages 153 | // readable. The translation is done by the 'type' member of the 154 | // Types template. 155 | 156 | $range i 1..n 157 | template <$for i, [[typename T$i = internal::None]]> 158 | struct Types { 159 | typedef internal::Types$n<$for i, [[T$i]]> type; 160 | }; 161 | 162 | template <> 163 | struct Types<$for i, [[internal::None]]> { 164 | typedef internal::Types0 type; 165 | }; 166 | 167 | $range i 1..n-1 168 | $for i [[ 169 | $range j 1..i 170 | $range k i+1..n 171 | template <$for j, [[typename T$j]]> 172 | struct Types<$for j, [[T$j]]$for k[[, internal::None]]> { 173 | typedef internal::Types$i<$for j, [[T$j]]> type; 174 | }; 175 | 176 | ]] 177 | 178 | namespace internal { 179 | 180 | # define GTEST_TEMPLATE_ template class 181 | 182 | // The template "selector" struct TemplateSel is used to 183 | // represent Tmpl, which must be a class template with one type 184 | // parameter, as a type. TemplateSel::Bind::type is defined 185 | // as the type Tmpl. This allows us to actually instantiate the 186 | // template "selected" by TemplateSel. 187 | // 188 | // This trick is necessary for simulating typedef for class templates, 189 | // which C++ doesn't support directly. 190 | template 191 | struct TemplateSel { 192 | template 193 | struct Bind { 194 | typedef Tmpl type; 195 | }; 196 | }; 197 | 198 | # define GTEST_BIND_(TmplSel, T) \ 199 | TmplSel::template Bind::type 200 | 201 | // A unique struct template used as the default value for the 202 | // arguments of class template Templates. This allows us to simulate 203 | // variadic templates (e.g. Templates, Templates, 204 | // and etc), which C++ doesn't support directly. 205 | template 206 | struct NoneT {}; 207 | 208 | // The following family of struct and struct templates are used to 209 | // represent template lists. In particular, TemplatesN represents a list of N templates (T1, T2, ..., and TN). Except 211 | // for Templates0, every struct in the family has two member types: 212 | // Head for the selector of the first template in the list, and Tail 213 | // for the rest of the list. 214 | 215 | // The empty template list. 216 | struct Templates0 {}; 217 | 218 | // Template lists of length 1, 2, 3, and so on. 219 | 220 | template 221 | struct Templates1 { 222 | typedef TemplateSel Head; 223 | typedef Templates0 Tail; 224 | }; 225 | 226 | $range i 2..n 227 | 228 | $for i [[ 229 | $range j 1..i 230 | $range k 2..i 231 | template <$for j, [[GTEST_TEMPLATE_ T$j]]> 232 | struct Templates$i { 233 | typedef TemplateSel Head; 234 | typedef Templates$(i-1)<$for k, [[T$k]]> Tail; 235 | }; 236 | 237 | 238 | ]] 239 | 240 | // We don't want to require the users to write TemplatesN<...> directly, 241 | // as that would require them to count the length. Templates<...> is much 242 | // easier to write, but generates horrible messages when there is a 243 | // compiler error, as gcc insists on printing out each template 244 | // argument, even if it has the default value (this means Templates 245 | // will appear as Templates in the compiler 246 | // errors). 247 | // 248 | // Our solution is to combine the best part of the two approaches: a 249 | // user would write Templates, and Google Test will translate 250 | // that to TemplatesN internally to make error messages 251 | // readable. The translation is done by the 'type' member of the 252 | // Templates template. 253 | 254 | $range i 1..n 255 | template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]> 256 | struct Templates { 257 | typedef Templates$n<$for i, [[T$i]]> type; 258 | }; 259 | 260 | template <> 261 | struct Templates<$for i, [[NoneT]]> { 262 | typedef Templates0 type; 263 | }; 264 | 265 | $range i 1..n-1 266 | $for i [[ 267 | $range j 1..i 268 | $range k i+1..n 269 | template <$for j, [[GTEST_TEMPLATE_ T$j]]> 270 | struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> { 271 | typedef Templates$i<$for j, [[T$j]]> type; 272 | }; 273 | 274 | ]] 275 | 276 | // The TypeList template makes it possible to use either a single type 277 | // or a Types<...> list in TYPED_TEST_CASE() and 278 | // INSTANTIATE_TYPED_TEST_CASE_P(). 279 | 280 | template 281 | struct TypeList { 282 | typedef Types1 type; 283 | }; 284 | 285 | 286 | $range i 1..n 287 | template <$for i, [[typename T$i]]> 288 | struct TypeList > { 289 | typedef typename Types<$for i, [[T$i]]>::type type; 290 | }; 291 | 292 | #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 293 | 294 | } // namespace internal 295 | } // namespace testing 296 | 297 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 298 | -------------------------------------------------------------------------------- /test/gtest/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 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build Google Test by compiling a single file. 35 | // This file serves this purpose. 36 | 37 | // This line ensures that gtest.h can be compiled on its own, even 38 | // when it's fused. 39 | #include "gtest/gtest.h" 40 | 41 | // The following lines pull in the real gtest *.cc files. 42 | #include "src/gtest.cc" 43 | #include "src/gtest-death-test.cc" 44 | #include "src/gtest-filepath.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 | -------------------------------------------------------------------------------- /test/gtest/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 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | 34 | #include "gtest/gtest-test-part.h" 35 | #include "src/gtest-internal-inl.h" 36 | 37 | namespace testing { 38 | 39 | using internal::GetUnitTestImpl; 40 | 41 | // Gets the summary of the failure message by omitting the stack trace 42 | // in it. 43 | std::string TestPartResult::ExtractSummary(const char* message) { 44 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 45 | return stack_trace == NULL ? message : 46 | 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 52 | << result.file_name() << ":" << result.line_number() << ": " 53 | << (result.type() == TestPartResult::kSuccess ? "Success" : 54 | result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : 55 | "Non-fatal failure") << ":\n" 56 | << result.message() << std::endl; 57 | } 58 | 59 | // Appends a TestPartResult to the array. 60 | void TestPartResultArray::Append(const TestPartResult& result) { 61 | array_.push_back(result); 62 | } 63 | 64 | // Returns the TestPartResult at the given index (0-based). 65 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 66 | if (index < 0 || index >= size()) { 67 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 68 | internal::posix::Abort(); 69 | } 70 | 71 | return array_[index]; 72 | } 73 | 74 | // Returns the number of TestPartResult objects in the array. 75 | int TestPartResultArray::size() const { 76 | return static_cast(array_.size()); 77 | } 78 | 79 | namespace internal { 80 | 81 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 82 | : has_new_fatal_failure_(false), 83 | original_reporter_(GetUnitTestImpl()-> 84 | GetTestPartResultReporterForCurrentThread()) { 85 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 86 | } 87 | 88 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 89 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 90 | original_reporter_); 91 | } 92 | 93 | void HasNewFatalFailureHelper::ReportTestPartResult( 94 | const TestPartResult& result) { 95 | if (result.fatally_failed()) 96 | has_new_fatal_failure_ = true; 97 | original_reporter_->ReportTestPartResult(result); 98 | } 99 | 100 | } // namespace internal 101 | 102 | } // namespace testing 103 | -------------------------------------------------------------------------------- /test/gtest/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 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest-typed-test.h" 33 | #include "gtest/gtest.h" 34 | 35 | namespace testing { 36 | namespace internal { 37 | 38 | #if GTEST_HAS_TYPED_TEST_P 39 | 40 | // Skips to the first non-space char in str. Returns an empty string if str 41 | // contains only whitespace characters. 42 | static const char* SkipSpaces(const char* str) { 43 | while (IsSpace(*str)) 44 | str++; 45 | return str; 46 | } 47 | 48 | static std::vector SplitIntoTestNames(const char* src) { 49 | std::vector name_vec; 50 | src = SkipSpaces(src); 51 | for (; src != NULL; src = SkipComma(src)) { 52 | name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); 53 | } 54 | return name_vec; 55 | } 56 | 57 | // Verifies that registered_tests match the test names in 58 | // registered_tests_; returns registered_tests if successful, or 59 | // aborts the program otherwise. 60 | const char* TypedTestCasePState::VerifyRegisteredTestNames( 61 | const char* file, int line, const char* registered_tests) { 62 | typedef RegisteredTestsMap::const_iterator RegisteredTestIter; 63 | registered_ = true; 64 | 65 | std::vector name_vec = SplitIntoTestNames(registered_tests); 66 | 67 | Message errors; 68 | 69 | std::set tests; 70 | for (std::vector::const_iterator name_it = name_vec.begin(); 71 | name_it != name_vec.end(); ++name_it) { 72 | const std::string& name = *name_it; 73 | if (tests.count(name) != 0) { 74 | errors << "Test " << name << " is listed more than once.\n"; 75 | continue; 76 | } 77 | 78 | bool found = false; 79 | for (RegisteredTestIter it = registered_tests_.begin(); 80 | it != registered_tests_.end(); 81 | ++it) { 82 | if (name == it->first) { 83 | found = true; 84 | break; 85 | } 86 | } 87 | 88 | if (found) { 89 | tests.insert(name); 90 | } else { 91 | errors << "No test named " << name 92 | << " can be found in this test case.\n"; 93 | } 94 | } 95 | 96 | for (RegisteredTestIter it = registered_tests_.begin(); 97 | it != registered_tests_.end(); 98 | ++it) { 99 | if (tests.count(it->first) == 0) { 100 | errors << "You forgot to list test " << it->first << ".\n"; 101 | } 102 | } 103 | 104 | const std::string& errors_str = errors.GetString(); 105 | if (errors_str != "") { 106 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 107 | errors_str.c_str()); 108 | fflush(stderr); 109 | posix::Abort(); 110 | } 111 | 112 | return registered_tests; 113 | } 114 | 115 | #endif // GTEST_HAS_TYPED_TEST_P 116 | 117 | } // namespace internal 118 | } // namespace testing 119 | -------------------------------------------------------------------------------- /test/gtest/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 | 31 | #include 32 | #include "gtest/gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | --------------------------------------------------------------------------------