OLD | NEW |
1 Google C++ Mocking Framework | 1 Google C++ Mocking Framework |
2 ============================ | 2 ============================ |
| 3 |
3 http://code.google.com/p/googlemock/ | 4 http://code.google.com/p/googlemock/ |
4 | 5 |
5 Overview | 6 Overview |
6 -------- | 7 -------- |
7 Google's framework for writing and using C++ mock classes on Linux, | 8 |
8 Mac OS X, and Windows. Inspired by jMock, EasyMock, and Hamcrest, and | 9 Google's framework for writing and using C++ mock classes on a variety |
9 designed with C++'s specifics in mind, it can help you derive better | 10 of platforms (Linux, Mac OS X, Windows, Windows CE, Symbian, etc). |
10 designs of your system and write better tests. | 11 Inspired by jMock, EasyMock, and Hamcrest, and designed with C++'s |
| 12 specifics in mind, it can help you derive better designs of your |
| 13 system and write better tests. |
11 | 14 |
12 Google Mock: | 15 Google Mock: |
13 | 16 |
14 - provides a declarative syntax for defining mocks, | 17 - provides a declarative syntax for defining mocks, |
15 - can easily define partial (hybrid) mocks, which are a cross of real | 18 - can easily define partial (hybrid) mocks, which are a cross of real |
16 and mock objects, | 19 and mock objects, |
17 - handles functions of arbitrary types and overloaded functions, | 20 - handles functions of arbitrary types and overloaded functions, |
18 - comes with a rich set of matchers for validating function arguments, | 21 - comes with a rich set of matchers for validating function arguments, |
19 - uses an intuitive syntax for controlling the behavior of a mock, | 22 - uses an intuitive syntax for controlling the behavior of a mock, |
20 - does automatic verification of expectations (no record-and-replay | 23 - does automatic verification of expectations (no record-and-replay |
21 needed), | 24 needed), |
22 - allows arbitrary (partial) ordering constraints on | 25 - allows arbitrary (partial) ordering constraints on |
23 function calls to be expressed, | 26 function calls to be expressed, |
24 - lets a user extend it by defining new matchers and actions. | 27 - lets a user extend it by defining new matchers and actions. |
25 - does not use exceptions, and | 28 - does not use exceptions, and |
26 - is easy to learn and use. | 29 - is easy to learn and use. |
27 | 30 |
28 Please see the project page above for more information as well as mailing lists | 31 Please see the project page above for more information as well as the |
29 for questions, discussions, and development. There is also an IRC channel on | 32 mailing list for questions, discussions, and development. There is |
30 OFTC (irc.oftc.net) #gtest available. Please join us! | 33 also an IRC channel on OFTC (irc.oftc.net) #gtest available. Please |
| 34 join us! |
31 | 35 |
32 Please note that code under scripts/generator/ is from the cppclean | 36 Please note that code under scripts/generator/ is from the cppclean |
33 project (http://code.google.com/p/cppclean/) and under the Apache | 37 project (http://code.google.com/p/cppclean/) and under the Apache |
34 License, which is different from Google Mock's license. | 38 License, which is different from Google Mock's license. |
35 | 39 |
36 Requirements | 40 Requirements for End Users |
37 ------------ | 41 -------------------------- |
38 Google Mock is not a testing framework itself. Instead, it needs a | 42 |
39 testing framework for writing tests. It works with Google Test | 43 Google Mock is implemented on top of the Google Test C++ testing |
40 (http://code.google.com/p/googletest/) out of the box. You can use | 44 framework (http://code.google.com/p/googletest/), and includes the |
41 either the copy of Google Test that comes with Google Mock, or a | 45 latter as part of the SVN repositary and distribution package. You |
42 compatible version you already have. This version of Google Mock | 46 must use the bundled version of Google Test when using Google Mock, or |
43 requires Google Test 1.4.0. | 47 you may get compiler/linker errors. |
44 | 48 |
45 You can also easily configure Google Mock to work with another testing | 49 You can also easily configure Google Mock to work with another testing |
46 framework of your choice; although it will still need Google Test as | 50 framework of your choice; although it will still need Google Test as |
47 an internal dependency. Please read | 51 an internal dependency. Please read |
48 http://code.google.com/p/googlemock/wiki/ForDummies#Using_Google_Mock_with_Any_T
esting_Framework | 52 http://code.google.com/p/googlemock/wiki/ForDummies#Using_Google_Mock_with_Any_T
esting_Framework |
49 for how to do it. | 53 for how to do it. |
50 | 54 |
51 Google Mock depends on advanced C++ features and thus requires a more | 55 Google Mock depends on advanced C++ features and thus requires a more |
52 modern compiler. The following are needed to use Google Mock: | 56 modern compiler. The following are needed to use Google Mock: |
53 | 57 |
54 ### Linux Requirements ### | 58 ### Linux Requirements ### |
| 59 |
55 These are the base requirements to build and use Google Mock from a source | 60 These are the base requirements to build and use Google Mock from a source |
56 package (as described below): | 61 package (as described below): |
| 62 |
57 * GNU-compatible Make or "gmake" | 63 * GNU-compatible Make or "gmake" |
58 * POSIX-standard shell | 64 * POSIX-standard shell |
59 * POSIX(-2) Regular Expressions (regex.h) | 65 * POSIX(-2) Regular Expressions (regex.h) |
60 * gcc 3.4 or newer. | 66 * C++98-standard-compliant compiler (e.g. GCC 3.4 or newer) |
61 | 67 |
62 Furthermore, if you are building Google Mock from a VCS Checkout (also | 68 ### Windows Requirements ### |
63 described below), there are further requirements: | 69 |
| 70 * Microsoft Visual C++ 8.0 SP1 or newer |
| 71 |
| 72 ### Mac OS X Requirements ### |
| 73 |
| 74 * Mac OS X 10.4 Tiger or newer |
| 75 * Developer Tools Installed |
| 76 |
| 77 Requirements for Contributors |
| 78 ----------------------------- |
| 79 |
| 80 We welcome patches. If you plan to contribute a patch, you need to |
| 81 build Google Mock and its own tests from an SVN checkout (described |
| 82 below), which has further requirements: |
| 83 |
64 * Automake version 1.9 or newer | 84 * Automake version 1.9 or newer |
65 * Autoconf version 2.59 or newer | 85 * Autoconf version 2.59 or newer |
66 * Libtool / Libtoolize | 86 * Libtool / Libtoolize |
67 * Python version 2.3 or newer | 87 * Python version 2.3 or newer (for running some of the tests and |
68 | 88 re-generating certain source files from templates) |
69 ### Windows Requirements ### | |
70 * Microsoft Visual C++ 8.0 SP1 or newer | |
71 | |
72 ### Mac OS X Requirements ### | |
73 * Mac OS X 10.4 Tiger or newer | |
74 * Developer Tools Installed | |
75 | 89 |
76 Getting the Source | 90 Getting the Source |
77 ------------------ | 91 ------------------ |
78 There are two primary ways of getting Google Mock's source code: you can | |
79 download a source release in your preferred archive format, or directly check | |
80 out the source from a Version Control System (VCS, we use Google Code's | |
81 Subversion hosting). The VCS checkout requires a few extra steps and some extra | |
82 software packages on your system, but lets you track development, and make | |
83 patches to contribute much more easily, so we highly encourage it. | |
84 | 92 |
85 ### VCS Checkout: ### | 93 There are two primary ways of getting Google Mock's source code: you |
86 The first step is to select whether you want to check out the main line of | 94 can download a stable source release in your preferred archive format, |
87 development on Google Mock, or one of the released branches. The former will be | 95 or directly check out the source from our Subversion (SVN) repositary. |
88 much more active and have the latest features, but the latter provides much | 96 The SVN checkout requires a few extra steps and some extra software |
89 more stability and predictability. Choose whichever fits your needs best, and | 97 packages on your system, but lets you track development and make |
90 proceed with the following Subversion commands: | 98 patches much more easily, so we highly encourage it. |
| 99 |
| 100 ### Source Package ### |
| 101 |
| 102 Google Mock is released in versioned source packages which can be |
| 103 downloaded from the download page [1]. Several different archive |
| 104 formats are provided, but the only difference is the tools needed to |
| 105 extract their contents, and the size of the resulting file. Download |
| 106 whichever you are most comfortable with. |
| 107 |
| 108 [1] http://code.google.com/p/googlemock/downloads/list |
| 109 |
| 110 Once downloaded expand the archive using whichever tools you prefer |
| 111 for that type. This will always result in a new directory with the |
| 112 name "gmock-X.Y.Z" which contains all of the source code. Here are |
| 113 some examples on Linux: |
| 114 |
| 115 tar -xvzf gmock-X.Y.Z.tar.gz |
| 116 tar -xvjf gmock-X.Y.Z.tar.bz2 |
| 117 unzip gmock-X.Y.Z.zip |
| 118 |
| 119 ### SVN Checkout ### |
| 120 |
| 121 To check out the main branch (also known as the "trunk") of Google |
| 122 Mock, run the following Subversion command: |
91 | 123 |
92 svn checkout http://googlemock.googlecode.com/svn/trunk/ gmock-svn | 124 svn checkout http://googlemock.googlecode.com/svn/trunk/ gmock-svn |
93 | 125 |
94 or for a release version X.Y.*'s branch: | 126 If you are using a *nix system and plan to use the GNU Autotools build |
| 127 system to build Google Mock (described below), you'll need to |
| 128 configure it now. Otherwise you are done with getting the source |
| 129 files. |
95 | 130 |
96 svn checkout http://googlemock.googlecode.com/svn/branches/release-X.Y/ \ | 131 To prepare the Autotools build system, enter the target directory of |
97 gmock-X.Y-svn | 132 the checkout command you used ('gmock-svn') and proceed with the |
98 | 133 following command: |
99 Next you will need to prepare the GNU Autotools build system, if you | |
100 are using Linux or Mac OS X. Enter the target directory of the | |
101 checkout command you used ('gmock-svn' or 'gmock-X.Y-svn' above) and | |
102 proceed with the following command: | |
103 | 134 |
104 autoreconf -fvi | 135 autoreconf -fvi |
105 | 136 |
106 Once you have completed this step, you are ready to build the library. Note | 137 Once you have completed this step, you are ready to build the library. |
107 that you should only need to complete this step once. The subsequent `make' | 138 Note that you should only need to complete this step once. The |
108 invocations will automatically re-generate the bits of the build system that | 139 subsequent 'make' invocations will automatically re-generate the bits |
109 need to be changed. | 140 of the build system that need to be changed. |
110 | 141 |
111 If your system uses older versions of the autotools, the above command will | 142 If your system uses older versions of the autotools, the above command |
112 fail. You may need to explicitly specify a version to use. For instance, if you | 143 will fail. You may need to explicitly specify a version to use. For |
113 have both GNU Automake 1.4 and 1.9 installed and `automake' would invoke the | 144 instance, if you have both GNU Automake 1.4 and 1.9 installed and |
114 1.4, use instead: | 145 'automake' would invoke the 1.4, use instead: |
115 | 146 |
116 AUTOMAKE=automake-1.9 ACLOCAL=aclocal-1.9 autoreconf -fvi | 147 AUTOMAKE=automake-1.9 ACLOCAL=aclocal-1.9 autoreconf -fvi |
117 | 148 |
118 Make sure you're using the same version of automake and aclocal. | 149 Make sure you're using the same version of automake and aclocal. |
119 | 150 |
120 ### Source Package: ### | 151 Setting up the Build |
121 Google Mock is also released in source packages which can be downloaded from | 152 -------------------- |
122 its Google Code download page[1]. Several different archive formats are | |
123 provided, but the only difference is the tools needed to extract their | |
124 contents, and the size of the resulting file. Download whichever you are most | |
125 comfortable with. | |
126 | 153 |
127 [1] Google Mock Downloads: http://code.google.com/p/googlemock/downloads/list | 154 To build Google Mock and your tests that use it, you need to tell your |
| 155 build system where to find its headers and source files. The exact |
| 156 way to do it depends on which build system you use, and is usually |
| 157 straightforward. |
128 | 158 |
129 Once downloaded expand the archive using whichever tools you prefer for that | 159 ### Generic Build Instructions ### |
130 type. This will always result in a new directory with the name "gmock-X.Y.Z" | |
131 which contains all of the source code. Here are some examples in Linux: | |
132 | 160 |
133 tar -xvzf gmock-X.Y.Z.tar.gz | 161 This section shows how you can integrate Google Mock into your |
134 tar -xvjf gmock-X.Y.Z.tar.bz2 | 162 existing build system. |
135 unzip gmock-X.Y.Z.zip | |
136 | 163 |
137 Choosing a TR1 Tuple Library | 164 Suppose you put Google Mock in directory ${GMOCK_DIR} and Google Test |
138 ---------------------------- | 165 in ${GTEST_DIR} (the latter is ${GMOCK_DIR}/gtest by default). To |
| 166 build Google Mock, create a library build target (or a project as |
| 167 called by Visual Studio and Xcode) to compile |
| 168 |
| 169 ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc |
| 170 |
| 171 with |
| 172 |
| 173 ${GTEST_DIR}/include, ${GTEST_DIR}, ${GMOCK_DIR}/include, and ${GMOCK_DIR} |
| 174 |
| 175 in the header search path. Assuming a Linux-like system and gcc, |
| 176 something like the following will do: |
| 177 |
| 178 g++ -I${GTEST_DIR}/include -I${GTEST_DIR} -I${GMOCK_DIR}/include \ |
| 179 -I${GMOCK_DIR} -c ${GTEST_DIR}/src/gtest-all.cc |
| 180 g++ -I${GTEST_DIR}/include -I${GTEST_DIR} -I${GMOCK_DIR}/include \ |
| 181 -I${GMOCK_DIR} -c ${GMOCK_DIR}/src/gmock-all.cc |
| 182 ar -rv libgmock.a gtest-all.o gmock-all.o |
| 183 |
| 184 Next, you should compile your test source file with |
| 185 ${GTEST_DIR}/include and ${GMOCK_DIR}/include in the header search |
| 186 path, and link it with gmock and any other necessary libraries: |
| 187 |
| 188 g++ -I${GTEST_DIR}/include -I${GMOCK_DIR}/include \ |
| 189 path/to/your_test.cc libgmock.a -o your_test |
| 190 |
| 191 As an example, the make/ directory contains a Makefile that you can |
| 192 use to build Google Mock on systems where GNU make is available |
| 193 (e.g. Linux, Mac OS X, and Cygwin). It doesn't try to build Google |
| 194 Mock's own tests. Instead, it just builds the Google Mock library and |
| 195 a sample test. You can use it as a starting point for your own build |
| 196 script. |
| 197 |
| 198 If the default settings are correct for your environment, the |
| 199 following commands should succeed: |
| 200 |
| 201 cd ${GMOCK_DIR}/make |
| 202 make |
| 203 ./gmock_test |
| 204 |
| 205 If you see errors, try to tweak the contents of make/Makefile to make |
| 206 them go away. There are instructions in make/Makefile on how to do |
| 207 it. |
| 208 |
| 209 ### Windows ### |
| 210 |
| 211 The msvc/ directory contains VC++ 2005 projects for building Google |
| 212 Mock and selected tests. |
| 213 |
| 214 Open msvc/gmock.sln and build the library and tests. If you want to |
| 215 create your own project to use with Google Mock, you'll have to |
| 216 configure it to use the gmock_config propety sheet. For that: |
| 217 |
| 218 * Open the Property Manager window (View | Other Windows | Property Manager) |
| 219 * Right-click on your project and select "Add Existing Property Sheet..." |
| 220 * Navigate to gmock_config.vsprops and select it. |
| 221 * In Project Properties | Configuration Properties | General | Additional |
| 222 Include Directories, type <path to Google Mock>/include. |
| 223 |
| 224 Tweaking Google Mock |
| 225 -------------------- |
| 226 |
| 227 Google Mock can be used in diverse environments. The default |
| 228 configuration may not work (or may not work well) out of the box in |
| 229 some environments. However, you can easily tweak Google Mock by |
| 230 defining control macros on the compiler command line. Generally, |
| 231 these macros are named like GTEST_XYZ and you define them to either 1 |
| 232 or 0 to enable or disable a certain feature. |
| 233 |
| 234 We list the most frequently used macros below. For a complete list, |
| 235 see file ${GTEST_DIR}/include/gtest/internal/gtest-port.h. |
| 236 |
| 237 ### Choosing a TR1 Tuple Library ### |
| 238 |
139 Google Mock uses the C++ Technical Report 1 (TR1) tuple library | 239 Google Mock uses the C++ Technical Report 1 (TR1) tuple library |
140 heavily. Unfortunately TR1 tuple is not yet widely available with all | 240 heavily. Unfortunately TR1 tuple is not yet widely available with all |
141 compilers. The good news is that Google Test 1.4.0+ implements a | 241 compilers. The good news is that Google Test 1.4.0+ implements a |
142 subset of TR1 tuple that's enough for Google Mock's need. Google Mock | 242 subset of TR1 tuple that's enough for Google Mock's need. Google Mock |
143 will automatically use that implementation when the compiler doesn't | 243 will automatically use that implementation when the compiler doesn't |
144 provide TR1 tuple. | 244 provide TR1 tuple. |
145 | 245 |
146 Usually you don't need to care about which tuple library Google Test | 246 Usually you don't need to care about which tuple library Google Test |
147 and Google Mock use. However, if your project already uses TR1 tuple, | 247 and Google Mock use. However, if your project already uses TR1 tuple, |
148 you need to tell Google Test and Google Mock to use the same TR1 tuple | 248 you need to tell Google Test and Google Mock to use the same TR1 tuple |
149 library the rest of your project uses (this requirement is new in | 249 library the rest of your project uses, or the two tuple |
150 Google Test 1.4.0 and Google Mock 1.2.0, so you may need to take care | |
151 of it when upgrading from an earlier version), or the two tuple | |
152 implementations will clash. To do that, add | 250 implementations will clash. To do that, add |
153 | 251 |
154 -DGTEST_USE_OWN_TR1_TUPLE=0 | 252 -DGTEST_USE_OWN_TR1_TUPLE=0 |
155 | 253 |
156 to the compiler flags while compiling Google Test, Google Mock, and | 254 to the compiler flags while compiling Google Test, Google Mock, and |
157 your tests. | 255 your tests. If you want to force Google Test and Google Mock to use |
| 256 their own tuple library, just add |
| 257 |
| 258 -DGTEST_USE_OWN_TR1_TUPLE=1 |
| 259 |
| 260 to the compiler flags instead. |
158 | 261 |
159 If you want to use Boost's TR1 tuple library with Google Mock, please | 262 If you want to use Boost's TR1 tuple library with Google Mock, please |
160 refer to the Boost website (http://www.boost.org/) for how to obtain | 263 refer to the Boost website (http://www.boost.org/) for how to obtain |
161 it and set it up. | 264 it and set it up. |
162 | 265 |
163 Building the Source | 266 ### Tweaking Google Test ### |
164 ------------------- | |
165 ### Linux and Mac OS X (without Xcode) ### | |
166 There are two primary options for building the source at this point: build it | |
167 inside the source code tree, or in a separate directory. We recommend building | |
168 in a separate directory as that tends to produce both more consistent results | |
169 and be easier to clean up should anything go wrong, but both patterns are | |
170 supported. The only hard restriction is that while the build directory can be | |
171 a subdirectory of the source directory, the opposite is not possible and will | |
172 result in errors. Once you have selected where you wish to build Google Mock, | |
173 create the directory if necessary, and enter it. The following steps apply for | |
174 either approach by simply substituting the shell variable SRCDIR with "." for | |
175 building inside the source directory, and the relative path to the source | |
176 directory otherwise. | |
177 | 267 |
178 ${SRCDIR}/configure # Standard GNU configure script, --help for more info | 268 Most of Google Test's control macros apply to Google Mock as well. |
| 269 Please see file ${GTEST_DIR}/README for how to tweak them. |
179 | 270 |
180 Once you have successfully configured Google Mock, the build steps are standard | 271 Upgrading from an Earlier Version |
181 for GNU-style OSS packages. | 272 --------------------------------- |
182 | 273 |
183 make # Standard makefile following GNU conventions | 274 We strive to keep Google Mock releases backward compatible. |
184 make check # Builds and runs all tests - all should pass | 275 Sometimes, though, we have to make some breaking changes for the |
| 276 users' long-term benefits. This section describes what you'll need to |
| 277 do if you are upgrading from an earlier version of Google Mock. |
| 278 |
| 279 ### Upgrading from 1.1.0 or Earlier ### |
| 280 |
| 281 You may need to explicitly enable or disable Google Test's own TR1 |
| 282 tuple library. See the instructions in section "Choosing a TR1 Tuple |
| 283 Library". |
| 284 |
| 285 ### Upgrading from 1.4.0 or Earlier ### |
| 286 |
| 287 On platforms where the pthread library is available, Google Test and |
| 288 Google Mock use it in order to be thread-safe. For this to work, you |
| 289 may need to tweak your compiler and/or linker flags. Please see the |
| 290 "Multi-threaded Tests" section in file ${GTEST_DIR}/README for what |
| 291 you may need to do. |
| 292 |
| 293 If you have custom matchers defined using MatcherInterface or |
| 294 MakePolymorphicMatcher(), you'll need to update their definitions to |
| 295 use the new matcher API [2]. Matchers defined using MATCHER() or |
| 296 MATCHER_P*() aren't affected. |
| 297 |
| 298 [2] http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Monomorphic_
Matchers, |
| 299 http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Polymorphic_
Matchers |
| 300 |
| 301 Developing Google Mock |
| 302 ---------------------- |
| 303 |
| 304 This section discusses how to make your own changes to Google Mock. |
| 305 |
| 306 ### Testing Google Mock Itself ### |
| 307 |
| 308 To make sure your changes work as intended and don't break existing |
| 309 functionality, you'll want to compile and run Google Test's own tests. |
| 310 For that you'll need Autotools. First, make sure you have followed |
| 311 the instructions in section "SVN Checkout" to configure Google Mock. |
| 312 Then, create a build output directory and enter it. Next, |
| 313 |
| 314 ${GMOCK_DIR}/configure # Standard GNU configure script, --help for more info |
| 315 |
| 316 Once you have successfully configured Google Mock, the build steps are |
| 317 standard for GNU-style OSS packages. |
| 318 |
| 319 make # Standard makefile following GNU conventions |
| 320 make check # Builds and runs all tests - all should pass. |
185 | 321 |
186 Note that when building your project against Google Mock, you are building | 322 Note that when building your project against Google Mock, you are building |
187 against Google Test as well. There is no need to configure Google Test | 323 against Google Test as well. There is no need to configure Google Test |
188 separately. | 324 separately. |
189 | 325 |
190 ### Windows ### | 326 ### Regenerating Source Files ### |
191 The msvc/ directory contains VC++ 2005 projects for building Google | |
192 Mock and selected tests. | |
193 | 327 |
194 If you want to use a version of Google Test other then the one bundled with | |
195 Google Mock, change the value of the GTestDir macro in gmock_config.vsprop | |
196 to point to the new location. | |
197 | |
198 Open msvc/gmock.sln and build the library and tests. If you want to | |
199 create your own project to use with Google Mock, you'll have to | |
200 configure it to use the gmock_config propety sheet. For that: | |
201 * Open the Property Manager window (View | Other Windows | Property Manager) | |
202 * Right-click on your project and select "Add Existing Property Sheet..." | |
203 * Navigate to gmock_config.vsprops and select it. | |
204 * In Project Properties | Configuration Properties | General | Additional | |
205 Include Directories, type <path to Google Mock>/include. | |
206 | |
207 TODO(wan@google.com): update the .vsprops and .vcproj files such that the | |
208 last step is unnecessary. | |
209 | |
210 ### Using GNU Make ### | |
211 The make/ directory contains a Makefile that you can use to build | |
212 Google Mock on systems where GNU make is available (e.g. Linux and Mac | |
213 OS X). It doesn't try to build Google Mock's own tests. Instead, it | |
214 just builds the Google Mock libraries and some sample tests. You can | |
215 use it as a starting point for your own Makefile. | |
216 | |
217 If the default settings are correct for your environment, the | |
218 following commands should succeed: | |
219 | |
220 cd ${SRCDIR}/make | |
221 make | |
222 ./gmock_test | |
223 | |
224 If you see errors, try to tweak the contents of make/Makefile to make | |
225 them go away. There are instructions in make/Makefile on how to do | |
226 it. | |
227 | |
228 ### Using Your Own Build System ### | |
229 If none of the build solutions we provide works for you, or if you | |
230 prefer your own build system, you just need to compile | |
231 ${GTEST_SRCDIR}/src/gtest-all.cc (where GTEST_SRCDIR is the root of | |
232 the Google Test source tree) and src/gmock-all.cc into a library and | |
233 link your tests with it. Assuming a Linux-like system and gcc, | |
234 something like the following will do: | |
235 | |
236 cd ${SRCDIR} | |
237 g++ -I. -I./include -I${GTEST_SRCDIR} -I${GTEST_SRCDIR}/include \ | |
238 -c {GTEST_SRCDIR}/src/gtest-all.cc | |
239 g++ -I. -I./include -I${GTEST_SRCDIR} -I${GTEST_SRCDIR}/include \ | |
240 -c src/gmock-all.cc | |
241 ar -rv libgmock.a gtest-all.o gmock-all.o | |
242 g++ -I. -I./include -I${GTEST_SRCDIR} -I${GTEST_SRCDIR}/include \ | |
243 path/to/your_test.cc libgmock.a -o your_test | |
244 | |
245 Regenerating Source Files | |
246 ------------------------- | |
247 Some of Google Mock's source files are generated from templates (not | 328 Some of Google Mock's source files are generated from templates (not |
248 in the C++ sense) using a script. A template file is named FOO.pump, | 329 in the C++ sense) using a script. A template file is named FOO.pump, |
249 where FOO is the name of the file it will generate. For example, the | 330 where FOO is the name of the file it will generate. For example, the |
250 file include/gmock/gmock-generated-actions.h.pump is used to generate | 331 file include/gmock/gmock-generated-actions.h.pump is used to generate |
251 gmock-generated-actions.h in the same directory. | 332 gmock-generated-actions.h in the same directory. |
252 | 333 |
253 Normally you don't need to worry about regenerating the source files, | 334 Normally you don't need to worry about regenerating the source files, |
254 unless you need to modify them (e.g. if you are working on a patch for | 335 unless you need to modify them. In that case, you should modify the |
255 Google Mock). In that case, you should modify the corresponding .pump | 336 corresponding .pump files instead and run the 'pump' script (for Pump |
256 files instead and run the 'pump' script (for Pump is Useful for Meta | 337 is Useful for Meta Programming) to regenerate them. You can find |
257 Programming) to regenerate them. We are still working on releasing | 338 pump.py in the ${GTEST_DIR}/scripts/ directory. Read the Pump manual |
258 the script and its documentation. If you need it now, please email | 339 [3] for how to use it. |
259 googlemock@googlegroups.com such that we know to make it happen | 340 |
260 sooner. | 341 [3] http://code.google.com/p/googletest/wiki/PumpManual. |
| 342 |
| 343 ### Contributing a Patch ### |
| 344 |
| 345 We welcome patches. Please read the Google Mock developer's guide [4] |
| 346 for how you can contribute. In particular, make sure you have signed |
| 347 the Contributor License Agreement, or we won't be able to accept the |
| 348 patch. |
| 349 |
| 350 [4] http://code.google.com/p/googlemock/wiki/DevGuide |
261 | 351 |
262 Happy testing! | 352 Happy testing! |
OLD | NEW |