mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
8222154: upgrade gtest to 1.8.1
Reviewed-by: jwilhelm, rwestberg
This commit is contained in:
parent
ca569937da
commit
1e4085b359
@ -80,8 +80,6 @@ $(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \
|
||||
self-assign-overloaded, \
|
||||
DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio) \
|
||||
identexpected, \
|
||||
DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft) \
|
||||
4996, \
|
||||
LDFLAGS := $(JVM_LDFLAGS), \
|
||||
LDFLAGS_solaris := -library=stlport4 $(call SET_SHARED_LIBRARY_ORIGIN), \
|
||||
LIBS := $(JVM_LIBS), \
|
||||
|
||||
37
test/fmw/gtest/CONTRIBUTORS
Normal file
37
test/fmw/gtest/CONTRIBUTORS
Normal file
@ -0,0 +1,37 @@
|
||||
# This file contains a list of people who've made non-trivial
|
||||
# contribution to the Google C++ Testing Framework project. People
|
||||
# who commit code to the project are encouraged to add their names
|
||||
# here. Please keep the list sorted by first names.
|
||||
|
||||
Ajay Joshi <jaj@google.com>
|
||||
Balázs Dán <balazs.dan@gmail.com>
|
||||
Bharat Mediratta <bharat@menalto.com>
|
||||
Chandler Carruth <chandlerc@google.com>
|
||||
Chris Prince <cprince@google.com>
|
||||
Chris Taylor <taylorc@google.com>
|
||||
Dan Egnor <egnor@google.com>
|
||||
Eric Roman <eroman@chromium.org>
|
||||
Hady Zalek <hady.zalek@gmail.com>
|
||||
Jeffrey Yasskin <jyasskin@google.com>
|
||||
Jói Sigurðsson <joi@google.com>
|
||||
Keir Mierle <mierle@gmail.com>
|
||||
Keith Ray <keith.ray@gmail.com>
|
||||
Kenton Varda <kenton@google.com>
|
||||
Manuel Klimek <klimek@google.com>
|
||||
Markus Heule <markus.heule@gmail.com>
|
||||
Mika Raento <mikie@iki.fi>
|
||||
Miklós Fazekas <mfazekas@szemafor.com>
|
||||
Pasi Valminen <pasi.valminen@gmail.com>
|
||||
Patrick Hanna <phanna@google.com>
|
||||
Patrick Riley <pfr@google.com>
|
||||
Peter Kaminski <piotrk@google.com>
|
||||
Preston Jackson <preston.a.jackson@gmail.com>
|
||||
Rainer Klaffenboeck <rainer.klaffenboeck@dynatrace.com>
|
||||
Russ Cox <rsc@google.com>
|
||||
Russ Rufer <russ@pentad.com>
|
||||
Sean Mcafee <eefacm@gmail.com>
|
||||
Sigurður Ásgeirsson <siggi@google.com>
|
||||
Tracy Bialik <tracy@pentad.com>
|
||||
Vadim Berman <vadimb@google.com>
|
||||
Vlad Losev <vladl@google.com>
|
||||
Zhanyong Wan <wan@google.com>
|
||||
@ -1,435 +0,0 @@
|
||||
Google C++ Testing Framework
|
||||
============================
|
||||
|
||||
http://code.google.com/p/googletest/
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
Google's framework for writing C++ tests on a variety of platforms
|
||||
(Linux, Mac OS X, Windows, Windows CE, Symbian, etc). Based on the
|
||||
xUnit architecture. Supports automatic test discovery, a rich set of
|
||||
assertions, user-defined assertions, death tests, fatal and non-fatal
|
||||
failures, various options for running the tests, and XML test report
|
||||
generation.
|
||||
|
||||
Please see the project page above for more information as well as the
|
||||
mailing list for questions, discussions, and development. There is
|
||||
also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please
|
||||
join us!
|
||||
|
||||
Requirements for End Users
|
||||
--------------------------
|
||||
|
||||
Google Test is designed to have fairly minimal requirements to build
|
||||
and use with your projects, but there are some. Currently, we support
|
||||
Linux, Windows, Mac OS X, and Cygwin. We will also make our best
|
||||
effort to support other platforms (e.g. Solaris, AIX, and z/OS).
|
||||
However, since core members of the Google Test project have no access
|
||||
to these platforms, Google Test may have outstanding issues there. If
|
||||
you notice any problems on your platform, please notify
|
||||
googletestframework@googlegroups.com. Patches for fixing them are
|
||||
even more welcome!
|
||||
|
||||
### Linux Requirements ###
|
||||
|
||||
These are the base requirements to build and use Google Test from a source
|
||||
package (as described below):
|
||||
* GNU-compatible Make or gmake
|
||||
* POSIX-standard shell
|
||||
* POSIX(-2) Regular Expressions (regex.h)
|
||||
* A C++98-standard-compliant compiler
|
||||
|
||||
### Windows Requirements ###
|
||||
|
||||
* Microsoft Visual C++ 7.1 or newer
|
||||
|
||||
### Cygwin Requirements ###
|
||||
|
||||
* Cygwin 1.5.25-14 or newer
|
||||
|
||||
### Mac OS X Requirements ###
|
||||
|
||||
* Mac OS X 10.4 Tiger or newer
|
||||
* Developer Tools Installed
|
||||
|
||||
Also, you'll need CMake 2.6.4 or higher if you want to build the
|
||||
samples using the provided CMake script, regardless of the platform.
|
||||
|
||||
Requirements for Contributors
|
||||
-----------------------------
|
||||
|
||||
We welcome patches. If you plan to contribute a patch, you need to
|
||||
build Google Test and its own tests from an SVN checkout (described
|
||||
below), which has further requirements:
|
||||
|
||||
* Python version 2.3 or newer (for running some of the tests and
|
||||
re-generating certain source files from templates)
|
||||
* CMake 2.6.4 or newer
|
||||
|
||||
Getting the Source
|
||||
------------------
|
||||
|
||||
There are two primary ways of getting Google Test's source code: you
|
||||
can download a stable source release in your preferred archive format,
|
||||
or directly check out the source from our Subversion (SVN) repositary.
|
||||
The SVN checkout requires a few extra steps and some extra software
|
||||
packages on your system, but lets you track the latest development and
|
||||
make patches much more easily, so we highly encourage it.
|
||||
|
||||
### Source Package ###
|
||||
|
||||
Google Test is released in versioned source packages which can be
|
||||
downloaded from the download page [1]. Several different archive
|
||||
formats are provided, but the only difference is the tools used to
|
||||
manipulate them, and the size of the resulting file. Download
|
||||
whichever you are most comfortable with.
|
||||
|
||||
[1] http://code.google.com/p/googletest/downloads/list
|
||||
|
||||
Once the package is downloaded, expand it using whichever tools you
|
||||
prefer for that type. This will result in a new directory with the
|
||||
name "gtest-X.Y.Z" which contains all of the source code. Here are
|
||||
some examples on Linux:
|
||||
|
||||
tar -xvzf gtest-X.Y.Z.tar.gz
|
||||
tar -xvjf gtest-X.Y.Z.tar.bz2
|
||||
unzip gtest-X.Y.Z.zip
|
||||
|
||||
### SVN Checkout ###
|
||||
|
||||
To check out the main branch (also known as the "trunk") of Google
|
||||
Test, run the following Subversion command:
|
||||
|
||||
svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn
|
||||
|
||||
Setting up the Build
|
||||
--------------------
|
||||
|
||||
To build Google Test and your tests that use it, you need to tell your
|
||||
build system where to find its headers and source files. The exact
|
||||
way to do it depends on which build system you use, and is usually
|
||||
straightforward.
|
||||
|
||||
### Generic Build Instructions ###
|
||||
|
||||
Suppose you put Google Test in directory ${GTEST_DIR}. To build it,
|
||||
create a library build target (or a project as called by Visual Studio
|
||||
and Xcode) to compile
|
||||
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
|
||||
with ${GTEST_DIR}/include in the system header search path and ${GTEST_DIR}
|
||||
in the normal header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
ar -rv libgtest.a gtest-all.o
|
||||
|
||||
(We need -pthread as Google Test uses threads.)
|
||||
|
||||
Next, you should compile your test source file with
|
||||
${GTEST_DIR}/include in the system header search path, and link it
|
||||
with gtest and any other necessary libraries:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
|
||||
-o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can
|
||||
use to build Google Test on systems where GNU make is available
|
||||
(e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google
|
||||
Test's own tests. Instead, it just builds the Google Test library and
|
||||
a sample test. You can use it as a starting point for your own build
|
||||
script.
|
||||
|
||||
If the default settings are correct for your environment, the
|
||||
following commands should succeed:
|
||||
|
||||
cd ${GTEST_DIR}/make
|
||||
make
|
||||
./sample1_unittest
|
||||
|
||||
If you see errors, try to tweak the contents of make/Makefile to make
|
||||
them go away. There are instructions in make/Makefile on how to do
|
||||
it.
|
||||
|
||||
### Using CMake ###
|
||||
|
||||
Google Test comes with a CMake build script (CMakeLists.txt) that can
|
||||
be used on a wide range of platforms ("C" stands for cross-platofrm.).
|
||||
If you don't have CMake installed already, you can download it for
|
||||
free from http://www.cmake.org/.
|
||||
|
||||
CMake works by generating native makefiles or build projects that can
|
||||
be used in the compiler environment of your choice. The typical
|
||||
workflow starts with:
|
||||
|
||||
mkdir mybuild # Create a directory to hold the build output.
|
||||
cd mybuild
|
||||
cmake ${GTEST_DIR} # Generate native build scripts.
|
||||
|
||||
If you want to build Google Test's samples, you should replace the
|
||||
last command with
|
||||
|
||||
cmake -Dgtest_build_samples=ON ${GTEST_DIR}
|
||||
|
||||
If you are on a *nix system, you should now see a Makefile in the
|
||||
current directory. Just type 'make' to build gtest.
|
||||
|
||||
If you use Windows and have Vistual Studio installed, a gtest.sln file
|
||||
and several .vcproj files will be created. You can then build them
|
||||
using Visual Studio.
|
||||
|
||||
On Mac OS X with Xcode installed, a .xcodeproj file will be generated.
|
||||
|
||||
### Legacy Build Scripts ###
|
||||
|
||||
Before settling on CMake, we have been providing hand-maintained build
|
||||
projects/scripts for Visual Studio, Xcode, and Autotools. While we
|
||||
continue to provide them for convenience, they are not actively
|
||||
maintained any more. We highly recommend that you follow the
|
||||
instructions in the previous two sections to integrate Google Test
|
||||
with your existing build system.
|
||||
|
||||
If you still need to use the legacy build scripts, here's how:
|
||||
|
||||
The msvc\ folder contains two solutions with Visual C++ projects.
|
||||
Open the gtest.sln or gtest-md.sln file using Visual Studio, and you
|
||||
are ready to build Google Test the same way you build any Visual
|
||||
Studio project. Files that have names ending with -md use DLL
|
||||
versions of Microsoft runtime libraries (the /MD or the /MDd compiler
|
||||
option). Files without that suffix use static versions of the runtime
|
||||
libraries (the /MT or the /MTd option). Please note that one must use
|
||||
the same option to compile both gtest and the test code. If you use
|
||||
Visual Studio 2005 or above, we recommend the -md version as /MD is
|
||||
the default for new projects in these versions of Visual Studio.
|
||||
|
||||
On Mac OS X, open the gtest.xcodeproj in the xcode/ folder using
|
||||
Xcode. Build the "gtest" target. The universal binary framework will
|
||||
end up in your selected build directory (selected in the Xcode
|
||||
"Preferences..." -> "Building" pane and defaults to xcode/build).
|
||||
Alternatively, at the command line, enter:
|
||||
|
||||
xcodebuild
|
||||
|
||||
This will build the "Release" configuration of gtest.framework in your
|
||||
default build location. See the "xcodebuild" man page for more
|
||||
information about building different configurations and building in
|
||||
different locations.
|
||||
|
||||
If you wish to use the Google Test Xcode project with Xcode 4.x and
|
||||
above, you need to either:
|
||||
* update the SDK configuration options in xcode/Config/General.xconfig.
|
||||
Comment options SDKROOT, MACOS_DEPLOYMENT_TARGET, and GCC_VERSION. If
|
||||
you choose this route you lose the ability to target earlier versions
|
||||
of MacOS X.
|
||||
* Install an SDK for an earlier version. This doesn't appear to be
|
||||
supported by Apple, but has been reported to work
|
||||
(http://stackoverflow.com/questions/5378518).
|
||||
|
||||
Tweaking Google Test
|
||||
--------------------
|
||||
|
||||
Google Test can be used in diverse environments. The default
|
||||
configuration may not work (or may not work well) out of the box in
|
||||
some environments. However, you can easily tweak Google Test by
|
||||
defining control macros on the compiler command line. Generally,
|
||||
these macros are named like GTEST_XYZ and you define them to either 1
|
||||
or 0 to enable or disable a certain feature.
|
||||
|
||||
We list the most frequently used macros below. For a complete list,
|
||||
see file include/gtest/internal/gtest-port.h.
|
||||
|
||||
### Choosing a TR1 Tuple Library ###
|
||||
|
||||
Some Google Test features require the C++ Technical Report 1 (TR1)
|
||||
tuple library, which is not yet available with all compilers. The
|
||||
good news is that Google Test implements a subset of TR1 tuple that's
|
||||
enough for its own need, and will automatically use this when the
|
||||
compiler doesn't provide TR1 tuple.
|
||||
|
||||
Usually you don't need to care about which tuple library Google Test
|
||||
uses. However, if your project already uses TR1 tuple, you need to
|
||||
tell Google Test to use the same TR1 tuple library the rest of your
|
||||
project uses, or the two tuple implementations will clash. To do
|
||||
that, add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=0
|
||||
|
||||
to the compiler flags while compiling Google Test and your tests. If
|
||||
you want to force Google Test to use its own tuple library, just add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=1
|
||||
|
||||
to the compiler flags instead.
|
||||
|
||||
If you don't want Google Test to use tuple at all, add
|
||||
|
||||
-DGTEST_HAS_TR1_TUPLE=0
|
||||
|
||||
and all features using tuple will be disabled.
|
||||
|
||||
### Multi-threaded Tests ###
|
||||
|
||||
Google Test is thread-safe where the pthread library is available.
|
||||
After #include "gtest/gtest.h", you can check the GTEST_IS_THREADSAFE
|
||||
macro to see whether this is the case (yes if the macro is #defined to
|
||||
1, no if it's undefined.).
|
||||
|
||||
If Google Test doesn't correctly detect whether pthread is available
|
||||
in your environment, you can force it with
|
||||
|
||||
-DGTEST_HAS_PTHREAD=1
|
||||
|
||||
or
|
||||
|
||||
-DGTEST_HAS_PTHREAD=0
|
||||
|
||||
When Google Test uses pthread, you may need to add flags to your
|
||||
compiler and/or linker to select the pthread library, or you'll get
|
||||
link errors. If you use the CMake script or the deprecated Autotools
|
||||
script, this is taken care of for you. If you use your own build
|
||||
script, you'll need to read your compiler and linker's manual to
|
||||
figure out what flags to add.
|
||||
|
||||
### As a Shared Library (DLL) ###
|
||||
|
||||
Google Test is compact, so most users can build and link it as a
|
||||
static library for the simplicity. You can choose to use Google Test
|
||||
as a shared library (known as a DLL on Windows) if you prefer.
|
||||
|
||||
To compile *gtest* as a shared library, add
|
||||
|
||||
-DGTEST_CREATE_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags. You'll also need to tell the linker to produce
|
||||
a shared library instead - consult your linker's manual for how to do
|
||||
it.
|
||||
|
||||
To compile your *tests* that use the gtest shared library, add
|
||||
|
||||
-DGTEST_LINKED_AS_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags.
|
||||
|
||||
Note: while the above steps aren't technically necessary today when
|
||||
using some compilers (e.g. GCC), they may become necessary in the
|
||||
future, if we decide to improve the speed of loading the library (see
|
||||
http://gcc.gnu.org/wiki/Visibility for details). Therefore you are
|
||||
recommended to always add the above flags when using Google Test as a
|
||||
shared library. Otherwise a future release of Google Test may break
|
||||
your build script.
|
||||
|
||||
### Avoiding Macro Name Clashes ###
|
||||
|
||||
In C++, macros don't obey namespaces. Therefore two libraries that
|
||||
both define a macro of the same name will clash if you #include both
|
||||
definitions. In case a Google Test macro clashes with another
|
||||
library, you can force Google Test to rename its macro to avoid the
|
||||
conflict.
|
||||
|
||||
Specifically, if both Google Test and some other code define macro
|
||||
FOO, you can add
|
||||
|
||||
-DGTEST_DONT_DEFINE_FOO=1
|
||||
|
||||
to the compiler flags to tell Google Test to change the macro's name
|
||||
from FOO to GTEST_FOO. Currently FOO can be FAIL, SUCCEED, or TEST.
|
||||
For example, with -DGTEST_DONT_DEFINE_TEST=1, you'll need to write
|
||||
|
||||
GTEST_TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
instead of
|
||||
|
||||
TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
in order to define a test.
|
||||
|
||||
Upgrating from an Earlier Version
|
||||
---------------------------------
|
||||
|
||||
We strive to keep Google Test releases backward compatible.
|
||||
Sometimes, though, we have to make some breaking changes for the
|
||||
users' long-term benefits. This section describes what you'll need to
|
||||
do if you are upgrading from an earlier version of Google Test.
|
||||
|
||||
### Upgrading from 1.3.0 or Earlier ###
|
||||
|
||||
You may need to explicitly enable or disable Google Test's own TR1
|
||||
tuple library. See the instructions in section "Choosing a TR1 Tuple
|
||||
Library".
|
||||
|
||||
### Upgrading from 1.4.0 or Earlier ###
|
||||
|
||||
The Autotools build script (configure + make) is no longer officially
|
||||
supportted. You are encouraged to migrate to your own build system or
|
||||
use CMake. If you still need to use Autotools, you can find
|
||||
instructions in the README file from Google Test 1.4.0.
|
||||
|
||||
On platforms where the pthread library is available, Google Test uses
|
||||
it in order to be thread-safe. See the "Multi-threaded Tests" section
|
||||
for what this means to your build script.
|
||||
|
||||
If you use Microsoft Visual C++ 7.1 with exceptions disabled, Google
|
||||
Test will no longer compile. This should affect very few people, as a
|
||||
large portion of STL (including <string>) doesn't compile in this mode
|
||||
anyway. We decided to stop supporting it in order to greatly simplify
|
||||
Google Test's implementation.
|
||||
|
||||
Developing Google Test
|
||||
----------------------
|
||||
|
||||
This section discusses how to make your own changes to Google Test.
|
||||
|
||||
### Testing Google Test Itself ###
|
||||
|
||||
To make sure your changes work as intended and don't break existing
|
||||
functionality, you'll want to compile and run Google Test's own tests.
|
||||
For that you can use CMake:
|
||||
|
||||
mkdir mybuild
|
||||
cd mybuild
|
||||
cmake -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Make sure you have Python installed, as some of Google Test's tests
|
||||
are written in Python. If the cmake command complains about not being
|
||||
able to find Python ("Could NOT find PythonInterp (missing:
|
||||
PYTHON_EXECUTABLE)"), try telling it explicitly where your Python
|
||||
executable can be found:
|
||||
|
||||
cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
|
||||
|
||||
Next, you can build Google Test and all of its own tests. On *nix,
|
||||
this is usually done by 'make'. To run the tests, do
|
||||
|
||||
make test
|
||||
|
||||
All tests should pass.
|
||||
|
||||
### Regenerating Source Files ###
|
||||
|
||||
Some of Google Test's source files are generated from templates (not
|
||||
in the C++ sense) using a script. A template file is named FOO.pump,
|
||||
where FOO is the name of the file it will generate. For example, the
|
||||
file include/gtest/internal/gtest-type-util.h.pump is used to generate
|
||||
gtest-type-util.h in the same directory.
|
||||
|
||||
Normally you don't need to worry about regenerating the source files,
|
||||
unless you need to modify them. In that case, you should modify the
|
||||
corresponding .pump files instead and run the pump.py Python script to
|
||||
regenerate them. You can find pump.py in the scripts/ directory.
|
||||
Read the Pump manual [2] for how to use it.
|
||||
|
||||
[2] http://code.google.com/p/googletest/wiki/PumpManual
|
||||
|
||||
### Contributing a Patch ###
|
||||
|
||||
We welcome patches. Please read the Google Test developer's guide [3]
|
||||
for how you can contribute. In particular, make sure you have signed
|
||||
the Contributor License Agreement, or we won't be able to accept the
|
||||
patch.
|
||||
|
||||
[3] http://code.google.com/p/googletest/wiki/GoogleTestDevGuide
|
||||
|
||||
Happy testing!
|
||||
345
test/fmw/gtest/README.md
Normal file
345
test/fmw/gtest/README.md
Normal file
@ -0,0 +1,345 @@
|
||||
### Generic Build Instructions
|
||||
|
||||
#### Setup
|
||||
|
||||
To build Google Test and your tests that use it, you need to tell your build
|
||||
system where to find its headers and source files. The exact way to do it
|
||||
depends on which build system you use, and is usually straightforward.
|
||||
|
||||
#### Build
|
||||
|
||||
Suppose you put Google Test in directory `${GTEST_DIR}`. To build it, create a
|
||||
library build target (or a project as called by Visual Studio and Xcode) to
|
||||
compile
|
||||
|
||||
${GTEST_DIR}/src/gtest-all.cc
|
||||
|
||||
with `${GTEST_DIR}/include` in the system header search path and `${GTEST_DIR}`
|
||||
in the normal header search path. Assuming a Linux-like system and gcc,
|
||||
something like the following will do:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
|
||||
-pthread -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
ar -rv libgtest.a gtest-all.o
|
||||
|
||||
(We need `-pthread` as Google Test uses threads.)
|
||||
|
||||
Next, you should compile your test source file with `${GTEST_DIR}/include` in
|
||||
the system header search path, and link it with gtest and any other necessary
|
||||
libraries:
|
||||
|
||||
g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
|
||||
-o your_test
|
||||
|
||||
As an example, the make/ directory contains a Makefile that you can use to build
|
||||
Google Test on systems where GNU make is available (e.g. Linux, Mac OS X, and
|
||||
Cygwin). It doesn't try to build Google Test's own tests. Instead, it just
|
||||
builds the Google Test library and a sample test. You can use it as a starting
|
||||
point for your own build script.
|
||||
|
||||
If the default settings are correct for your environment, the following commands
|
||||
should succeed:
|
||||
|
||||
cd ${GTEST_DIR}/make
|
||||
make
|
||||
./sample1_unittest
|
||||
|
||||
If you see errors, try to tweak the contents of `make/Makefile` to make them go
|
||||
away. There are instructions in `make/Makefile` on how to do it.
|
||||
|
||||
### Using CMake
|
||||
|
||||
Google Test comes with a CMake build script (
|
||||
[CMakeLists.txt](https://github.com/google/googletest/blob/master/CMakeLists.txt))
|
||||
that can be used on a wide range of platforms ("C" stands for cross-platform.).
|
||||
If you don't have CMake installed already, you can download it for free from
|
||||
<http://www.cmake.org/>.
|
||||
|
||||
CMake works by generating native makefiles or build projects that can be used in
|
||||
the compiler environment of your choice. You can either build Google Test as a
|
||||
standalone project or it can be incorporated into an existing CMake build for
|
||||
another project.
|
||||
|
||||
#### Standalone CMake Project
|
||||
|
||||
When building Google Test as a standalone project, the typical workflow starts
|
||||
with:
|
||||
|
||||
mkdir mybuild # Create a directory to hold the build output.
|
||||
cd mybuild
|
||||
cmake ${GTEST_DIR} # Generate native build scripts.
|
||||
|
||||
If you want to build Google Test's samples, you should replace the last command
|
||||
with
|
||||
|
||||
cmake -Dgtest_build_samples=ON ${GTEST_DIR}
|
||||
|
||||
If you are on a \*nix system, you should now see a Makefile in the current
|
||||
directory. Just type 'make' to build gtest.
|
||||
|
||||
If you use Windows and have Visual Studio installed, a `gtest.sln` file and
|
||||
several `.vcproj` files will be created. You can then build them using Visual
|
||||
Studio.
|
||||
|
||||
On Mac OS X with Xcode installed, a `.xcodeproj` file will be generated.
|
||||
|
||||
#### Incorporating Into An Existing CMake Project
|
||||
|
||||
If you want to use gtest in a project which already uses CMake, then a more
|
||||
robust and flexible approach is to build gtest as part of that project directly.
|
||||
This is done by making the GoogleTest source code available to the main build
|
||||
and adding it using CMake's `add_subdirectory()` command. This has the
|
||||
significant advantage that the same compiler and linker settings are used
|
||||
between gtest and the rest of your project, so issues associated with using
|
||||
incompatible libraries (eg debug/release), etc. are avoided. This is
|
||||
particularly useful on Windows. Making GoogleTest's source code available to the
|
||||
main build can be done a few different ways:
|
||||
|
||||
* Download the GoogleTest source code manually and place it at a known
|
||||
location. This is the least flexible approach and can make it more difficult
|
||||
to use with continuous integration systems, etc.
|
||||
* Embed the GoogleTest source code as a direct copy in the main project's
|
||||
source tree. This is often the simplest approach, but is also the hardest to
|
||||
keep up to date. Some organizations may not permit this method.
|
||||
* Add GoogleTest as a git submodule or equivalent. This may not always be
|
||||
possible or appropriate. Git submodules, for example, have their own set of
|
||||
advantages and drawbacks.
|
||||
* Use CMake to download GoogleTest as part of the build's configure step. This
|
||||
is just a little more complex, but doesn't have the limitations of the other
|
||||
methods.
|
||||
|
||||
The last of the above methods is implemented with a small piece of CMake code in
|
||||
a separate file (e.g. `CMakeLists.txt.in`) which is copied to the build area and
|
||||
then invoked as a sub-build _during the CMake stage_. That directory is then
|
||||
pulled into the main build with `add_subdirectory()`. For example:
|
||||
|
||||
New file `CMakeLists.txt.in`:
|
||||
|
||||
``` cmake
|
||||
cmake_minimum_required(VERSION 2.8.2)
|
||||
|
||||
project(googletest-download NONE)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG master
|
||||
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
||||
```
|
||||
|
||||
Existing build's `CMakeLists.txt`:
|
||||
|
||||
``` cmake
|
||||
# Download and unpack googletest at configure time
|
||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
# Prevent overriding the parent project's compiler/linker
|
||||
# settings on Windows
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Add googletest directly to our build. This defines
|
||||
# the gtest and gtest_main targets.
|
||||
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
|
||||
${CMAKE_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# The gtest/gtest_main targets carry header search path
|
||||
# dependencies automatically when using CMake 2.8.11 or
|
||||
# later. Otherwise we have to add them here ourselves.
|
||||
if (CMAKE_VERSION VERSION_LESS 2.8.11)
|
||||
include_directories("${gtest_SOURCE_DIR}/include")
|
||||
endif()
|
||||
|
||||
# Now simply link against gtest or gtest_main as needed. Eg
|
||||
add_executable(example example.cpp)
|
||||
target_link_libraries(example gtest_main)
|
||||
add_test(NAME example_test COMMAND example)
|
||||
```
|
||||
|
||||
Note that this approach requires CMake 2.8.2 or later due to its use of the
|
||||
`ExternalProject_Add()` command. The above technique is discussed in more detail
|
||||
in [this separate article](http://crascit.com/2015/07/25/cmake-gtest/) which
|
||||
also contains a link to a fully generalized implementation of the technique.
|
||||
|
||||
##### Visual Studio Dynamic vs Static Runtimes
|
||||
|
||||
By default, new Visual Studio projects link the C runtimes dynamically but
|
||||
Google Test links them statically. This will generate an error that looks
|
||||
something like the following: gtest.lib(gtest-all.obj) : error LNK2038: mismatch
|
||||
detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value
|
||||
'MDd_DynamicDebug' in main.obj
|
||||
|
||||
Google Test already has a CMake option for this: `gtest_force_shared_crt`
|
||||
|
||||
Enabling this option will make gtest link the runtimes dynamically too, and
|
||||
match the project in which it is included.
|
||||
|
||||
### Legacy Build Scripts
|
||||
|
||||
Before settling on CMake, we have been providing hand-maintained build
|
||||
projects/scripts for Visual Studio, Xcode, and Autotools. While we continue to
|
||||
provide them for convenience, they are not actively maintained any more. We
|
||||
highly recommend that you follow the instructions in the above sections to
|
||||
integrate Google Test with your existing build system.
|
||||
|
||||
If you still need to use the legacy build scripts, here's how:
|
||||
|
||||
The msvc\ folder contains two solutions with Visual C++ projects. Open the
|
||||
`gtest.sln` or `gtest-md.sln` file using Visual Studio, and you are ready to
|
||||
build Google Test the same way you build any Visual Studio project. Files that
|
||||
have names ending with -md use DLL versions of Microsoft runtime libraries (the
|
||||
/MD or the /MDd compiler option). Files without that suffix use static versions
|
||||
of the runtime libraries (the /MT or the /MTd option). Please note that one must
|
||||
use the same option to compile both gtest and the test code. If you use Visual
|
||||
Studio 2005 or above, we recommend the -md version as /MD is the default for new
|
||||
projects in these versions of Visual Studio.
|
||||
|
||||
On Mac OS X, open the `gtest.xcodeproj` in the `xcode/` folder using Xcode.
|
||||
Build the "gtest" target. The universal binary framework will end up in your
|
||||
selected build directory (selected in the Xcode "Preferences..." -> "Building"
|
||||
pane and defaults to xcode/build). Alternatively, at the command line, enter:
|
||||
|
||||
xcodebuild
|
||||
|
||||
This will build the "Release" configuration of gtest.framework in your default
|
||||
build location. See the "xcodebuild" man page for more information about
|
||||
building different configurations and building in different locations.
|
||||
|
||||
If you wish to use the Google Test Xcode project with Xcode 4.x and above, you
|
||||
need to either:
|
||||
|
||||
* update the SDK configuration options in xcode/Config/General.xconfig.
|
||||
Comment options `SDKROOT`, `MACOS_DEPLOYMENT_TARGET`, and `GCC_VERSION`. If
|
||||
you choose this route you lose the ability to target earlier versions of
|
||||
MacOS X.
|
||||
* Install an SDK for an earlier version. This doesn't appear to be supported
|
||||
by Apple, but has been reported to work
|
||||
(http://stackoverflow.com/questions/5378518).
|
||||
|
||||
### Tweaking Google Test
|
||||
|
||||
Google Test can be used in diverse environments. The default configuration may
|
||||
not work (or may not work well) out of the box in some environments. However,
|
||||
you can easily tweak Google Test by defining control macros on the compiler
|
||||
command line. Generally, these macros are named like `GTEST_XYZ` and you define
|
||||
them to either 1 or 0 to enable or disable a certain feature.
|
||||
|
||||
We list the most frequently used macros below. For a complete list, see file
|
||||
[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/master/include/gtest/internal/gtest-port.h).
|
||||
|
||||
### Choosing a TR1 Tuple Library
|
||||
|
||||
Some Google Test features require the C++ Technical Report 1 (TR1) tuple
|
||||
library, which is not yet available with all compilers. The good news is that
|
||||
Google Test implements a subset of TR1 tuple that's enough for its own need, and
|
||||
will automatically use this when the compiler doesn't provide TR1 tuple.
|
||||
|
||||
Usually you don't need to care about which tuple library Google Test uses.
|
||||
However, if your project already uses TR1 tuple, you need to tell Google Test to
|
||||
use the same TR1 tuple library the rest of your project uses, or the two tuple
|
||||
implementations will clash. To do that, add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=0
|
||||
|
||||
to the compiler flags while compiling Google Test and your tests. If you want to
|
||||
force Google Test to use its own tuple library, just add
|
||||
|
||||
-DGTEST_USE_OWN_TR1_TUPLE=1
|
||||
|
||||
to the compiler flags instead.
|
||||
|
||||
If you don't want Google Test to use tuple at all, add
|
||||
|
||||
-DGTEST_HAS_TR1_TUPLE=0
|
||||
|
||||
and all features using tuple will be disabled.
|
||||
|
||||
### Multi-threaded Tests
|
||||
|
||||
Google Test is thread-safe where the pthread library is available. After
|
||||
`#include "gtest/gtest.h"`, you can check the `GTEST_IS_THREADSAFE` macro to see
|
||||
whether this is the case (yes if the macro is `#defined` to 1, no if it's
|
||||
undefined.).
|
||||
|
||||
If Google Test doesn't correctly detect whether pthread is available in your
|
||||
environment, you can force it with
|
||||
|
||||
-DGTEST_HAS_PTHREAD=1
|
||||
|
||||
or
|
||||
|
||||
-DGTEST_HAS_PTHREAD=0
|
||||
|
||||
When Google Test uses pthread, you may need to add flags to your compiler and/or
|
||||
linker to select the pthread library, or you'll get link errors. If you use the
|
||||
CMake script or the deprecated Autotools script, this is taken care of for you.
|
||||
If you use your own build script, you'll need to read your compiler and linker's
|
||||
manual to figure out what flags to add.
|
||||
|
||||
### As a Shared Library (DLL)
|
||||
|
||||
Google Test is compact, so most users can build and link it as a static library
|
||||
for the simplicity. You can choose to use Google Test as a shared library (known
|
||||
as a DLL on Windows) if you prefer.
|
||||
|
||||
To compile *gtest* as a shared library, add
|
||||
|
||||
-DGTEST_CREATE_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags. You'll also need to tell the linker to produce a shared
|
||||
library instead - consult your linker's manual for how to do it.
|
||||
|
||||
To compile your *tests* that use the gtest shared library, add
|
||||
|
||||
-DGTEST_LINKED_AS_SHARED_LIBRARY=1
|
||||
|
||||
to the compiler flags.
|
||||
|
||||
Note: while the above steps aren't technically necessary today when using some
|
||||
compilers (e.g. GCC), they may become necessary in the future, if we decide to
|
||||
improve the speed of loading the library (see
|
||||
<http://gcc.gnu.org/wiki/Visibility> for details). Therefore you are recommended
|
||||
to always add the above flags when using Google Test as a shared library.
|
||||
Otherwise a future release of Google Test may break your build script.
|
||||
|
||||
### Avoiding Macro Name Clashes
|
||||
|
||||
In C++, macros don't obey namespaces. Therefore two libraries that both define a
|
||||
macro of the same name will clash if you `#include` both definitions. In case a
|
||||
Google Test macro clashes with another library, you can force Google Test to
|
||||
rename its macro to avoid the conflict.
|
||||
|
||||
Specifically, if both Google Test and some other code define macro FOO, you can
|
||||
add
|
||||
|
||||
-DGTEST_DONT_DEFINE_FOO=1
|
||||
|
||||
to the compiler flags to tell Google Test to change the macro's name from `FOO`
|
||||
to `GTEST_FOO`. Currently `FOO` can be `FAIL`, `SUCCEED`, or `TEST`. For
|
||||
example, with `-DGTEST_DONT_DEFINE_TEST=1`, you'll need to write
|
||||
|
||||
GTEST_TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
instead of
|
||||
|
||||
TEST(SomeTest, DoesThis) { ... }
|
||||
|
||||
in order to define a test.
|
||||
@ -26,14 +26,14 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the public API for death tests. It is
|
||||
// #included by gtest.h so a user doesn't need to include this
|
||||
// directly.
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
@ -99,10 +99,11 @@ GTEST_API_ bool InDeathTestChild();
|
||||
//
|
||||
// On the regular expressions used in death tests:
|
||||
//
|
||||
// GOOGLETEST_CM0005 DO NOT DELETE
|
||||
// On POSIX-compliant systems (*nix), we use the <regex.h> library,
|
||||
// which uses the POSIX extended regex syntax.
|
||||
//
|
||||
// On other platforms (e.g. Windows), we only support a simple regex
|
||||
// On other platforms (e.g. Windows or Mac), we only support a simple regex
|
||||
// syntax implemented as part of Google Test. This limited
|
||||
// implementation should be enough most of the time when writing
|
||||
// death tests; though it lacks many features you can find in PCRE
|
||||
@ -160,7 +161,7 @@ GTEST_API_ bool InDeathTestChild();
|
||||
// is rarely a problem as people usually don't put the test binary
|
||||
// directory in PATH.
|
||||
//
|
||||
// TODO(wan@google.com): make thread-safe death tests search the PATH.
|
||||
// FIXME: make thread-safe death tests search the PATH.
|
||||
|
||||
// Asserts that a given statement causes the program to exit, with an
|
||||
// integer exit status that satisfies predicate, and emitting error output
|
||||
@ -198,9 +199,10 @@ class GTEST_API_ ExitedWithCode {
|
||||
const int exit_code_;
|
||||
};
|
||||
|
||||
# if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
// Tests that an exit code describes an exit due to termination by a
|
||||
// given signal.
|
||||
// GOOGLETEST_CM0006 DO NOT DELETE
|
||||
class GTEST_API_ KilledBySignal {
|
||||
public:
|
||||
explicit KilledBySignal(int signum);
|
||||
@ -272,6 +274,54 @@ class GTEST_API_ KilledBySignal {
|
||||
# endif // NDEBUG for EXPECT_DEBUG_DEATH
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// This macro is used for implementing macros such as
|
||||
// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
|
||||
// death tests are not supported. Those macros must compile on such systems
|
||||
// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
|
||||
// systems that support death tests. This allows one to write such a macro
|
||||
// on a system that does not support death tests and be sure that it will
|
||||
// compile on a death-test supporting system. It is exposed publicly so that
|
||||
// systems that have death-tests with stricter requirements than
|
||||
// GTEST_HAS_DEATH_TEST can write their own equivalent of
|
||||
// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED.
|
||||
//
|
||||
// Parameters:
|
||||
// statement - A statement that a macro such as EXPECT_DEATH would test
|
||||
// for program termination. This macro has to make sure this
|
||||
// statement is compiled but not executed, to ensure that
|
||||
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
|
||||
// parameter iff EXPECT_DEATH compiles with it.
|
||||
// regex - A regex that a macro such as EXPECT_DEATH would use to test
|
||||
// the output of statement. This parameter has to be
|
||||
// compiled but not evaluated by this macro, to ensure that
|
||||
// this macro only accepts expressions that a macro such as
|
||||
// EXPECT_DEATH would accept.
|
||||
// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
|
||||
// and a return statement for ASSERT_DEATH_IF_SUPPORTED.
|
||||
// This ensures that ASSERT_DEATH_IF_SUPPORTED will not
|
||||
// compile inside functions where ASSERT_DEATH doesn't
|
||||
// compile.
|
||||
//
|
||||
// The branch that has an always false condition is used to ensure that
|
||||
// statement and regex are compiled (and thus syntactically correct) but
|
||||
// never executed. The unreachable code macro protects the terminator
|
||||
// statement from generating an 'unreachable code' warning in case
|
||||
// statement unconditionally returns or throws. The Message constructor at
|
||||
// the end allows the syntax of streaming additional messages into the
|
||||
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
||||
# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_LOG_(WARNING) \
|
||||
<< "Death tests are not supported on this platform.\n" \
|
||||
<< "Statement '" #statement "' cannot be verified."; \
|
||||
} else if (::testing::internal::AlwaysFalse()) { \
|
||||
::testing::internal::RE::PartialMatch(".*", (regex)); \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
terminator; \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
|
||||
// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
|
||||
// death tests are supported; otherwise they just issue a warning. This is
|
||||
@ -284,9 +334,9 @@ class GTEST_API_ KilledBySignal {
|
||||
ASSERT_DEATH(statement, regex)
|
||||
#else
|
||||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )
|
||||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
|
||||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)
|
||||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
|
||||
#endif
|
||||
|
||||
} // namespace testing
|
||||
|
||||
@ -26,10 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the Message class.
|
||||
//
|
||||
@ -43,6 +42,8 @@
|
||||
// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
|
||||
// program!
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
|
||||
@ -50,6 +51,9 @@
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// Ensures that there is at least one operator<< in the global namespace.
|
||||
// See Message& operator<<(...) below for why.
|
||||
void operator<<(const testing::internal::Secret&, int);
|
||||
@ -196,7 +200,6 @@ class GTEST_API_ Message {
|
||||
std::string GetString() const;
|
||||
|
||||
private:
|
||||
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// These are needed as the Nokia Symbian Compiler cannot decide between
|
||||
// const T& and const T* in a function template. The Nokia compiler _can_
|
||||
@ -247,4 +250,6 @@ std::string StreamableToString(const T& streamable) {
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
|
||||
@ -31,13 +31,12 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: vladl@google.com (Vlad Losev)
|
||||
//
|
||||
// Macros and functions for implementing parameterized tests
|
||||
// in Google C++ Testing Framework (Google Test)
|
||||
// in Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
||||
@ -79,7 +78,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
||||
// case with any set of parameters you want. Google Test defines a number
|
||||
// of functions for generating test parameters. They return what we call
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
// are all in the testing namespace:
|
||||
//
|
||||
//
|
||||
@ -185,15 +184,10 @@ TEST_P(DerivedTest, DoesBlah) {
|
||||
# include <utility>
|
||||
#endif
|
||||
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-param-util-generated.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Functions producing parameter generators.
|
||||
@ -273,7 +267,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// each with C-string values of "foo", "bar", and "baz":
|
||||
//
|
||||
// const char* strings[] = {"foo", "bar", "baz"};
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
//
|
||||
// This instantiates tests from test case StlStringTest
|
||||
// each with STL strings with values "a" and "b":
|
||||
@ -1375,8 +1369,6 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
}
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public test_case_name { \
|
||||
@ -1387,14 +1379,17 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
static int AddToRegistry() { \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
|
||||
#test_case_name, \
|
||||
#test_name, \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestPattern(\
|
||||
GTEST_STRINGIFY_(test_case_name), \
|
||||
GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(\
|
||||
test_case_name, test_name)>()); \
|
||||
return 0; \
|
||||
} \
|
||||
static int gtest_registering_dummy_; \
|
||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
||||
}; \
|
||||
@ -1403,19 +1398,37 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
|
||||
::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
||||
// to specify a function or functor that generates custom test name suffixes
|
||||
// based on the test parameters. The function should accept one argument of
|
||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||
//
|
||||
// testing::PrintToStringParamName is a builtin test suffix generator that
|
||||
// returns the value of testing::PrintToString(GetParam()).
|
||||
//
|
||||
// Note: test names must be non-empty, unique, and may only contain ASCII
|
||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||
// to std::string and C strings, it won't work for these types.
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||
int gtest_##prefix##test_case_name##_dummy_ = \
|
||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
||||
(__VA_ARGS__)(info); \
|
||||
} \
|
||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
__FILE__, __LINE__)
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
||||
@ -30,13 +30,12 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: vladl@google.com (Vlad Losev)
|
||||
//
|
||||
// Macros and functions for implementing parameterized tests
|
||||
// in Google C++ Testing Framework (Google Test)
|
||||
// in Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
||||
@ -78,7 +77,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
||||
// case with any set of parameters you want. Google Test defines a number
|
||||
// of functions for generating test parameters. They return what we call
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
// (surprise!) parameter generators. Here is a summary of them, which
|
||||
// are all in the testing namespace:
|
||||
//
|
||||
//
|
||||
@ -184,15 +183,10 @@ TEST_P(DerivedTest, DoesBlah) {
|
||||
# include <utility>
|
||||
#endif
|
||||
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-param-util-generated.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Functions producing parameter generators.
|
||||
@ -272,7 +266,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
// each with C-string values of "foo", "bar", and "baz":
|
||||
//
|
||||
// const char* strings[] = {"foo", "bar", "baz"};
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
|
||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||
//
|
||||
// This instantiates tests from test case StlStringTest
|
||||
// each with STL strings with values "a" and "b":
|
||||
@ -441,8 +435,6 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
]]
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
|
||||
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public test_case_name { \
|
||||
@ -453,14 +445,17 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
static int AddToRegistry() { \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
|
||||
#test_case_name, \
|
||||
#test_name, \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestPattern(\
|
||||
GTEST_STRINGIFY_(test_case_name), \
|
||||
GTEST_STRINGIFY_(test_name), \
|
||||
new ::testing::internal::TestMetaFactory< \
|
||||
GTEST_TEST_CLASS_NAME_(\
|
||||
test_case_name, test_name)>()); \
|
||||
return 0; \
|
||||
} \
|
||||
static int gtest_registering_dummy_; \
|
||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
||||
}; \
|
||||
@ -469,19 +464,37 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
|
||||
::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
||||
// to specify a function or functor that generates custom test name suffixes
|
||||
// based on the test parameters. The function should accept one argument of
|
||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||
//
|
||||
// testing::PrintToStringParamName is a builtin test suffix generator that
|
||||
// returns the value of testing::PrintToString(GetParam()).
|
||||
//
|
||||
// Note: test names must be non-empty, unique, and may only contain ASCII
|
||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||
// to std::string and C strings, it won't work for these types.
|
||||
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||
int gtest_##prefix##test_case_name##_dummy_ = \
|
||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
||||
(__VA_ARGS__)(info); \
|
||||
} \
|
||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||
GetTestCasePatternHolder<test_case_name>(\
|
||||
#test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
__FILE__, __LINE__)
|
||||
#test_case_name, \
|
||||
::testing::internal::CodeLocation(\
|
||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
||||
#prefix, \
|
||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
||||
__FILE__, __LINE__)
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||
|
||||
@ -26,10 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
// Google Test - The Google C++ Testing Framework
|
||||
|
||||
// Google Test - The Google C++ Testing and Mocking Framework
|
||||
//
|
||||
// This file implements a universal value printer that can print a
|
||||
// value of any type T:
|
||||
@ -46,6 +45,10 @@
|
||||
// 2. operator<<(ostream&, const T&) defined in either foo or the
|
||||
// global namespace.
|
||||
//
|
||||
// However if T is an STL-style container then it is printed element-wise
|
||||
// unless foo::PrintTo(const T&, ostream*) is defined. Note that
|
||||
// operator<<() is ignored for container types.
|
||||
//
|
||||
// If none of the above is defined, it will print the debug string of
|
||||
// the value if it is a protocol buffer, or print the raw bytes in the
|
||||
// value otherwise.
|
||||
@ -92,6 +95,8 @@
|
||||
// being defined as many user-defined container types don't have
|
||||
// value_type.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
|
||||
@ -103,6 +108,16 @@
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
# include <tuple>
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "absl/types/variant.h"
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Definitions in the 'internal' and 'internal2' name spaces are
|
||||
@ -121,7 +136,11 @@ enum TypeKind {
|
||||
kProtobuf, // a protobuf type
|
||||
kConvertibleToInteger, // a type implicitly convertible to BiggestInt
|
||||
// (e.g. a named or unnamed enum type)
|
||||
kOtherType // anything else
|
||||
#if GTEST_HAS_ABSL
|
||||
kConvertibleToStringView, // a type implicitly convertible to
|
||||
// absl::string_view
|
||||
#endif
|
||||
kOtherType // anything else
|
||||
};
|
||||
|
||||
// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
|
||||
@ -133,7 +152,8 @@ class TypeWithoutFormatter {
|
||||
public:
|
||||
// This default version is called when kTypeKind is kOtherType.
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
PrintBytesInObjectTo(reinterpret_cast<const unsigned char*>(&value),
|
||||
PrintBytesInObjectTo(static_cast<const unsigned char*>(
|
||||
reinterpret_cast<const void*>(&value)),
|
||||
sizeof(value), os);
|
||||
}
|
||||
};
|
||||
@ -147,10 +167,10 @@ template <typename T>
|
||||
class TypeWithoutFormatter<T, kProtobuf> {
|
||||
public:
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
const ::testing::internal::string short_str = value.ShortDebugString();
|
||||
const ::testing::internal::string pretty_str =
|
||||
short_str.length() <= kProtobufOneLinerMaxLength ?
|
||||
short_str : ("\n" + value.DebugString());
|
||||
std::string pretty_str = value.ShortDebugString();
|
||||
if (pretty_str.length() > kProtobufOneLinerMaxLength) {
|
||||
pretty_str = "\n" + value.DebugString();
|
||||
}
|
||||
*os << ("<" + pretty_str + ">");
|
||||
}
|
||||
};
|
||||
@ -171,6 +191,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
|
||||
}
|
||||
};
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kConvertibleToStringView> {
|
||||
public:
|
||||
// Since T has neither operator<< nor PrintTo() but can be implicitly
|
||||
// converted to absl::string_view, we print it as a absl::string_view.
|
||||
//
|
||||
// Note: the implementation is further below, as it depends on
|
||||
// internal::PrintTo symbol which is defined later in the file.
|
||||
static void PrintValue(const T& value, ::std::ostream* os);
|
||||
};
|
||||
#endif
|
||||
|
||||
// Prints the given value to the given ostream. If the value is a
|
||||
// protocol message, its debug string is printed; if it's an enum or
|
||||
// of a type implicitly convertible to BiggestInt, it's printed as an
|
||||
@ -198,10 +231,19 @@ class TypeWithoutFormatter<T, kConvertibleToInteger> {
|
||||
template <typename Char, typename CharTraits, typename T>
|
||||
::std::basic_ostream<Char, CharTraits>& operator<<(
|
||||
::std::basic_ostream<Char, CharTraits>& os, const T& x) {
|
||||
TypeWithoutFormatter<T,
|
||||
(internal::IsAProtocolMessage<T>::value ? kProtobuf :
|
||||
internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ?
|
||||
kConvertibleToInteger : kOtherType)>::PrintValue(x, &os);
|
||||
TypeWithoutFormatter<T, (internal::IsAProtocolMessage<T>::value
|
||||
? kProtobuf
|
||||
: internal::ImplicitlyConvertible<
|
||||
const T&, internal::BiggestInt>::value
|
||||
? kConvertibleToInteger
|
||||
:
|
||||
#if GTEST_HAS_ABSL
|
||||
internal::ImplicitlyConvertible<
|
||||
const T&, absl::string_view>::value
|
||||
? kConvertibleToStringView
|
||||
:
|
||||
#endif
|
||||
kOtherType)>::PrintValue(x, &os);
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -250,6 +292,103 @@ void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
|
||||
// value of type ToPrint that is an operand of a comparison assertion
|
||||
// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
|
||||
// the comparison, and is used to help determine the best way to
|
||||
// format the value. In particular, when the value is a C string
|
||||
// (char pointer) and the other operand is an STL string object, we
|
||||
// want to format the C string as a string, since we know it is
|
||||
// compared by value with the string object. If the value is a char
|
||||
// pointer but the other operand is not an STL string object, we don't
|
||||
// know whether the pointer is supposed to point to a NUL-terminated
|
||||
// string, and thus want to print it as a pointer to be safe.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
|
||||
// The default case.
|
||||
template <typename ToPrint, typename OtherOperand>
|
||||
class FormatForComparison {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint& value) {
|
||||
return ::testing::PrintToString(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Array.
|
||||
template <typename ToPrint, size_t N, typename OtherOperand>
|
||||
class FormatForComparison<ToPrint[N], OtherOperand> {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint* value) {
|
||||
return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
|
||||
}
|
||||
};
|
||||
|
||||
// By default, print C string as pointers to be safe, as we don't know
|
||||
// whether they actually point to a NUL-terminated string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
|
||||
template <typename OtherOperand> \
|
||||
class FormatForComparison<CharType*, OtherOperand> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(static_cast<const void*>(value)); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
|
||||
|
||||
// If a C string is compared with an STL string object, we know it's meant
|
||||
// to point to a NUL-terminated string, and thus can print it as a string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
|
||||
template <> \
|
||||
class FormatForComparison<CharType*, OtherStringType> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(value); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_GLOBAL_WSTRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
|
||||
#endif
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
|
||||
|
||||
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
|
||||
// operand to be used in a failure message. The type (but not value)
|
||||
// of the other operand may affect the format. This allows us to
|
||||
// print a char* as a raw pointer when it is compared against another
|
||||
// char* or void*, and print it as a C string when it is compared
|
||||
// against an std::string object, for example.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
template <typename T1, typename T2>
|
||||
std::string FormatForComparisonFailureMessage(
|
||||
const T1& value, const T2& /* other_operand */) {
|
||||
return FormatForComparison<T1, T2>::Format(value);
|
||||
}
|
||||
|
||||
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
|
||||
// value to the given ostream. The caller must ensure that
|
||||
// 'ostream_ptr' is not NULL, or the behavior is undefined.
|
||||
@ -263,11 +402,18 @@ class UniversalPrinter;
|
||||
template <typename T>
|
||||
void UniversalPrint(const T& value, ::std::ostream* os);
|
||||
|
||||
enum DefaultPrinterType {
|
||||
kPrintContainer,
|
||||
kPrintPointer,
|
||||
kPrintFunctionPointer,
|
||||
kPrintOther,
|
||||
};
|
||||
template <DefaultPrinterType type> struct WrapPrinterType {};
|
||||
|
||||
// Used to print an STL-style container when the user doesn't define
|
||||
// a PrintTo() for it.
|
||||
template <typename C>
|
||||
void DefaultPrintTo(IsContainer /* dummy */,
|
||||
false_type /* is not a pointer */,
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintContainer> /* dummy */,
|
||||
const C& container, ::std::ostream* os) {
|
||||
const size_t kMaxCount = 32; // The maximum number of elements to print.
|
||||
*os << '{';
|
||||
@ -300,40 +446,34 @@ void DefaultPrintTo(IsContainer /* dummy */,
|
||||
// implementation-defined. Therefore they will be printed as raw
|
||||
// bytes.)
|
||||
template <typename T>
|
||||
void DefaultPrintTo(IsNotContainer /* dummy */,
|
||||
true_type /* is a pointer */,
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintPointer> /* dummy */,
|
||||
T* p, ::std::ostream* os) {
|
||||
if (p == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
// C++ doesn't allow casting from a function pointer to any object
|
||||
// pointer.
|
||||
//
|
||||
// IsTrue() silences warnings: "Condition is always true",
|
||||
// "unreachable code".
|
||||
if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) {
|
||||
// T is not a function type. We just call << to print p,
|
||||
// relying on ADL to pick up user-defined << for their pointer
|
||||
// types, if any.
|
||||
*os << p;
|
||||
} else {
|
||||
// T is a function type, so '*os << p' doesn't do what we want
|
||||
// (it just prints p as bool). We want to print p as a const
|
||||
// void*. However, we cannot cast it to const void* directly,
|
||||
// even using reinterpret_cast, as earlier versions of gcc
|
||||
// (e.g. 3.4.5) cannot compile the cast when p is a function
|
||||
// pointer. Casting to UInt64 first solves the problem.
|
||||
*os << reinterpret_cast<const void*>(
|
||||
reinterpret_cast<internal::UInt64>(p));
|
||||
}
|
||||
// T is not a function type. We just call << to print p,
|
||||
// relying on ADL to pick up user-defined << for their pointer
|
||||
// types, if any.
|
||||
*os << p;
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
|
||||
T* p, ::std::ostream* os) {
|
||||
if (p == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
// T is a function type, so '*os << p' doesn't do what we want
|
||||
// (it just prints p as bool). We want to print p as a const
|
||||
// void*.
|
||||
*os << reinterpret_cast<const void*>(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Used to print a non-container, non-pointer value when the user
|
||||
// doesn't define PrintTo() for it.
|
||||
template <typename T>
|
||||
void DefaultPrintTo(IsNotContainer /* dummy */,
|
||||
false_type /* is not a pointer */,
|
||||
void DefaultPrintTo(WrapPrinterType<kPrintOther> /* dummy */,
|
||||
const T& value, ::std::ostream* os) {
|
||||
::testing_internal::DefaultPrintNonContainerTo(value, os);
|
||||
}
|
||||
@ -351,11 +491,8 @@ void DefaultPrintTo(IsNotContainer /* dummy */,
|
||||
// wants).
|
||||
template <typename T>
|
||||
void PrintTo(const T& value, ::std::ostream* os) {
|
||||
// DefaultPrintTo() is overloaded. The type of its first two
|
||||
// arguments determine which version will be picked. If T is an
|
||||
// STL-style container, the version for container will be called; if
|
||||
// T is a pointer, the pointer version will be called; otherwise the
|
||||
// generic version will be called.
|
||||
// DefaultPrintTo() is overloaded. The type of its first argument
|
||||
// determines which version will be picked.
|
||||
//
|
||||
// Note that we check for container types here, prior to we check
|
||||
// for protocol message types in our operator<<. The rationale is:
|
||||
@ -367,13 +504,27 @@ void PrintTo(const T& value, ::std::ostream* os) {
|
||||
// elements; therefore we check for container types here to ensure
|
||||
// that our format is used.
|
||||
//
|
||||
// The second argument of DefaultPrintTo() is needed to bypass a bug
|
||||
// in Symbian's C++ compiler that prevents it from picking the right
|
||||
// overload between:
|
||||
//
|
||||
// PrintTo(const T& x, ...);
|
||||
// PrintTo(T* x, ...);
|
||||
DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);
|
||||
// Note that MSVC and clang-cl do allow an implicit conversion from
|
||||
// pointer-to-function to pointer-to-object, but clang-cl warns on it.
|
||||
// So don't use ImplicitlyConvertible if it can be helped since it will
|
||||
// cause this warning, and use a separate overload of DefaultPrintTo for
|
||||
// function pointers so that the `*os << p` in the object pointer overload
|
||||
// doesn't cause that warning either.
|
||||
DefaultPrintTo(
|
||||
WrapPrinterType <
|
||||
(sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
|
||||
!IsRecursiveContainer<T>::value
|
||||
? kPrintContainer
|
||||
: !is_pointer<T>::value
|
||||
? kPrintOther
|
||||
#if GTEST_LANG_CXX11
|
||||
: std::is_function<typename std::remove_pointer<T>::type>::value
|
||||
#else
|
||||
: !internal::ImplicitlyConvertible<T, const void*>::value
|
||||
#endif
|
||||
? kPrintFunctionPointer
|
||||
: kPrintPointer > (),
|
||||
value, os);
|
||||
}
|
||||
|
||||
// The following list of PrintTo() overloads tells
|
||||
@ -480,14 +631,27 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
||||
// which are packed as tuples.
|
||||
#if GTEST_HAS_ABSL
|
||||
// Overload for absl::string_view.
|
||||
inline void PrintTo(absl::string_view sp, ::std::ostream* os) {
|
||||
PrintTo(::std::string(sp), os);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T& t, ::std::ostream* os);
|
||||
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
||||
// which are packed as tuples.
|
||||
|
||||
// Overloaded PrintTo() for tuples of various arities. We support
|
||||
// tuples of up-to 10 fields. The following implementation works
|
||||
@ -561,6 +725,13 @@ void PrintTo(
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
template <typename... Types>
|
||||
void PrintTo(const ::std::tuple<Types...>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
// Overload for std::pair.
|
||||
template <typename T1, typename T2>
|
||||
void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
|
||||
@ -580,10 +751,7 @@ class UniversalPrinter {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
||||
#endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||
|
||||
// Note: we deliberately don't call this PrintTo(), as that name
|
||||
// conflicts with ::testing::internal::PrintTo in the body of the
|
||||
@ -600,11 +768,51 @@ class UniversalPrinter {
|
||||
PrintTo(value, os);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
};
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
|
||||
// Printer for absl::optional
|
||||
|
||||
template <typename T>
|
||||
class UniversalPrinter<::absl::optional<T>> {
|
||||
public:
|
||||
static void Print(const ::absl::optional<T>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
if (!value) {
|
||||
*os << "nullopt";
|
||||
} else {
|
||||
UniversalPrint(*value, os);
|
||||
}
|
||||
*os << ')';
|
||||
}
|
||||
};
|
||||
|
||||
// Printer for absl::variant
|
||||
|
||||
template <typename... T>
|
||||
class UniversalPrinter<::absl::variant<T...>> {
|
||||
public:
|
||||
static void Print(const ::absl::variant<T...>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
absl::visit(Visitor{os}, value);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
private:
|
||||
struct Visitor {
|
||||
template <typename U>
|
||||
void operator()(const U& u) const {
|
||||
*os << "'" << GetTypeName<U>() << "' with value ";
|
||||
UniversalPrint(u, os);
|
||||
}
|
||||
::std::ostream* os;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||
// elements, starting at address 'begin'.
|
||||
template <typename T>
|
||||
@ -618,7 +826,7 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
|
||||
// If the array has more than kThreshold elements, we'll have to
|
||||
// omit some details by printing only the first and the last
|
||||
// kChunkSize elements.
|
||||
// TODO(wan@google.com): let the user control the threshold using a flag.
|
||||
// FIXME: let the user control the threshold using a flag.
|
||||
if (len <= kThreshold) {
|
||||
PrintRawArrayTo(begin, len, os);
|
||||
} else {
|
||||
@ -654,10 +862,7 @@ class UniversalPrinter<T&> {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
||||
#endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
|
||||
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
// Prints the address of the value. We use reinterpret_cast here
|
||||
@ -668,9 +873,7 @@ class UniversalPrinter<T&> {
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
};
|
||||
|
||||
// Prints a value tersely: for a reference type, the referenced value
|
||||
@ -705,7 +908,7 @@ class UniversalTersePrinter<const char*> {
|
||||
if (str == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
UniversalPrint(string(str), os);
|
||||
UniversalPrint(std::string(str), os);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -756,16 +959,70 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
|
||||
UniversalPrinter<T1>::Print(value, os);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
typedef ::std::vector<string> Strings;
|
||||
typedef ::std::vector< ::std::string> Strings;
|
||||
|
||||
// TuplePolicy<TupleT> must provide:
|
||||
// - tuple_size
|
||||
// size of tuple TupleT.
|
||||
// - get<size_t I>(const TupleT& t)
|
||||
// static function extracting element I of tuple TupleT.
|
||||
// - tuple_element<size_t I>::type
|
||||
// type of element I of tuple TupleT.
|
||||
template <typename TupleT>
|
||||
struct TuplePolicy;
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
template <typename TupleT>
|
||||
struct TuplePolicy {
|
||||
typedef TupleT Tuple;
|
||||
static const size_t tuple_size = ::std::tr1::tuple_size<Tuple>::value;
|
||||
|
||||
template <size_t I>
|
||||
struct tuple_element : ::std::tr1::tuple_element<static_cast<int>(I), Tuple> {
|
||||
};
|
||||
|
||||
template <size_t I>
|
||||
static typename AddReference<const typename ::std::tr1::tuple_element<
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
I, Tuple>::type>::type
|
||||
#else
|
||||
static_cast<int>(I), Tuple>::type>::type
|
||||
#endif
|
||||
get(const Tuple& tuple) {
|
||||
return ::std::tr1::get<I>(tuple);
|
||||
}
|
||||
};
|
||||
template <typename TupleT>
|
||||
const size_t TuplePolicy<TupleT>::tuple_size;
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
template <typename... Types>
|
||||
struct TuplePolicy< ::std::tuple<Types...> > {
|
||||
typedef ::std::tuple<Types...> Tuple;
|
||||
static const size_t tuple_size = ::std::tuple_size<Tuple>::value;
|
||||
|
||||
template <size_t I>
|
||||
struct tuple_element : ::std::tuple_element<I, Tuple> {};
|
||||
|
||||
template <size_t I>
|
||||
static const typename ::std::tuple_element<I, Tuple>::type& get(
|
||||
const Tuple& tuple) {
|
||||
return ::std::get<I>(tuple);
|
||||
}
|
||||
};
|
||||
template <typename... Types>
|
||||
const size_t TuplePolicy< ::std::tuple<Types...> >::tuple_size;
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
// This helper template allows PrintTo() for tuples and
|
||||
// UniversalTersePrintTupleFieldsToStrings() to be defined by
|
||||
// induction on the number of tuple fields. The idea is that
|
||||
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
|
||||
// fields in tuple t, and can be defined in terms of
|
||||
// TuplePrefixPrinter<N - 1>.
|
||||
|
||||
//
|
||||
// The inductive case.
|
||||
template <size_t N>
|
||||
struct TuplePrefixPrinter {
|
||||
@ -773,9 +1030,14 @@ struct TuplePrefixPrinter {
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
||||
*os << ", ";
|
||||
UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
|
||||
::Print(::std::tr1::get<N - 1>(t), os);
|
||||
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
||||
if (N > 1) {
|
||||
GTEST_INTENTIONAL_CONST_COND_POP_()
|
||||
*os << ", ";
|
||||
}
|
||||
UniversalPrinter<
|
||||
typename TuplePolicy<Tuple>::template tuple_element<N - 1>::type>
|
||||
::Print(TuplePolicy<Tuple>::template get<N - 1>(t), os);
|
||||
}
|
||||
|
||||
// Tersely prints the first N fields of a tuple to a string vector,
|
||||
@ -784,12 +1046,12 @@ struct TuplePrefixPrinter {
|
||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
|
||||
UniversalTersePrint(TuplePolicy<Tuple>::template get<N - 1>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
// Base cases.
|
||||
// Base case.
|
||||
template <>
|
||||
struct TuplePrefixPrinter<0> {
|
||||
template <typename Tuple>
|
||||
@ -798,34 +1060,13 @@ struct TuplePrefixPrinter<0> {
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
|
||||
};
|
||||
// We have to specialize the entire TuplePrefixPrinter<> class
|
||||
// template here, even though the definition of
|
||||
// TersePrintPrefixToStrings() is the same as the generic version, as
|
||||
// Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't
|
||||
// support specializing a method template of a class template.
|
||||
template <>
|
||||
struct TuplePrefixPrinter<1> {
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||
UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
|
||||
Print(::std::tr1::get<0>(t), os);
|
||||
}
|
||||
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(::std::tr1::get<0>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T& t, ::std::ostream* os) {
|
||||
// Helper function for printing a tuple.
|
||||
// Tuple must be either std::tr1::tuple or std::tuple type.
|
||||
template <typename Tuple>
|
||||
void PrintTupleTo(const Tuple& t, ::std::ostream* os) {
|
||||
*os << "(";
|
||||
TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
|
||||
PrintPrefixTo(t, os);
|
||||
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::PrintPrefixTo(t, os);
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
@ -835,14 +1076,24 @@ void PrintTupleTo(const T& t, ::std::ostream* os) {
|
||||
template <typename Tuple>
|
||||
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
||||
Strings result;
|
||||
TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
|
||||
TuplePrefixPrinter<TuplePolicy<Tuple>::tuple_size>::
|
||||
TersePrintPrefixToStrings(value, &result);
|
||||
return result;
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
|
||||
} // namespace internal
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
namespace internal2 {
|
||||
template <typename T>
|
||||
void TypeWithoutFormatter<T, kConvertibleToStringView>::PrintValue(
|
||||
const T& value, ::std::ostream* os) {
|
||||
internal::PrintTo(absl::string_view(value), os);
|
||||
}
|
||||
} // namespace internal2
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
::std::string PrintToString(const T& value) {
|
||||
::std::stringstream ss;
|
||||
@ -852,4 +1103,9 @@ template <typename T>
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Include any custom printer added by the local installation.
|
||||
// We must include this header at the end to make sure it can use the
|
||||
// declarations from this file.
|
||||
#include "gtest/internal/custom/gtest-printers.h"
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
|
||||
@ -26,17 +26,21 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
//
|
||||
// Utilities for testing Google Test itself and code that uses Google Test
|
||||
// (e.g. frameworks built on top of Google Test).
|
||||
|
||||
// GOOGLETEST_CM0004 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This helper class can be used to mock out Google Test failure reporting
|
||||
@ -97,13 +101,12 @@ class GTEST_API_ SingleFailureChecker {
|
||||
public:
|
||||
// The constructor remembers the arguments.
|
||||
SingleFailureChecker(const TestPartResultArray* results,
|
||||
TestPartResult::Type type,
|
||||
const string& substr);
|
||||
TestPartResult::Type type, const std::string& substr);
|
||||
~SingleFailureChecker();
|
||||
private:
|
||||
const TestPartResultArray* const results_;
|
||||
const TestPartResult::Type type_;
|
||||
const string substr_;
|
||||
const std::string substr_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
|
||||
};
|
||||
@ -112,6 +115,8 @@ class GTEST_API_ SingleFailureChecker {
|
||||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// A set of macros for testing Google Test assertions or code that's expected
|
||||
// to generate Google Test fatal failures. It verifies that the given
|
||||
// statement will cause exactly one fatal Google Test failure with 'substr'
|
||||
|
||||
@ -27,8 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: mheule@google.com (Markus Heule)
|
||||
//
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
@ -38,6 +37,9 @@
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// A copyable object representing the result of a test part (i.e. an
|
||||
@ -143,7 +145,7 @@ class GTEST_API_ TestPartResultArray {
|
||||
};
|
||||
|
||||
// This interface knows how to report a test part result.
|
||||
class TestPartResultReporterInterface {
|
||||
class GTEST_API_ TestPartResultReporterInterface {
|
||||
public:
|
||||
virtual ~TestPartResultReporterInterface() {}
|
||||
|
||||
@ -176,4 +178,6 @@ class GTEST_API_ HasNewFatalFailureHelper
|
||||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
|
||||
@ -26,8 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||
@ -82,6 +83,24 @@ TYPED_TEST(FooTest, DoesBlah) {
|
||||
|
||||
TYPED_TEST(FooTest, HasPropertyA) { ... }
|
||||
|
||||
// TYPED_TEST_CASE takes an optional third argument which allows to specify a
|
||||
// class that generates custom test name suffixes based on the type. This should
|
||||
// be a class which has a static template function GetName(int index) returning
|
||||
// a string for each type. The provided integer index equals the index of the
|
||||
// type in the provided type list. In many cases the index can be ignored.
|
||||
//
|
||||
// For example:
|
||||
// class MyTypeNames {
|
||||
// public:
|
||||
// template <typename T>
|
||||
// static std::string GetName(int) {
|
||||
// if (std::is_same<T, char>()) return "char";
|
||||
// if (std::is_same<T, int>()) return "int";
|
||||
// if (std::is_same<T, unsigned int>()) return "unsignedInt";
|
||||
// }
|
||||
// };
|
||||
// TYPED_TEST_CASE(FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
// Type-parameterized tests are abstract test patterns parameterized
|
||||
@ -143,6 +162,11 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// If the type list contains only one type, you can write that type
|
||||
// directly without Types<...>:
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
|
||||
//
|
||||
// Similar to the optional argument of TYPED_TEST_CASE above,
|
||||
// INSTANTIATE_TEST_CASE_P takes an optional fourth argument which allows to
|
||||
// generate custom names.
|
||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes, MyTypeNames);
|
||||
|
||||
#endif // 0
|
||||
|
||||
@ -159,31 +183,46 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// given test case.
|
||||
# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
|
||||
|
||||
// Expands to the name of the typedef for the NameGenerator, responsible for
|
||||
// creating the suffixes of the name.
|
||||
#define GTEST_NAME_GENERATOR_(TestCaseName) \
|
||||
gtest_type_params_##TestCaseName##_NameGenerator
|
||||
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
# define TYPED_TEST_CASE(CaseName, Types) \
|
||||
typedef ::testing::internal::TypeList< Types >::type \
|
||||
GTEST_TYPE_PARAMS_(CaseName)
|
||||
# define TYPED_TEST_CASE(CaseName, Types, ...) \
|
||||
typedef ::testing::internal::TypeList< Types >::type GTEST_TYPE_PARAMS_( \
|
||||
CaseName); \
|
||||
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
||||
GTEST_NAME_GENERATOR_(CaseName)
|
||||
|
||||
# define TYPED_TEST(CaseName, TestName) \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
||||
: public CaseName<gtest_TypeParam_> { \
|
||||
private: \
|
||||
typedef CaseName<gtest_TypeParam_> TestFixture; \
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTest< \
|
||||
CaseName, \
|
||||
::testing::internal::TemplateSel< \
|
||||
GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
|
||||
GTEST_TYPE_PARAMS_(CaseName)>::Register(\
|
||||
"", #CaseName, #TestName, 0); \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()
|
||||
# define TYPED_TEST(CaseName, TestName) \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
||||
: public CaseName<gtest_TypeParam_> { \
|
||||
private: \
|
||||
typedef CaseName<gtest_TypeParam_> TestFixture; \
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
static bool gtest_##CaseName##_##TestName##_registered_ \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTest< \
|
||||
CaseName, \
|
||||
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||
TestName)>, \
|
||||
GTEST_TYPE_PARAMS_( \
|
||||
CaseName)>::Register("", \
|
||||
::testing::internal::CodeLocation( \
|
||||
__FILE__, __LINE__), \
|
||||
#CaseName, #TestName, 0, \
|
||||
::testing::internal::GenerateNames< \
|
||||
GTEST_NAME_GENERATOR_(CaseName), \
|
||||
GTEST_TYPE_PARAMS_(CaseName)>()); \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||
TestName)<gtest_TypeParam_>::TestBody()
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
@ -240,19 +279,27 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||
} \
|
||||
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
|
||||
__FILE__, __LINE__, #__VA_ARGS__)
|
||||
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \
|
||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames( \
|
||||
__FILE__, __LINE__, #__VA_ARGS__)
|
||||
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
|
||||
bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestCase<CaseName, \
|
||||
GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList< Types >::type>::Register(\
|
||||
#Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
|
||||
# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types, ...) \
|
||||
static bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestCase< \
|
||||
CaseName, GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList< Types >::type>:: \
|
||||
Register(#Prefix, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||
>EST_TYPED_TEST_CASE_P_STATE_(CaseName), #CaseName, \
|
||||
GTEST_REGISTERED_TEST_NAMES_(CaseName), \
|
||||
::testing::internal::GenerateNames< \
|
||||
::testing::internal::NameGeneratorSelector< \
|
||||
__VA_ARGS__>::type, \
|
||||
::testing::internal::TypeList< Types >::type>())
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
|
||||
@ -26,10 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the public API for Google Test. It should be
|
||||
// included by any test program that uses Google Test.
|
||||
@ -48,6 +47,8 @@
|
||||
// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
|
||||
// easyUnit framework.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
|
||||
@ -65,23 +66,35 @@
|
||||
#include "gtest/gtest-test-part.h"
|
||||
#include "gtest/gtest-typed-test.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// Depending on the platform, different string classes are available.
|
||||
// On Linux, in addition to ::std::string, Google also makes use of
|
||||
// class ::string, which has the same interface as ::std::string, but
|
||||
// has a different implementation.
|
||||
//
|
||||
// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
|
||||
// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
|
||||
// ::string is available AND is a distinct type to ::std::string, or
|
||||
// define it to 0 to indicate otherwise.
|
||||
//
|
||||
// If the user's ::std::string and ::string are the same class due to
|
||||
// aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
|
||||
// If ::std::string and ::string are the same class on your platform
|
||||
// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
|
||||
//
|
||||
// If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
|
||||
// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
|
||||
// heuristically.
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Silence C4100 (unreferenced formal parameter) and 4805
|
||||
// unsafe mix of type 'const int' and type 'const bool'
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4805)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
|
||||
// Declares the flags.
|
||||
|
||||
// This flag temporary enables the disabled tests.
|
||||
@ -103,6 +116,10 @@ GTEST_DECLARE_string_(color);
|
||||
// the tests to run. If the filter is not given all tests are executed.
|
||||
GTEST_DECLARE_string_(filter);
|
||||
|
||||
// This flag controls whether Google Test installs a signal handler that dumps
|
||||
// debugging information when fatal signals are raised.
|
||||
GTEST_DECLARE_bool_(install_failure_signal_handler);
|
||||
|
||||
// This flag causes the Google Test to list tests. None of the tests listed
|
||||
// are actually run if the flag is provided.
|
||||
GTEST_DECLARE_bool_(list_tests);
|
||||
@ -115,6 +132,9 @@ GTEST_DECLARE_string_(output);
|
||||
// test.
|
||||
GTEST_DECLARE_bool_(print_time);
|
||||
|
||||
// This flags control whether Google Test prints UTF8 characters as text.
|
||||
GTEST_DECLARE_bool_(print_utf8);
|
||||
|
||||
// This flag specifies the random number seed.
|
||||
GTEST_DECLARE_int32_(random_seed);
|
||||
|
||||
@ -135,7 +155,7 @@ GTEST_DECLARE_int32_(stack_trace_depth);
|
||||
|
||||
// When this flag is specified, a failed assertion will throw an
|
||||
// exception if exceptions are enabled, or exit the program with a
|
||||
// non-zero code otherwise.
|
||||
// non-zero code otherwise. For use with an external test framework.
|
||||
GTEST_DECLARE_bool_(throw_on_failure);
|
||||
|
||||
// When this flag is set with a "host:port" string, on supported
|
||||
@ -143,6 +163,10 @@ GTEST_DECLARE_bool_(throw_on_failure);
|
||||
// the specified host machine.
|
||||
GTEST_DECLARE_string_(stream_result_to);
|
||||
|
||||
#if GTEST_USE_OWN_FLAGFILE_FLAG_
|
||||
GTEST_DECLARE_string_(flagfile);
|
||||
#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
|
||||
|
||||
// The upper limit for valid stack trace depths.
|
||||
const int kMaxStackTraceDepth = 100;
|
||||
|
||||
@ -160,6 +184,7 @@ class TestEventListenersAccessor;
|
||||
class TestEventRepeater;
|
||||
class UnitTestRecordPropertyTestHelper;
|
||||
class WindowsDeathTest;
|
||||
class FuchsiaDeathTest;
|
||||
class UnitTestImpl* GetUnitTestImpl();
|
||||
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
||||
const std::string& message);
|
||||
@ -258,8 +283,35 @@ class GTEST_API_ AssertionResult {
|
||||
// Copy constructor.
|
||||
// Used in EXPECT_TRUE/FALSE(assertion_result).
|
||||
AssertionResult(const AssertionResult& other);
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
|
||||
#endif
|
||||
|
||||
// Used in the EXPECT_TRUE/FALSE(bool_expression).
|
||||
explicit AssertionResult(bool success) : success_(success) {}
|
||||
//
|
||||
// T must be contextually convertible to bool.
|
||||
//
|
||||
// The second parameter prevents this overload from being considered if
|
||||
// the argument is implicitly convertible to AssertionResult. In that case
|
||||
// we want AssertionResult's copy constructor to be used.
|
||||
template <typename T>
|
||||
explicit AssertionResult(
|
||||
const T& success,
|
||||
typename internal::EnableIf<
|
||||
!internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
|
||||
/*enabler*/ = NULL)
|
||||
: success_(success) {}
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#endif
|
||||
|
||||
// Assignment operator.
|
||||
AssertionResult& operator=(AssertionResult other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Returns true iff the assertion succeeded.
|
||||
operator bool() const { return success_; } // NOLINT
|
||||
@ -274,7 +326,7 @@ class GTEST_API_ AssertionResult {
|
||||
const char* message() const {
|
||||
return message_.get() != NULL ? message_->c_str() : "";
|
||||
}
|
||||
// TODO(vladl@google.com): Remove this after making sure no clients use it.
|
||||
// FIXME: Remove this after making sure no clients use it.
|
||||
// Deprecated; please use message() instead.
|
||||
const char* failure_message() const { return message(); }
|
||||
|
||||
@ -300,6 +352,9 @@ class GTEST_API_ AssertionResult {
|
||||
message_->append(a_message.GetString().c_str());
|
||||
}
|
||||
|
||||
// Swap the contents of this AssertionResult with other.
|
||||
void swap(AssertionResult& other);
|
||||
|
||||
// Stores result of the assertion predicate.
|
||||
bool success_;
|
||||
// Stores the message describing the condition in case the expectation
|
||||
@ -307,8 +362,6 @@ class GTEST_API_ AssertionResult {
|
||||
// Referenced via a pointer to avoid taking too much stack frame space
|
||||
// with test assertions.
|
||||
internal::scoped_ptr< ::std::string> message_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(AssertionResult);
|
||||
};
|
||||
|
||||
// Makes a successful assertion result.
|
||||
@ -321,6 +374,15 @@ GTEST_API_ AssertionResult AssertionFailure();
|
||||
// Deprecated; use AssertionFailure() << msg.
|
||||
GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Includes the auto-generated header that implements a family of generic
|
||||
// predicate assertion macros. This include comes late because it relies on
|
||||
// APIs declared above.
|
||||
#include "gtest/gtest_pred_impl.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// The abstract class that all tests inherit from.
|
||||
//
|
||||
// In Google Test, a unit test program contains one or many TestCases, and
|
||||
@ -331,12 +393,12 @@ GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
|
||||
// this for you.
|
||||
//
|
||||
// The only time you derive from Test is when defining a test fixture
|
||||
// to be used a TEST_F. For example:
|
||||
// to be used in a TEST_F. For example:
|
||||
//
|
||||
// class FooTest : public testing::Test {
|
||||
// protected:
|
||||
// virtual void SetUp() { ... }
|
||||
// virtual void TearDown() { ... }
|
||||
// void SetUp() override { ... }
|
||||
// void TearDown() override { ... }
|
||||
// ...
|
||||
// };
|
||||
//
|
||||
@ -428,20 +490,19 @@ class GTEST_API_ Test {
|
||||
// internal method to avoid clashing with names used in user TESTs.
|
||||
void DeleteSelf_() { delete this; }
|
||||
|
||||
// Uses a GTestFlagSaver to save and restore all Google Test flags.
|
||||
const internal::GTestFlagSaver* const gtest_flag_saver_;
|
||||
const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
|
||||
|
||||
// Often a user mis-spells SetUp() as Setup() and spends a long time
|
||||
// Often a user misspells SetUp() as Setup() and spends a long time
|
||||
// wondering why it is never called by Google Test. The declaration of
|
||||
// the following method is solely for catching such an error at
|
||||
// compile time:
|
||||
//
|
||||
// - The return type is deliberately chosen to be not void, so it
|
||||
// will be a conflict if a user declares void Setup() in his test
|
||||
// fixture.
|
||||
// will be a conflict if void Setup() is declared in the user's
|
||||
// test fixture.
|
||||
//
|
||||
// - This method is private, so it will be another compiler error
|
||||
// if a user calls it from his test fixture.
|
||||
// if the method is called from the user's test fixture.
|
||||
//
|
||||
// DO NOT OVERRIDE THIS FUNCTION.
|
||||
//
|
||||
@ -527,9 +588,8 @@ class GTEST_API_ TestResult {
|
||||
// Returns the elapsed time, in milliseconds.
|
||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||
|
||||
// Returns the i-th test part result among all the results. i can range
|
||||
// from 0 to test_property_count() - 1. If i is not in that range, aborts
|
||||
// the program.
|
||||
// Returns the i-th test part result among all the results. i can range from 0
|
||||
// to total_part_count() - 1. If i is not in that range, aborts the program.
|
||||
const TestPartResult& GetTestPartResult(int i) const;
|
||||
|
||||
// Returns the i-th test property. i can range from 0 to
|
||||
@ -546,6 +606,7 @@ class GTEST_API_ TestResult {
|
||||
friend class internal::TestResultAccessor;
|
||||
friend class internal::UnitTestImpl;
|
||||
friend class internal::WindowsDeathTest;
|
||||
friend class internal::FuchsiaDeathTest;
|
||||
|
||||
// Gets the vector of TestPartResults.
|
||||
const std::vector<TestPartResult>& test_part_results() const {
|
||||
@ -571,7 +632,7 @@ class GTEST_API_ TestResult {
|
||||
|
||||
// Adds a failure if the key is a reserved attribute of Google Test
|
||||
// testcase tags. Returns true if the property is valid.
|
||||
// TODO(russr): Validate attribute names are legal and human readable.
|
||||
// FIXME: Validate attribute names are legal and human readable.
|
||||
static bool ValidateTestProperty(const std::string& xml_element,
|
||||
const TestProperty& test_property);
|
||||
|
||||
@ -646,6 +707,15 @@ class GTEST_API_ TestInfo {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns the file name where this test is defined.
|
||||
const char* file() const { return location_.file.c_str(); }
|
||||
|
||||
// Returns the line where this test is defined.
|
||||
int line() const { return location_.line; }
|
||||
|
||||
// Return true if this test should not be run because it's in another shard.
|
||||
bool is_in_another_shard() const { return is_in_another_shard_; }
|
||||
|
||||
// Returns true if this test should run, that is if the test is not
|
||||
// disabled (or it is disabled but the also_run_disabled_tests flag has
|
||||
// been specified) and its full name matches the user-specified filter.
|
||||
@ -666,10 +736,9 @@ class GTEST_API_ TestInfo {
|
||||
|
||||
// Returns true iff this test will appear in the XML report.
|
||||
bool is_reportable() const {
|
||||
// For now, the XML report includes all tests matching the filter.
|
||||
// In the future, we may trim tests that are excluded because of
|
||||
// sharding.
|
||||
return matches_filter_;
|
||||
// The XML report includes tests matching the filter, excluding those
|
||||
// run in other shards.
|
||||
return matches_filter_ && !is_in_another_shard_;
|
||||
}
|
||||
|
||||
// Returns the result of the test.
|
||||
@ -688,6 +757,7 @@ class GTEST_API_ TestInfo {
|
||||
const char* name,
|
||||
const char* type_param,
|
||||
const char* value_param,
|
||||
internal::CodeLocation code_location,
|
||||
internal::TypeId fixture_class_id,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc,
|
||||
@ -699,6 +769,7 @@ class GTEST_API_ TestInfo {
|
||||
const std::string& name,
|
||||
const char* a_type_param, // NULL if not a type-parameterized test
|
||||
const char* a_value_param, // NULL if not a value-parameterized test
|
||||
internal::CodeLocation a_code_location,
|
||||
internal::TypeId fixture_class_id,
|
||||
internal::TestFactoryBase* factory);
|
||||
|
||||
@ -725,11 +796,13 @@ class GTEST_API_ TestInfo {
|
||||
// Text representation of the value parameter, or NULL if this is not a
|
||||
// value-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> value_param_;
|
||||
internal::CodeLocation location_;
|
||||
const internal::TypeId fixture_class_id_; // ID of the test fixture class
|
||||
bool should_run_; // True iff this test should run
|
||||
bool is_disabled_; // True iff this test is disabled
|
||||
bool matches_filter_; // True if this test matches the
|
||||
// user-specified filter.
|
||||
bool is_in_another_shard_; // Will be run in another shard.
|
||||
internal::TestFactoryBase* const factory_; // The factory that creates
|
||||
// the test object
|
||||
|
||||
@ -924,7 +997,7 @@ class GTEST_API_ TestCase {
|
||||
};
|
||||
|
||||
// An Environment object is capable of setting up and tearing down an
|
||||
// environment. The user should subclass this to define his own
|
||||
// environment. You should subclass this to define your own
|
||||
// environment(s).
|
||||
//
|
||||
// An Environment object does the set-up and tear-down in virtual
|
||||
@ -954,6 +1027,18 @@ class Environment {
|
||||
virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
|
||||
};
|
||||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
||||
// Exception which can be thrown from TestEventListener::OnTestPartResult.
|
||||
class GTEST_API_ AssertionException
|
||||
: public internal::GoogleTestFailureException {
|
||||
public:
|
||||
explicit AssertionException(const TestPartResult& result)
|
||||
: GoogleTestFailureException(result) {}
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
// The interface for tracing execution of tests. The methods are organized in
|
||||
// the order the corresponding events are fired.
|
||||
class TestEventListener {
|
||||
@ -982,6 +1067,8 @@ class TestEventListener {
|
||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||
|
||||
// Fired after a failed assertion or a SUCCEED() invocation.
|
||||
// If you want to throw an exception from this function to skip to the next
|
||||
// TEST, it must be AssertionException defined above, or inherited from it.
|
||||
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
|
||||
|
||||
// Fired after the test ends.
|
||||
@ -1148,14 +1235,12 @@ class GTEST_API_ UnitTest {
|
||||
// Returns the random seed used at the start of the current test run.
|
||||
int random_seed() const;
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
// Returns the ParameterizedTestCaseRegistry object used to keep track of
|
||||
// value-parameterized tests and instantiate and register them.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
|
||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
// Gets the number of successful test cases.
|
||||
int successful_test_case_count() const;
|
||||
@ -1255,11 +1340,11 @@ class GTEST_API_ UnitTest {
|
||||
internal::UnitTestImpl* impl() { return impl_; }
|
||||
const internal::UnitTestImpl* impl() const { return impl_; }
|
||||
|
||||
// These classes and funcions are friends as they need to access private
|
||||
// These classes and functions are friends as they need to access private
|
||||
// members of UnitTest.
|
||||
friend class ScopedTrace;
|
||||
friend class Test;
|
||||
friend class internal::AssertHelper;
|
||||
friend class internal::ScopedTrace;
|
||||
friend class internal::StreamingListenerTest;
|
||||
friend class internal::UnitTestRecordPropertyTestHelper;
|
||||
friend Environment* AddGlobalTestEnvironment(Environment* env);
|
||||
@ -1336,137 +1421,40 @@ GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
|
||||
|
||||
namespace internal {
|
||||
|
||||
// FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
|
||||
// value of type ToPrint that is an operand of a comparison assertion
|
||||
// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
|
||||
// the comparison, and is used to help determine the best way to
|
||||
// format the value. In particular, when the value is a C string
|
||||
// (char pointer) and the other operand is an STL string object, we
|
||||
// want to format the C string as a string, since we know it is
|
||||
// compared by value with the string object. If the value is a char
|
||||
// pointer but the other operand is not an STL string object, we don't
|
||||
// know whether the pointer is supposed to point to a NUL-terminated
|
||||
// string, and thus want to print it as a pointer to be safe.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
|
||||
// The default case.
|
||||
template <typename ToPrint, typename OtherOperand>
|
||||
class FormatForComparison {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint& value) {
|
||||
return ::testing::PrintToString(value);
|
||||
}
|
||||
};
|
||||
|
||||
// Array.
|
||||
template <typename ToPrint, size_t N, typename OtherOperand>
|
||||
class FormatForComparison<ToPrint[N], OtherOperand> {
|
||||
public:
|
||||
static ::std::string Format(const ToPrint* value) {
|
||||
return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
|
||||
}
|
||||
};
|
||||
|
||||
// By default, print C string as pointers to be safe, as we don't know
|
||||
// whether they actually point to a NUL-terminated string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
|
||||
template <typename OtherOperand> \
|
||||
class FormatForComparison<CharType*, OtherOperand> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(static_cast<const void*>(value)); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
|
||||
|
||||
// If a C string is compared with an STL string object, we know it's meant
|
||||
// to point to a NUL-terminated string, and thus can print it as a string.
|
||||
|
||||
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
|
||||
template <> \
|
||||
class FormatForComparison<CharType*, OtherStringType> { \
|
||||
public: \
|
||||
static ::std::string Format(CharType* value) { \
|
||||
return ::testing::PrintToString(value); \
|
||||
} \
|
||||
}
|
||||
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_GLOBAL_WSTRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
|
||||
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
|
||||
#endif
|
||||
|
||||
#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
|
||||
|
||||
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
|
||||
// operand to be used in a failure message. The type (but not value)
|
||||
// of the other operand may affect the format. This allows us to
|
||||
// print a char* as a raw pointer when it is compared against another
|
||||
// char* or void*, and print it as a C string when it is compared
|
||||
// against an std::string object, for example.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
// Separate the error generating code from the code path to reduce the stack
|
||||
// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
|
||||
// when calling EXPECT_* in a tight loop.
|
||||
template <typename T1, typename T2>
|
||||
std::string FormatForComparisonFailureMessage(
|
||||
const T1& value, const T2& /* other_operand */) {
|
||||
return FormatForComparison<T1, T2>::Format(value);
|
||||
AssertionResult CmpHelperEQFailure(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
const T1& lhs, const T2& rhs) {
|
||||
return EqFailure(lhs_expression,
|
||||
rhs_expression,
|
||||
FormatForComparisonFailureMessage(lhs, rhs),
|
||||
FormatForComparisonFailureMessage(rhs, lhs),
|
||||
false);
|
||||
}
|
||||
|
||||
// The helper function for {ASSERT|EXPECT}_EQ.
|
||||
template <typename T1, typename T2>
|
||||
AssertionResult CmpHelperEQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& expected,
|
||||
const T2& actual) {
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4389) // Temporarily disables warning on
|
||||
// signed/unsigned mismatch.
|
||||
#endif
|
||||
|
||||
if (expected == actual) {
|
||||
AssertionResult CmpHelperEQ(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
const T1& lhs,
|
||||
const T2& rhs) {
|
||||
if (lhs == rhs) {
|
||||
return AssertionSuccess();
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif
|
||||
|
||||
return EqFailure(expected_expression,
|
||||
actual_expression,
|
||||
FormatForComparisonFailureMessage(expected, actual),
|
||||
FormatForComparisonFailureMessage(actual, expected),
|
||||
false);
|
||||
return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
|
||||
// With this overloaded version, we allow anonymous enums to be used
|
||||
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
|
||||
// can be implicitly cast to BiggestInt.
|
||||
GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
BiggestInt expected,
|
||||
BiggestInt actual);
|
||||
GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
BiggestInt lhs,
|
||||
BiggestInt rhs);
|
||||
|
||||
// The helper class for {ASSERT|EXPECT}_EQ. The template argument
|
||||
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
|
||||
@ -1477,12 +1465,11 @@ class EqHelper {
|
||||
public:
|
||||
// This templatized version is for the general case.
|
||||
template <typename T1, typename T2>
|
||||
static AssertionResult Compare(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& expected,
|
||||
const T2& actual) {
|
||||
return CmpHelperEQ(expected_expression, actual_expression, expected,
|
||||
actual);
|
||||
static AssertionResult Compare(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
const T1& lhs,
|
||||
const T2& rhs) {
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
|
||||
// With this overloaded version, we allow anonymous enums to be used
|
||||
@ -1491,12 +1478,11 @@ class EqHelper {
|
||||
//
|
||||
// Even though its body looks the same as the above version, we
|
||||
// cannot merge the two, as it will make anonymous enums unhappy.
|
||||
static AssertionResult Compare(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
BiggestInt expected,
|
||||
BiggestInt actual) {
|
||||
return CmpHelperEQ(expected_expression, actual_expression, expected,
|
||||
actual);
|
||||
static AssertionResult Compare(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
BiggestInt lhs,
|
||||
BiggestInt rhs) {
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1511,40 +1497,52 @@ class EqHelper<true> {
|
||||
// EXPECT_EQ(false, a_bool).
|
||||
template <typename T1, typename T2>
|
||||
static AssertionResult Compare(
|
||||
const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& expected,
|
||||
const T2& actual,
|
||||
const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
const T1& lhs,
|
||||
const T2& rhs,
|
||||
// The following line prevents this overload from being considered if T2
|
||||
// is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
|
||||
// expands to Compare("", "", NULL, my_ptr), which requires a conversion
|
||||
// to match the Secret* in the other overload, which would otherwise make
|
||||
// this template match better.
|
||||
typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
|
||||
return CmpHelperEQ(expected_expression, actual_expression, expected,
|
||||
actual);
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
|
||||
// This version will be picked when the second argument to ASSERT_EQ() is a
|
||||
// pointer, e.g. ASSERT_EQ(NULL, a_pointer).
|
||||
template <typename T>
|
||||
static AssertionResult Compare(
|
||||
const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
// We used to have a second template parameter instead of Secret*. That
|
||||
// template parameter would deduce to 'long', making this a better match
|
||||
// than the first overload even without the first overload's EnableIf.
|
||||
// Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
|
||||
// non-pointer argument" (even a deduced integral argument), so the old
|
||||
// implementation caused warnings in user code.
|
||||
Secret* /* expected (NULL) */,
|
||||
T* actual) {
|
||||
// We already know that 'expected' is a null pointer.
|
||||
return CmpHelperEQ(expected_expression, actual_expression,
|
||||
static_cast<T*>(NULL), actual);
|
||||
Secret* /* lhs (NULL) */,
|
||||
T* rhs) {
|
||||
// We already know that 'lhs' is a null pointer.
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression,
|
||||
static_cast<T*>(NULL), rhs);
|
||||
}
|
||||
};
|
||||
|
||||
// Separate the error generating code from the code path to reduce the stack
|
||||
// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
|
||||
// when calling EXPECT_OP in a tight loop.
|
||||
template <typename T1, typename T2>
|
||||
AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
|
||||
const T1& val1, const T2& val2,
|
||||
const char* op) {
|
||||
return AssertionFailure()
|
||||
<< "Expected: (" << expr1 << ") " << op << " (" << expr2
|
||||
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)
|
||||
<< " vs " << FormatForComparisonFailureMessage(val2, val1);
|
||||
}
|
||||
|
||||
// A macro for implementing the helper functions needed to implement
|
||||
// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
|
||||
// of similar code.
|
||||
@ -1555,6 +1553,7 @@ class EqHelper<true> {
|
||||
// with gcc 4.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
|
||||
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
|
||||
template <typename T1, typename T2>\
|
||||
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
|
||||
@ -1562,10 +1561,7 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
|
||||
if (val1 op val2) {\
|
||||
return AssertionSuccess();\
|
||||
} else {\
|
||||
return AssertionFailure() \
|
||||
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
|
||||
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
|
||||
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
|
||||
return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
|
||||
}\
|
||||
}\
|
||||
GTEST_API_ AssertionResult CmpHelper##op_name(\
|
||||
@ -1589,18 +1585,18 @@ GTEST_IMPL_CMP_HELPER_(GT, >);
|
||||
// The helper function for {ASSERT|EXPECT}_STREQ.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const char* expected,
|
||||
const char* actual);
|
||||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
|
||||
const char* s2_expression,
|
||||
const char* s1,
|
||||
const char* s2);
|
||||
|
||||
// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const char* expected,
|
||||
const char* actual);
|
||||
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
|
||||
const char* s2_expression,
|
||||
const char* s1,
|
||||
const char* s2);
|
||||
|
||||
// The helper function for {ASSERT|EXPECT}_STRNE.
|
||||
//
|
||||
@ -1622,10 +1618,10 @@ GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
|
||||
// Helper function for *_STREQ on wide strings.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const wchar_t* expected,
|
||||
const wchar_t* actual);
|
||||
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
|
||||
const char* s2_expression,
|
||||
const wchar_t* s1,
|
||||
const wchar_t* s2);
|
||||
|
||||
// Helper function for *_STRNE on wide strings.
|
||||
//
|
||||
@ -1683,28 +1679,28 @@ namespace internal {
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
template <typename RawType>
|
||||
AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
RawType expected,
|
||||
RawType actual) {
|
||||
const FloatingPoint<RawType> lhs(expected), rhs(actual);
|
||||
AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
|
||||
const char* rhs_expression,
|
||||
RawType lhs_value,
|
||||
RawType rhs_value) {
|
||||
const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
|
||||
|
||||
if (lhs.AlmostEquals(rhs)) {
|
||||
return AssertionSuccess();
|
||||
}
|
||||
|
||||
::std::stringstream expected_ss;
|
||||
expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< expected;
|
||||
::std::stringstream lhs_ss;
|
||||
lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< lhs_value;
|
||||
|
||||
::std::stringstream actual_ss;
|
||||
actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< actual;
|
||||
::std::stringstream rhs_ss;
|
||||
rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< rhs_value;
|
||||
|
||||
return EqFailure(expected_expression,
|
||||
actual_expression,
|
||||
StringStreamToString(&expected_ss),
|
||||
StringStreamToString(&actual_ss),
|
||||
return EqFailure(lhs_expression,
|
||||
rhs_expression,
|
||||
StringStreamToString(&lhs_ss),
|
||||
StringStreamToString(&rhs_ss),
|
||||
false);
|
||||
}
|
||||
|
||||
@ -1761,7 +1757,6 @@ class GTEST_API_ AssertHelper {
|
||||
|
||||
} // namespace internal
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
// The pure interface class that all value-parameterized tests inherit from.
|
||||
// A value-parameterized class must inherit from both ::testing::Test and
|
||||
// ::testing::WithParamInterface. In most cases that just means inheriting
|
||||
@ -1838,8 +1833,6 @@ template <typename T>
|
||||
class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
// Macros for indicating success/failure in test code.
|
||||
|
||||
// ADD_FAILURE unconditionally adds a failure to the current test.
|
||||
@ -1924,18 +1917,14 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
|
||||
GTEST_FATAL_FAILURE_)
|
||||
|
||||
// Includes the auto-generated header that implements a family of
|
||||
// generic predicate assertion macros.
|
||||
#include "gtest/gtest_pred_impl.h"
|
||||
|
||||
// Macros for testing equalities and inequalities.
|
||||
//
|
||||
// * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
|
||||
// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
|
||||
// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
|
||||
// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
|
||||
// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
|
||||
// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
|
||||
// * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
|
||||
// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
|
||||
// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
|
||||
// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
|
||||
// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
|
||||
// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
|
||||
//
|
||||
// When they are not, Google Test prints both the tested expressions and
|
||||
// their actual values. The values must be compatible built-in types,
|
||||
@ -1957,8 +1946,8 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
// are related, not how their content is related. To compare two C
|
||||
// strings by content, use {ASSERT|EXPECT}_STR*().
|
||||
//
|
||||
// 3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
|
||||
// {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
|
||||
// 3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
|
||||
// {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
|
||||
// what the actual value is when it fails, and similarly for the
|
||||
// other comparisons.
|
||||
//
|
||||
@ -1969,17 +1958,17 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// EXPECT_NE(5, Foo());
|
||||
// EXPECT_EQ(NULL, a_pointer);
|
||||
// EXPECT_NE(Foo(), 5);
|
||||
// EXPECT_EQ(a_pointer, NULL);
|
||||
// ASSERT_LT(i, array_size);
|
||||
// ASSERT_GT(records.size(), 0) << "There is no record left.";
|
||||
|
||||
#define EXPECT_EQ(expected, actual) \
|
||||
#define EXPECT_EQ(val1, val2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal:: \
|
||||
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
|
||||
expected, actual)
|
||||
#define EXPECT_NE(expected, actual) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
|
||||
EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
|
||||
val1, val2)
|
||||
#define EXPECT_NE(val1, val2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
|
||||
#define EXPECT_LE(val1, val2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
|
||||
#define EXPECT_LT(val1, val2) \
|
||||
@ -1989,10 +1978,10 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
#define EXPECT_GT(val1, val2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
|
||||
|
||||
#define GTEST_ASSERT_EQ(expected, actual) \
|
||||
#define GTEST_ASSERT_EQ(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal:: \
|
||||
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
|
||||
expected, actual)
|
||||
EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
|
||||
val1, val2)
|
||||
#define GTEST_ASSERT_NE(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
|
||||
#define GTEST_ASSERT_LE(val1, val2) \
|
||||
@ -2047,29 +2036,29 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
//
|
||||
// These macros evaluate their arguments exactly once.
|
||||
|
||||
#define EXPECT_STREQ(expected, actual) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
|
||||
#define EXPECT_STREQ(s1, s2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
|
||||
#define EXPECT_STRNE(s1, s2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
|
||||
#define EXPECT_STRCASEEQ(expected, actual) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
|
||||
#define EXPECT_STRCASEEQ(s1, s2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
|
||||
#define EXPECT_STRCASENE(s1, s2)\
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
|
||||
|
||||
#define ASSERT_STREQ(expected, actual) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
|
||||
#define ASSERT_STREQ(s1, s2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
|
||||
#define ASSERT_STRNE(s1, s2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
|
||||
#define ASSERT_STRCASEEQ(expected, actual) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
|
||||
#define ASSERT_STRCASEEQ(s1, s2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
|
||||
#define ASSERT_STRCASENE(s1, s2)\
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
|
||||
|
||||
// Macros for comparing floating-point numbers.
|
||||
//
|
||||
// * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
|
||||
// * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
|
||||
// Tests that two float values are almost equal.
|
||||
// * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
|
||||
// * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
|
||||
// Tests that two double values are almost equal.
|
||||
// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
|
||||
// Tests that v1 and v2 are within the given distance to each other.
|
||||
@ -2079,21 +2068,21 @@ class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
// FloatingPoint template class in gtest-internal.h if you are
|
||||
// interested in the implementation details.
|
||||
|
||||
#define EXPECT_FLOAT_EQ(expected, actual)\
|
||||
#define EXPECT_FLOAT_EQ(val1, val2)\
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
|
||||
expected, actual)
|
||||
val1, val2)
|
||||
|
||||
#define EXPECT_DOUBLE_EQ(expected, actual)\
|
||||
#define EXPECT_DOUBLE_EQ(val1, val2)\
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
|
||||
expected, actual)
|
||||
val1, val2)
|
||||
|
||||
#define ASSERT_FLOAT_EQ(expected, actual)\
|
||||
#define ASSERT_FLOAT_EQ(val1, val2)\
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
|
||||
expected, actual)
|
||||
val1, val2)
|
||||
|
||||
#define ASSERT_DOUBLE_EQ(expected, actual)\
|
||||
#define ASSERT_DOUBLE_EQ(val1, val2)\
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
|
||||
expected, actual)
|
||||
val1, val2)
|
||||
|
||||
#define EXPECT_NEAR(val1, val2, abs_error)\
|
||||
EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
|
||||
@ -2156,6 +2145,57 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
|
||||
#define EXPECT_NO_FATAL_FAILURE(statement) \
|
||||
GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
|
||||
|
||||
// Causes a trace (including the given source file path and line number,
|
||||
// and the given message) to be included in every test failure message generated
|
||||
// by code in the scope of the lifetime of an instance of this class. The effect
|
||||
// is undone with the destruction of the instance.
|
||||
//
|
||||
// The message argument can be anything streamable to std::ostream.
|
||||
//
|
||||
// Example:
|
||||
// testing::ScopedTrace trace("file.cc", 123, "message");
|
||||
//
|
||||
class GTEST_API_ ScopedTrace {
|
||||
public:
|
||||
// The c'tor pushes the given source file location and message onto
|
||||
// a trace stack maintained by Google Test.
|
||||
|
||||
// Template version. Uses Message() to convert the values into strings.
|
||||
// Slow, but flexible.
|
||||
template <typename T>
|
||||
ScopedTrace(const char* file, int line, const T& message) {
|
||||
PushTrace(file, line, (Message() << message).GetString());
|
||||
}
|
||||
|
||||
// Optimize for some known types.
|
||||
ScopedTrace(const char* file, int line, const char* message) {
|
||||
PushTrace(file, line, message ? message : "(null)");
|
||||
}
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
ScopedTrace(const char* file, int line, const ::string& message) {
|
||||
PushTrace(file, line, message);
|
||||
}
|
||||
#endif
|
||||
|
||||
ScopedTrace(const char* file, int line, const std::string& message) {
|
||||
PushTrace(file, line, message);
|
||||
}
|
||||
|
||||
// The d'tor pops the info pushed by the c'tor.
|
||||
//
|
||||
// Note that the d'tor is not virtual in order to be efficient.
|
||||
// Don't inherit from ScopedTrace!
|
||||
~ScopedTrace();
|
||||
|
||||
private:
|
||||
void PushTrace(const char* file, int line, std::string message);
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
|
||||
} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its
|
||||
// c'tor and d'tor. Therefore it doesn't
|
||||
// need to be used otherwise.
|
||||
|
||||
// Causes a trace (including the source file path, the current line
|
||||
// number, and the given message) to be included in every test failure
|
||||
// message generated by code in the current scope. The effect is
|
||||
@ -2167,9 +2207,14 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
|
||||
// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
|
||||
// to appear in the same block - as long as they are on different
|
||||
// lines.
|
||||
//
|
||||
// Assuming that each thread maintains its own stack of traces.
|
||||
// Therefore, a SCOPED_TRACE() would (correctly) only affect the
|
||||
// assertions in its own thread.
|
||||
#define SCOPED_TRACE(message) \
|
||||
::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
|
||||
__FILE__, __LINE__, ::testing::Message() << (message))
|
||||
::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
|
||||
__FILE__, __LINE__, (message))
|
||||
|
||||
|
||||
// Compile-time assertion for type equality.
|
||||
// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
|
||||
@ -2215,8 +2260,8 @@ bool StaticAssertTypeEq() {
|
||||
// The convention is to end the test case name with "Test". For
|
||||
// example, a test case for the Foo class can be named FooTest.
|
||||
//
|
||||
// The user should put his test code between braces after using this
|
||||
// macro. Example:
|
||||
// Test code should appear between braces after an invocation of
|
||||
// this macro. Example:
|
||||
//
|
||||
// TEST(FooTest, InitializesCorrectly) {
|
||||
// Foo foo;
|
||||
@ -2249,7 +2294,7 @@ bool StaticAssertTypeEq() {
|
||||
// name of the test within the test case.
|
||||
//
|
||||
// A test fixture class must be declared earlier. The user should put
|
||||
// his test code between braces after using this macro. Example:
|
||||
// the test code between braces after using this macro. Example:
|
||||
//
|
||||
// class FooTest : public testing::Test {
|
||||
// protected:
|
||||
@ -2264,14 +2309,22 @@ bool StaticAssertTypeEq() {
|
||||
// }
|
||||
//
|
||||
// TEST_F(FooTest, ReturnsElementCountCorrectly) {
|
||||
// EXPECT_EQ(0, a_.size());
|
||||
// EXPECT_EQ(1, b_.size());
|
||||
// EXPECT_EQ(a_.size(), 0);
|
||||
// EXPECT_EQ(b_.size(), 1);
|
||||
// }
|
||||
|
||||
#define TEST_F(test_fixture, test_name)\
|
||||
GTEST_TEST_(test_fixture, test_name, test_fixture, \
|
||||
::testing::internal::GetTypeId<test_fixture>())
|
||||
|
||||
// Returns a path to temporary directory.
|
||||
// Tries to determine an appropriate directory for the platform.
|
||||
GTEST_API_ std::string TempDir();
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Use this function in main() to run all tests. It returns 0 if all
|
||||
@ -2288,4 +2341,6 @@ inline int RUN_ALL_TESTS() {
|
||||
return ::testing::UnitTest::GetInstance()->Run();
|
||||
}
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
|
||||
@ -27,18 +27,19 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 10/31/2011 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Implements a family of generic predicate assertion macros.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
|
||||
// Makes sure this header is not included before gtest.h.
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
# error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This header implements a family of generic predicate assertion
|
||||
// macros:
|
||||
@ -66,8 +67,6 @@
|
||||
// We also define the EXPECT_* variations.
|
||||
//
|
||||
// For now we only support predicates whose arity is at most 5.
|
||||
// Please email googletestframework@googlegroups.com if you need
|
||||
// support for higher arities.
|
||||
|
||||
// GTEST_ASSERT_ is the basic statement to which all of the assertions
|
||||
// in this file reduce. Don't use this in your code.
|
||||
@ -355,4 +354,6 @@ AssertionResult AssertPred5Helper(const char* pred_text,
|
||||
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// Google C++ Testing Framework definitions useful in production code.
|
||||
// Google C++ Testing and Mocking Framework definitions useful in production code.
|
||||
// GOOGLETEST_CM0003 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
|
||||
@ -40,17 +40,20 @@
|
||||
//
|
||||
// class MyClass {
|
||||
// private:
|
||||
// void MyMethod();
|
||||
// FRIEND_TEST(MyClassTest, MyMethod);
|
||||
// void PrivateMethod();
|
||||
// FRIEND_TEST(MyClassTest, PrivateMethodWorks);
|
||||
// };
|
||||
//
|
||||
// class MyClassTest : public testing::Test {
|
||||
// // ...
|
||||
// };
|
||||
//
|
||||
// TEST_F(MyClassTest, MyMethod) {
|
||||
// // Can call MyClass::MyMethod() here.
|
||||
// TEST_F(MyClassTest, PrivateMethodWorks) {
|
||||
// // Can call MyClass::PrivateMethod() here.
|
||||
// }
|
||||
//
|
||||
// Note: The test class must be in the same namespace as the class being tested.
|
||||
// For example, putting MyClassTest in an anonymous namespace will not work.
|
||||
|
||||
#define FRIEND_TEST(test_case_name, test_name)\
|
||||
friend class test_case_name##_##test_name##_Test
|
||||
|
||||
56
test/fmw/gtest/include/gtest/internal/custom/README.md
Normal file
56
test/fmw/gtest/include/gtest/internal/custom/README.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Customization Points
|
||||
|
||||
The custom directory is an injection point for custom user configurations.
|
||||
|
||||
## Header `gtest.h`
|
||||
|
||||
### The following macros can be defined:
|
||||
|
||||
* `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of
|
||||
`OsStackTraceGetterInterface`.
|
||||
* `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See
|
||||
`testing::TempDir` for semantics and signature.
|
||||
|
||||
## Header `gtest-port.h`
|
||||
|
||||
The following macros can be defined:
|
||||
|
||||
### Flag related macros:
|
||||
|
||||
* `GTEST_FLAG(flag_name)`
|
||||
* `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its
|
||||
own flagfile flag parsing.
|
||||
* `GTEST_DECLARE_bool_(name)`
|
||||
* `GTEST_DECLARE_int32_(name)`
|
||||
* `GTEST_DECLARE_string_(name)`
|
||||
* `GTEST_DEFINE_bool_(name, default_val, doc)`
|
||||
* `GTEST_DEFINE_int32_(name, default_val, doc)`
|
||||
* `GTEST_DEFINE_string_(name, default_val, doc)`
|
||||
|
||||
### Logging:
|
||||
|
||||
* `GTEST_LOG_(severity)`
|
||||
* `GTEST_CHECK_(condition)`
|
||||
* Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too.
|
||||
|
||||
### Threading:
|
||||
|
||||
* `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided.
|
||||
* `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal`
|
||||
are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)`
|
||||
and `GTEST_DEFINE_STATIC_MUTEX_(mutex)`
|
||||
* `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)`
|
||||
* `GTEST_LOCK_EXCLUDED_(locks)`
|
||||
|
||||
### Underlying library support features
|
||||
|
||||
* `GTEST_HAS_CXXABI_H_`
|
||||
|
||||
### Exporting API symbols:
|
||||
|
||||
* `GTEST_API_` - Specifier for exported symbols.
|
||||
|
||||
## Header `gtest-printers.h`
|
||||
|
||||
* See documentation at `gtest/gtest-printers.h` for details on how to define a
|
||||
custom printer.
|
||||
37
test/fmw/gtest/include/gtest/internal/custom/gtest-port.h
Normal file
37
test/fmw/gtest/include/gtest/internal/custom/gtest-port.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
|
||||
@ -0,0 +1,42 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This file provides an injection point for custom printers in a local
|
||||
// installation of gTest.
|
||||
// It will be included from gtest-printers.h and the overrides in this file
|
||||
// will be visible to everyone.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
|
||||
37
test/fmw/gtest/include/gtest/internal/custom/gtest.h
Normal file
37
test/fmw/gtest/include/gtest/internal/custom/gtest.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Injection point for custom user configurations. See README for details
|
||||
//
|
||||
// ** Custom implementation starts here **
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
|
||||
@ -27,12 +27,11 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines internal utilities needed for implementing
|
||||
// death tests. They are subject to change without notice.
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
@ -53,6 +52,9 @@ const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// DeathTest is a class that hides much of the complexity of the
|
||||
// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
|
||||
// returns a concrete class that depends on the prevailing death test
|
||||
@ -136,6 +138,8 @@ class GTEST_API_ DeathTest {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Factory interface for death tests. May be mocked out for testing.
|
||||
class DeathTestFactory {
|
||||
public:
|
||||
@ -218,14 +222,18 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
// can be streamed.
|
||||
|
||||
// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
|
||||
// NDEBUG mode. In this case we need the statements to be executed, the regex is
|
||||
// ignored, and the macro must accept a streamed message even though the message
|
||||
// is never printed.
|
||||
# define GTEST_EXECUTE_STATEMENT_(statement, regex) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} else \
|
||||
// NDEBUG mode. In this case we need the statements to be executed and the macro
|
||||
// must accept a streamed message even though the message is never printed.
|
||||
// The regex object is not evaluated, but it is used to prevent "unused"
|
||||
// warnings and to avoid an expression that doesn't compile in debug mode.
|
||||
#define GTEST_EXECUTE_STATEMENT_(statement, regex) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} else if (!::testing::internal::AlwaysTrue()) { \
|
||||
const ::testing::internal::RE& gtest_regex = (regex); \
|
||||
static_cast<void>(gtest_regex); \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
// A class representing the parsed contents of the
|
||||
@ -264,53 +272,6 @@ class InternalRunDeathTestFlag {
|
||||
// the flag is specified; otherwise returns NULL.
|
||||
InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
|
||||
|
||||
#else // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// This macro is used for implementing macros such as
|
||||
// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
|
||||
// death tests are not supported. Those macros must compile on such systems
|
||||
// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
|
||||
// systems that support death tests. This allows one to write such a macro
|
||||
// on a system that does not support death tests and be sure that it will
|
||||
// compile on a death-test supporting system.
|
||||
//
|
||||
// Parameters:
|
||||
// statement - A statement that a macro such as EXPECT_DEATH would test
|
||||
// for program termination. This macro has to make sure this
|
||||
// statement is compiled but not executed, to ensure that
|
||||
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
|
||||
// parameter iff EXPECT_DEATH compiles with it.
|
||||
// regex - A regex that a macro such as EXPECT_DEATH would use to test
|
||||
// the output of statement. This parameter has to be
|
||||
// compiled but not evaluated by this macro, to ensure that
|
||||
// this macro only accepts expressions that a macro such as
|
||||
// EXPECT_DEATH would accept.
|
||||
// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
|
||||
// and a return statement for ASSERT_DEATH_IF_SUPPORTED.
|
||||
// This ensures that ASSERT_DEATH_IF_SUPPORTED will not
|
||||
// compile inside functions where ASSERT_DEATH doesn't
|
||||
// compile.
|
||||
//
|
||||
// The branch that has an always false condition is used to ensure that
|
||||
// statement and regex are compiled (and thus syntactically correct) but
|
||||
// never executed. The unreachable code macro protects the terminator
|
||||
// statement from generating an 'unreachable code' warning in case
|
||||
// statement unconditionally returns or throws. The Message constructor at
|
||||
// the end allows the syntax of streaming additional messages into the
|
||||
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
||||
# define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_LOG_(WARNING) \
|
||||
<< "Death tests are not supported on this platform.\n" \
|
||||
<< "Statement '" #statement "' cannot be verified."; \
|
||||
} else if (::testing::internal::AlwaysFalse()) { \
|
||||
::testing::internal::RE::PartialMatch(".*", (regex)); \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
terminator; \
|
||||
} else \
|
||||
::testing::Message()
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -27,21 +27,24 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: keith.ray@gmail.com (Keith Ray)
|
||||
//
|
||||
// Google Test filepath utilities
|
||||
//
|
||||
// This header file declares classes and functions used internally by
|
||||
// Google Test. They are subject to change without notice.
|
||||
//
|
||||
// This file is #included in <gtest/internal/gtest-internal.h>.
|
||||
// This file is #included in gtest/internal/gtest-internal.h.
|
||||
// Do not include this header file separately!
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
@ -203,4 +206,6 @@ class GTEST_API_ FilePath {
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
|
||||
@ -27,13 +27,13 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file declares functions and macros used internally by
|
||||
// Google Test. They are subject to change without notice.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
|
||||
@ -55,11 +55,14 @@
|
||||
#include <string.h>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/internal/gtest-type-util.h"
|
||||
|
||||
// Due to C++ preprocessor weirdness, we need double indirection to
|
||||
@ -73,6 +76,9 @@
|
||||
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
|
||||
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
|
||||
|
||||
// Stringifies its argument.
|
||||
#define GTEST_STRINGIFY_(name) #name
|
||||
|
||||
class ProtocolMessage;
|
||||
namespace proto2 { class Message; }
|
||||
|
||||
@ -93,13 +99,9 @@ template <typename T>
|
||||
namespace internal {
|
||||
|
||||
struct TraceInfo; // Information about a trace point.
|
||||
class ScopedTrace; // Implements scoped trace.
|
||||
class TestInfoImpl; // Opaque implementation of TestInfo
|
||||
class UnitTestImpl; // Opaque implementation of UnitTest
|
||||
|
||||
// How many times InitGoogleTest() has been called.
|
||||
GTEST_API_ extern int g_init_gtest_count;
|
||||
|
||||
// The text used in failure messages to indicate the start of the
|
||||
// stack trace.
|
||||
GTEST_API_ extern const char kStackTraceMarker[];
|
||||
@ -139,6 +141,9 @@ GTEST_API_ std::string AppendUserMessage(
|
||||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \
|
||||
/* an exported class was derived from a class that was not exported */)
|
||||
|
||||
// This exception is thrown by (and only by) a failed Google Test
|
||||
// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
|
||||
// are enabled). We derive it from std::runtime_error, which is for
|
||||
@ -150,26 +155,39 @@ class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
|
||||
explicit GoogleTestFailureException(const TestPartResult& failure);
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4275
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
// A helper class for creating scoped traces in user programs.
|
||||
class GTEST_API_ ScopedTrace {
|
||||
public:
|
||||
// The c'tor pushes the given source file location and message onto
|
||||
// a trace stack maintained by Google Test.
|
||||
ScopedTrace(const char* file, int line, const Message& message);
|
||||
namespace edit_distance {
|
||||
// Returns the optimal edits to go from 'left' to 'right'.
|
||||
// All edits cost the same, with replace having lower priority than
|
||||
// add/remove.
|
||||
// Simple implementation of the Wagner-Fischer algorithm.
|
||||
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
||||
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||
const std::vector<size_t>& left, const std::vector<size_t>& right);
|
||||
|
||||
// The d'tor pops the info pushed by the c'tor.
|
||||
//
|
||||
// Note that the d'tor is not virtual in order to be efficient.
|
||||
// Don't inherit from ScopedTrace!
|
||||
~ScopedTrace();
|
||||
// Same as above, but the input is represented as strings.
|
||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||
const std::vector<std::string>& left,
|
||||
const std::vector<std::string>& right);
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
|
||||
} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its
|
||||
// c'tor and d'tor. Therefore it doesn't
|
||||
// need to be used otherwise.
|
||||
// Create a diff of the input strings in Unified diff format.
|
||||
GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
|
||||
const std::vector<std::string>& right,
|
||||
size_t context = 2);
|
||||
|
||||
} // namespace edit_distance
|
||||
|
||||
// Calculate the diff between 'left' and 'right' and return it in unified diff
|
||||
// format.
|
||||
// If not null, stores in 'total_line_count' the total number of lines found
|
||||
// in left + right.
|
||||
GTEST_API_ std::string DiffStrings(const std::string& left,
|
||||
const std::string& right,
|
||||
size_t* total_line_count);
|
||||
|
||||
// Constructs and returns the message for an equality assertion
|
||||
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
|
||||
@ -471,6 +489,14 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
|
||||
typedef void (*SetUpTestCaseFunc)();
|
||||
typedef void (*TearDownTestCaseFunc)();
|
||||
|
||||
struct CodeLocation {
|
||||
CodeLocation(const std::string& a_file, int a_line)
|
||||
: file(a_file), line(a_line) {}
|
||||
|
||||
std::string file;
|
||||
int line;
|
||||
};
|
||||
|
||||
// Creates a new TestInfo object and registers it with Google Test;
|
||||
// returns the created object.
|
||||
//
|
||||
@ -482,6 +508,7 @@ typedef void (*TearDownTestCaseFunc)();
|
||||
// this is not a typed or a type-parameterized test.
|
||||
// value_param text representation of the test's value parameter,
|
||||
// or NULL if this is not a type-parameterized test.
|
||||
// code_location: code location where the test is defined
|
||||
// fixture_class_id: ID of the test fixture class
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
@ -493,6 +520,7 @@ GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||
const char* name,
|
||||
const char* type_param,
|
||||
const char* value_param,
|
||||
CodeLocation code_location,
|
||||
TypeId fixture_class_id,
|
||||
SetUpTestCaseFunc set_up_tc,
|
||||
TearDownTestCaseFunc tear_down_tc,
|
||||
@ -505,6 +533,9 @@ GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// State of the definition of a type-parameterized test case.
|
||||
class GTEST_API_ TypedTestCasePState {
|
||||
public:
|
||||
@ -522,10 +553,21 @@ class GTEST_API_ TypedTestCasePState {
|
||||
fflush(stderr);
|
||||
posix::Abort();
|
||||
}
|
||||
defined_test_names_.insert(test_name);
|
||||
registered_tests_.insert(
|
||||
::std::make_pair(test_name, CodeLocation(file, line)));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestExists(const std::string& test_name) const {
|
||||
return registered_tests_.count(test_name) > 0;
|
||||
}
|
||||
|
||||
const CodeLocation& GetCodeLocation(const std::string& test_name) const {
|
||||
RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
|
||||
GTEST_CHECK_(it != registered_tests_.end());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// Verifies that registered_tests match the test names in
|
||||
// defined_test_names_; returns registered_tests if successful, or
|
||||
// aborts the program otherwise.
|
||||
@ -533,10 +575,14 @@ class GTEST_API_ TypedTestCasePState {
|
||||
const char* file, int line, const char* registered_tests);
|
||||
|
||||
private:
|
||||
typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
|
||||
|
||||
bool registered_;
|
||||
::std::set<const char*> defined_test_names_;
|
||||
RegisteredTestsMap registered_tests_;
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Skips to the first non-space char after the first comma in 'str';
|
||||
// returns NULL if no comma is found in 'str'.
|
||||
inline const char* SkipComma(const char* str) {
|
||||
@ -555,6 +601,42 @@ inline std::string GetPrefixUntilComma(const char* str) {
|
||||
return comma == NULL ? str : std::string(str, comma);
|
||||
}
|
||||
|
||||
// Splits a given string on a given delimiter, populating a given
|
||||
// vector with the fields.
|
||||
void SplitString(const ::std::string& str, char delimiter,
|
||||
::std::vector< ::std::string>* dest);
|
||||
|
||||
// The default argument to the template below for the case when the user does
|
||||
// not provide a name generator.
|
||||
struct DefaultNameGenerator {
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
return StreamableToString(i);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Provided = DefaultNameGenerator>
|
||||
struct NameGeneratorSelector {
|
||||
typedef Provided type;
|
||||
};
|
||||
|
||||
template <typename NameGenerator>
|
||||
void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
|
||||
|
||||
template <typename NameGenerator, typename Types>
|
||||
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
|
||||
result->push_back(NameGenerator::template GetName<typename Types::Head>(i));
|
||||
GenerateNamesRecursively<NameGenerator>(typename Types::Tail(), result,
|
||||
i + 1);
|
||||
}
|
||||
|
||||
template <typename NameGenerator, typename Types>
|
||||
std::vector<std::string> GenerateNames() {
|
||||
std::vector<std::string> result;
|
||||
GenerateNamesRecursively<NameGenerator>(Types(), &result, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
|
||||
// registers a list of type-parameterized tests with Google Test. The
|
||||
// return value is insignificant - we just need to return something
|
||||
@ -569,8 +651,10 @@ class TypeParameterizedTest {
|
||||
// specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
|
||||
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
||||
// length of Types.
|
||||
static bool Register(const char* prefix, const char* case_name,
|
||||
const char* test_names, int index) {
|
||||
static bool Register(const char* prefix, const CodeLocation& code_location,
|
||||
const char* case_name, const char* test_names, int index,
|
||||
const std::vector<std::string>& type_names =
|
||||
GenerateNames<DefaultNameGenerator, Types>()) {
|
||||
typedef typename Types::Head Type;
|
||||
typedef Fixture<Type> FixtureClass;
|
||||
typedef typename GTEST_BIND_(TestSel, Type) TestClass;
|
||||
@ -578,19 +662,23 @@ class TypeParameterizedTest {
|
||||
// First, registers the first type-parameterized test in the type
|
||||
// list.
|
||||
MakeAndRegisterTestInfo(
|
||||
(std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
|
||||
+ StreamableToString(index)).c_str(),
|
||||
GetPrefixUntilComma(test_names).c_str(),
|
||||
(std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name +
|
||||
"/" + type_names[index])
|
||||
.c_str(),
|
||||
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
|
||||
GetTypeName<Type>().c_str(),
|
||||
NULL, // No value parameter.
|
||||
GetTypeId<FixtureClass>(),
|
||||
TestClass::SetUpTestCase,
|
||||
TestClass::TearDownTestCase,
|
||||
new TestFactoryImpl<TestClass>);
|
||||
code_location, GetTypeId<FixtureClass>(), TestClass::SetUpTestCase,
|
||||
TestClass::TearDownTestCase, new TestFactoryImpl<TestClass>);
|
||||
|
||||
// Next, recurses (at compile time) with the tail of the type list.
|
||||
return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
|
||||
::Register(prefix, case_name, test_names, index + 1);
|
||||
return TypeParameterizedTest<Fixture, TestSel,
|
||||
typename Types::Tail>::Register(prefix,
|
||||
code_location,
|
||||
case_name,
|
||||
test_names,
|
||||
index + 1,
|
||||
type_names);
|
||||
}
|
||||
};
|
||||
|
||||
@ -598,8 +686,11 @@ class TypeParameterizedTest {
|
||||
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
||||
class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||
public:
|
||||
static bool Register(const char* /*prefix*/, const char* /*case_name*/,
|
||||
const char* /*test_names*/, int /*index*/) {
|
||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||
const char* /*case_name*/, const char* /*test_names*/,
|
||||
int /*index*/,
|
||||
const std::vector<std::string>& =
|
||||
std::vector<std::string>() /*type_names*/) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -611,17 +702,35 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
||||
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
||||
class TypeParameterizedTestCase {
|
||||
public:
|
||||
static bool Register(const char* prefix, const char* case_name,
|
||||
const char* test_names) {
|
||||
static bool Register(const char* prefix, CodeLocation code_location,
|
||||
const TypedTestCasePState* state, const char* case_name,
|
||||
const char* test_names,
|
||||
const std::vector<std::string>& type_names =
|
||||
GenerateNames<DefaultNameGenerator, Types>()) {
|
||||
std::string test_name = StripTrailingSpaces(
|
||||
GetPrefixUntilComma(test_names));
|
||||
if (!state->TestExists(test_name)) {
|
||||
fprintf(stderr, "Failed to get code location for test %s.%s at %s.",
|
||||
case_name, test_name.c_str(),
|
||||
FormatFileLocation(code_location.file.c_str(),
|
||||
code_location.line).c_str());
|
||||
fflush(stderr);
|
||||
posix::Abort();
|
||||
}
|
||||
const CodeLocation& test_location = state->GetCodeLocation(test_name);
|
||||
|
||||
typedef typename Tests::Head Head;
|
||||
|
||||
// First, register the first test in 'Test' for each type in 'Types'.
|
||||
TypeParameterizedTest<Fixture, Head, Types>::Register(
|
||||
prefix, case_name, test_names, 0);
|
||||
prefix, test_location, case_name, test_names, 0, type_names);
|
||||
|
||||
// Next, recurses (at compile time) with the tail of the test list.
|
||||
return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
|
||||
::Register(prefix, case_name, SkipComma(test_names));
|
||||
return TypeParameterizedTestCase<Fixture, typename Tests::Tail,
|
||||
Types>::Register(prefix, code_location,
|
||||
state, case_name,
|
||||
SkipComma(test_names),
|
||||
type_names);
|
||||
}
|
||||
};
|
||||
|
||||
@ -629,8 +738,11 @@ class TypeParameterizedTestCase {
|
||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
||||
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
||||
public:
|
||||
static bool Register(const char* /*prefix*/, const char* /*case_name*/,
|
||||
const char* /*test_names*/) {
|
||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||
const TypedTestCasePState* /*state*/,
|
||||
const char* /*case_name*/, const char* /*test_names*/,
|
||||
const std::vector<std::string>& =
|
||||
std::vector<std::string>() /*type_names*/) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -747,31 +859,6 @@ struct RemoveConst<T[N]> {
|
||||
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
|
||||
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
|
||||
|
||||
// Adds reference to a type if it is not a reference type,
|
||||
// otherwise leaves it unchanged. This is the same as
|
||||
// tr1::add_reference, which is not widely available yet.
|
||||
template <typename T>
|
||||
struct AddReference { typedef T& type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct AddReference<T&> { typedef T& type; }; // NOLINT
|
||||
|
||||
// A handy wrapper around AddReference that works when the argument T
|
||||
// depends on template parameters.
|
||||
#define GTEST_ADD_REFERENCE_(T) \
|
||||
typename ::testing::internal::AddReference<T>::type
|
||||
|
||||
// Adds a reference to const on top of T as necessary. For example,
|
||||
// it transforms
|
||||
//
|
||||
// char ==> const char&
|
||||
// const char ==> const char&
|
||||
// char& ==> const char&
|
||||
// const char& ==> const char&
|
||||
//
|
||||
// The argument T must depend on some template parameters.
|
||||
#define GTEST_REFERENCE_TO_CONST_(T) \
|
||||
GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
|
||||
|
||||
// ImplicitlyConvertible<From, To>::value is a compile-time bool
|
||||
// constant that's true iff type From can be implicitly converted to
|
||||
// type To.
|
||||
@ -784,7 +871,7 @@ class ImplicitlyConvertible {
|
||||
// MakeFrom() is an expression whose type is From. We cannot simply
|
||||
// use From(), as the type From may not have a public default
|
||||
// constructor.
|
||||
static From MakeFrom();
|
||||
static typename AddReference<From>::type MakeFrom();
|
||||
|
||||
// These two functions are overloaded. Given an expression
|
||||
// Helper(x), the compiler will pick the first version if x can be
|
||||
@ -802,25 +889,20 @@ class ImplicitlyConvertible {
|
||||
// We have to put the 'public' section after the 'private' section,
|
||||
// or MSVC refuses to compile the code.
|
||||
public:
|
||||
// MSVC warns about implicitly converting from double to int for
|
||||
// possible loss of data, so we need to temporarily disable the
|
||||
// warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4244) // Temporarily disables warning 4244.
|
||||
|
||||
static const bool value =
|
||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#elif defined(__BORLANDC__)
|
||||
#if defined(__BORLANDC__)
|
||||
// C++Builder cannot use member overload resolution during template
|
||||
// instantiation. The simplest workaround is to use its C++0x type traits
|
||||
// functions (C++Builder 2009 and above only).
|
||||
static const bool value = __is_convertible(From, To);
|
||||
#else
|
||||
// MSVC warns about implicitly converting from double to int for
|
||||
// possible loss of data, so we need to temporarily disable the
|
||||
// warning.
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244)
|
||||
static const bool value =
|
||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
||||
#endif // _MSV_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_()
|
||||
#endif // __BORLANDC__
|
||||
};
|
||||
template <typename From, typename To>
|
||||
const bool ImplicitlyConvertible<From, To>::value;
|
||||
@ -846,8 +928,11 @@ struct IsAProtocolMessage
|
||||
// a container class by checking the type of IsContainerTest<C>(0).
|
||||
// The value of the expression is insignificant.
|
||||
//
|
||||
// Note that we look for both C::iterator and C::const_iterator. The
|
||||
// reason is that C++ injects the name of a class as a member of the
|
||||
// In C++11 mode we check the existence of a const_iterator and that an
|
||||
// iterator is properly implemented for the container.
|
||||
//
|
||||
// For pre-C++11 that we look for both C::iterator and C::const_iterator.
|
||||
// The reason is that C++ injects the name of a class as a member of the
|
||||
// class itself (e.g. you can refer to class iterator as either
|
||||
// 'iterator' or 'iterator::iterator'). If we look for C::iterator
|
||||
// only, for example, we would mistakenly think that a class named
|
||||
@ -857,17 +942,96 @@ struct IsAProtocolMessage
|
||||
// IsContainerTest(typename C::const_iterator*) and
|
||||
// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
|
||||
typedef int IsContainer;
|
||||
#if GTEST_LANG_CXX11
|
||||
template <class C,
|
||||
class Iterator = decltype(::std::declval<const C&>().begin()),
|
||||
class = decltype(::std::declval<const C&>().end()),
|
||||
class = decltype(++::std::declval<Iterator&>()),
|
||||
class = decltype(*::std::declval<Iterator>()),
|
||||
class = typename C::const_iterator>
|
||||
IsContainer IsContainerTest(int /* dummy */) {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
template <class C>
|
||||
IsContainer IsContainerTest(int /* dummy */,
|
||||
typename C::iterator* /* it */ = NULL,
|
||||
typename C::const_iterator* /* const_it */ = NULL) {
|
||||
return 0;
|
||||
}
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
typedef char IsNotContainer;
|
||||
template <class C>
|
||||
IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
|
||||
|
||||
// Trait to detect whether a type T is a hash table.
|
||||
// The heuristic used is that the type contains an inner type `hasher` and does
|
||||
// not contain an inner type `reverse_iterator`.
|
||||
// If the container is iterable in reverse, then order might actually matter.
|
||||
template <typename T>
|
||||
struct IsHashTable {
|
||||
private:
|
||||
template <typename U>
|
||||
static char test(typename U::hasher*, typename U::reverse_iterator*);
|
||||
template <typename U>
|
||||
static int test(typename U::hasher*, ...);
|
||||
template <typename U>
|
||||
static char test(...);
|
||||
|
||||
public:
|
||||
static const bool value = sizeof(test<T>(0, 0)) == sizeof(int);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const bool IsHashTable<T>::value;
|
||||
|
||||
template<typename T>
|
||||
struct VoidT {
|
||||
typedef void value_type;
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct HasValueType : false_type {};
|
||||
template <typename T>
|
||||
struct HasValueType<T, VoidT<typename T::value_type> > : true_type {
|
||||
};
|
||||
|
||||
template <typename C,
|
||||
bool = sizeof(IsContainerTest<C>(0)) == sizeof(IsContainer),
|
||||
bool = HasValueType<C>::value>
|
||||
struct IsRecursiveContainerImpl;
|
||||
|
||||
template <typename C, bool HV>
|
||||
struct IsRecursiveContainerImpl<C, false, HV> : public false_type {};
|
||||
|
||||
// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to
|
||||
// obey the same inconsistencies as the IsContainerTest, namely check if
|
||||
// something is a container is relying on only const_iterator in C++11 and
|
||||
// is relying on both const_iterator and iterator otherwise
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, false> : public false_type {};
|
||||
|
||||
template <typename C>
|
||||
struct IsRecursiveContainerImpl<C, true, true> {
|
||||
#if GTEST_LANG_CXX11
|
||||
typedef typename IteratorTraits<typename C::const_iterator>::value_type
|
||||
value_type;
|
||||
#else
|
||||
typedef typename IteratorTraits<typename C::iterator>::value_type value_type;
|
||||
#endif
|
||||
typedef is_same<value_type, C> type;
|
||||
};
|
||||
|
||||
// IsRecursiveContainer<Type> is a unary compile-time predicate that
|
||||
// evaluates whether C is a recursive container type. A recursive container
|
||||
// type is a container type whose value_type is equal to the container type
|
||||
// itself. An example for a recursive container type is
|
||||
// boost::filesystem::path, whose iterator has a value_type that is equal to
|
||||
// boost::filesystem::path.
|
||||
template <typename C>
|
||||
struct IsRecursiveContainer : public IsRecursiveContainerImpl<C>::type {};
|
||||
|
||||
// EnableIf<condition>::type is void when 'Cond' is true, and
|
||||
// undefined when 'Cond' is false. To use SFINAE to make a function
|
||||
// overload only apply when a particular expression is true, add
|
||||
@ -946,11 +1110,10 @@ void CopyArray(const T* from, size_t size, U* to) {
|
||||
|
||||
// The relation between an NativeArray object (see below) and the
|
||||
// native array it represents.
|
||||
enum RelationToSource {
|
||||
kReference, // The NativeArray references the native array.
|
||||
kCopy // The NativeArray makes a copy of the native array and
|
||||
// owns the copy.
|
||||
};
|
||||
// We use 2 different structs to allow non-copyable types to be used, as long
|
||||
// as RelationToSourceReference() is passed.
|
||||
struct RelationToSourceReference {};
|
||||
struct RelationToSourceCopy {};
|
||||
|
||||
// Adapts a native array to a read-only STL-style container. Instead
|
||||
// of the complete STL container concept, this adaptor only implements
|
||||
@ -968,22 +1131,23 @@ class NativeArray {
|
||||
typedef Element* iterator;
|
||||
typedef const Element* const_iterator;
|
||||
|
||||
// Constructs from a native array.
|
||||
NativeArray(const Element* array, size_t count, RelationToSource relation) {
|
||||
Init(array, count, relation);
|
||||
// Constructs from a native array. References the source.
|
||||
NativeArray(const Element* array, size_t count, RelationToSourceReference) {
|
||||
InitRef(array, count);
|
||||
}
|
||||
|
||||
// Constructs from a native array. Copies the source.
|
||||
NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
|
||||
InitCopy(array, count);
|
||||
}
|
||||
|
||||
// Copy constructor.
|
||||
NativeArray(const NativeArray& rhs) {
|
||||
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
|
||||
(this->*rhs.clone_)(rhs.array_, rhs.size_);
|
||||
}
|
||||
|
||||
~NativeArray() {
|
||||
// Ensures that the user doesn't instantiate NativeArray with a
|
||||
// const or reference type.
|
||||
static_cast<void>(StaticAssertTypeEqHelper<Element,
|
||||
GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
|
||||
if (relation_to_source_ == kCopy)
|
||||
if (clone_ != &NativeArray::InitRef)
|
||||
delete[] array_;
|
||||
}
|
||||
|
||||
@ -997,23 +1161,30 @@ class NativeArray {
|
||||
}
|
||||
|
||||
private:
|
||||
// Initializes this object; makes a copy of the input array if
|
||||
// 'relation' is kCopy.
|
||||
void Init(const Element* array, size_t a_size, RelationToSource relation) {
|
||||
if (relation == kReference) {
|
||||
array_ = array;
|
||||
} else {
|
||||
Element* const copy = new Element[a_size];
|
||||
CopyArray(array, a_size, copy);
|
||||
array_ = copy;
|
||||
}
|
||||
enum {
|
||||
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
|
||||
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value
|
||||
};
|
||||
|
||||
// Initializes this object with a copy of the input.
|
||||
void InitCopy(const Element* array, size_t a_size) {
|
||||
Element* const copy = new Element[a_size];
|
||||
CopyArray(array, a_size, copy);
|
||||
array_ = copy;
|
||||
size_ = a_size;
|
||||
relation_to_source_ = relation;
|
||||
clone_ = &NativeArray::InitCopy;
|
||||
}
|
||||
|
||||
// Initializes this object with a reference of the input.
|
||||
void InitRef(const Element* array, size_t a_size) {
|
||||
array_ = array;
|
||||
size_ = a_size;
|
||||
clone_ = &NativeArray::InitRef;
|
||||
}
|
||||
|
||||
const Element* array_;
|
||||
size_t size_;
|
||||
RelationToSource relation_to_source_;
|
||||
void (NativeArray::*clone_)(const Element*, size_t);
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||
};
|
||||
@ -1037,7 +1208,7 @@ class NativeArray {
|
||||
#define GTEST_SUCCESS_(message) \
|
||||
GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
|
||||
|
||||
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
|
||||
// Suppress MSVC warning 4702 (unreachable code) for the code following
|
||||
// statement if it returns or throws (or doesn't return or throw in some
|
||||
// situations).
|
||||
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
|
||||
@ -1148,6 +1319,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||
::test_info_ =\
|
||||
::testing::internal::MakeAndRegisterTestInfo(\
|
||||
#test_case_name, #test_name, NULL, NULL, \
|
||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||
(parent_id), \
|
||||
parent_class::SetUpTestCase, \
|
||||
parent_class::TearDownTestCase, \
|
||||
|
||||
@ -27,8 +27,6 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: Dan Egnor (egnor@google.com)
|
||||
//
|
||||
// A "smart" pointer type with reference tracking. Every pointer to a
|
||||
// particular object is kept on a circular linked list. When the last pointer
|
||||
// to an object is destroyed or reassigned, the object is deleted.
|
||||
@ -62,9 +60,11 @@
|
||||
// raw pointer (e.g. via get()) concurrently, and
|
||||
// - it's safe to write to two linked_ptrs that point to the same
|
||||
// shared object concurrently.
|
||||
// TODO(wan@google.com): rename this to safe_linked_ptr to avoid
|
||||
// FIXME: rename this to safe_linked_ptr to avoid
|
||||
// confusion with normal linked_ptr.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
|
||||
|
||||
@ -110,7 +110,12 @@ class linked_ptr_internal {
|
||||
MutexLock lock(&g_linked_ptr_mutex);
|
||||
|
||||
linked_ptr_internal const* p = ptr;
|
||||
while (p->next_ != ptr) p = p->next_;
|
||||
while (p->next_ != ptr) {
|
||||
assert(p->next_ != this &&
|
||||
"Trying to join() a linked ring we are already in. "
|
||||
"Is GMock thread safety enabled?");
|
||||
p = p->next_;
|
||||
}
|
||||
p->next_ = this;
|
||||
next_ = ptr;
|
||||
}
|
||||
@ -123,7 +128,12 @@ class linked_ptr_internal {
|
||||
|
||||
if (next_ == this) return true;
|
||||
linked_ptr_internal const* p = next_;
|
||||
while (p->next_ != this) p = p->next_;
|
||||
while (p->next_ != this) {
|
||||
assert(p->next_ != next_ &&
|
||||
"Trying to depart() a linked ring we are not in. "
|
||||
"Is GMock thread safety enabled?");
|
||||
p = p->next_;
|
||||
}
|
||||
p->next_ = next_;
|
||||
return false;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -29,8 +29,7 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: vladl@google.com (Vlad Losev)
|
||||
|
||||
|
||||
// Type and function utilities for implementing parameterized tests.
|
||||
// This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
@ -39,20 +38,17 @@ $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
|
||||
// and at most $maxtuple arguments in Combine. Please contact
|
||||
// googletestframework@googlegroups.com if you need more.
|
||||
// Please note that the number of arguments to Combine is limited
|
||||
// by the maximum arity of the implementation of tr1::tuple which is
|
||||
// by the maximum arity of the implementation of tuple which is
|
||||
// currently set at $maxtuple.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
|
||||
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Forward declarations of ValuesIn(), which is implemented in
|
||||
@ -72,29 +68,14 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
||||
namespace internal {
|
||||
|
||||
// Used in the Values() function to provide polymorphic capabilities.
|
||||
template <typename T1>
|
||||
class ValueArray1 {
|
||||
public:
|
||||
explicit ValueArray1(T1 v1) : v1_(v1) {}
|
||||
|
||||
template <typename T>
|
||||
operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
|
||||
|
||||
private:
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const ValueArray1& other);
|
||||
|
||||
const T1 v1_;
|
||||
};
|
||||
|
||||
$range i 2..n
|
||||
$range i 1..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
|
||||
template <$for j, [[typename T$j]]>
|
||||
class ValueArray$i {
|
||||
public:
|
||||
ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
|
||||
$if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
|
||||
|
||||
template <typename T>
|
||||
operator ParamGenerator<T>() const {
|
||||
@ -102,6 +83,8 @@ class ValueArray$i {
|
||||
return ValuesIn(array);
|
||||
}
|
||||
|
||||
ValueArray$i(const ValueArray$i& other) : $for j, [[v$(j)_(other.v$(j)_)]] {}
|
||||
|
||||
private:
|
||||
// No implementation - assignment is unsupported.
|
||||
void operator=(const ValueArray$i& other);
|
||||
@ -128,9 +111,9 @@ $range k 2..i
|
||||
|
||||
template <$for j, [[typename T$j]]>
|
||||
class CartesianProductGenerator$i
|
||||
: public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > {
|
||||
: public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > {
|
||||
public:
|
||||
typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType;
|
||||
typedef ::testing::tuple<$for j, [[T$j]]> ParamType;
|
||||
|
||||
CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
|
||||
: $for j, [[g$(j)_(g$j)]] {}
|
||||
@ -180,7 +163,7 @@ $for k [[
|
||||
virtual ParamIteratorInterface<ParamType>* Clone() const {
|
||||
return new Iterator(*this);
|
||||
}
|
||||
virtual const ParamType* Current() const { return ¤t_value_; }
|
||||
virtual const ParamType* Current() const { return current_value_.get(); }
|
||||
virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
|
||||
// Having the same base generator guarantees that the other
|
||||
// iterator is of the same type and we can downcast.
|
||||
@ -212,7 +195,7 @@ $for k [[
|
||||
|
||||
void ComputeCurrentValue() {
|
||||
if (!AtEnd())
|
||||
current_value_ = ParamType($for j, [[*current$(j)_]]);
|
||||
current_value_.reset(new ParamType($for j, [[*current$(j)_]]));
|
||||
}
|
||||
bool AtEnd() const {
|
||||
// We must report iterator past the end of the range when either of the
|
||||
@ -237,7 +220,7 @@ $for j [[
|
||||
typename ParamGenerator<T$j>::iterator current$(j)_;
|
||||
]]
|
||||
|
||||
ParamType current_value_;
|
||||
linked_ptr<ParamType> current_value_;
|
||||
}; // class CartesianProductGenerator$i::Iterator
|
||||
|
||||
// No implementation - assignment is unsupported.
|
||||
@ -269,8 +252,8 @@ class CartesianProductHolder$i {
|
||||
CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
|
||||
: $for j, [[g$(j)_(g$j)]] {}
|
||||
template <$for j, [[typename T$j]]>
|
||||
operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const {
|
||||
return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >(
|
||||
operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const {
|
||||
return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >(
|
||||
new CartesianProductGenerator$i<$for j, [[T$j]]>(
|
||||
$for j,[[
|
||||
|
||||
@ -296,6 +279,4 @@ $for j [[
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
|
||||
|
||||
@ -26,29 +26,49 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: vladl@google.com (Vlad Losev)
|
||||
|
||||
|
||||
// Type and function utilities for implementing parameterized tests.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Input to a parameterized test name generator, describing a test parameter.
|
||||
// Consists of the parameter value and the integer parameter index.
|
||||
template <class ParamType>
|
||||
struct TestParamInfo {
|
||||
TestParamInfo(const ParamType& a_param, size_t an_index) :
|
||||
param(a_param),
|
||||
index(an_index) {}
|
||||
ParamType param;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
// A builtin parameterized test name generator which returns the result of
|
||||
// testing::PrintToString.
|
||||
struct PrintToStringParamName {
|
||||
template <class ParamType>
|
||||
std::string operator()(const TestParamInfo<ParamType>& info) const {
|
||||
return PrintToString(info.param);
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
@ -58,7 +78,7 @@ namespace internal {
|
||||
// TEST_P macro is used to define two tests with the same name
|
||||
// but in different namespaces.
|
||||
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
||||
const char* file, int line);
|
||||
CodeLocation code_location);
|
||||
|
||||
template <typename> class ParamGeneratorInterface;
|
||||
template <typename> class ParamGenerator;
|
||||
@ -206,7 +226,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||
return base_;
|
||||
}
|
||||
virtual void Advance() {
|
||||
value_ = value_ + step_;
|
||||
value_ = static_cast<T>(value_ + step_);
|
||||
index_++;
|
||||
}
|
||||
virtual ParamIteratorInterface<T>* Clone() const {
|
||||
@ -243,7 +263,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
|
||||
const T& end,
|
||||
const IncrementT& step) {
|
||||
int end_index = 0;
|
||||
for (T i = begin; i < end; i = i + step)
|
||||
for (T i = begin; i < end; i = static_cast<T>(i + step))
|
||||
end_index++;
|
||||
return end_index;
|
||||
}
|
||||
@ -345,6 +365,37 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
const ContainerType container_;
|
||||
}; // class ValuesInIteratorRangeGenerator
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Default parameterized test name generator, returns a string containing the
|
||||
// integer test parameter index.
|
||||
template <class ParamType>
|
||||
std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
|
||||
Message name_stream;
|
||||
name_stream << info.index;
|
||||
return name_stream.GetString();
|
||||
}
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Parameterized test name overload helpers, which help the
|
||||
// INSTANTIATE_TEST_CASE_P macro choose between the default parameterized
|
||||
// test name generator and user param name generator.
|
||||
template <class ParamType, class ParamNameGenFunctor>
|
||||
ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) {
|
||||
return func;
|
||||
}
|
||||
|
||||
template <class ParamType>
|
||||
struct ParamNameGenFunc {
|
||||
typedef std::string Type(const TestParamInfo<ParamType>&);
|
||||
};
|
||||
|
||||
template <class ParamType>
|
||||
typename ParamNameGenFunc<ParamType>::Type *GetParamNameGen() {
|
||||
return DefaultParamName;
|
||||
}
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Stores a parameter value and later creates tests parameterized with that
|
||||
@ -417,7 +468,7 @@ class ParameterizedTestCaseInfoBase {
|
||||
virtual ~ParameterizedTestCaseInfoBase() {}
|
||||
|
||||
// Base part of test case name for display purposes.
|
||||
virtual const string& GetTestCaseName() const = 0;
|
||||
virtual const std::string& GetTestCaseName() const = 0;
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const = 0;
|
||||
// UnitTest class invokes this method to register tests in this
|
||||
@ -449,12 +500,14 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
typedef typename TestCase::ParamType ParamType;
|
||||
// A function that returns an instance of appropriate generator type.
|
||||
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
||||
typedef typename ParamNameGenFunc<ParamType>::Type ParamNameGeneratorFunc;
|
||||
|
||||
explicit ParameterizedTestCaseInfo(const char* name)
|
||||
: test_case_name_(name) {}
|
||||
explicit ParameterizedTestCaseInfo(
|
||||
const char* name, CodeLocation code_location)
|
||||
: test_case_name_(name), code_location_(code_location) {}
|
||||
|
||||
// Test case base name for display purposes.
|
||||
virtual const string& GetTestCaseName() const { return test_case_name_; }
|
||||
virtual const std::string& GetTestCaseName() const { return test_case_name_; }
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
|
||||
// TEST_P macro uses AddTestPattern() to record information
|
||||
@ -472,11 +525,12 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
}
|
||||
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
|
||||
// about a generator.
|
||||
int AddTestCaseInstantiation(const string& instantiation_name,
|
||||
int AddTestCaseInstantiation(const std::string& instantiation_name,
|
||||
GeneratorCreationFunc* func,
|
||||
const char* /* file */,
|
||||
int /* line */) {
|
||||
instantiations_.push_back(::std::make_pair(instantiation_name, func));
|
||||
ParamNameGeneratorFunc* name_func,
|
||||
const char* file, int line) {
|
||||
instantiations_.push_back(
|
||||
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
||||
return 0; // Return value used only to run this method in namespace scope.
|
||||
}
|
||||
// UnitTest class invokes this method to register tests in this test case
|
||||
@ -491,25 +545,45 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
for (typename InstantiationContainer::iterator gen_it =
|
||||
instantiations_.begin(); gen_it != instantiations_.end();
|
||||
++gen_it) {
|
||||
const string& instantiation_name = gen_it->first;
|
||||
ParamGenerator<ParamType> generator((*gen_it->second)());
|
||||
const std::string& instantiation_name = gen_it->name;
|
||||
ParamGenerator<ParamType> generator((*gen_it->generator)());
|
||||
ParamNameGeneratorFunc* name_func = gen_it->name_func;
|
||||
const char* file = gen_it->file;
|
||||
int line = gen_it->line;
|
||||
|
||||
string test_case_name;
|
||||
std::string test_case_name;
|
||||
if ( !instantiation_name.empty() )
|
||||
test_case_name = instantiation_name + "/";
|
||||
test_case_name += test_info->test_case_base_name;
|
||||
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
std::set<std::string> test_param_names;
|
||||
for (typename ParamGenerator<ParamType>::iterator param_it =
|
||||
generator.begin();
|
||||
param_it != generator.end(); ++param_it, ++i) {
|
||||
Message test_name_stream;
|
||||
test_name_stream << test_info->test_base_name << "/" << i;
|
||||
|
||||
std::string param_name = name_func(
|
||||
TestParamInfo<ParamType>(*param_it, i));
|
||||
|
||||
GTEST_CHECK_(IsValidParamName(param_name))
|
||||
<< "Parameterized test name '" << param_name
|
||||
<< "' is invalid, in " << file
|
||||
<< " line " << line << std::endl;
|
||||
|
||||
GTEST_CHECK_(test_param_names.count(param_name) == 0)
|
||||
<< "Duplicate parameterized test name '" << param_name
|
||||
<< "', in " << file << " line " << line << std::endl;
|
||||
|
||||
test_param_names.insert(param_name);
|
||||
|
||||
test_name_stream << test_info->test_base_name << "/" << param_name;
|
||||
MakeAndRegisterTestInfo(
|
||||
test_case_name.c_str(),
|
||||
test_name_stream.GetString().c_str(),
|
||||
NULL, // No type parameter.
|
||||
PrintToString(*param_it).c_str(),
|
||||
code_location_,
|
||||
GetTestCaseTypeId(),
|
||||
TestCase::SetUpTestCase,
|
||||
TestCase::TearDownTestCase,
|
||||
@ -530,17 +604,50 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
test_base_name(a_test_base_name),
|
||||
test_meta_factory(a_test_meta_factory) {}
|
||||
|
||||
const string test_case_base_name;
|
||||
const string test_base_name;
|
||||
const std::string test_case_base_name;
|
||||
const std::string test_base_name;
|
||||
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
};
|
||||
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
|
||||
// Keeps pairs of <Instantiation name, Sequence generator creation function>
|
||||
// received from INSTANTIATE_TEST_CASE_P macros.
|
||||
typedef ::std::vector<std::pair<string, GeneratorCreationFunc*> >
|
||||
InstantiationContainer;
|
||||
// Records data received from INSTANTIATE_TEST_CASE_P macros:
|
||||
// <Instantiation name, Sequence generator creation function,
|
||||
// Name generator function, Source file, Source line>
|
||||
struct InstantiationInfo {
|
||||
InstantiationInfo(const std::string &name_in,
|
||||
GeneratorCreationFunc* generator_in,
|
||||
ParamNameGeneratorFunc* name_func_in,
|
||||
const char* file_in,
|
||||
int line_in)
|
||||
: name(name_in),
|
||||
generator(generator_in),
|
||||
name_func(name_func_in),
|
||||
file(file_in),
|
||||
line(line_in) {}
|
||||
|
||||
const string test_case_name_;
|
||||
std::string name;
|
||||
GeneratorCreationFunc* generator;
|
||||
ParamNameGeneratorFunc* name_func;
|
||||
const char* file;
|
||||
int line;
|
||||
};
|
||||
typedef ::std::vector<InstantiationInfo> InstantiationContainer;
|
||||
|
||||
static bool IsValidParamName(const std::string& name) {
|
||||
// Check for empty string
|
||||
if (name.empty())
|
||||
return false;
|
||||
|
||||
// Check for invalid characters
|
||||
for (std::string::size_type index = 0; index < name.size(); ++index) {
|
||||
if (!isalnum(name[index]) && name[index] != '_')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string test_case_name_;
|
||||
CodeLocation code_location_;
|
||||
TestInfoContainer tests_;
|
||||
InstantiationContainer instantiations_;
|
||||
|
||||
@ -568,8 +675,7 @@ class ParameterizedTestCaseRegistry {
|
||||
template <class TestCase>
|
||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
||||
const char* test_case_name,
|
||||
const char* file,
|
||||
int line) {
|
||||
CodeLocation code_location) {
|
||||
ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;
|
||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
||||
it != test_case_infos_.end(); ++it) {
|
||||
@ -578,7 +684,7 @@ class ParameterizedTestCaseRegistry {
|
||||
// Complain about incorrect usage of Google Test facilities
|
||||
// and terminate the program since we cannot guaranty correct
|
||||
// test case setup and tear-down in this case.
|
||||
ReportInvalidTestCaseType(test_case_name, file, line);
|
||||
ReportInvalidTestCaseType(test_case_name, code_location);
|
||||
posix::Abort();
|
||||
} else {
|
||||
// At this point we are sure that the object we found is of the same
|
||||
@ -591,7 +697,8 @@ class ParameterizedTestCaseRegistry {
|
||||
}
|
||||
}
|
||||
if (typed_test_info == NULL) {
|
||||
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(test_case_name);
|
||||
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(
|
||||
test_case_name, code_location);
|
||||
test_case_infos_.push_back(typed_test_info);
|
||||
}
|
||||
return typed_test_info;
|
||||
@ -614,6 +721,4 @@ class ParameterizedTestCaseRegistry {
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
|
||||
|
||||
100
test/fmw/gtest/include/gtest/internal/gtest-port-arch.h
Normal file
100
test/fmw/gtest/include/gtest/internal/gtest-port-arch.h
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright 2015, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file defines the GTEST_OS_* macro.
|
||||
// It is separate from gtest-port.h so that custom/gtest-port.h can include it.
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
|
||||
// Determines the platform on which Google Test is compiled.
|
||||
#ifdef __CYGWIN__
|
||||
# define GTEST_OS_CYGWIN 1
|
||||
#elif defined __SYMBIAN32__
|
||||
# define GTEST_OS_SYMBIAN 1
|
||||
#elif defined _WIN32
|
||||
# define GTEST_OS_WINDOWS 1
|
||||
# ifdef _WIN32_WCE
|
||||
# define GTEST_OS_WINDOWS_MOBILE 1
|
||||
# elif defined(__MINGW__) || defined(__MINGW32__)
|
||||
# define GTEST_OS_WINDOWS_MINGW 1
|
||||
# elif defined(WINAPI_FAMILY)
|
||||
# include <winapifamily.h>
|
||||
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
|
||||
# define GTEST_OS_WINDOWS_PHONE 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
|
||||
# define GTEST_OS_WINDOWS_RT 1
|
||||
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)
|
||||
# define GTEST_OS_WINDOWS_PHONE 1
|
||||
# define GTEST_OS_WINDOWS_TV_TITLE 1
|
||||
# else
|
||||
// WINAPI_FAMILY defined but no known partition matched.
|
||||
// Default to desktop.
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# endif
|
||||
# else
|
||||
# define GTEST_OS_WINDOWS_DESKTOP 1
|
||||
# endif // _WIN32_WCE
|
||||
#elif defined __APPLE__
|
||||
# define GTEST_OS_MAC 1
|
||||
# if TARGET_OS_IPHONE
|
||||
# define GTEST_OS_IOS 1
|
||||
# endif
|
||||
#elif defined __FreeBSD__
|
||||
# define GTEST_OS_FREEBSD 1
|
||||
#elif defined __Fuchsia__
|
||||
# define GTEST_OS_FUCHSIA 1
|
||||
#elif defined __linux__
|
||||
# define GTEST_OS_LINUX 1
|
||||
# if defined __ANDROID__
|
||||
# define GTEST_OS_LINUX_ANDROID 1
|
||||
# endif
|
||||
#elif defined __MVS__
|
||||
# define GTEST_OS_ZOS 1
|
||||
#elif defined(__sun) && defined(__SVR4)
|
||||
# define GTEST_OS_SOLARIS 1
|
||||
#elif defined(_AIX)
|
||||
# define GTEST_OS_AIX 1
|
||||
#elif defined(__hpux)
|
||||
# define GTEST_OS_HPUX 1
|
||||
#elif defined __native_client__
|
||||
# define GTEST_OS_NACL 1
|
||||
#elif defined __NetBSD__
|
||||
# define GTEST_OS_NETBSD 1
|
||||
#elif defined __OpenBSD__
|
||||
# define GTEST_OS_OPENBSD 1
|
||||
#elif defined __QNX__
|
||||
# define GTEST_OS_QNX 1
|
||||
#endif // __CYGWIN__
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
|
||||
File diff suppressed because it is too large
Load Diff
@ -27,17 +27,17 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// This header file declares the String class and functions used internally by
|
||||
// Google Test. They are subject to change without notice. They should not used
|
||||
// by code external to Google Test.
|
||||
//
|
||||
// This header file is #included by <gtest/internal/gtest-internal.h>.
|
||||
// This header file is #included by gtest-internal.h.
|
||||
// It should not be #included by other files.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
|
||||
|
||||
|
||||
@ -30,11 +30,12 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
|
||||
@ -42,7 +43,7 @@
|
||||
|
||||
// The compiler used in Symbian has a bug that prevents us from declaring the
|
||||
// tuple template as a friend (it complains that tuple is redefined). This
|
||||
// hack bypasses the bug by declaring the members that should otherwise be
|
||||
// bypasses the bug by declaring the members that should otherwise be
|
||||
// private as public.
|
||||
// Sun Studio versions < 12 also have the above bug.
|
||||
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
|
||||
@ -53,6 +54,14 @@
|
||||
private:
|
||||
#endif
|
||||
|
||||
// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
|
||||
// with our own definitions. Therefore using our own tuple does not work on
|
||||
// those compilers.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */
|
||||
# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \
|
||||
GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers."
|
||||
#endif
|
||||
|
||||
// GTEST_n_TUPLE_(T) is the type of an n-tuple.
|
||||
#define GTEST_0_TUPLE_(T) tuple<>
|
||||
#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
|
||||
|
||||
@ -29,11 +29,12 @@ $$ This meta comment fixes auto-indentation in Emacs. }}
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// Implements a subset of TR1 tuple needed by Google Test and Google Mock.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
|
||||
|
||||
@ -41,7 +42,7 @@ $$ This meta comment fixes auto-indentation in Emacs. }}
|
||||
|
||||
// The compiler used in Symbian has a bug that prevents us from declaring the
|
||||
// tuple template as a friend (it complains that tuple is redefined). This
|
||||
// hack bypasses the bug by declaring the members that should otherwise be
|
||||
// bypasses the bug by declaring the members that should otherwise be
|
||||
// private as public.
|
||||
// Sun Studio versions < 12 also have the above bug.
|
||||
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
|
||||
@ -52,6 +53,14 @@ $$ This meta comment fixes auto-indentation in Emacs. }}
|
||||
private:
|
||||
#endif
|
||||
|
||||
// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
|
||||
// with our own definitions. Therefore using our own tuple does not work on
|
||||
// those compilers.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */
|
||||
# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \
|
||||
GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers."
|
||||
#endif
|
||||
|
||||
|
||||
$range i 0..n-1
|
||||
$range j 0..n
|
||||
|
||||
@ -30,8 +30,7 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// Type utilities needed for implementing typed and type-parameterized
|
||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
@ -41,6 +40,8 @@
|
||||
// Please contact googletestframework@googlegroups.com if you need
|
||||
// more.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
|
||||
@ -57,6 +58,22 @@
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Canonicalizes a given name with respect to the Standard C++ Library.
|
||||
// This handles removing the inline namespace within `std` that is
|
||||
// used by various standard libraries (e.g., `std::__1`). Names outside
|
||||
// of namespace std are returned unmodified.
|
||||
inline std::string CanonicalizeForStdLibVersioning(std::string s) {
|
||||
static const char prefix[] = "std::__";
|
||||
if (s.compare(0, strlen(prefix), prefix) == 0) {
|
||||
std::string::size_type end = s.find("::", strlen(prefix));
|
||||
if (end != s.npos) {
|
||||
// Erase everything between the initial `std` and the second `::`.
|
||||
s.erase(strlen("std"), end - strlen("std"));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
// NB: This function is also used in Google Mock, so don't move it inside of
|
||||
// the typed-test-only section below.
|
||||
@ -75,7 +92,7 @@ std::string GetTypeName() {
|
||||
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
||||
const std::string name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return name_str;
|
||||
return CanonicalizeForStdLibVersioning(name_str);
|
||||
# else
|
||||
return name;
|
||||
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
|
||||
|
||||
@ -28,8 +28,7 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// Type utilities needed for implementing typed and type-parameterized
|
||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||
@ -39,6 +38,8 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||
// Please contact googletestframework@googlegroups.com if you need
|
||||
// more.
|
||||
|
||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
|
||||
@ -55,6 +56,22 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Canonicalizes a given name with respect to the Standard C++ Library.
|
||||
// This handles removing the inline namespace within `std` that is
|
||||
// used by various standard libraries (e.g., `std::__1`). Names outside
|
||||
// of namespace std are returned unmodified.
|
||||
inline std::string CanonicalizeForStdLibVersioning(std::string s) {
|
||||
static const char prefix[] = "std::__";
|
||||
if (s.compare(0, strlen(prefix), prefix) == 0) {
|
||||
std::string::size_type end = s.find("::", strlen(prefix));
|
||||
if (end != s.npos) {
|
||||
// Erase everything between the initial `std` and the second `::`.
|
||||
s.erase(strlen("std"), end - strlen("std"));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
// NB: This function is also used in Google Mock, so don't move it inside of
|
||||
// the typed-test-only section below.
|
||||
@ -73,7 +90,7 @@ std::string GetTypeName() {
|
||||
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
||||
const std::string name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return name_str;
|
||||
return CanonicalizeForStdLibVersioning(name_str);
|
||||
# else
|
||||
return name;
|
||||
# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
|
||||
|
||||
@ -26,10 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: mheule@google.com (Markus Heule)
|
||||
//
|
||||
// Google C++ Testing Framework (Google Test)
|
||||
// Google C++ Testing and Mocking Framework (Google Test)
|
||||
//
|
||||
// Sometimes it's desirable to build Google Test by compiling a single file.
|
||||
// This file serves this purpose.
|
||||
|
||||
@ -26,13 +26,13 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
|
||||
|
||||
//
|
||||
// This file implements death tests.
|
||||
|
||||
#include "gtest/gtest-death-test.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/custom/gtest.h"
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
@ -61,26 +61,30 @@
|
||||
# include <spawn.h>
|
||||
# endif // GTEST_OS_QNX
|
||||
|
||||
# if GTEST_OS_FUCHSIA
|
||||
# include <lib/fdio/io.h>
|
||||
# include <lib/fdio/spawn.h>
|
||||
# include <zircon/processargs.h>
|
||||
# include <zircon/syscalls.h>
|
||||
# include <zircon/syscalls/port.h>
|
||||
# endif // GTEST_OS_FUCHSIA
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
// included, or there will be a compiler error. This trick is to
|
||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
||||
// his code.
|
||||
#define GTEST_IMPLEMENTATION_ 1
|
||||
#include "src/gtest-internal-inl.h"
|
||||
#undef GTEST_IMPLEMENTATION_
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Constants.
|
||||
|
||||
// The default death test style.
|
||||
static const char kDefaultDeathTestStyle[] = "fast";
|
||||
//
|
||||
// This is defined in internal/gtest-port.h as "fast", but can be overridden by
|
||||
// a definition in internal/custom/gtest-port.h. The recommended value, which is
|
||||
// used internally at Google, is "threadsafe".
|
||||
static const char kDefaultDeathTestStyle[] = GTEST_DEFAULT_DEATH_TEST_STYLE;
|
||||
|
||||
GTEST_DEFINE_string_(
|
||||
death_test_style,
|
||||
@ -120,7 +124,9 @@ namespace internal {
|
||||
|
||||
// Valid only for fast death tests. Indicates the code is running in the
|
||||
// child process of a fast style death test.
|
||||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
static bool g_in_fast_death_test_child = false;
|
||||
# endif
|
||||
|
||||
// Returns a Boolean value indicating whether the caller is currently
|
||||
// executing in the context of the death test child process. Tools such as
|
||||
@ -128,10 +134,10 @@ static bool g_in_fast_death_test_child = false;
|
||||
// tests. IMPORTANT: This is an internal utility. Using it may break the
|
||||
// implementation of death tests. User code MUST NOT use it.
|
||||
bool InDeathTestChild() {
|
||||
# if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// On Windows, death tests are thread-safe regardless of the value of the
|
||||
// death_test_style flag.
|
||||
// On Windows and Fuchsia, death tests are thread-safe regardless of the value
|
||||
// of the death_test_style flag.
|
||||
return !GTEST_FLAG(internal_run_death_test).empty();
|
||||
|
||||
# else
|
||||
@ -151,7 +157,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
|
||||
|
||||
// ExitedWithCode function-call operator.
|
||||
bool ExitedWithCode::operator()(int exit_status) const {
|
||||
# if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
return exit_status == exit_code_;
|
||||
|
||||
@ -159,19 +165,27 @@ bool ExitedWithCode::operator()(int exit_status) const {
|
||||
|
||||
return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
}
|
||||
|
||||
# if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
// KilledBySignal constructor.
|
||||
KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
|
||||
}
|
||||
|
||||
// KilledBySignal function-call operator.
|
||||
bool KilledBySignal::operator()(int exit_status) const {
|
||||
# if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
|
||||
{
|
||||
bool result;
|
||||
if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
# endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
|
||||
return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
|
||||
}
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -182,7 +196,7 @@ namespace internal {
|
||||
static std::string ExitSummary(int exit_code) {
|
||||
Message m;
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
m << "Exited with exit status " << exit_code;
|
||||
|
||||
@ -198,7 +212,7 @@ static std::string ExitSummary(int exit_code) {
|
||||
m << " (core dumped)";
|
||||
}
|
||||
# endif
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
return m.GetString();
|
||||
}
|
||||
@ -209,7 +223,7 @@ bool ExitedUnsuccessfully(int exit_status) {
|
||||
return !ExitedWithCode(0)(exit_status);
|
||||
}
|
||||
|
||||
# if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
// Generates a textual failure message when a death test finds more than
|
||||
// one thread running, or cannot determine the number of threads, prior
|
||||
// to executing the given statement. It is the responsibility of the
|
||||
@ -218,13 +232,19 @@ static std::string DeathTestThreadWarning(size_t thread_count) {
|
||||
Message msg;
|
||||
msg << "Death tests use fork(), which is unsafe particularly"
|
||||
<< " in a threaded context. For this test, " << GTEST_NAME_ << " ";
|
||||
if (thread_count == 0)
|
||||
if (thread_count == 0) {
|
||||
msg << "couldn't detect the number of threads.";
|
||||
else
|
||||
} else {
|
||||
msg << "detected " << thread_count << " threads.";
|
||||
}
|
||||
msg << " See "
|
||||
"https://github.com/google/googletest/blob/master/googletest/docs/"
|
||||
"advanced.md#death-tests-and-threads"
|
||||
<< " for more explanation and suggested solutions, especially if"
|
||||
<< " this is the last message you see before your test times out.";
|
||||
return msg.GetString();
|
||||
}
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
|
||||
|
||||
// Flag characters for reporting a death test that did not die.
|
||||
static const char kDeathTestLived = 'L';
|
||||
@ -232,6 +252,13 @@ static const char kDeathTestReturned = 'R';
|
||||
static const char kDeathTestThrew = 'T';
|
||||
static const char kDeathTestInternalError = 'I';
|
||||
|
||||
#if GTEST_OS_FUCHSIA
|
||||
|
||||
// File descriptor used for the pipe in the child process.
|
||||
static const int kFuchsiaReadPipeFd = 3;
|
||||
|
||||
#endif
|
||||
|
||||
// An enumeration describing all of the possible ways that a death test can
|
||||
// conclude. DIED means that the process died while executing the test
|
||||
// code; LIVED means that process lived beyond the end of the test code;
|
||||
@ -239,7 +266,7 @@ static const char kDeathTestInternalError = 'I';
|
||||
// statement, which is not allowed; THREW means that the test statement
|
||||
// returned control by throwing an exception. IN_PROGRESS means the test
|
||||
// has not yet concluded.
|
||||
// TODO(vladl@google.com): Unify names and possibly values for
|
||||
// FIXME: Unify names and possibly values for
|
||||
// AbortReason, DeathTestOutcome, and flag characters above.
|
||||
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
|
||||
|
||||
@ -248,7 +275,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
|
||||
// message is propagated back to the parent process. Otherwise, the
|
||||
// message is simply printed to stderr. In either case, the program
|
||||
// then exits with status 1.
|
||||
void DeathTestAbort(const std::string& message) {
|
||||
static void DeathTestAbort(const std::string& message) {
|
||||
// On a POSIX system, this function may be called from a threadsafe-style
|
||||
// death test child process, which operates on a very small stack. Use
|
||||
// the heap for any additional non-minuscule memory requirements.
|
||||
@ -552,7 +579,12 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
break;
|
||||
case DIED:
|
||||
if (status_ok) {
|
||||
# if GTEST_USES_PCRE
|
||||
// PCRE regexes support embedded NULs.
|
||||
const bool matched = RE::PartialMatch(error_message, *regex());
|
||||
# else
|
||||
const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
|
||||
# endif // GTEST_USES_PCRE
|
||||
if (matched) {
|
||||
success = true;
|
||||
} else {
|
||||
@ -768,7 +800,200 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
set_spawned(true);
|
||||
return OVERSEE_TEST;
|
||||
}
|
||||
# else // We are not on Windows.
|
||||
|
||||
# elif GTEST_OS_FUCHSIA
|
||||
|
||||
class FuchsiaDeathTest : public DeathTestImpl {
|
||||
public:
|
||||
FuchsiaDeathTest(const char* a_statement,
|
||||
const RE* a_regex,
|
||||
const char* file,
|
||||
int line)
|
||||
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
|
||||
virtual ~FuchsiaDeathTest() {
|
||||
zx_status_t status = zx_handle_close(child_process_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
status = zx_handle_close(port_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
}
|
||||
|
||||
// All of these virtual functions are inherited from DeathTest.
|
||||
virtual int Wait();
|
||||
virtual TestRole AssumeRole();
|
||||
|
||||
private:
|
||||
// The name of the file in which the death test is located.
|
||||
const char* const file_;
|
||||
// The line number on which the death test is located.
|
||||
const int line_;
|
||||
|
||||
zx_handle_t child_process_ = ZX_HANDLE_INVALID;
|
||||
zx_handle_t port_ = ZX_HANDLE_INVALID;
|
||||
};
|
||||
|
||||
// Utility class for accumulating command-line arguments.
|
||||
class Arguments {
|
||||
public:
|
||||
Arguments() {
|
||||
args_.push_back(NULL);
|
||||
}
|
||||
|
||||
~Arguments() {
|
||||
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
|
||||
++i) {
|
||||
free(*i);
|
||||
}
|
||||
}
|
||||
void AddArgument(const char* argument) {
|
||||
args_.insert(args_.end() - 1, posix::StrDup(argument));
|
||||
}
|
||||
|
||||
template <typename Str>
|
||||
void AddArguments(const ::std::vector<Str>& arguments) {
|
||||
for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
|
||||
i != arguments.end();
|
||||
++i) {
|
||||
args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
|
||||
}
|
||||
}
|
||||
char* const* Argv() {
|
||||
return &args_[0];
|
||||
}
|
||||
|
||||
int size() {
|
||||
return args_.size() - 1;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char*> args_;
|
||||
};
|
||||
|
||||
// Waits for the child in a death test to exit, returning its exit
|
||||
// status, or 0 if no child process exists. As a side effect, sets the
|
||||
// outcome data member.
|
||||
int FuchsiaDeathTest::Wait() {
|
||||
if (!spawned())
|
||||
return 0;
|
||||
|
||||
// Register to wait for the child process to terminate.
|
||||
zx_status_t status_zx;
|
||||
status_zx = zx_object_wait_async(child_process_,
|
||||
port_,
|
||||
0 /* key */,
|
||||
ZX_PROCESS_TERMINATED,
|
||||
ZX_WAIT_ASYNC_ONCE);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Wait for it to terminate, or an exception to be received.
|
||||
zx_port_packet_t packet;
|
||||
status_zx = zx_port_wait(port_, ZX_TIME_INFINITE, &packet);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
if (ZX_PKT_IS_EXCEPTION(packet.type)) {
|
||||
// Process encountered an exception. Kill it directly rather than letting
|
||||
// other handlers process the event.
|
||||
status_zx = zx_task_kill(child_process_);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
// Now wait for |child_process_| to terminate.
|
||||
zx_signals_t signals = 0;
|
||||
status_zx = zx_object_wait_one(
|
||||
child_process_, ZX_PROCESS_TERMINATED, ZX_TIME_INFINITE, &signals);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
GTEST_DEATH_TEST_CHECK_(signals & ZX_PROCESS_TERMINATED);
|
||||
} else {
|
||||
// Process terminated.
|
||||
GTEST_DEATH_TEST_CHECK_(ZX_PKT_IS_SIGNAL_ONE(packet.type));
|
||||
GTEST_DEATH_TEST_CHECK_(packet.signal.observed & ZX_PROCESS_TERMINATED);
|
||||
}
|
||||
|
||||
ReadAndInterpretStatusByte();
|
||||
|
||||
zx_info_process_t buffer;
|
||||
status_zx = zx_object_get_info(
|
||||
child_process_,
|
||||
ZX_INFO_PROCESS,
|
||||
&buffer,
|
||||
sizeof(buffer),
|
||||
nullptr,
|
||||
nullptr);
|
||||
GTEST_DEATH_TEST_CHECK_(status_zx == ZX_OK);
|
||||
|
||||
GTEST_DEATH_TEST_CHECK_(buffer.exited);
|
||||
set_status(buffer.return_code);
|
||||
return status();
|
||||
}
|
||||
|
||||
// The AssumeRole process for a Fuchsia death test. It creates a child
|
||||
// process with the same executable as the current process to run the
|
||||
// death test. The child process is given the --gtest_filter and
|
||||
// --gtest_internal_run_death_test flags such that it knows to run the
|
||||
// current death test only.
|
||||
DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
||||
const UnitTestImpl* const impl = GetUnitTestImpl();
|
||||
const InternalRunDeathTestFlag* const flag =
|
||||
impl->internal_run_death_test_flag();
|
||||
const TestInfo* const info = impl->current_test_info();
|
||||
const int death_test_index = info->result()->death_test_count();
|
||||
|
||||
if (flag != NULL) {
|
||||
// ParseInternalRunDeathTestFlag() has performed all the necessary
|
||||
// processing.
|
||||
set_write_fd(kFuchsiaReadPipeFd);
|
||||
return EXECUTE_TEST;
|
||||
}
|
||||
|
||||
CaptureStderr();
|
||||
// Flush the log buffers since the log streams are shared with the child.
|
||||
FlushInfoLog();
|
||||
|
||||
// Build the child process command line.
|
||||
const std::string filter_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
||||
+ info->test_case_name() + "." + info->name();
|
||||
const std::string internal_flag =
|
||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||
+ file_ + "|"
|
||||
+ StreamableToString(line_) + "|"
|
||||
+ StreamableToString(death_test_index);
|
||||
Arguments args;
|
||||
args.AddArguments(GetInjectableArgvs());
|
||||
args.AddArgument(filter_flag.c_str());
|
||||
args.AddArgument(internal_flag.c_str());
|
||||
|
||||
// Build the pipe for communication with the child.
|
||||
zx_status_t status;
|
||||
zx_handle_t child_pipe_handle;
|
||||
uint32_t type;
|
||||
status = fdio_pipe_half(&child_pipe_handle, &type);
|
||||
GTEST_DEATH_TEST_CHECK_(status >= 0);
|
||||
set_read_fd(status);
|
||||
|
||||
// Set the pipe handle for the child.
|
||||
fdio_spawn_action_t add_handle_action = {};
|
||||
add_handle_action.action = FDIO_SPAWN_ACTION_ADD_HANDLE;
|
||||
add_handle_action.h.id = PA_HND(type, kFuchsiaReadPipeFd);
|
||||
add_handle_action.h.handle = child_pipe_handle;
|
||||
|
||||
// Spawn the child process.
|
||||
status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL,
|
||||
args.Argv()[0], args.Argv(), nullptr, 1,
|
||||
&add_handle_action, &child_process_, nullptr);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
// Create an exception port and attach it to the |child_process_|, to allow
|
||||
// us to suppress the system default exception handler from firing.
|
||||
status = zx_port_create(0, &port_);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
status = zx_task_bind_exception_port(
|
||||
child_process_, port_, 0 /* key */, 0 /*options */);
|
||||
GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
|
||||
|
||||
set_spawned(true);
|
||||
return OVERSEE_TEST;
|
||||
}
|
||||
|
||||
#else // We are neither on Windows, nor on Fuchsia.
|
||||
|
||||
// ForkingDeathTest provides implementations for most of the abstract
|
||||
// methods of the DeathTest interface. Only the AssumeRole method is
|
||||
@ -872,9 +1097,13 @@ class ExecDeathTest : public ForkingDeathTest {
|
||||
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
|
||||
virtual TestRole AssumeRole();
|
||||
private:
|
||||
static ::std::vector<testing::internal::string>
|
||||
GetArgvsForDeathTestChildProcess() {
|
||||
::std::vector<testing::internal::string> args = GetInjectableArgvs();
|
||||
static ::std::vector<std::string> GetArgvsForDeathTestChildProcess() {
|
||||
::std::vector<std::string> args = GetInjectableArgvs();
|
||||
# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
|
||||
::std::vector<std::string> extra_args =
|
||||
GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_();
|
||||
args.insert(args.end(), extra_args.begin(), extra_args.end());
|
||||
# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
|
||||
return args;
|
||||
}
|
||||
// The name of the file in which the death test is located.
|
||||
@ -970,6 +1199,7 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||
}
|
||||
# endif // !GTEST_OS_QNX
|
||||
|
||||
# if GTEST_HAS_CLONE
|
||||
// Two utility routines that together determine the direction the stack
|
||||
// grows.
|
||||
// This could be accomplished more elegantly by a single recursive
|
||||
@ -979,18 +1209,22 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
|
||||
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
|
||||
// correct answer.
|
||||
void StackLowerThanAddress(const void* ptr, bool* result) GTEST_NO_INLINE_;
|
||||
void StackLowerThanAddress(const void* ptr, bool* result) {
|
||||
static void StackLowerThanAddress(const void* ptr,
|
||||
bool* result) GTEST_NO_INLINE_;
|
||||
static void StackLowerThanAddress(const void* ptr, bool* result) {
|
||||
int dummy;
|
||||
*result = (&dummy < ptr);
|
||||
}
|
||||
|
||||
bool StackGrowsDown() {
|
||||
// Make sure AddressSanitizer does not tamper with the stack here.
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||
static bool StackGrowsDown() {
|
||||
int dummy;
|
||||
bool result;
|
||||
StackLowerThanAddress(&dummy, &result);
|
||||
return result;
|
||||
}
|
||||
# endif // GTEST_HAS_CLONE
|
||||
|
||||
// Spawns a child process with the same executable as the current process in
|
||||
// a thread-safe manner and instructs it to run the death test. The
|
||||
@ -1182,6 +1416,13 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||
*test = new WindowsDeathTest(statement, regex, file, line);
|
||||
}
|
||||
|
||||
# elif GTEST_OS_FUCHSIA
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
|
||||
GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new FuchsiaDeathTest(statement, regex, file, line);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe") {
|
||||
@ -1202,31 +1443,11 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Splits a given string on a given delimiter, populating a given
|
||||
// vector with the fields. GTEST_HAS_DEATH_TEST implies that we have
|
||||
// ::std::string, so we can use it here.
|
||||
static void SplitString(const ::std::string& str, char delimiter,
|
||||
::std::vector< ::std::string>* dest) {
|
||||
::std::vector< ::std::string> parsed;
|
||||
::std::string::size_type pos = 0;
|
||||
while (::testing::internal::AlwaysTrue()) {
|
||||
const ::std::string::size_type colon = str.find(delimiter, pos);
|
||||
if (colon == ::std::string::npos) {
|
||||
parsed.push_back(str.substr(pos));
|
||||
break;
|
||||
} else {
|
||||
parsed.push_back(str.substr(pos, colon - pos));
|
||||
pos = colon + 1;
|
||||
}
|
||||
}
|
||||
dest->swap(parsed);
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
// Recreates the pipe and event handles from the provided parameters,
|
||||
// signals the event, and returns a file descriptor wrapped around the pipe
|
||||
// handle. This function is called in the child process only.
|
||||
int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
static int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
size_t write_handle_as_size_t,
|
||||
size_t event_handle_as_size_t) {
|
||||
AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
|
||||
@ -1237,7 +1458,7 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
StreamableToString(parent_process_id));
|
||||
}
|
||||
|
||||
// TODO(vladl@google.com): Replace the following check with a
|
||||
// FIXME: Replace the following check with a
|
||||
// compile-time assertion when available.
|
||||
GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
|
||||
|
||||
@ -1245,7 +1466,7 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
reinterpret_cast<HANDLE>(write_handle_as_size_t);
|
||||
HANDLE dup_write_handle;
|
||||
|
||||
// The newly initialized handle is accessible only in in the parent
|
||||
// The newly initialized handle is accessible only in the parent
|
||||
// process. To obtain one accessible within the child, we need to use
|
||||
// DuplicateHandle.
|
||||
if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
|
||||
@ -1322,6 +1543,16 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||
write_fd = GetStatusFileDescriptor(parent_process_id,
|
||||
write_handle_as_size_t,
|
||||
event_handle_as_size_t);
|
||||
|
||||
# elif GTEST_OS_FUCHSIA
|
||||
|
||||
if (fields.size() != 3
|
||||
|| !ParseNaturalNumber(fields[1], &line)
|
||||
|| !ParseNaturalNumber(fields[2], &index)) {
|
||||
DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
|
||||
+ GTEST_FLAG(internal_run_death_test));
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
if (fields.size() != 4
|
||||
|
||||
@ -26,14 +26,12 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Authors: keith.ray@gmail.com (Keith Ray)
|
||||
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-message.h"
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
# include <windows.h>
|
||||
@ -48,6 +46,8 @@
|
||||
# include <climits> // Some Linux distributions define PATH_MAX here.
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# define GTEST_PATH_MAX_ _MAX_PATH
|
||||
#elif defined(PATH_MAX)
|
||||
@ -58,8 +58,6 @@
|
||||
# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
@ -70,7 +68,6 @@ namespace internal {
|
||||
// of them.
|
||||
const char kPathSeparator = '\\';
|
||||
const char kAlternatePathSeparator = '/';
|
||||
const char kPathSeparatorString[] = "\\";
|
||||
const char kAlternatePathSeparatorString[] = "/";
|
||||
# if GTEST_OS_WINDOWS_MOBILE
|
||||
// Windows CE doesn't have a current directory. You should not use
|
||||
@ -84,7 +81,6 @@ const char kCurrentDirectoryString[] = ".\\";
|
||||
# endif // GTEST_OS_WINDOWS_MOBILE
|
||||
#else
|
||||
const char kPathSeparator = '/';
|
||||
const char kPathSeparatorString[] = "/";
|
||||
const char kCurrentDirectoryString[] = "./";
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
@ -99,7 +95,7 @@ static bool IsPathSeparator(char c) {
|
||||
|
||||
// Returns the current working directory, or "" if unsuccessful.
|
||||
FilePath FilePath::GetCurrentDir() {
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
|
||||
// Windows CE doesn't have a current directory, so we just return
|
||||
// something reasonable.
|
||||
return FilePath(kCurrentDirectoryString);
|
||||
@ -108,7 +104,14 @@ FilePath FilePath::GetCurrentDir() {
|
||||
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
||||
#else
|
||||
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
||||
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
||||
char* result = getcwd(cwd, sizeof(cwd));
|
||||
# if GTEST_OS_NACL
|
||||
// getcwd will likely fail in NaCl due to the sandbox, so return something
|
||||
// reasonable. The user may have provided a shim implementation for getcwd,
|
||||
// however, so fallback only when failure is detected.
|
||||
return FilePath(result == NULL ? kCurrentDirectoryString : cwd);
|
||||
# endif // GTEST_OS_NACL
|
||||
return FilePath(result == NULL ? "" : cwd);
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
}
|
||||
|
||||
@ -125,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Returns a pointer to the last occurence of a valid path separator in
|
||||
// Returns a pointer to the last occurrence of a valid path separator in
|
||||
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
||||
// separators. Returns NULL if no path separator was found.
|
||||
const char* FilePath::FindLastPathSeparator() const {
|
||||
@ -247,7 +250,7 @@ bool FilePath::DirectoryExists() const {
|
||||
// root directory per disk drive.)
|
||||
bool FilePath::IsRootDirectory() const {
|
||||
#if GTEST_OS_WINDOWS
|
||||
// TODO(wan@google.com): on Windows a network share like
|
||||
// FIXME: on Windows a network share like
|
||||
// \\server\share can be a root directory, although it cannot be the
|
||||
// current directory. Handle this properly.
|
||||
return pathname_.length() == 3 && IsAbsolutePath();
|
||||
@ -347,7 +350,7 @@ FilePath FilePath::RemoveTrailingPathSeparator() const {
|
||||
// Removes any redundant separators that might be in the pathname.
|
||||
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
|
||||
// redundancies that might be in a pathname involving "." or "..".
|
||||
// TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
|
||||
// FIXME: handle Windows network shares (e.g. \\server\share).
|
||||
void FilePath::Normalize() {
|
||||
if (pathname_.c_str() == NULL) {
|
||||
pathname_ = "";
|
||||
|
||||
@ -27,24 +27,13 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Utility functions and classes used by the Google C++ testing framework.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
//
|
||||
// Utility functions and classes used by the Google C++ testing framework.//
|
||||
// This file contains purely Google Test's internal implementation. Please
|
||||
// DO NOT #INCLUDE IT IN A USER PROGRAM.
|
||||
|
||||
#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
|
||||
#define GTEST_SRC_GTEST_INTERNAL_INL_H_
|
||||
|
||||
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
|
||||
// part of Google Test's implementation; otherwise it's undefined.
|
||||
#if !GTEST_IMPLEMENTATION_
|
||||
// A user is trying to include this from his code - just say no.
|
||||
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
||||
# error "It must not be included except by Google Test itself."
|
||||
#endif // GTEST_IMPLEMENTATION_
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
# include <errno.h>
|
||||
#endif // !_WIN32_WCE
|
||||
@ -67,9 +56,12 @@
|
||||
# include <windows.h> // NOLINT
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include "gtest/gtest.h" // NOLINT
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Declares the flags.
|
||||
@ -94,12 +86,14 @@ const char kFilterFlag[] = "filter";
|
||||
const char kListTestsFlag[] = "list_tests";
|
||||
const char kOutputFlag[] = "output";
|
||||
const char kPrintTimeFlag[] = "print_time";
|
||||
const char kPrintUTF8Flag[] = "print_utf8";
|
||||
const char kRandomSeedFlag[] = "random_seed";
|
||||
const char kRepeatFlag[] = "repeat";
|
||||
const char kShuffleFlag[] = "shuffle";
|
||||
const char kStackTraceDepthFlag[] = "stack_trace_depth";
|
||||
const char kStreamResultToFlag[] = "stream_result_to";
|
||||
const char kThrowOnFailureFlag[] = "throw_on_failure";
|
||||
const char kFlagfileFlag[] = "flagfile";
|
||||
|
||||
// A valid random seed must be in [1, kMaxRandomSeed].
|
||||
const int kMaxRandomSeed = 99999;
|
||||
@ -173,6 +167,7 @@ class GTestFlagSaver {
|
||||
list_tests_ = GTEST_FLAG(list_tests);
|
||||
output_ = GTEST_FLAG(output);
|
||||
print_time_ = GTEST_FLAG(print_time);
|
||||
print_utf8_ = GTEST_FLAG(print_utf8);
|
||||
random_seed_ = GTEST_FLAG(random_seed);
|
||||
repeat_ = GTEST_FLAG(repeat);
|
||||
shuffle_ = GTEST_FLAG(shuffle);
|
||||
@ -194,6 +189,7 @@ class GTestFlagSaver {
|
||||
GTEST_FLAG(list_tests) = list_tests_;
|
||||
GTEST_FLAG(output) = output_;
|
||||
GTEST_FLAG(print_time) = print_time_;
|
||||
GTEST_FLAG(print_utf8) = print_utf8_;
|
||||
GTEST_FLAG(random_seed) = random_seed_;
|
||||
GTEST_FLAG(repeat) = repeat_;
|
||||
GTEST_FLAG(shuffle) = shuffle_;
|
||||
@ -215,6 +211,7 @@ class GTestFlagSaver {
|
||||
bool list_tests_;
|
||||
std::string output_;
|
||||
bool print_time_;
|
||||
bool print_utf8_;
|
||||
internal::Int32 random_seed_;
|
||||
internal::Int32 repeat_;
|
||||
bool shuffle_;
|
||||
@ -425,13 +422,17 @@ class OsStackTraceGetterInterface {
|
||||
// in the trace.
|
||||
// skip_count - the number of top frames to be skipped; doesn't count
|
||||
// against max_depth.
|
||||
virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
|
||||
virtual std::string CurrentStackTrace(int max_depth, int skip_count) = 0;
|
||||
|
||||
// UponLeavingGTest() should be called immediately before Google Test calls
|
||||
// user code. It saves some information about the current stack that
|
||||
// CurrentStackTrace() will use to find and hide Google Test stack frames.
|
||||
virtual void UponLeavingGTest() = 0;
|
||||
|
||||
// This string is inserted in place of stack frames that are part of
|
||||
// Google Test's implementation.
|
||||
static const char* const kElidedFramesMarker;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
|
||||
};
|
||||
@ -439,25 +440,21 @@ class OsStackTraceGetterInterface {
|
||||
// A working implementation of the OsStackTraceGetterInterface interface.
|
||||
class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
||||
public:
|
||||
OsStackTraceGetter() : caller_frame_(NULL) {}
|
||||
OsStackTraceGetter() {}
|
||||
|
||||
virtual string CurrentStackTrace(int max_depth, int skip_count)
|
||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
|
||||
|
||||
// This string is inserted in place of stack frames that are part of
|
||||
// Google Test's implementation.
|
||||
static const char* const kElidedFramesMarker;
|
||||
virtual std::string CurrentStackTrace(int max_depth, int skip_count);
|
||||
virtual void UponLeavingGTest();
|
||||
|
||||
private:
|
||||
Mutex mutex_; // protects all internal state
|
||||
#if GTEST_HAS_ABSL
|
||||
Mutex mutex_; // Protects all internal state.
|
||||
|
||||
// We save the stack frame below the frame that calls user code.
|
||||
// We do this because the address of the frame immediately below
|
||||
// the user code changes between the call to UponLeavingGTest()
|
||||
// and any calls to CurrentStackTrace() from within the user code.
|
||||
void* caller_frame_;
|
||||
// and any calls to the stack trace code from within the user code.
|
||||
void* caller_frame_ = nullptr;
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
|
||||
};
|
||||
@ -673,13 +670,11 @@ class GTEST_API_ UnitTestImpl {
|
||||
tear_down_tc)->AddTestInfo(test_info);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
// Returns ParameterizedTestCaseRegistry object used to keep track of
|
||||
// value-parameterized tests and instantiate and register them.
|
||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
|
||||
return parameterized_test_registry_;
|
||||
}
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
// Sets the TestCase object for the test that's currently running.
|
||||
void set_current_test_case(TestCase* a_current_test_case) {
|
||||
@ -854,14 +849,12 @@ class GTEST_API_ UnitTestImpl {
|
||||
// shuffled order.
|
||||
std::vector<int> test_case_indices_;
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
// ParameterizedTestRegistry object used to register value-parameterized
|
||||
// tests.
|
||||
internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
|
||||
|
||||
// Indicates whether RegisterParameterizedTests() has been called already.
|
||||
bool parameterized_tests_registered_;
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
// Index of the last death test case registered. Initially -1.
|
||||
int last_death_test_case_;
|
||||
@ -968,32 +961,6 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
|
||||
// platform.
|
||||
GTEST_API_ std::string GetLastErrnoDescription();
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
// Provides leak-safe Windows kernel handle ownership.
|
||||
class AutoHandle {
|
||||
public:
|
||||
AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
|
||||
explicit AutoHandle(HANDLE handle) : handle_(handle) {}
|
||||
|
||||
~AutoHandle() { Reset(); }
|
||||
|
||||
HANDLE Get() const { return handle_; }
|
||||
void Reset() { Reset(INVALID_HANDLE_VALUE); }
|
||||
void Reset(HANDLE handle) {
|
||||
if (handle != handle_) {
|
||||
if (handle_ != INVALID_HANDLE_VALUE)
|
||||
::CloseHandle(handle_);
|
||||
handle_ = handle;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE handle_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
||||
};
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Attempts to parse a string into a positive integer pointed to by the
|
||||
// number parameter. Returns true if that is possible.
|
||||
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
|
||||
@ -1027,7 +994,7 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
||||
|
||||
const bool parse_success = *end == '\0' && errno == 0;
|
||||
|
||||
// TODO(vladl@google.com): Convert this to compile time assertion when it is
|
||||
// FIXME: Convert this to compile time assertion when it is
|
||||
// available.
|
||||
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
|
||||
|
||||
@ -1075,21 +1042,19 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
virtual ~AbstractSocketWriter() {}
|
||||
|
||||
// Sends a string to the socket.
|
||||
virtual void Send(const string& message) = 0;
|
||||
virtual void Send(const std::string& message) = 0;
|
||||
|
||||
// Closes the socket.
|
||||
virtual void CloseConnection() {}
|
||||
|
||||
// Sends a string and a newline to the socket.
|
||||
void SendLn(const string& message) {
|
||||
Send(message + "\n");
|
||||
}
|
||||
void SendLn(const std::string& message) { Send(message + "\n"); }
|
||||
};
|
||||
|
||||
// Concrete class for actually writing strings to a socket.
|
||||
class SocketWriter : public AbstractSocketWriter {
|
||||
public:
|
||||
SocketWriter(const string& host, const string& port)
|
||||
SocketWriter(const std::string& host, const std::string& port)
|
||||
: sockfd_(-1), host_name_(host), port_num_(port) {
|
||||
MakeConnection();
|
||||
}
|
||||
@ -1100,7 +1065,7 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
}
|
||||
|
||||
// Sends a string to the socket.
|
||||
virtual void Send(const string& message) {
|
||||
virtual void Send(const std::string& message) {
|
||||
GTEST_CHECK_(sockfd_ != -1)
|
||||
<< "Send() can be called only when there is a connection.";
|
||||
|
||||
@ -1126,17 +1091,19 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
}
|
||||
|
||||
int sockfd_; // socket file descriptor
|
||||
const string host_name_;
|
||||
const string port_num_;
|
||||
const std::string host_name_;
|
||||
const std::string port_num_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
|
||||
}; // class SocketWriter
|
||||
|
||||
// Escapes '=', '&', '%', and '\n' characters in str as "%xx".
|
||||
static string UrlEncode(const char* str);
|
||||
static std::string UrlEncode(const char* str);
|
||||
|
||||
StreamingListener(const string& host, const string& port)
|
||||
: socket_writer_(new SocketWriter(host, port)) { Start(); }
|
||||
StreamingListener(const std::string& host, const std::string& port)
|
||||
: socket_writer_(new SocketWriter(host, port)) {
|
||||
Start();
|
||||
}
|
||||
|
||||
explicit StreamingListener(AbstractSocketWriter* socket_writer)
|
||||
: socket_writer_(socket_writer) { Start(); }
|
||||
@ -1197,13 +1164,13 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
|
||||
private:
|
||||
// Sends the given message and a newline to the socket.
|
||||
void SendLn(const string& message) { socket_writer_->SendLn(message); }
|
||||
void SendLn(const std::string& message) { socket_writer_->SendLn(message); }
|
||||
|
||||
// Called at the start of streaming to notify the receiver what
|
||||
// protocol we are using.
|
||||
void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
|
||||
|
||||
string FormatBool(bool value) { return value ? "1" : "0"; }
|
||||
std::string FormatBool(bool value) { return value ? "1" : "0"; }
|
||||
|
||||
const scoped_ptr<AbstractSocketWriter> socket_writer_;
|
||||
|
||||
@ -1215,4 +1182,6 @@ class StreamingListener : public EmptyTestEventListener {
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
|
||||
|
||||
@ -26,8 +26,7 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
@ -35,15 +34,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
# include <windows.h> // For TerminateProcess()
|
||||
#elif GTEST_OS_WINDOWS
|
||||
#if GTEST_OS_WINDOWS
|
||||
# include <windows.h>
|
||||
# include <io.h>
|
||||
# include <sys/stat.h>
|
||||
# include <map> // Used in ThreadLocal.
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
# include <mach/mach_init.h>
|
||||
@ -53,22 +53,25 @@
|
||||
|
||||
#if GTEST_OS_QNX
|
||||
# include <devctl.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/procfs.h>
|
||||
#endif // GTEST_OS_QNX
|
||||
|
||||
#if GTEST_OS_AIX
|
||||
# include <procinfo.h>
|
||||
# include <sys/types.h>
|
||||
#endif // GTEST_OS_AIX
|
||||
|
||||
#if GTEST_OS_FUCHSIA
|
||||
# include <zircon/process.h>
|
||||
# include <zircon/syscalls.h>
|
||||
#endif // GTEST_OS_FUCHSIA
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
// included, or there will be a compiler error. This trick is to
|
||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
||||
// his code.
|
||||
#define GTEST_IMPLEMENTATION_ 1
|
||||
#include "src/gtest-internal-inl.h"
|
||||
#undef GTEST_IMPLEMENTATION_
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -82,10 +85,31 @@ const int kStdOutFileno = STDOUT_FILENO;
|
||||
const int kStdErrFileno = STDERR_FILENO;
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
#if GTEST_OS_LINUX
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
T ReadProcFileField(const std::string& filename, int field) {
|
||||
std::string dummy;
|
||||
std::ifstream file(filename.c_str());
|
||||
while (field-- > 0) {
|
||||
file >> dummy;
|
||||
}
|
||||
T output = 0;
|
||||
file >> output;
|
||||
return output;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Returns the number of active threads, or 0 when there is an error.
|
||||
size_t GetThreadCount() {
|
||||
const std::string filename =
|
||||
(Message() << "/proc/" << getpid() << "/stat").GetString();
|
||||
return ReadProcFileField<int>(filename, 19);
|
||||
}
|
||||
|
||||
#elif GTEST_OS_MAC
|
||||
|
||||
// Returns the number of threads running in the process, or 0 to indicate that
|
||||
// we cannot detect it.
|
||||
size_t GetThreadCount() {
|
||||
const task_t task = mach_task_self();
|
||||
mach_msg_type_number_t thread_count;
|
||||
@ -123,6 +147,38 @@ size_t GetThreadCount() {
|
||||
}
|
||||
}
|
||||
|
||||
#elif GTEST_OS_AIX
|
||||
|
||||
size_t GetThreadCount() {
|
||||
struct procentry64 entry;
|
||||
pid_t pid = getpid();
|
||||
int status = getprocs64(&entry, sizeof(entry), NULL, 0, &pid, 1);
|
||||
if (status == 1) {
|
||||
return entry.pi_thcount;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#elif GTEST_OS_FUCHSIA
|
||||
|
||||
size_t GetThreadCount() {
|
||||
int dummy_buffer;
|
||||
size_t avail;
|
||||
zx_status_t status = zx_object_get_info(
|
||||
zx_process_self(),
|
||||
ZX_INFO_PROCESS_THREADS,
|
||||
&dummy_buffer,
|
||||
0,
|
||||
nullptr,
|
||||
&avail);
|
||||
if (status == ZX_OK) {
|
||||
return avail;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
size_t GetThreadCount() {
|
||||
@ -131,7 +187,432 @@ size_t GetThreadCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // GTEST_OS_MAC
|
||||
#endif // GTEST_OS_LINUX
|
||||
|
||||
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||
|
||||
void SleepMilliseconds(int n) {
|
||||
::Sleep(n);
|
||||
}
|
||||
|
||||
AutoHandle::AutoHandle()
|
||||
: handle_(INVALID_HANDLE_VALUE) {}
|
||||
|
||||
AutoHandle::AutoHandle(Handle handle)
|
||||
: handle_(handle) {}
|
||||
|
||||
AutoHandle::~AutoHandle() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
AutoHandle::Handle AutoHandle::Get() const {
|
||||
return handle_;
|
||||
}
|
||||
|
||||
void AutoHandle::Reset() {
|
||||
Reset(INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
void AutoHandle::Reset(HANDLE handle) {
|
||||
// Resetting with the same handle we already own is invalid.
|
||||
if (handle_ != handle) {
|
||||
if (IsCloseable()) {
|
||||
::CloseHandle(handle_);
|
||||
}
|
||||
handle_ = handle;
|
||||
} else {
|
||||
GTEST_CHECK_(!IsCloseable())
|
||||
<< "Resetting a valid handle to itself is likely a programmer error "
|
||||
"and thus not allowed.";
|
||||
}
|
||||
}
|
||||
|
||||
bool AutoHandle::IsCloseable() const {
|
||||
// Different Windows APIs may use either of these values to represent an
|
||||
// invalid handle.
|
||||
return handle_ != NULL && handle_ != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
Notification::Notification()
|
||||
: event_(::CreateEvent(NULL, // Default security attributes.
|
||||
TRUE, // Do not reset automatically.
|
||||
FALSE, // Initially unset.
|
||||
NULL)) { // Anonymous event.
|
||||
GTEST_CHECK_(event_.Get() != NULL);
|
||||
}
|
||||
|
||||
void Notification::Notify() {
|
||||
GTEST_CHECK_(::SetEvent(event_.Get()) != FALSE);
|
||||
}
|
||||
|
||||
void Notification::WaitForNotification() {
|
||||
GTEST_CHECK_(
|
||||
::WaitForSingleObject(event_.Get(), INFINITE) == WAIT_OBJECT_0);
|
||||
}
|
||||
|
||||
Mutex::Mutex()
|
||||
: owner_thread_id_(0),
|
||||
type_(kDynamic),
|
||||
critical_section_init_phase_(0),
|
||||
critical_section_(new CRITICAL_SECTION) {
|
||||
::InitializeCriticalSection(critical_section_);
|
||||
}
|
||||
|
||||
Mutex::~Mutex() {
|
||||
// Static mutexes are leaked intentionally. It is not thread-safe to try
|
||||
// to clean them up.
|
||||
// FIXME: Switch to Slim Reader/Writer (SRW) Locks, which requires
|
||||
// nothing to clean it up but is available only on Vista and later.
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/Sync/slim-reader-writer--srw--locks
|
||||
if (type_ == kDynamic) {
|
||||
::DeleteCriticalSection(critical_section_);
|
||||
delete critical_section_;
|
||||
critical_section_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Mutex::Lock() {
|
||||
ThreadSafeLazyInit();
|
||||
::EnterCriticalSection(critical_section_);
|
||||
owner_thread_id_ = ::GetCurrentThreadId();
|
||||
}
|
||||
|
||||
void Mutex::Unlock() {
|
||||
ThreadSafeLazyInit();
|
||||
// We don't protect writing to owner_thread_id_ here, as it's the
|
||||
// caller's responsibility to ensure that the current thread holds the
|
||||
// mutex when this is called.
|
||||
owner_thread_id_ = 0;
|
||||
::LeaveCriticalSection(critical_section_);
|
||||
}
|
||||
|
||||
// Does nothing if the current thread holds the mutex. Otherwise, crashes
|
||||
// with high probability.
|
||||
void Mutex::AssertHeld() {
|
||||
ThreadSafeLazyInit();
|
||||
GTEST_CHECK_(owner_thread_id_ == ::GetCurrentThreadId())
|
||||
<< "The current thread is not holding the mutex @" << this;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Use the RAII idiom to flag mem allocs that are intentionally never
|
||||
// deallocated. The motivation is to silence the false positive mem leaks
|
||||
// that are reported by the debug version of MS's CRT which can only detect
|
||||
// if an alloc is missing a matching deallocation.
|
||||
// Example:
|
||||
// MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
// critical_section_ = new CRITICAL_SECTION;
|
||||
//
|
||||
class MemoryIsNotDeallocated
|
||||
{
|
||||
public:
|
||||
MemoryIsNotDeallocated() : old_crtdbg_flag_(0) {
|
||||
#ifdef _MSC_VER
|
||||
old_crtdbg_flag_ = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
// Set heap allocation block type to _IGNORE_BLOCK so that MS debug CRT
|
||||
// doesn't report mem leak if there's no matching deallocation.
|
||||
_CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF);
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
~MemoryIsNotDeallocated() {
|
||||
#ifdef _MSC_VER
|
||||
// Restore the original _CRTDBG_ALLOC_MEM_DF flag
|
||||
_CrtSetDbgFlag(old_crtdbg_flag_);
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
private:
|
||||
int old_crtdbg_flag_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MemoryIsNotDeallocated);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Initializes owner_thread_id_ and critical_section_ in static mutexes.
|
||||
void Mutex::ThreadSafeLazyInit() {
|
||||
// Dynamic mutexes are initialized in the constructor.
|
||||
if (type_ == kStatic) {
|
||||
switch (
|
||||
::InterlockedCompareExchange(&critical_section_init_phase_, 1L, 0L)) {
|
||||
case 0:
|
||||
// If critical_section_init_phase_ was 0 before the exchange, we
|
||||
// are the first to test it and need to perform the initialization.
|
||||
owner_thread_id_ = 0;
|
||||
{
|
||||
// Use RAII to flag that following mem alloc is never deallocated.
|
||||
MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
critical_section_ = new CRITICAL_SECTION;
|
||||
}
|
||||
::InitializeCriticalSection(critical_section_);
|
||||
// Updates the critical_section_init_phase_ to 2 to signal
|
||||
// initialization complete.
|
||||
GTEST_CHECK_(::InterlockedCompareExchange(
|
||||
&critical_section_init_phase_, 2L, 1L) ==
|
||||
1L);
|
||||
break;
|
||||
case 1:
|
||||
// Somebody else is already initializing the mutex; spin until they
|
||||
// are done.
|
||||
while (::InterlockedCompareExchange(&critical_section_init_phase_,
|
||||
2L,
|
||||
2L) != 2L) {
|
||||
// Possibly yields the rest of the thread's time slice to other
|
||||
// threads.
|
||||
::Sleep(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
break; // The mutex is already initialized and ready for use.
|
||||
|
||||
default:
|
||||
GTEST_CHECK_(false)
|
||||
<< "Unexpected value of critical_section_init_phase_ "
|
||||
<< "while initializing a static mutex.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class ThreadWithParamSupport : public ThreadWithParamBase {
|
||||
public:
|
||||
static HANDLE CreateThread(Runnable* runnable,
|
||||
Notification* thread_can_start) {
|
||||
ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start);
|
||||
DWORD thread_id;
|
||||
// FIXME: Consider to use _beginthreadex instead.
|
||||
HANDLE thread_handle = ::CreateThread(
|
||||
NULL, // Default security.
|
||||
0, // Default stack size.
|
||||
&ThreadWithParamSupport::ThreadMain,
|
||||
param, // Parameter to ThreadMainStatic
|
||||
0x0, // Default creation flags.
|
||||
&thread_id); // Need a valid pointer for the call to work under Win98.
|
||||
GTEST_CHECK_(thread_handle != NULL) << "CreateThread failed with error "
|
||||
<< ::GetLastError() << ".";
|
||||
if (thread_handle == NULL) {
|
||||
delete param;
|
||||
}
|
||||
return thread_handle;
|
||||
}
|
||||
|
||||
private:
|
||||
struct ThreadMainParam {
|
||||
ThreadMainParam(Runnable* runnable, Notification* thread_can_start)
|
||||
: runnable_(runnable),
|
||||
thread_can_start_(thread_can_start) {
|
||||
}
|
||||
scoped_ptr<Runnable> runnable_;
|
||||
// Does not own.
|
||||
Notification* thread_can_start_;
|
||||
};
|
||||
|
||||
static DWORD WINAPI ThreadMain(void* ptr) {
|
||||
// Transfers ownership.
|
||||
scoped_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
|
||||
if (param->thread_can_start_ != NULL)
|
||||
param->thread_can_start_->WaitForNotification();
|
||||
param->runnable_->Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prohibit instantiation.
|
||||
ThreadWithParamSupport();
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParamSupport);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ThreadWithParamBase::ThreadWithParamBase(Runnable *runnable,
|
||||
Notification* thread_can_start)
|
||||
: thread_(ThreadWithParamSupport::CreateThread(runnable,
|
||||
thread_can_start)) {
|
||||
}
|
||||
|
||||
ThreadWithParamBase::~ThreadWithParamBase() {
|
||||
Join();
|
||||
}
|
||||
|
||||
void ThreadWithParamBase::Join() {
|
||||
GTEST_CHECK_(::WaitForSingleObject(thread_.Get(), INFINITE) == WAIT_OBJECT_0)
|
||||
<< "Failed to join the thread with error " << ::GetLastError() << ".";
|
||||
}
|
||||
|
||||
// Maps a thread to a set of ThreadIdToThreadLocals that have values
|
||||
// instantiated on that thread and notifies them when the thread exits. A
|
||||
// ThreadLocal instance is expected to persist until all threads it has
|
||||
// values on have terminated.
|
||||
class ThreadLocalRegistryImpl {
|
||||
public:
|
||||
// Registers thread_local_instance as having value on the current thread.
|
||||
// Returns a value that can be used to identify the thread from other threads.
|
||||
static ThreadLocalValueHolderBase* GetValueOnCurrentThread(
|
||||
const ThreadLocalBase* thread_local_instance) {
|
||||
DWORD current_thread = ::GetCurrentThreadId();
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||
GetThreadLocalsMapLocked();
|
||||
ThreadIdToThreadLocals::iterator thread_local_pos =
|
||||
thread_to_thread_locals->find(current_thread);
|
||||
if (thread_local_pos == thread_to_thread_locals->end()) {
|
||||
thread_local_pos = thread_to_thread_locals->insert(
|
||||
std::make_pair(current_thread, ThreadLocalValues())).first;
|
||||
StartWatcherThreadFor(current_thread);
|
||||
}
|
||||
ThreadLocalValues& thread_local_values = thread_local_pos->second;
|
||||
ThreadLocalValues::iterator value_pos =
|
||||
thread_local_values.find(thread_local_instance);
|
||||
if (value_pos == thread_local_values.end()) {
|
||||
value_pos =
|
||||
thread_local_values
|
||||
.insert(std::make_pair(
|
||||
thread_local_instance,
|
||||
linked_ptr<ThreadLocalValueHolderBase>(
|
||||
thread_local_instance->NewValueForCurrentThread())))
|
||||
.first;
|
||||
}
|
||||
return value_pos->second.get();
|
||||
}
|
||||
|
||||
static void OnThreadLocalDestroyed(
|
||||
const ThreadLocalBase* thread_local_instance) {
|
||||
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
// Clean up the ThreadLocalValues data structure while holding the lock, but
|
||||
// defer the destruction of the ThreadLocalValueHolderBases.
|
||||
{
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||
GetThreadLocalsMapLocked();
|
||||
for (ThreadIdToThreadLocals::iterator it =
|
||||
thread_to_thread_locals->begin();
|
||||
it != thread_to_thread_locals->end();
|
||||
++it) {
|
||||
ThreadLocalValues& thread_local_values = it->second;
|
||||
ThreadLocalValues::iterator value_pos =
|
||||
thread_local_values.find(thread_local_instance);
|
||||
if (value_pos != thread_local_values.end()) {
|
||||
value_holders.push_back(value_pos->second);
|
||||
thread_local_values.erase(value_pos);
|
||||
// This 'if' can only be successful at most once, so theoretically we
|
||||
// could break out of the loop here, but we don't bother doing so.
|
||||
}
|
||||
}
|
||||
}
|
||||
// Outside the lock, let the destructor for 'value_holders' deallocate the
|
||||
// ThreadLocalValueHolderBases.
|
||||
}
|
||||
|
||||
static void OnThreadExit(DWORD thread_id) {
|
||||
GTEST_CHECK_(thread_id != 0) << ::GetLastError();
|
||||
std::vector<linked_ptr<ThreadLocalValueHolderBase> > value_holders;
|
||||
// Clean up the ThreadIdToThreadLocals data structure while holding the
|
||||
// lock, but defer the destruction of the ThreadLocalValueHolderBases.
|
||||
{
|
||||
MutexLock lock(&mutex_);
|
||||
ThreadIdToThreadLocals* const thread_to_thread_locals =
|
||||
GetThreadLocalsMapLocked();
|
||||
ThreadIdToThreadLocals::iterator thread_local_pos =
|
||||
thread_to_thread_locals->find(thread_id);
|
||||
if (thread_local_pos != thread_to_thread_locals->end()) {
|
||||
ThreadLocalValues& thread_local_values = thread_local_pos->second;
|
||||
for (ThreadLocalValues::iterator value_pos =
|
||||
thread_local_values.begin();
|
||||
value_pos != thread_local_values.end();
|
||||
++value_pos) {
|
||||
value_holders.push_back(value_pos->second);
|
||||
}
|
||||
thread_to_thread_locals->erase(thread_local_pos);
|
||||
}
|
||||
}
|
||||
// Outside the lock, let the destructor for 'value_holders' deallocate the
|
||||
// ThreadLocalValueHolderBases.
|
||||
}
|
||||
|
||||
private:
|
||||
// In a particular thread, maps a ThreadLocal object to its value.
|
||||
typedef std::map<const ThreadLocalBase*,
|
||||
linked_ptr<ThreadLocalValueHolderBase> > ThreadLocalValues;
|
||||
// Stores all ThreadIdToThreadLocals having values in a thread, indexed by
|
||||
// thread's ID.
|
||||
typedef std::map<DWORD, ThreadLocalValues> ThreadIdToThreadLocals;
|
||||
|
||||
// Holds the thread id and thread handle that we pass from
|
||||
// StartWatcherThreadFor to WatcherThreadFunc.
|
||||
typedef std::pair<DWORD, HANDLE> ThreadIdAndHandle;
|
||||
|
||||
static void StartWatcherThreadFor(DWORD thread_id) {
|
||||
// The returned handle will be kept in thread_map and closed by
|
||||
// watcher_thread in WatcherThreadFunc.
|
||||
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
|
||||
FALSE,
|
||||
thread_id);
|
||||
GTEST_CHECK_(thread != NULL);
|
||||
// We need to pass a valid thread ID pointer into CreateThread for it
|
||||
// to work correctly under Win98.
|
||||
DWORD watcher_thread_id;
|
||||
HANDLE watcher_thread = ::CreateThread(
|
||||
NULL, // Default security.
|
||||
0, // Default stack size
|
||||
&ThreadLocalRegistryImpl::WatcherThreadFunc,
|
||||
reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
|
||||
CREATE_SUSPENDED,
|
||||
&watcher_thread_id);
|
||||
GTEST_CHECK_(watcher_thread != NULL);
|
||||
// Give the watcher thread the same priority as ours to avoid being
|
||||
// blocked by it.
|
||||
::SetThreadPriority(watcher_thread,
|
||||
::GetThreadPriority(::GetCurrentThread()));
|
||||
::ResumeThread(watcher_thread);
|
||||
::CloseHandle(watcher_thread);
|
||||
}
|
||||
|
||||
// Monitors exit from a given thread and notifies those
|
||||
// ThreadIdToThreadLocals about thread termination.
|
||||
static DWORD WINAPI WatcherThreadFunc(LPVOID param) {
|
||||
const ThreadIdAndHandle* tah =
|
||||
reinterpret_cast<const ThreadIdAndHandle*>(param);
|
||||
GTEST_CHECK_(
|
||||
::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0);
|
||||
OnThreadExit(tah->first);
|
||||
::CloseHandle(tah->second);
|
||||
delete tah;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Returns map of thread local instances.
|
||||
static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() {
|
||||
mutex_.AssertHeld();
|
||||
MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals();
|
||||
return map;
|
||||
}
|
||||
|
||||
// Protects access to GetThreadLocalsMapLocked() and its return value.
|
||||
static Mutex mutex_;
|
||||
// Protects access to GetThreadMapLocked() and its return value.
|
||||
static Mutex thread_map_mutex_;
|
||||
};
|
||||
|
||||
Mutex ThreadLocalRegistryImpl::mutex_(Mutex::kStaticMutex);
|
||||
Mutex ThreadLocalRegistryImpl::thread_map_mutex_(Mutex::kStaticMutex);
|
||||
|
||||
ThreadLocalValueHolderBase* ThreadLocalRegistry::GetValueOnCurrentThread(
|
||||
const ThreadLocalBase* thread_local_instance) {
|
||||
return ThreadLocalRegistryImpl::GetValueOnCurrentThread(
|
||||
thread_local_instance);
|
||||
}
|
||||
|
||||
void ThreadLocalRegistry::OnThreadLocalDestroyed(
|
||||
const ThreadLocalBase* thread_local_instance) {
|
||||
ThreadLocalRegistryImpl::OnThreadLocalDestroyed(thread_local_instance);
|
||||
}
|
||||
|
||||
#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||
|
||||
#if GTEST_USES_POSIX_RE
|
||||
|
||||
@ -247,7 +728,7 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
|
||||
}
|
||||
|
||||
// Helper function used by ValidateRegex() to format error messages.
|
||||
std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||
static std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||
return (Message() << "Syntax error at index " << index
|
||||
<< " in simple regular expression \"" << regex << "\": ").GetString();
|
||||
}
|
||||
@ -256,7 +737,7 @@ std::string FormatRegexSyntaxError(const char* regex, int index) {
|
||||
// otherwise returns true.
|
||||
bool ValidateRegex(const char* regex) {
|
||||
if (regex == NULL) {
|
||||
// TODO(wan@google.com): fix the source file location in the
|
||||
// FIXME: fix the source file location in the
|
||||
// assertion failures to match where the regex is used in user
|
||||
// code.
|
||||
ADD_FAILURE() << "NULL is not a valid simple regular expression.";
|
||||
@ -481,7 +962,6 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
|
||||
return file_name + ":" + StreamableToString(line);
|
||||
}
|
||||
|
||||
|
||||
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
|
||||
: severity_(severity) {
|
||||
const char* const marker =
|
||||
@ -500,12 +980,10 @@ GTestLog::~GTestLog() {
|
||||
posix::Abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Disable Microsoft deprecation warnings for POSIX functions called from
|
||||
// this class (creat, dup, dup2, and close)
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996)
|
||||
#endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
@ -581,12 +1059,6 @@ class CapturedStream {
|
||||
}
|
||||
|
||||
private:
|
||||
// Reads the entire content of a file as an std::string.
|
||||
static std::string ReadEntireFile(FILE* file);
|
||||
|
||||
// Returns the size (in bytes) of a file.
|
||||
static size_t GetFileSize(FILE* file);
|
||||
|
||||
const int fd_; // A stream to capture.
|
||||
int uncaptured_fd_;
|
||||
// Name of the temporary file holding the stderr output.
|
||||
@ -595,44 +1067,14 @@ class CapturedStream {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
|
||||
};
|
||||
|
||||
// Returns the size (in bytes) of a file.
|
||||
size_t CapturedStream::GetFileSize(FILE* file) {
|
||||
fseek(file, 0, SEEK_END);
|
||||
return static_cast<size_t>(ftell(file));
|
||||
}
|
||||
|
||||
// Reads the entire content of a file as a string.
|
||||
std::string CapturedStream::ReadEntireFile(FILE* file) {
|
||||
const size_t file_size = GetFileSize(file);
|
||||
char* const buffer = new char[file_size];
|
||||
|
||||
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
||||
size_t bytes_read = 0; // # of bytes read so far
|
||||
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// Keeps reading the file until we cannot read further or the
|
||||
// pre-determined file size is reached.
|
||||
do {
|
||||
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
|
||||
bytes_read += bytes_last_read;
|
||||
} while (bytes_last_read > 0 && bytes_read < file_size);
|
||||
|
||||
const std::string content(buffer, bytes_read);
|
||||
delete[] buffer;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
# endif // _MSC_VER
|
||||
GTEST_DISABLE_MSC_DEPRECATED_POP_()
|
||||
|
||||
static CapturedStream* g_captured_stderr = NULL;
|
||||
static CapturedStream* g_captured_stdout = NULL;
|
||||
|
||||
// Starts capturing an output stream (stdout/stderr).
|
||||
void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
|
||||
static void CaptureStream(int fd, const char* stream_name,
|
||||
CapturedStream** stream) {
|
||||
if (*stream != NULL) {
|
||||
GTEST_LOG_(FATAL) << "Only one " << stream_name
|
||||
<< " capturer can exist at a time.";
|
||||
@ -641,7 +1083,7 @@ void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
|
||||
}
|
||||
|
||||
// Stops capturing the output stream and returns the captured string.
|
||||
std::string GetCapturedStream(CapturedStream** captured_stream) {
|
||||
static std::string GetCapturedStream(CapturedStream** captured_stream) {
|
||||
const std::string content = (*captured_stream)->GetCapturedString();
|
||||
|
||||
delete *captured_stream;
|
||||
@ -672,25 +1114,67 @@ std::string GetCapturedStderr() {
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
// A copy of all command line arguments. Set by InitGoogleTest().
|
||||
::std::vector<testing::internal::string> g_argvs;
|
||||
|
||||
static const ::std::vector<testing::internal::string>* g_injected_test_argvs =
|
||||
NULL; // Owned.
|
||||
|
||||
void SetInjectableArgvs(const ::std::vector<testing::internal::string>* argvs) {
|
||||
if (g_injected_test_argvs != argvs)
|
||||
delete g_injected_test_argvs;
|
||||
g_injected_test_argvs = argvs;
|
||||
|
||||
size_t GetFileSize(FILE* file) {
|
||||
fseek(file, 0, SEEK_END);
|
||||
return static_cast<size_t>(ftell(file));
|
||||
}
|
||||
|
||||
const ::std::vector<testing::internal::string>& GetInjectableArgvs() {
|
||||
std::string ReadEntireFile(FILE* file) {
|
||||
const size_t file_size = GetFileSize(file);
|
||||
char* const buffer = new char[file_size];
|
||||
|
||||
size_t bytes_last_read = 0; // # of bytes read in the last fread()
|
||||
size_t bytes_read = 0; // # of bytes read so far
|
||||
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
// Keeps reading the file until we cannot read further or the
|
||||
// pre-determined file size is reached.
|
||||
do {
|
||||
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
|
||||
bytes_read += bytes_last_read;
|
||||
} while (bytes_last_read > 0 && bytes_read < file_size);
|
||||
|
||||
const std::string content(buffer, bytes_read);
|
||||
delete[] buffer;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
static const std::vector<std::string>* g_injected_test_argvs = NULL; // Owned.
|
||||
|
||||
std::vector<std::string> GetInjectableArgvs() {
|
||||
if (g_injected_test_argvs != NULL) {
|
||||
return *g_injected_test_argvs;
|
||||
}
|
||||
return g_argvs;
|
||||
return GetArgvs();
|
||||
}
|
||||
|
||||
void SetInjectableArgvs(const std::vector<std::string>* new_argvs) {
|
||||
if (g_injected_test_argvs != new_argvs) delete g_injected_test_argvs;
|
||||
g_injected_test_argvs = new_argvs;
|
||||
}
|
||||
|
||||
void SetInjectableArgvs(const std::vector<std::string>& new_argvs) {
|
||||
SetInjectableArgvs(
|
||||
new std::vector<std::string>(new_argvs.begin(), new_argvs.end()));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
void SetInjectableArgvs(const std::vector< ::string>& new_argvs) {
|
||||
SetInjectableArgvs(
|
||||
new std::vector<std::string>(new_argvs.begin(), new_argvs.end()));
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
void ClearInjectableArgvs() {
|
||||
delete g_injected_test_argvs;
|
||||
g_injected_test_argvs = NULL;
|
||||
}
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
@ -764,16 +1248,23 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
|
||||
//
|
||||
// The value is considered true iff it's not "0".
|
||||
bool BoolFromGTestEnv(const char* flag, bool default_value) {
|
||||
#if defined(GTEST_GET_BOOL_FROM_ENV_)
|
||||
return GTEST_GET_BOOL_FROM_ENV_(flag, default_value);
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||
return string_value == NULL ?
|
||||
default_value : strcmp(string_value, "0") != 0;
|
||||
#endif // defined(GTEST_GET_BOOL_FROM_ENV_)
|
||||
}
|
||||
|
||||
// Reads and returns a 32-bit integer stored in the environment
|
||||
// variable corresponding to the given flag; if it isn't set or
|
||||
// doesn't represent a valid 32-bit integer, returns default_value.
|
||||
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
||||
#if defined(GTEST_GET_INT32_FROM_ENV_)
|
||||
return GTEST_GET_INT32_FROM_ENV_(flag, default_value);
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const string_value = posix::GetEnv(env_var.c_str());
|
||||
if (string_value == NULL) {
|
||||
@ -791,14 +1282,36 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif // defined(GTEST_GET_INT32_FROM_ENV_)
|
||||
}
|
||||
|
||||
// As a special case for the 'output' flag, if GTEST_OUTPUT is not
|
||||
// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build
|
||||
// system. The value of XML_OUTPUT_FILE is a filename without the
|
||||
// "xml:" prefix of GTEST_OUTPUT.
|
||||
// Note that this is meant to be called at the call site so it does
|
||||
// not check that the flag is 'output'
|
||||
// In essence this checks an env variable called XML_OUTPUT_FILE
|
||||
// and if it is set we prepend "xml:" to its value, if it not set we return ""
|
||||
std::string OutputFlagAlsoCheckEnvVar(){
|
||||
std::string default_value_for_output_flag = "";
|
||||
const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE");
|
||||
if (NULL != xml_output_file_env) {
|
||||
default_value_for_output_flag = std::string("xml:") + xml_output_file_env;
|
||||
}
|
||||
return default_value_for_output_flag;
|
||||
}
|
||||
|
||||
// Reads and returns the string environment variable corresponding to
|
||||
// the given flag; if it's not set, returns default_value.
|
||||
const char* StringFromGTestEnv(const char* flag, const char* default_value) {
|
||||
#if defined(GTEST_GET_STRING_FROM_ENV_)
|
||||
return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
|
||||
#else
|
||||
const std::string env_var = FlagToEnvVar(flag);
|
||||
const char* const value = posix::GetEnv(env_var.c_str());
|
||||
return value == NULL ? default_value : value;
|
||||
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -26,10 +26,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
// Google Test - The Google C++ Testing Framework
|
||||
|
||||
// Google Test - The Google C++ Testing and Mocking Framework
|
||||
//
|
||||
// This file implements a universal value printer that can print a
|
||||
// value of any type T:
|
||||
@ -43,11 +42,13 @@
|
||||
// defines Foo.
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <cctype>
|
||||
#include <cwchar>
|
||||
#include <ostream> // NOLINT
|
||||
#include <string>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "src/gtest-internal-inl.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -56,6 +57,9 @@ namespace {
|
||||
using ::std::ostream;
|
||||
|
||||
// Prints a segment of bytes in the given object.
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
|
||||
size_t count, ostream* os) {
|
||||
char text[5] = "";
|
||||
@ -85,7 +89,7 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
|
||||
// If the object size is bigger than kThreshold, we'll have to omit
|
||||
// some details by printing only the first and the last kChunkSize
|
||||
// bytes.
|
||||
// TODO(wan): let the user control the threshold using a flag.
|
||||
// FIXME: let the user control the threshold using a flag.
|
||||
if (count < kThreshold) {
|
||||
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
|
||||
} else {
|
||||
@ -119,7 +123,7 @@ namespace internal {
|
||||
// Depending on the value of a char (or wchar_t), we print it in one
|
||||
// of three formats:
|
||||
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
|
||||
// - as a hexidecimal escape sequence (e.g. '\x7F'), or
|
||||
// - as a hexadecimal escape sequence (e.g. '\x7F'), or
|
||||
// - as a special escape sequence (e.g. '\r', '\n').
|
||||
enum CharFormat {
|
||||
kAsIs,
|
||||
@ -176,7 +180,10 @@ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
|
||||
*os << static_cast<char>(c);
|
||||
return kAsIs;
|
||||
} else {
|
||||
*os << "\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c));
|
||||
ostream::fmtflags flags = os->flags();
|
||||
*os << "\\x" << std::hex << std::uppercase
|
||||
<< static_cast<int>(static_cast<UnsignedChar>(c));
|
||||
os->flags(flags);
|
||||
return kHexEscape;
|
||||
}
|
||||
}
|
||||
@ -223,7 +230,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
|
||||
return;
|
||||
*os << " (" << static_cast<int>(c);
|
||||
|
||||
// For more convenience, we print c's code again in hexidecimal,
|
||||
// For more convenience, we print c's code again in hexadecimal,
|
||||
// unless c was already printed in the form '\x##' or the code is in
|
||||
// [1, 9].
|
||||
if (format == kHexEscape || (1 <= c && c <= 9)) {
|
||||
@ -252,11 +259,15 @@ void PrintTo(wchar_t wc, ostream* os) {
|
||||
// The array starts at begin, the length is len, it may include '\0' characters
|
||||
// and may not be NUL-terminated.
|
||||
template <typename CharType>
|
||||
static void PrintCharsAsStringTo(
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||
static CharFormat PrintCharsAsStringTo(
|
||||
const CharType* begin, size_t len, ostream* os) {
|
||||
const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
|
||||
*os << kQuoteBegin;
|
||||
bool is_previous_hex = false;
|
||||
CharFormat print_format = kAsIs;
|
||||
for (size_t index = 0; index < len; ++index) {
|
||||
const CharType cur = begin[index];
|
||||
if (is_previous_hex && IsXDigit(cur)) {
|
||||
@ -266,13 +277,21 @@ static void PrintCharsAsStringTo(
|
||||
*os << "\" " << kQuoteBegin;
|
||||
}
|
||||
is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
|
||||
// Remember if any characters required hex escaping.
|
||||
if (is_previous_hex) {
|
||||
print_format = kHexEscape;
|
||||
}
|
||||
}
|
||||
*os << "\"";
|
||||
return print_format;
|
||||
}
|
||||
|
||||
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
|
||||
// 'begin'. CharType must be either char or wchar_t.
|
||||
template <typename CharType>
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
|
||||
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
|
||||
static void UniversalPrintCharArray(
|
||||
const CharType* begin, size_t len, ostream* os) {
|
||||
// The code
|
||||
@ -329,20 +348,95 @@ void PrintTo(const wchar_t* s, ostream* os) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
||||
PrintCharsAsStringTo(s, wcslen(s), os);
|
||||
PrintCharsAsStringTo(s, std::wcslen(s), os);
|
||||
}
|
||||
}
|
||||
#endif // wchar_t is native
|
||||
|
||||
namespace {
|
||||
|
||||
bool ContainsUnprintableControlCodes(const char* str, size_t length) {
|
||||
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
unsigned char ch = *s++;
|
||||
if (std::iscntrl(ch)) {
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsUTF8TrailByte(unsigned char t) { return 0x80 <= t && t<= 0xbf; }
|
||||
|
||||
bool IsValidUTF8(const char* str, size_t length) {
|
||||
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
|
||||
|
||||
for (size_t i = 0; i < length;) {
|
||||
unsigned char lead = s[i++];
|
||||
|
||||
if (lead <= 0x7f) {
|
||||
continue; // single-byte character (ASCII) 0..7F
|
||||
}
|
||||
if (lead < 0xc2) {
|
||||
return false; // trail byte or non-shortest form
|
||||
} else if (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) {
|
||||
++i; // 2-byte character
|
||||
} else if (0xe0 <= lead && lead <= 0xef && (i + 2) <= length &&
|
||||
IsUTF8TrailByte(s[i]) &&
|
||||
IsUTF8TrailByte(s[i + 1]) &&
|
||||
// check for non-shortest form and surrogate
|
||||
(lead != 0xe0 || s[i] >= 0xa0) &&
|
||||
(lead != 0xed || s[i] < 0xa0)) {
|
||||
i += 2; // 3-byte character
|
||||
} else if (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length &&
|
||||
IsUTF8TrailByte(s[i]) &&
|
||||
IsUTF8TrailByte(s[i + 1]) &&
|
||||
IsUTF8TrailByte(s[i + 2]) &&
|
||||
// check for non-shortest form
|
||||
(lead != 0xf0 || s[i] >= 0x90) &&
|
||||
(lead != 0xf4 || s[i] < 0x90)) {
|
||||
i += 3; // 4-byte character
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConditionalPrintAsText(const char* str, size_t length, ostream* os) {
|
||||
if (!ContainsUnprintableControlCodes(str, length) &&
|
||||
IsValidUTF8(str, length)) {
|
||||
*os << "\n As Text: \"" << str << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// Prints a ::string object.
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
void PrintStringTo(const ::string& s, ostream* os) {
|
||||
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||
if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) {
|
||||
if (GTEST_FLAG(print_utf8)) {
|
||||
ConditionalPrintAsText(s.data(), s.size(), os);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
void PrintStringTo(const ::std::string& s, ostream* os) {
|
||||
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||
if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) {
|
||||
if (GTEST_FLAG(print_utf8)) {
|
||||
ConditionalPrintAsText(s.data(), s.size(), os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prints a ::wstring object.
|
||||
|
||||
@ -26,21 +26,12 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Author: mheule@google.com (Markus Heule)
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
// The Google C++ Testing and Mocking Framework (Google Test)
|
||||
|
||||
#include "gtest/gtest-test-part.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
// included, or there will be a compiler error. This trick is to
|
||||
// prevent a user from accidentally including gtest-internal-inl.h in
|
||||
// his code.
|
||||
#define GTEST_IMPLEMENTATION_ 1
|
||||
#include "src/gtest-internal-inl.h"
|
||||
#undef GTEST_IMPLEMENTATION_
|
||||
|
||||
namespace testing {
|
||||
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
#include "gtest/gtest-typed-test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
@ -45,33 +45,41 @@ static const char* SkipSpaces(const char* str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
static std::vector<std::string> SplitIntoTestNames(const char* src) {
|
||||
std::vector<std::string> name_vec;
|
||||
src = SkipSpaces(src);
|
||||
for (; src != NULL; src = SkipComma(src)) {
|
||||
name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src)));
|
||||
}
|
||||
return name_vec;
|
||||
}
|
||||
|
||||
// Verifies that registered_tests match the test names in
|
||||
// defined_test_names_; returns registered_tests if successful, or
|
||||
// registered_tests_; returns registered_tests if successful, or
|
||||
// aborts the program otherwise.
|
||||
const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||
const char* file, int line, const char* registered_tests) {
|
||||
typedef ::std::set<const char*>::const_iterator DefinedTestIter;
|
||||
typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
|
||||
registered_ = true;
|
||||
|
||||
// Skip initial whitespace in registered_tests since some
|
||||
// preprocessors prefix stringizied literals with whitespace.
|
||||
registered_tests = SkipSpaces(registered_tests);
|
||||
std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
|
||||
|
||||
Message errors;
|
||||
::std::set<std::string> tests;
|
||||
for (const char* names = registered_tests; names != NULL;
|
||||
names = SkipComma(names)) {
|
||||
const std::string name = GetPrefixUntilComma(names);
|
||||
|
||||
std::set<std::string> tests;
|
||||
for (std::vector<std::string>::const_iterator name_it = name_vec.begin();
|
||||
name_it != name_vec.end(); ++name_it) {
|
||||
const std::string& name = *name_it;
|
||||
if (tests.count(name) != 0) {
|
||||
errors << "Test " << name << " is listed more than once.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for (DefinedTestIter it = defined_test_names_.begin();
|
||||
it != defined_test_names_.end();
|
||||
for (RegisteredTestIter it = registered_tests_.begin();
|
||||
it != registered_tests_.end();
|
||||
++it) {
|
||||
if (name == *it) {
|
||||
if (name == it->first) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -85,11 +93,11 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
||||
}
|
||||
}
|
||||
|
||||
for (DefinedTestIter it = defined_test_names_.begin();
|
||||
it != defined_test_names_.end();
|
||||
for (RegisteredTestIter it = registered_tests_.begin();
|
||||
it != registered_tests_.end();
|
||||
++it) {
|
||||
if (tests.count(*it) == 0) {
|
||||
errors << "You forgot to list test " << *it << ".\n";
|
||||
if (tests.count(it->first) == 0) {
|
||||
errors << "You forgot to list test " << it->first << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -28,11 +28,10 @@
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
GTEST_API_ int main(int argc, char **argv) {
|
||||
printf("Running main() from gtest_main.cc\n");
|
||||
printf("Running main() from %s\n", __FILE__);
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user