Back to home page

sPhenix code displayed by LXR

 
 

    


Warning, /JETSCAPE/external_packages/googletest/googlemock/README.md is written in an unsupported language. File is not indexed.

0001 ## Google Mock ##
0002 
0003 The Google C++ mocking framework.
0004 
0005 ### Overview ###
0006 
0007 Google's framework for writing and using C++ mock classes.
0008 It can help you derive better designs of your system and write better tests.
0009 
0010 It is inspired by:
0011 
0012   * [jMock](http://www.jmock.org/),
0013   * [EasyMock](http://www.easymock.org/), and
0014   * [Hamcrest](http://code.google.com/p/hamcrest/),
0015 
0016 and designed with C++'s specifics in mind.
0017 
0018 Google mock:
0019 
0020   * lets you create mock classes trivially using simple macros.
0021   * supports a rich set of matchers and actions.
0022   * handles unordered, partially ordered, or completely ordered expectations.
0023   * is extensible by users.
0024 
0025 We hope you find it useful!
0026 
0027 ### Features ###
0028 
0029   * Provides a declarative syntax for defining mocks.
0030   * Can easily define partial (hybrid) mocks, which are a cross of real
0031     and mock objects.
0032   * Handles functions of arbitrary types and overloaded functions.
0033   * Comes with a rich set of matchers for validating function arguments.
0034   * Uses an intuitive syntax for controlling the behavior of a mock.
0035   * Does automatic verification of expectations (no record-and-replay needed).
0036   * Allows arbitrary (partial) ordering constraints on
0037     function calls to be expressed,.
0038   * Lets a user extend it by defining new matchers and actions.
0039   * Does not use exceptions.
0040   * Is easy to learn and use.
0041 
0042 Please see the project page above for more information as well as the
0043 mailing list for questions, discussions, and development.  There is
0044 also an IRC channel on OFTC (irc.oftc.net) #gtest available.  Please
0045 join us!
0046 
0047 Please note that code under [scripts/generator](scripts/generator/) is
0048 from [cppclean](http://code.google.com/p/cppclean/) and released under
0049 the Apache License, which is different from Google Mock's license.
0050 
0051 ## Getting Started ##
0052 
0053 If you are new to the project, we suggest that you read the user
0054 documentation in the following order:
0055 
0056   * Learn the [basics](../../master/googletest/docs/Primer.md) of
0057     Google Test, if you choose to use Google Mock with it (recommended).
0058   * Read [Google Mock for Dummies](../../master/googlemock/docs/ForDummies.md).
0059   * Read the instructions below on how to build Google Mock.
0060 
0061 You can also watch Zhanyong's [talk](http://www.youtube.com/watch?v=sYpCyLI47rM) on Google Mock's usage and implementation.
0062 
0063 Once you understand the basics, check out the rest of the docs:
0064 
0065   * [CheatSheet](../../master/googlemock/docs/CheatSheet.md) - all the commonly used stuff
0066     at a glance.
0067   * [CookBook](../../master/googlemock/docs/CookBook.md) - recipes for getting things done,
0068     including advanced techniques.
0069 
0070 If you need help, please check the
0071 [KnownIssues](docs/KnownIssues.md) and
0072 [FrequentlyAskedQuestions](docs/FrequentlyAskedQuestions.md) before
0073 posting a question on the
0074 [discussion group](http://groups.google.com/group/googlemock).
0075 
0076 
0077 ### Using Google Mock Without Google Test ###
0078 
0079 Google Mock is not a testing framework itself.  Instead, it needs a
0080 testing framework for writing tests.  Google Mock works seamlessly
0081 with [Google Test](http://code.google.com/p/googletest/), but
0082 you can also use it with [any C++ testing framework](../../master/googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework).
0083 
0084 ### Requirements for End Users ###
0085 
0086 Google Mock is implemented on top of [Google Test](
0087 http://github.com/google/googletest/), and depends on it.
0088 You must use the bundled version of Google Test when using Google Mock.
0089 
0090 You can also easily configure Google Mock to work with another testing
0091 framework, although it will still need Google Test.  Please read
0092 ["Using_Google_Mock_with_Any_Testing_Framework"](
0093     ../../master/googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework)
0094 for instructions.
0095 
0096 Google Mock depends on advanced C++ features and thus requires a more
0097 modern compiler. The following are needed to use Google Mock:
0098 
0099 #### Linux Requirements ####
0100 
0101   * GNU-compatible Make or "gmake"
0102   * POSIX-standard shell
0103   * POSIX(-2) Regular Expressions (regex.h)
0104   * C++98-standard-compliant compiler (e.g. GCC 3.4 or newer)
0105 
0106 #### Windows Requirements ####
0107 
0108   * Microsoft Visual C++ 8.0 SP1 or newer
0109 
0110 #### Mac OS X Requirements ####
0111 
0112   * Mac OS X 10.4 Tiger or newer
0113   * Developer Tools Installed
0114 
0115 ### Requirements for Contributors ###
0116 
0117 We welcome patches. If you plan to contribute a patch, you need to
0118 build Google Mock and its tests, which has further requirements:
0119 
0120   * Automake version 1.9 or newer
0121   * Autoconf version 2.59 or newer
0122   * Libtool / Libtoolize
0123   * Python version 2.3 or newer (for running some of the tests and
0124     re-generating certain source files from templates)
0125 
0126 ### Building Google Mock ###
0127 
0128 If you have CMake available, it is recommended that you follow the
0129 [build instructions][gtest_cmakebuild]
0130 as described for Google Test. If are using Google Mock with an
0131 existing CMake project, the section
0132 [Incorporating Into An Existing CMake Project][gtest_incorpcmake]
0133 may be of particular interest. Otherwise, the following sections
0134 detail how to build Google Mock without CMake.
0135 
0136 #### Preparing to Build (Unix only) ####
0137 
0138 If you are using a Unix system and plan to use the GNU Autotools build
0139 system to build Google Mock (described below), you'll need to
0140 configure it now.
0141 
0142 To prepare the Autotools build system:
0143 
0144     cd googlemock
0145     autoreconf -fvi
0146 
0147 To build Google Mock and your tests that use it, you need to tell your
0148 build system where to find its headers and source files.  The exact
0149 way to do it depends on which build system you use, and is usually
0150 straightforward.
0151 
0152 This section shows how you can integrate Google Mock into your
0153 existing build system.
0154 
0155 Suppose you put Google Mock in directory `${GMOCK_DIR}` and Google Test
0156 in `${GTEST_DIR}` (the latter is `${GMOCK_DIR}/gtest` by default).  To
0157 build Google Mock, create a library build target (or a project as
0158 called by Visual Studio and Xcode) to compile
0159 
0160     ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
0161 
0162 with
0163 
0164     ${GTEST_DIR}/include and ${GMOCK_DIR}/include
0165 
0166 in the system header search path, and
0167 
0168     ${GTEST_DIR} and ${GMOCK_DIR}
0169 
0170 in the normal header search path.  Assuming a Linux-like system and gcc,
0171 something like the following will do:
0172 
0173     g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
0174         -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
0175         -pthread -c ${GTEST_DIR}/src/gtest-all.cc
0176     g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
0177         -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
0178         -pthread -c ${GMOCK_DIR}/src/gmock-all.cc
0179     ar -rv libgmock.a gtest-all.o gmock-all.o
0180 
0181 (We need -pthread as Google Test and Google Mock use threads.)
0182 
0183 Next, you should compile your test source file with
0184 ${GTEST\_DIR}/include and ${GMOCK\_DIR}/include in the header search
0185 path, and link it with gmock and any other necessary libraries:
0186 
0187     g++ -isystem ${GTEST_DIR}/include -isystem ${GMOCK_DIR}/include \
0188         -pthread path/to/your_test.cc libgmock.a -o your_test
0189 
0190 As an example, the make/ directory contains a Makefile that you can
0191 use to build Google Mock on systems where GNU make is available
0192 (e.g. Linux, Mac OS X, and Cygwin).  It doesn't try to build Google
0193 Mock's own tests.  Instead, it just builds the Google Mock library and
0194 a sample test.  You can use it as a starting point for your own build
0195 script.
0196 
0197 If the default settings are correct for your environment, the
0198 following commands should succeed:
0199 
0200     cd ${GMOCK_DIR}/make
0201     make
0202     ./gmock_test
0203 
0204 If you see errors, try to tweak the contents of
0205 [make/Makefile](make/Makefile) to make them go away.
0206 
0207 ### Windows ###
0208 
0209 The msvc/2005 directory contains VC++ 2005 projects and the msvc/2010
0210 directory contains VC++ 2010 projects for building Google Mock and
0211 selected tests.
0212 
0213 Change to the appropriate directory and run "msbuild gmock.sln" to
0214 build the library and tests (or open the gmock.sln in the MSVC IDE).
0215 If you want to create your own project to use with Google Mock, you'll
0216 have to configure it to use the `gmock_config` propety sheet.  For that:
0217 
0218  * Open the Property Manager window (View | Other Windows | Property Manager)
0219  * Right-click on your project and select "Add Existing Property Sheet..."
0220  * Navigate to `gmock_config.vsprops` or `gmock_config.props` and select it.
0221  * In Project Properties | Configuration Properties | General | Additional
0222    Include Directories, type <path to Google Mock>/include.
0223 
0224 ### Tweaking Google Mock ###
0225 
0226 Google Mock can be used in diverse environments.  The default
0227 configuration may not work (or may not work well) out of the box in
0228 some environments.  However, you can easily tweak Google Mock by
0229 defining control macros on the compiler command line.  Generally,
0230 these macros are named like `GTEST_XYZ` and you define them to either 1
0231 or 0 to enable or disable a certain feature.
0232 
0233 We list the most frequently used macros below.  For a complete list,
0234 see file [${GTEST\_DIR}/include/gtest/internal/gtest-port.h](
0235 ../googletest/include/gtest/internal/gtest-port.h).
0236 
0237 ### Choosing a TR1 Tuple Library ###
0238 
0239 Google Mock uses the C++ Technical Report 1 (TR1) tuple library
0240 heavily.  Unfortunately TR1 tuple is not yet widely available with all
0241 compilers.  The good news is that Google Test 1.4.0+ implements a
0242 subset of TR1 tuple that's enough for Google Mock's need.  Google Mock
0243 will automatically use that implementation when the compiler doesn't
0244 provide TR1 tuple.
0245 
0246 Usually you don't need to care about which tuple library Google Test
0247 and Google Mock use.  However, if your project already uses TR1 tuple,
0248 you need to tell Google Test and Google Mock to use the same TR1 tuple
0249 library the rest of your project uses, or the two tuple
0250 implementations will clash.  To do that, add
0251 
0252     -DGTEST_USE_OWN_TR1_TUPLE=0
0253 
0254 to the compiler flags while compiling Google Test, Google Mock, and
0255 your tests.  If you want to force Google Test and Google Mock to use
0256 their own tuple library, just add
0257 
0258     -DGTEST_USE_OWN_TR1_TUPLE=1
0259 
0260 to the compiler flags instead.
0261 
0262 If you want to use Boost's TR1 tuple library with Google Mock, please
0263 refer to the Boost website (http://www.boost.org/) for how to obtain
0264 it and set it up.
0265 
0266 ### As a Shared Library (DLL) ###
0267 
0268 Google Mock is compact, so most users can build and link it as a static
0269 library for the simplicity.  Google Mock can be used as a DLL, but the
0270 same DLL must contain Google Test as well.  See
0271 [Google Test's README][gtest_readme]
0272 for instructions on how to set up necessary compiler settings.
0273 
0274 ### Tweaking Google Mock ###
0275 
0276 Most of Google Test's control macros apply to Google Mock as well.
0277 Please see [Google Test's README][gtest_readme] for how to tweak them.
0278 
0279 ### Upgrading from an Earlier Version ###
0280 
0281 We strive to keep Google Mock releases backward compatible.
0282 Sometimes, though, we have to make some breaking changes for the
0283 users' long-term benefits.  This section describes what you'll need to
0284 do if you are upgrading from an earlier version of Google Mock.
0285 
0286 #### Upgrading from 1.1.0 or Earlier ####
0287 
0288 You may need to explicitly enable or disable Google Test's own TR1
0289 tuple library.  See the instructions in section "[Choosing a TR1 Tuple
0290 Library](../googletest/#choosing-a-tr1-tuple-library)".
0291 
0292 #### Upgrading from 1.4.0 or Earlier ####
0293 
0294 On platforms where the pthread library is available, Google Test and
0295 Google Mock use it in order to be thread-safe.  For this to work, you
0296 may need to tweak your compiler and/or linker flags.  Please see the
0297 "[Multi-threaded Tests](../googletest#multi-threaded-tests
0298 )" section in file Google Test's README for what you may need to do.
0299 
0300 If you have custom matchers defined using `MatcherInterface` or
0301 `MakePolymorphicMatcher()`, you'll need to update their definitions to
0302 use the new matcher API (
0303 [monomorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Monomorphic_Matchers),
0304 [polymorphic](http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Polymorphic_Matchers)).
0305 Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected.
0306 
0307 ### Developing Google Mock ###
0308 
0309 This section discusses how to make your own changes to Google Mock.
0310 
0311 #### Testing Google Mock Itself ####
0312 
0313 To make sure your changes work as intended and don't break existing
0314 functionality, you'll want to compile and run Google Test's own tests.
0315 For that you'll need Autotools.  First, make sure you have followed
0316 the instructions above to configure Google Mock.
0317 Then, create a build output directory and enter it.  Next,
0318 
0319     ${GMOCK_DIR}/configure  # try --help for more info
0320 
0321 Once you have successfully configured Google Mock, the build steps are
0322 standard for GNU-style OSS packages.
0323 
0324     make        # Standard makefile following GNU conventions
0325     make check  # Builds and runs all tests - all should pass.
0326 
0327 Note that when building your project against Google Mock, you are building
0328 against Google Test as well.  There is no need to configure Google Test
0329 separately.
0330 
0331 #### Contributing a Patch ####
0332 
0333 We welcome patches.
0334 Please read the [Developer's Guide](docs/DevGuide.md)
0335 for how you can contribute. In particular, make sure you have signed
0336 the Contributor License Agreement, or we won't be able to accept the
0337 patch.
0338 
0339 Happy testing!
0340 
0341 [gtest_readme]: ../googletest/README.md "googletest"
0342 [gtest_cmakebuild]:  ../googletest/README.md#using-cmake "Using CMake"
0343 [gtest_incorpcmake]: ../googletest/README.md#incorporating-into-an-existing-cmake-project "Incorporating Into An Existing CMake Project"