test/fmw/gtest/googlemock/README.md
author ysuenaga
Wed, 13 Nov 2019 10:27:06 +0900
changeset 59045 846fee5ea75e
parent 55049 4853b1ceb3d6
permissions -rw-r--r--
8233785: Incorrect JDK version is reported in hs_err log Reviewed-by: dholmes, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     1
## Google Mock ##
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     2
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     3
The Google C++ mocking framework.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     4
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     5
### Overview ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     6
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     7
Google's framework for writing and using C++ mock classes.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     8
It can help you derive better designs of your system and write better tests.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     9
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    10
It is inspired by:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    11
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    12
  * [jMock](http://www.jmock.org/),
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    13
  * [EasyMock](http://www.easymock.org/), and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    14
  * [Hamcrest](http://code.google.com/p/hamcrest/),
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    15
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    16
and designed with C++'s specifics in mind.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    17
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    18
Google mock:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    19
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    20
  * lets you create mock classes trivially using simple macros.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    21
  * supports a rich set of matchers and actions.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    22
  * handles unordered, partially ordered, or completely ordered expectations.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    23
  * is extensible by users.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    24
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    25
We hope you find it useful!
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    26
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    27
### Features ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    28
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    29
  * Provides a declarative syntax for defining mocks.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    30
  * Can easily define partial (hybrid) mocks, which are a cross of real
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    31
    and mock objects.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    32
  * Handles functions of arbitrary types and overloaded functions.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    33
  * Comes with a rich set of matchers for validating function arguments.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    34
  * Uses an intuitive syntax for controlling the behavior of a mock.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    35
  * Does automatic verification of expectations (no record-and-replay needed).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    36
  * Allows arbitrary (partial) ordering constraints on
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    37
    function calls to be expressed,.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    38
  * Lets an user extend it by defining new matchers and actions.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    39
  * Does not use exceptions.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    40
  * Is easy to learn and use.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    41
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    42
Please see the project page above for more information as well as the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    43
mailing list for questions, discussions, and development.  There is
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    44
also an IRC channel on OFTC (irc.oftc.net) #gtest available.  Please
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    45
join us!
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    46
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    47
Please note that code under [scripts/generator](scripts/generator/) is
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    48
from [cppclean](http://code.google.com/p/cppclean/) and released under
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    49
the Apache License, which is different from Google Mock's license.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    50
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    51
## Getting Started ##
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    52
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    53
If you are new to the project, we suggest that you read the user
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    54
documentation in the following order:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    55
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    56
  * Learn the [basics](../googletest/docs/primer.md) of
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    57
    Google Test, if you choose to use Google Mock with it (recommended).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    58
  * Read [Google Mock for Dummies](../googlemock/docs/ForDummies.md).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    59
  * Read the instructions below on how to build Google Mock.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    60
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    61
You can also watch Zhanyong's [talk](http://www.youtube.com/watch?v=sYpCyLI47rM) on Google Mock's usage and implementation.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    62
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    63
Once you understand the basics, check out the rest of the docs:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    64
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    65
  * [CheatSheet](../googlemock/docs/CheatSheet.md) - all the commonly used stuff
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    66
    at a glance.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    67
  * [CookBook](../googlemock/docs/CookBook.md) - recipes for getting things done,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    68
    including advanced techniques.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    69
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    70
If you need help, please check the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    71
[KnownIssues](docs/KnownIssues.md) and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    72
[FrequentlyAskedQuestions](docs/FrequentlyAskedQuestions.md) before
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    73
posting a question on the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    74
[discussion group](http://groups.google.com/group/googlemock).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    75
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    76
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    77
### Using Google Mock Without Google Test ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    78
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    79
Google Mock is not a testing framework itself.  Instead, it needs a
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    80
testing framework for writing tests.  Google Mock works seamlessly
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    81
with [Google Test](https://github.com/google/googletest), but
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    82
you can also use it with [any C++ testing framework](../googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    83
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    84
### Requirements for End Users ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    85
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    86
Google Mock is implemented on top of [Google Test](
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    87
http://github.com/google/googletest/), and depends on it.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    88
You must use the bundled version of Google Test when using Google Mock.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    89
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    90
You can also easily configure Google Mock to work with another testing
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    91
framework, although it will still need Google Test.  Please read
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    92
["Using_Google_Mock_with_Any_Testing_Framework"](
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    93
    ../googlemock/docs/ForDummies.md#using-google-mock-with-any-testing-framework)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    94
for instructions.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    95
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    96
Google Mock depends on advanced C++ features and thus requires a more
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    97
modern compiler. The following are needed to use Google Mock:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    98
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    99
#### Linux Requirements ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   100
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   101
  * GNU-compatible Make or "gmake"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   102
  * POSIX-standard shell
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   103
  * POSIX(-2) Regular Expressions (regex.h)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   104
  * C++98-standard-compliant compiler (e.g. GCC 3.4 or newer)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   105
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   106
#### Windows Requirements ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   107
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   108
  * Microsoft Visual C++ 8.0 SP1 or newer
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   109
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   110
#### Mac OS X Requirements ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   111
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   112
  * Mac OS X 10.4 Tiger or newer
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   113
  * Developer Tools Installed
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   114
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   115
### Requirements for Contributors ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   116
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   117
We welcome patches. If you plan to contribute a patch, you need to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   118
build Google Mock and its tests, which has further requirements:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   119
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   120
  * Automake version 1.9 or newer
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   121
  * Autoconf version 2.59 or newer
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   122
  * Libtool / Libtoolize
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   123
  * Python version 2.3 or newer (for running some of the tests and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   124
    re-generating certain source files from templates)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   125
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   126
### Building Google Mock ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   127
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   128
#### Using CMake ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   129
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   130
If you have CMake available, it is recommended that you follow the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   131
[build instructions][gtest_cmakebuild]
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   132
as described for Google Test.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   133
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   134
If are using Google Mock with an
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   135
existing CMake project, the section
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   136
[Incorporating Into An Existing CMake Project][gtest_incorpcmake]
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   137
may be of particular interest.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   138
To make it work for Google Mock you will need to change
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   139
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   140
    target_link_libraries(example gtest_main)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   141
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   142
to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   143
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   144
    target_link_libraries(example gmock_main)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   145
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   146
This works because `gmock_main` library is compiled with Google Test.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   147
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   148
#### Preparing to Build (Unix only) ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   149
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   150
If you are using a Unix system and plan to use the GNU Autotools build
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   151
system to build Google Mock (described below), you'll need to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   152
configure it now.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   153
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   154
To prepare the Autotools build system:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   155
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   156
    cd googlemock
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   157
    autoreconf -fvi
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   158
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   159
To build Google Mock and your tests that use it, you need to tell your
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   160
build system where to find its headers and source files.  The exact
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   161
way to do it depends on which build system you use, and is usually
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   162
straightforward.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   163
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   164
This section shows how you can integrate Google Mock into your
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   165
existing build system.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   166
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   167
Suppose you put Google Mock in directory `${GMOCK_DIR}` and Google Test
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   168
in `${GTEST_DIR}` (the latter is `${GMOCK_DIR}/gtest` by default).  To
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   169
build Google Mock, create a library build target (or a project as
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   170
called by Visual Studio and Xcode) to compile
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   171
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   172
    ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   173
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   174
with
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   175
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   176
    ${GTEST_DIR}/include and ${GMOCK_DIR}/include
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   177
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   178
in the system header search path, and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   179
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   180
    ${GTEST_DIR} and ${GMOCK_DIR}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   181
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   182
in the normal header search path.  Assuming a Linux-like system and gcc,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   183
something like the following will do:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   184
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   185
    g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   186
        -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   187
        -pthread -c ${GTEST_DIR}/src/gtest-all.cc
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   188
    g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   189
        -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   190
        -pthread -c ${GMOCK_DIR}/src/gmock-all.cc
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   191
    ar -rv libgmock.a gtest-all.o gmock-all.o
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   192
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   193
(We need -pthread as Google Test and Google Mock use threads.)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   194
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   195
Next, you should compile your test source file with
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   196
${GTEST\_DIR}/include and ${GMOCK\_DIR}/include in the header search
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   197
path, and link it with gmock and any other necessary libraries:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   198
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   199
    g++ -isystem ${GTEST_DIR}/include -isystem ${GMOCK_DIR}/include \
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   200
        -pthread path/to/your_test.cc libgmock.a -o your_test
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   201
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   202
As an example, the make/ directory contains a Makefile that you can
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   203
use to build Google Mock on systems where GNU make is available
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   204
(e.g. Linux, Mac OS X, and Cygwin).  It doesn't try to build Google
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   205
Mock's own tests.  Instead, it just builds the Google Mock library and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   206
a sample test.  You can use it as a starting point for your own build
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   207
script.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   208
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   209
If the default settings are correct for your environment, the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   210
following commands should succeed:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   211
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   212
    cd ${GMOCK_DIR}/make
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   213
    make
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   214
    ./gmock_test
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   215
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   216
If you see errors, try to tweak the contents of
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   217
[make/Makefile](make/Makefile) to make them go away.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   218
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   219
### Windows ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   220
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   221
The msvc/2005 directory contains VC++ 2005 projects and the msvc/2010
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   222
directory contains VC++ 2010 projects for building Google Mock and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   223
selected tests.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   224
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   225
Change to the appropriate directory and run "msbuild gmock.sln" to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   226
build the library and tests (or open the gmock.sln in the MSVC IDE).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   227
If you want to create your own project to use with Google Mock, you'll
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   228
have to configure it to use the `gmock_config` propety sheet.  For that:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   229
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   230
 * Open the Property Manager window (View | Other Windows | Property Manager)
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   231
 * Right-click on your project and select "Add Existing Property Sheet..."
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   232
 * Navigate to `gmock_config.vsprops` or `gmock_config.props` and select it.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   233
 * In Project Properties | Configuration Properties | General | Additional
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   234
   Include Directories, type <path to Google Mock>/include.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   235
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   236
### Tweaking Google Mock ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   237
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   238
Google Mock can be used in diverse environments.  The default
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   239
configuration may not work (or may not work well) out of the box in
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   240
some environments.  However, you can easily tweak Google Mock by
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   241
defining control macros on the compiler command line.  Generally,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   242
these macros are named like `GTEST_XYZ` and you define them to either 1
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   243
or 0 to enable or disable a certain feature.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   244
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   245
We list the most frequently used macros below.  For a complete list,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   246
see file [${GTEST\_DIR}/include/gtest/internal/gtest-port.h](
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   247
../googletest/include/gtest/internal/gtest-port.h).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   248
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   249
### Choosing a TR1 Tuple Library ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   250
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   251
Google Mock uses the C++ Technical Report 1 (TR1) tuple library
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   252
heavily.  Unfortunately TR1 tuple is not yet widely available with all
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   253
compilers.  The good news is that Google Test 1.4.0+ implements a
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   254
subset of TR1 tuple that's enough for Google Mock's need.  Google Mock
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   255
will automatically use that implementation when the compiler doesn't
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   256
provide TR1 tuple.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   257
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   258
Usually you don't need to care about which tuple library Google Test
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   259
and Google Mock use.  However, if your project already uses TR1 tuple,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   260
you need to tell Google Test and Google Mock to use the same TR1 tuple
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   261
library the rest of your project uses, or the two tuple
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   262
implementations will clash.  To do that, add
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   263
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   264
    -DGTEST_USE_OWN_TR1_TUPLE=0
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   265
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   266
to the compiler flags while compiling Google Test, Google Mock, and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   267
your tests.  If you want to force Google Test and Google Mock to use
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   268
their own tuple library, just add
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   269
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   270
    -DGTEST_USE_OWN_TR1_TUPLE=1
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   271
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   272
to the compiler flags instead.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   273
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   274
If you want to use Boost's TR1 tuple library with Google Mock, please
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   275
refer to the Boost website (http://www.boost.org/) for how to obtain
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   276
it and set it up.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   277
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   278
### As a Shared Library (DLL) ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   279
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   280
Google Mock is compact, so most users can build and link it as a static
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   281
library for the simplicity.  Google Mock can be used as a DLL, but the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   282
same DLL must contain Google Test as well.  See
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   283
[Google Test's README][gtest_readme]
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   284
for instructions on how to set up necessary compiler settings.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   285
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   286
### Tweaking Google Mock ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   287
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   288
Most of Google Test's control macros apply to Google Mock as well.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   289
Please see [Google Test's README][gtest_readme] for how to tweak them.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   290
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   291
### Upgrading from an Earlier Version ###
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   292
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   293
We strive to keep Google Mock releases backward compatible.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   294
Sometimes, though, we have to make some breaking changes for the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   295
users' long-term benefits.  This section describes what you'll need to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   296
do if you are upgrading from an earlier version of Google Mock.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   297
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   298
#### Upgrading from 1.1.0 or Earlier ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   299
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   300
You may need to explicitly enable or disable Google Test's own TR1
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   301
tuple library.  See the instructions in section "[Choosing a TR1 Tuple
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   302
Library](#choosing-a-tr1-tuple-library)".
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   303
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   304
#### Upgrading from 1.4.0 or Earlier ####
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   305
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   306
On platforms where the pthread library is available, Google Test and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   307
Google Mock use it in order to be thread-safe.  For this to work, you
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   308
may need to tweak your compiler and/or linker flags.  Please see the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   309
"[Multi-threaded Tests](../googletest/README.md#multi-threaded-tests)" section in file Google Test's README for what you may need to do.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   310
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   311
If you have custom matchers defined using `MatcherInterface` or
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   312
`MakePolymorphicMatcher()`, you'll need to update their definitions to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   313
use the new matcher API (
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   314
[monomorphic](./docs/CookBook.md#writing-new-monomorphic-matchers),
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   315
[polymorphic](./docs/CookBook.md#writing-new-polymorphic-matchers)).
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   316
Matchers defined using `MATCHER()` or `MATCHER_P*()` aren't affected.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   317
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   318
Happy testing!
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   319
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   320
[gtest_readme]: ../googletest/README.md "googletest"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   321
[gtest_cmakebuild]:  ../googletest/README.md#using-cmake "Using CMake"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   322
[gtest_incorpcmake]: ../googletest/README.md#incorporating-into-an-existing-cmake-project "Incorporating Into An Existing CMake Project"