14b6829f0d28990dd645e16386eb226d0f10c8731shiqianGoogle C++ Testing Framework
24b6829f0d28990dd645e16386eb226d0f10c8731shiqian============================
30ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
44b6829f0d28990dd645e16386eb226d0f10c8731shiqianhttp://code.google.com/p/googletest/
54b6829f0d28990dd645e16386eb226d0f10c8731shiqian
64b6829f0d28990dd645e16386eb226d0f10c8731shiqianOverview
74b6829f0d28990dd645e16386eb226d0f10c8731shiqian--------
80ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
90ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle's framework for writing C++ tests on a variety of platforms
100ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan(Linux, Mac OS X, Windows, Windows CE, Symbian, etc).  Based on the
110ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanxUnit architecture.  Supports automatic test discovery, a rich set of
120ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanassertions, user-defined assertions, death tests, fatal and non-fatal
130ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfailures, various options for running the tests, and XML test report
140ce424bbe0eed43e66709712da295232c759ec7azhanyong.wangeneration.
150ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
160ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanPlease see the project page above for more information as well as the
170ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanmailing list for questions, discussions, and development.  There is
180ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanalso an IRC channel on OFTC (irc.oftc.net) #gtest available.  Please
190ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanjoin us!
200ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
210ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanRequirements for End Users
220ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan--------------------------
230ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
246c84bcf915f498278cd28c9180b699595e7b6470shiqianGoogle Test is designed to have fairly minimal requirements to build
250ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanand use with your projects, but there are some.  Currently, we support
260ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanLinux, Windows, Mac OS X, and Cygwin.  We will also make our best
270ce424bbe0eed43e66709712da295232c759ec7azhanyong.waneffort to support other platforms (e.g. Solaris, AIX, and z/OS).
280ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanHowever, since core members of the Google Test project have no access
290ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto these platforms, Google Test may have outstanding issues there.  If
300ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanyou notice any problems on your platform, please notify
310ce424bbe0eed43e66709712da295232c759ec7azhanyong.wangoogletestframework@googlegroups.com.  Patches for fixing them are
320ce424bbe0eed43e66709712da295232c759ec7azhanyong.waneven more welcome!
334b6829f0d28990dd645e16386eb226d0f10c8731shiqian
344b6829f0d28990dd645e16386eb226d0f10c8731shiqian### Linux Requirements ###
350ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
364b6829f0d28990dd645e16386eb226d0f10c8731shiqianThese are the base requirements to build and use Google Test from a source
374b6829f0d28990dd645e16386eb226d0f10c8731shiqianpackage (as described below):
380ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  * GNU-compatible Make or gmake
394b6829f0d28990dd645e16386eb226d0f10c8731shiqian  * POSIX-standard shell
404b6829f0d28990dd645e16386eb226d0f10c8731shiqian  * POSIX(-2) Regular Expressions (regex.h)
410ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  * A C++98-standard-compliant compiler
424b6829f0d28990dd645e16386eb226d0f10c8731shiqian
434f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian### Windows Requirements ###
440ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
450ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  * Microsoft Visual C++ 7.1 or newer
464f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian
474f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian### Cygwin Requirements ###
480ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
494f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian  * Cygwin 1.5.25-14 or newer
504f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian
514f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian### Mac OS X Requirements ###
520ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
534f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian  * Mac OS X 10.4 Tiger or newer
5454a5d37313dd00be48501f80c41b700eee11176cshiqian  * Developer Tools Installed
550ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
560ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanAlso, you'll need CMake 2.6.4 or higher if you want to build the
570ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansamples using the provided CMake script, regardless of the platform.
580ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
590ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanRequirements for Contributors
600ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan-----------------------------
610ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
620ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanWe welcome patches.  If you plan to contribute a patch, you need to
630ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanbuild Google Test and its own tests from an SVN checkout (described
640ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanbelow), which has further requirements:
650ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
660ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  * Python version 2.3 or newer (for running some of the tests and
670ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan    re-generating certain source files from templates)
680ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  * CMake 2.6.4 or newer
694f1d72ed86ade239a3a03b4cb4482012daab0bffshiqian
704b6829f0d28990dd645e16386eb226d0f10c8731shiqianGetting the Source
714b6829f0d28990dd645e16386eb226d0f10c8731shiqian------------------
720ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
730ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThere are two primary ways of getting Google Test's source code: you
740ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancan download a stable source release in your preferred archive format,
75237d7a871eea8c1ef5227795e81ff071f15c2710kosak@google.comor directly check out the source from our Subversion (SVN) repository.
760ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThe SVN checkout requires a few extra steps and some extra software
770ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanpackages on your system, but lets you track the latest development and
780ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanmake patches much more easily, so we highly encourage it.
790ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
800ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Source Package ###
810ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
820ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test is released in versioned source packages which can be
830ce424bbe0eed43e66709712da295232c759ec7azhanyong.wandownloaded from the download page [1].  Several different archive
840ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanformats are provided, but the only difference is the tools used to
850ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanmanipulate them, and the size of the resulting file.  Download
860ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanwhichever you are most comfortable with.
870ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
880ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  [1] http://code.google.com/p/googletest/downloads/list
890ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
900ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanOnce the package is downloaded, expand it using whichever tools you
910ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanprefer for that type.  This will result in a new directory with the
920ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanname "gtest-X.Y.Z" which contains all of the source code.  Here are
930ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansome examples on Linux:
940ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
950ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  tar -xvzf gtest-X.Y.Z.tar.gz
960ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  tar -xvjf gtest-X.Y.Z.tar.bz2
970ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  unzip gtest-X.Y.Z.zip
980ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
990ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### SVN Checkout ###
1000ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1010ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTo check out the main branch (also known as the "trunk") of Google
1020ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTest, run the following Subversion command:
1034b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1049908dd8fb38de66f72f6dc056ec57dd252c2cffdshiqian  svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn
1054b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1060ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanSetting up the Build
1070ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan--------------------
1084b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1090ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTo build Google Test and your tests that use it, you need to tell your
1100ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanbuild system where to find its headers and source files.  The exact
1110ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanway to do it depends on which build system you use, and is usually
1120ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanstraightforward.
1134b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1140ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Generic Build Instructions ###
1154b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1160ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanSuppose you put Google Test in directory ${GTEST_DIR}.  To build it,
1170ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancreate a library build target (or a project as called by Visual Studio
1180ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanand Xcode) to compile
1194b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1200ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  ${GTEST_DIR}/src/gtest-all.cc
12158a098f9542a5bb51299433705a9b3245e02bb73shiqian
122b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wanwith ${GTEST_DIR}/include in the system header search path and ${GTEST_DIR}
123b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wanin the normal header search path.  Assuming a Linux-like system and gcc,
1240ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansomething like the following will do:
1254b6829f0d28990dd645e16386eb226d0f10c8731shiqian
126b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan  g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
127b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan      -pthread -c ${GTEST_DIR}/src/gtest-all.cc
1280ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  ar -rv libgtest.a gtest-all.o
1294b6829f0d28990dd645e16386eb226d0f10c8731shiqian
130b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan(We need -pthread as Google Test uses threads.)
131b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan
1320ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanNext, you should compile your test source file with
133b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan${GTEST_DIR}/include in the system header search path, and link it
134b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wanwith gtest and any other necessary libraries:
1354b6829f0d28990dd645e16386eb226d0f10c8731shiqian
136b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan  g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \
137b4dbe2896c589928ec0b5a65eff1c58283da1038zhanyong.wan      -o your_test
1384b6829f0d28990dd645e16386eb226d0f10c8731shiqian
1390ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanAs an example, the make/ directory contains a Makefile that you can
1400ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanuse to build Google Test on systems where GNU make is available
1410ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan(e.g. Linux, Mac OS X, and Cygwin).  It doesn't try to build Google
1420ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTest's own tests.  Instead, it just builds the Google Test library and
1430ce424bbe0eed43e66709712da295232c759ec7azhanyong.wana sample test.  You can use it as a starting point for your own build
1440ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanscript.
1450ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1460ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf the default settings are correct for your environment, the
1470ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfollowing commands should succeed:
1480ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1490ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  cd ${GTEST_DIR}/make
1500ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  make
1510ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  ./sample1_unittest
1520ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1530ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you see errors, try to tweak the contents of make/Makefile to make
1540ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthem go away.  There are instructions in make/Makefile on how to do
1550ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanit.
1560ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1570ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Using CMake ###
1580ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1590ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test comes with a CMake build script (CMakeLists.txt) that can
160bfa2638bc2e88091bb6a4a4496ef10d7f8575553kosak@google.combe used on a wide range of platforms ("C" stands for cross-platform.).
1610ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you don't have CMake installed already, you can download it for
1620ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfree from http://www.cmake.org/.
1630ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1640ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanCMake works by generating native makefiles or build projects that can
1650ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanbe used in the compiler environment of your choice.  The typical
1660ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanworkflow starts with:
1670ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1680ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  mkdir mybuild       # Create a directory to hold the build output.
1690ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  cd mybuild
1700ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  cmake ${GTEST_DIR}  # Generate native build scripts.
1710ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1720ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you want to build Google Test's samples, you should replace the
1730ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanlast command with
1740ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
175e9f02382977c4e3c156198ba771f663ed63cbc7bvladlosev  cmake -Dgtest_build_samples=ON ${GTEST_DIR}
1760ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1770ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you are on a *nix system, you should now see a Makefile in the
1780ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancurrent directory.  Just type 'make' to build gtest.
1790ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
180bfa2638bc2e88091bb6a4a4496ef10d7f8575553kosak@google.comIf you use Windows and have Visual Studio installed, a gtest.sln file
1810ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanand several .vcproj files will be created.  You can then build them
1820ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanusing Visual Studio.
1830ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1840ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanOn Mac OS X with Xcode installed, a .xcodeproj file will be generated.
1850ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1860ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Legacy Build Scripts ###
1870ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1880ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanBefore settling on CMake, we have been providing hand-maintained build
1890ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanprojects/scripts for Visual Studio, Xcode, and Autotools.  While we
1900ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancontinue to provide them for convenience, they are not actively
1910ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanmaintained any more.  We highly recommend that you follow the
1920ce424bbe0eed43e66709712da295232c759ec7azhanyong.waninstructions in the previous two sections to integrate Google Test
1930ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanwith your existing build system.
1940ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1950ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you still need to use the legacy build scripts, here's how:
1960ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
1970ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThe msvc\ folder contains two solutions with Visual C++ projects.
1980ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanOpen the gtest.sln or gtest-md.sln file using Visual Studio, and you
1990ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanare ready to build Google Test the same way you build any Visual
2000ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanStudio project.  Files that have names ending with -md use DLL
2010ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanversions of Microsoft runtime libraries (the /MD or the /MDd compiler
2020ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanoption).  Files without that suffix use static versions of the runtime
2030ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanlibraries (the /MT or the /MTd option).  Please note that one must use
2040ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthe same option to compile both gtest and the test code.  If you use
2050ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanVisual Studio 2005 or above, we recommend the -md version as /MD is
2060ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthe default for new projects in these versions of Visual Studio.
2070ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2080ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanOn Mac OS X, open the gtest.xcodeproj in the xcode/ folder using
2090ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanXcode.  Build the "gtest" target.  The universal binary framework will
2100ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanend up in your selected build directory (selected in the Xcode
2110ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan"Preferences..." -> "Building" pane and defaults to xcode/build).
2120ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanAlternatively, at the command line, enter:
2130ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2140ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  xcodebuild
2150ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2160ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThis will build the "Release" configuration of gtest.framework in your
2170ce424bbe0eed43e66709712da295232c759ec7azhanyong.wandefault build location.  See the "xcodebuild" man page for more
2180ce424bbe0eed43e66709712da295232c759ec7azhanyong.waninformation about building different configurations and building in
2190ce424bbe0eed43e66709712da295232c759ec7azhanyong.wandifferent locations.
2200ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
221e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosevIf you wish to use the Google Test Xcode project with Xcode 4.x and
222e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosevabove, you need to either:
223e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev * update the SDK configuration options in xcode/Config/General.xconfig.
224e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev   Comment options SDKROOT, MACOS_DEPLOYMENT_TARGET, and GCC_VERSION. If
225e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev   you choose this route you lose the ability to target earlier versions
226e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev   of MacOS X.
227e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev * Install an SDK for an earlier version. This doesn't appear to be
228e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev   supported by Apple, but has been reported to work
229e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev   (http://stackoverflow.com/questions/5378518).
230e0e93e5547c71906b6c70eb06e781ced1dae0407vladlosev
2310ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTweaking Google Test
2320ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan--------------------
2330ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2340ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test can be used in diverse environments.  The default
2350ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanconfiguration may not work (or may not work well) out of the box in
2360ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansome environments.  However, you can easily tweak Google Test by
2370ce424bbe0eed43e66709712da295232c759ec7azhanyong.wandefining control macros on the compiler command line.  Generally,
2380ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthese macros are named like GTEST_XYZ and you define them to either 1
2390ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanor 0 to enable or disable a certain feature.
2400ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2410ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanWe list the most frequently used macros below.  For a complete list,
2420ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansee file include/gtest/internal/gtest-port.h.
2430ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2440ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Choosing a TR1 Tuple Library ###
2454b6829f0d28990dd645e16386eb226d0f10c8731shiqian
2466d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wanSome Google Test features require the C++ Technical Report 1 (TR1)
2470ce424bbe0eed43e66709712da295232c759ec7azhanyong.wantuple library, which is not yet available with all compilers.  The
2480ce424bbe0eed43e66709712da295232c759ec7azhanyong.wangood news is that Google Test implements a subset of TR1 tuple that's
2490ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanenough for its own need, and will automatically use this when the
2500ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancompiler doesn't provide TR1 tuple.
2516d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2526d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wanUsually you don't need to care about which tuple library Google Test
2536d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wanuses.  However, if your project already uses TR1 tuple, you need to
2546d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wantell Google Test to use the same TR1 tuple library the rest of your
2550ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanproject uses, or the two tuple implementations will clash.  To do
2560ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthat, add
2576d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2586d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan  -DGTEST_USE_OWN_TR1_TUPLE=0
2596d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2600ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto the compiler flags while compiling Google Test and your tests.  If
2610ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanyou want to force Google Test to use its own tuple library, just add
2620ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2630ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_USE_OWN_TR1_TUPLE=1
2640ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
2650ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto the compiler flags instead.
2666d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2676d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wanIf you don't want Google Test to use tuple at all, add
2686d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2696d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan  -DGTEST_HAS_TR1_TUPLE=0
2706d63ee6720540cadb8919037c5d41a6413cc9101zhanyong.wan
2710ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanand all features using tuple will be disabled.
27254a5d37313dd00be48501f80c41b700eee11176cshiqian
2730ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Multi-threaded Tests ###
274f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
2750ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test is thread-safe where the pthread library is available.
2762620c79810d4741922e9fa89050c0af564994f24zhanyong.wanAfter #include "gtest/gtest.h", you can check the GTEST_IS_THREADSAFE
2770ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanmacro to see whether this is the case (yes if the macro is #defined to
2780ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan1, no if it's undefined.).
2799210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
2800ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf Google Test doesn't correctly detect whether pthread is available
2810ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanin your environment, you can force it with
2829210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
2830ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_HAS_PTHREAD=1
284f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
2850ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanor
28634e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
2870ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_HAS_PTHREAD=0
288f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
2890ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanWhen Google Test uses pthread, you may need to add flags to your
2900ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancompiler and/or linker to select the pthread library, or you'll get
2910ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanlink errors.  If you use the CMake script or the deprecated Autotools
2920ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanscript, this is taken care of for you.  If you use your own build
2930ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanscript, you'll need to read your compiler and linker's manual to
2940ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfigure out what flags to add.
29534e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
2960ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### As a Shared Library (DLL) ###
297f39160b423e8f90902066cf6774e4180667dcbeezhanyong.wan
2980ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test is compact, so most users can build and link it as a
2990ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanstatic library for the simplicity.  You can choose to use Google Test
3000ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanas a shared library (known as a DLL on Windows) if you prefer.
30134e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
3029c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanTo compile *gtest* as a shared library, add
30334e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
3040ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_CREATE_SHARED_LIBRARY=1
30534e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
3060ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto the compiler flags.  You'll also need to tell the linker to produce
3070ce424bbe0eed43e66709712da295232c759ec7azhanyong.wana shared library instead - consult your linker's manual for how to do
3080ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanit.
3099210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
3109c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanTo compile your *tests* that use the gtest shared library, add
3119210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
3120ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_LINKED_AS_SHARED_LIBRARY=1
3139210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
3140ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto the compiler flags.
3159210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
3169c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanNote: while the above steps aren't technically necessary today when
3179c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanusing some compilers (e.g. GCC), they may become necessary in the
3189c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanfuture, if we decide to improve the speed of loading the library (see
3199c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanhttp://gcc.gnu.org/wiki/Visibility for details).  Therefore you are
3209c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanrecommended to always add the above flags when using Google Test as a
3219c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanshared library.  Otherwise a future release of Google Test may break
3229c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wanyour build script.
3239c3d66814955c7c147bb46e0369f1e0c40c018d6zhanyong.wan
3240ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Avoiding Macro Name Clashes ###
3259210e179469ec720af19da6ad9a4656eb096d8e7preston.jackson
3260ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIn C++, macros don't obey namespaces.  Therefore two libraries that
3270ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanboth define a macro of the same name will clash if you #include both
3280ce424bbe0eed43e66709712da295232c759ec7azhanyong.wandefinitions.  In case a Google Test macro clashes with another
3290ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanlibrary, you can force Google Test to rename its macro to avoid the
3300ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanconflict.
33134e42df5b87572c93fea8e4ada2b2b437fbfe4e4preston.a.jackson
3320ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanSpecifically, if both Google Test and some other code define macro
3330ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanFOO, you can add
33454a5d37313dd00be48501f80c41b700eee11176cshiqian
3350ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  -DGTEST_DONT_DEFINE_FOO=1
3365cd5b671ab4ad97794c74a7fc4907bd3d102c889shiqian
3370ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanto the compiler flags to tell Google Test to change the macro's name
3380ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfrom FOO to GTEST_FOO.  Currently FOO can be FAIL, SUCCEED, or TEST.
3390ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanFor example, with -DGTEST_DONT_DEFINE_TEST=1, you'll need to write
3405cd5b671ab4ad97794c74a7fc4907bd3d102c889shiqian
3410ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  GTEST_TEST(SomeTest, DoesThis) { ... }
3425cd5b671ab4ad97794c74a7fc4907bd3d102c889shiqian
3430ce424bbe0eed43e66709712da295232c759ec7azhanyong.waninstead of
3445cd5b671ab4ad97794c74a7fc4907bd3d102c889shiqian
3450ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  TEST(SomeTest, DoesThis) { ... }
3466c84bcf915f498278cd28c9180b699595e7b6470shiqian
3470ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanin order to define a test.
3480ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3490ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanUpgrating from an Earlier Version
3500ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan---------------------------------
3510ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3520ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanWe strive to keep Google Test releases backward compatible.
3530ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanSometimes, though, we have to make some breaking changes for the
3540ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanusers' long-term benefits.  This section describes what you'll need to
3550ce424bbe0eed43e66709712da295232c759ec7azhanyong.wando if you are upgrading from an earlier version of Google Test.
3560ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3570ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Upgrading from 1.3.0 or Earlier ###
3580ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3590ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanYou may need to explicitly enable or disable Google Test's own TR1
3600ce424bbe0eed43e66709712da295232c759ec7azhanyong.wantuple library.  See the instructions in section "Choosing a TR1 Tuple
3610ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanLibrary".
3620ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3630ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Upgrading from 1.4.0 or Earlier ###
3640ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3650ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThe Autotools build script (configure + make) is no longer officially
3660ce424bbe0eed43e66709712da295232c759ec7azhanyong.wansupportted.  You are encouraged to migrate to your own build system or
3670ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanuse CMake.  If you still need to use Autotools, you can find
3680ce424bbe0eed43e66709712da295232c759ec7azhanyong.waninstructions in the README file from Google Test 1.4.0.
3690ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3700ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanOn platforms where the pthread library is available, Google Test uses
3710ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanit in order to be thread-safe.  See the "Multi-threaded Tests" section
3720ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfor what this means to your build script.
3730ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3740ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanIf you use Microsoft Visual C++ 7.1 with exceptions disabled, Google
3750ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTest will no longer compile.  This should affect very few people, as a
3760ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanlarge portion of STL (including <string>) doesn't compile in this mode
3770ce424bbe0eed43e66709712da295232c759ec7azhanyong.wananyway.  We decided to stop supporting it in order to greatly simplify
3780ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanGoogle Test's implementation.
3790ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3800ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanDeveloping Google Test
3810ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan----------------------
3820ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3830ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanThis section discusses how to make your own changes to Google Test.
3840ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3850ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Testing Google Test Itself ###
3860ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3870ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanTo make sure your changes work as intended and don't break existing
3880ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfunctionality, you'll want to compile and run Google Test's own tests.
3890ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanFor that you can use CMake:
3900ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3910ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  mkdir mybuild
3920ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  cd mybuild
393e9f02382977c4e3c156198ba771f663ed63cbc7bvladlosev  cmake -Dgtest_build_tests=ON ${GTEST_DIR}
3940ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
3950ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanMake sure you have Python installed, as some of Google Test's tests
3960ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanare written in Python.  If the cmake command complains about not being
3970ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanable to find Python ("Could NOT find PythonInterp (missing:
3980ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanPYTHON_EXECUTABLE)"), try telling it explicitly where your Python
3990ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanexecutable can be found:
4000ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
401e9f02382977c4e3c156198ba771f663ed63cbc7bvladlosev  cmake -DPYTHON_EXECUTABLE=path/to/python -Dgtest_build_tests=ON ${GTEST_DIR}
4020ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4030ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanNext, you can build Google Test and all of its own tests.  On *nix,
4040ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthis is usually done by 'make'.  To run the tests, do
4050ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4060ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  make test
4070ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4080ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanAll tests should pass.
4090ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4100ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Regenerating Source Files ###
4116c84bcf915f498278cd28c9180b699595e7b6470shiqian
412e8ff148b4309e115da1c55089dc3b9a241a928dcshiqianSome of Google Test's source files are generated from templates (not
413e8ff148b4309e115da1c55089dc3b9a241a928dcshiqianin the C++ sense) using a script.  A template file is named FOO.pump,
414e8ff148b4309e115da1c55089dc3b9a241a928dcshiqianwhere FOO is the name of the file it will generate.  For example, the
415e8ff148b4309e115da1c55089dc3b9a241a928dcshiqianfile include/gtest/internal/gtest-type-util.h.pump is used to generate
416e8ff148b4309e115da1c55089dc3b9a241a928dcshiqiangtest-type-util.h in the same directory.
417e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
418e8ff148b4309e115da1c55089dc3b9a241a928dcshiqianNormally you don't need to worry about regenerating the source files,
4190ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanunless you need to modify them.  In that case, you should modify the
4200ce424bbe0eed43e66709712da295232c759ec7azhanyong.wancorresponding .pump files instead and run the pump.py Python script to
4210ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanregenerate them.  You can find pump.py in the scripts/ directory.
4220ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanRead the Pump manual [2] for how to use it.
4230ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4240ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  [2] http://code.google.com/p/googletest/wiki/PumpManual
4250ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4260ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan### Contributing a Patch ###
4270ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4280ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanWe welcome patches.  Please read the Google Test developer's guide [3]
4290ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanfor how you can contribute.  In particular, make sure you have signed
4300ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanthe Contributor License Agreement, or we won't be able to accept the
4310ce424bbe0eed43e66709712da295232c759ec7azhanyong.wanpatch.
4320ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan
4330ce424bbe0eed43e66709712da295232c759ec7azhanyong.wan  [3] http://code.google.com/p/googletest/wiki/GoogleTestDevGuide
434e8ff148b4309e115da1c55089dc3b9a241a928dcshiqian
4354b6829f0d28990dd645e16386eb226d0f10c8731shiqianHappy testing!
436