| 1 |
|
| 2 |
/* |
| 3 |
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions are met: |
| 8 |
* * Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* * Redistributions in binary form must reproduce the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer in the |
| 12 |
* documentation and/or other materials provided with the distribution. |
| 13 |
* * Neither the name of the <organization> nor the |
| 14 |
* names of its contributors may be used to endorse or promote products |
| 15 |
* derived from this software without specific prior written permission. |
| 16 |
* |
| 17 |
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY |
| 18 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 |
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
| 21 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "CppUTest/TestHarness.h" |
| 30 |
#include "MockFailureReporterForTest.h" |
| 31 |
|
| 32 |
TEST_GROUP(MockParameterTest) |
| 33 |
{ |
| 34 |
void teardown() |
| 35 |
{ |
| 36 |
mock().checkExpectations(); |
| 37 |
mock().clear(); |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
TEST(MockParameterTest, expectOneBooleanParameterAndValue) |
| 42 |
{ |
| 43 |
mock().expectOneCall("foo").withParameter("parameter", true); |
| 44 |
mock().actualCall("foo").withParameter("parameter", true); |
| 45 |
|
| 46 |
mock().checkExpectations(); |
| 47 |
} |
| 48 |
|
| 49 |
TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndValue) |
| 50 |
{ |
| 51 |
unsigned int value = 14400; |
| 52 |
mock().expectOneCall("foo").withParameter("parameter", value); |
| 53 |
mock().actualCall("foo").withParameter("parameter", value); |
| 54 |
|
| 55 |
mock().checkExpectations(); |
| 56 |
} |
| 57 |
|
| 58 |
TEST(MockParameterTest, expectOneIntegerParameterAndValue) |
| 59 |
{ |
| 60 |
mock().expectOneCall("foo").withParameter("parameter", 10); |
| 61 |
mock().actualCall("foo").withParameter("parameter", 10); |
| 62 |
|
| 63 |
mock().checkExpectations(); |
| 64 |
} |
| 65 |
|
| 66 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 67 |
|
| 68 |
TEST(MockParameterTest, expectOneUnsignedLongLongIntegerParameterAndValue) |
| 69 |
{ |
| 70 |
unsigned long long value = 0xFFFFAAAAFFFFAAAA; |
| 71 |
mock().expectOneCall("foo").withParameter("parameter", value); |
| 72 |
mock().actualCall("foo").withParameter("parameter", value); |
| 73 |
|
| 74 |
mock().checkExpectations(); |
| 75 |
} |
| 76 |
|
| 77 |
TEST(MockParameterTest, expectOneLongLongIntegerParameterAndValue) |
| 78 |
{ |
| 79 |
long long value = 0x7FFFAAAAFFFFAAAA; |
| 80 |
|
| 81 |
mock().expectOneCall("foo").withParameter("parameter", value); |
| 82 |
mock().actualCall("foo").withParameter("parameter", value); |
| 83 |
|
| 84 |
mock().checkExpectations(); |
| 85 |
} |
| 86 |
|
| 87 |
#endif |
| 88 |
|
| 89 |
TEST(MockParameterTest, mismatchedIntegerTypesIntAndLongAreAllowed) |
| 90 |
{ |
| 91 |
mock().expectOneCall("foo").withParameter("parameter", (int)1); |
| 92 |
mock().actualCall("foo").withParameter("parameter", (long)1); |
| 93 |
|
| 94 |
mock().expectOneCall("foo").withParameter("parameter", (long)1); |
| 95 |
mock().actualCall("foo").withParameter("parameter", (int)1); |
| 96 |
|
| 97 |
mock().checkExpectations(); |
| 98 |
} |
| 99 |
|
| 100 |
TEST(MockParameterTest, mismatchedIntegerTypesIntAndUnsignedAreAllowed) |
| 101 |
{ |
| 102 |
mock().expectOneCall("foo").withParameter("parameter", (int)1); |
| 103 |
mock().actualCall("foo").withParameter("parameter", (unsigned)1); |
| 104 |
|
| 105 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned)1); |
| 106 |
mock().actualCall("foo").withParameter("parameter", (int)1); |
| 107 |
|
| 108 |
mock().checkExpectations(); |
| 109 |
} |
| 110 |
|
| 111 |
TEST(MockParameterTest, mismatchedIntegerTypesIntAndUnsignedLongAreAllowed) |
| 112 |
{ |
| 113 |
mock().expectOneCall("foo").withParameter("parameter", (int)1); |
| 114 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)1); |
| 115 |
|
| 116 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)1); |
| 117 |
mock().actualCall("foo").withParameter("parameter", (int)1); |
| 118 |
|
| 119 |
mock().checkExpectations(); |
| 120 |
} |
| 121 |
|
| 122 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedAndLongAreAllowed) |
| 123 |
{ |
| 124 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned)1); |
| 125 |
mock().actualCall("foo").withParameter("parameter", (long)1); |
| 126 |
|
| 127 |
mock().expectOneCall("foo").withParameter("parameter", (long)1); |
| 128 |
mock().actualCall("foo").withParameter("parameter", (unsigned)1); |
| 129 |
|
| 130 |
mock().checkExpectations(); |
| 131 |
} |
| 132 |
|
| 133 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedAndUnsignedLongAreAllowed) |
| 134 |
{ |
| 135 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned)1); |
| 136 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)1); |
| 137 |
|
| 138 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)1); |
| 139 |
mock().actualCall("foo").withParameter("parameter", (unsigned)1); |
| 140 |
|
| 141 |
mock().checkExpectations(); |
| 142 |
} |
| 143 |
|
| 144 |
TEST(MockParameterTest, mismatchedIntegerTypesLongAndUnsignedLongAreAllowed) |
| 145 |
{ |
| 146 |
mock().expectOneCall("foo").withParameter("parameter", (long)1); |
| 147 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)1); |
| 148 |
|
| 149 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)1); |
| 150 |
mock().actualCall("foo").withParameter("parameter", (long)1); |
| 151 |
|
| 152 |
mock().checkExpectations(); |
| 153 |
} |
| 154 |
|
| 155 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 156 |
|
| 157 |
TEST(MockParameterTest, mismatchedIntegerTypesIntAndLongLongAreAllowed) |
| 158 |
{ |
| 159 |
mock().expectOneCall("foo").withParameter("parameter", (int)1); |
| 160 |
mock().actualCall("foo").withParameter("parameter", (long long)1); |
| 161 |
|
| 162 |
mock().expectOneCall("foo").withParameter("parameter", (long long)1); |
| 163 |
mock().actualCall("foo").withParameter("parameter", (int)1); |
| 164 |
|
| 165 |
mock().checkExpectations(); |
| 166 |
} |
| 167 |
|
| 168 |
TEST(MockParameterTest, mismatchedIntegerTypesIntAndUnsignedLongLongAreAllowed) |
| 169 |
{ |
| 170 |
mock().expectOneCall("foo").withParameter("parameter", (int)1); |
| 171 |
mock().actualCall("foo").withParameter("parameter", (unsigned long long)1); |
| 172 |
|
| 173 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long long)1); |
| 174 |
mock().actualCall("foo").withParameter("parameter", (int)1); |
| 175 |
|
| 176 |
mock().checkExpectations(); |
| 177 |
} |
| 178 |
|
| 179 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedAndLongLongAreAllowed) |
| 180 |
{ |
| 181 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned)1); |
| 182 |
mock().actualCall("foo").withParameter("parameter", (long long)1); |
| 183 |
|
| 184 |
mock().expectOneCall("foo").withParameter("parameter", (long long)1); |
| 185 |
mock().actualCall("foo").withParameter("parameter", (unsigned)1); |
| 186 |
|
| 187 |
mock().checkExpectations(); |
| 188 |
} |
| 189 |
|
| 190 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedAndUnsignedLongLongAreAllowed) |
| 191 |
{ |
| 192 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned)1); |
| 193 |
mock().actualCall("foo").withParameter("parameter", (unsigned long long)1); |
| 194 |
|
| 195 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long long)1); |
| 196 |
mock().actualCall("foo").withParameter("parameter", (unsigned)1); |
| 197 |
|
| 198 |
mock().checkExpectations(); |
| 199 |
} |
| 200 |
|
| 201 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedLongAndUnsignedLongLongAreAllowed) |
| 202 |
{ |
| 203 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)1); |
| 204 |
mock().actualCall("foo").withParameter("parameter", (unsigned long long)1); |
| 205 |
|
| 206 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long long)1); |
| 207 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)1); |
| 208 |
|
| 209 |
mock().checkExpectations(); |
| 210 |
} |
| 211 |
|
| 212 |
TEST(MockParameterTest, mismatchedIntegerTypesLongAndLongLongAreAllowed) |
| 213 |
{ |
| 214 |
mock().expectOneCall("foo").withParameter("parameter", (long)1); |
| 215 |
mock().actualCall("foo").withParameter("parameter", (long long)1); |
| 216 |
|
| 217 |
mock().expectOneCall("foo").withParameter("parameter", (long long)1); |
| 218 |
mock().actualCall("foo").withParameter("parameter", (long)1); |
| 219 |
|
| 220 |
mock().checkExpectations(); |
| 221 |
} |
| 222 |
|
| 223 |
TEST(MockParameterTest, mismatchedIntegerTypesLongAndUnsignedLongLongAreAllowed) |
| 224 |
{ |
| 225 |
mock().expectOneCall("foo").withParameter("parameter", (long)1); |
| 226 |
mock().actualCall("foo").withParameter("parameter", (unsigned long long)1); |
| 227 |
|
| 228 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long long)1); |
| 229 |
mock().actualCall("foo").withParameter("parameter", (long)1); |
| 230 |
|
| 231 |
mock().checkExpectations(); |
| 232 |
} |
| 233 |
|
| 234 |
TEST(MockParameterTest, mismatchedIntegerTypesUnsignedLongAndLongLongAreAllowed) |
| 235 |
{ |
| 236 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)1); |
| 237 |
mock().actualCall("foo").withParameter("parameter", (long long)1); |
| 238 |
|
| 239 |
mock().expectOneCall("foo").withParameter("parameter", (long long)1); |
| 240 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)1); |
| 241 |
|
| 242 |
mock().checkExpectations(); |
| 243 |
} |
| 244 |
|
| 245 |
TEST(MockParameterTest, mismatchedIntegerTypesLongLongAndUnsignedLongLongAreAllowed) |
| 246 |
{ |
| 247 |
mock().expectOneCall("foo").withParameter("parameter", (long long)1); |
| 248 |
mock().actualCall("foo").withParameter("parameter", (unsigned long long)1); |
| 249 |
|
| 250 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long long)1); |
| 251 |
mock().actualCall("foo").withParameter("parameter", (long long)1); |
| 252 |
|
| 253 |
mock().checkExpectations(); |
| 254 |
} |
| 255 |
|
| 256 |
#endif |
| 257 |
|
| 258 |
TEST(MockParameterTest, longAndUnsignedLongWithSameBitRepresentationShouldNotBeTreatedAsEqual) |
| 259 |
{ |
| 260 |
MockFailureReporterInstaller failureReporterInstaller; |
| 261 |
|
| 262 |
MockExpectedCallsListForTest expectations; |
| 263 |
expectations.addFunction("foo")->withParameter("parameter", (long)-1); |
| 264 |
MockNamedValue parameter("parameter"); |
| 265 |
parameter.setValue((unsigned long)-1); |
| 266 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 267 |
|
| 268 |
mock().expectOneCall("foo").withParameter("parameter", (long)-1); |
| 269 |
mock().actualCall("foo").withParameter("parameter", (unsigned long)-1); |
| 270 |
|
| 271 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 272 |
} |
| 273 |
|
| 274 |
TEST(MockParameterTest, unsignedLongAndLongWithSameBitRepresentationShouldnotBeTreatedAsEqual) |
| 275 |
{ |
| 276 |
MockFailureReporterInstaller failureReporterInstaller; |
| 277 |
|
| 278 |
MockExpectedCallsListForTest expectations; |
| 279 |
expectations.addFunction("foo")->withParameter("parameter", (unsigned long)-1); |
| 280 |
MockNamedValue parameter("parameter"); |
| 281 |
parameter.setValue((long)-1); |
| 282 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 283 |
|
| 284 |
mock().expectOneCall("foo").withParameter("parameter", (unsigned long)-1); |
| 285 |
mock().actualCall("foo").withParameter("parameter", (long)-1); |
| 286 |
|
| 287 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 288 |
} |
| 289 |
|
| 290 |
TEST(MockParameterTest, expectOneDoubleParameterAndValue) |
| 291 |
{ |
| 292 |
mock().expectOneCall("foo").withParameter("parameter", 1.0); |
| 293 |
mock().actualCall("foo").withParameter("parameter", 1.0); |
| 294 |
|
| 295 |
mock().checkExpectations(); |
| 296 |
} |
| 297 |
|
| 298 |
TEST(MockParameterTest, expectOneDoubleParameterAndValueAndTolerance) |
| 299 |
{ |
| 300 |
mock( ).expectOneCall("foo").withParameter("parameter", 100.0, 5.0); |
| 301 |
mock( ).actualCall("foo").withParameter("parameter", 96.0); |
| 302 |
|
| 303 |
mock( ).checkExpectations(); |
| 304 |
} |
| 305 |
|
| 306 |
TEST(MockParameterTest, doubleParameterNotEqualIfOutsideTolerance) |
| 307 |
{ |
| 308 |
MockFailureReporterInstaller failureReporterInstaller; |
| 309 |
|
| 310 |
MockExpectedCallsListForTest expectations; |
| 311 |
expectations.addFunction("foo")->withParameter("parameter", 100.0); |
| 312 |
MockNamedValue parameter("parameter"); |
| 313 |
parameter.setValue(106.0); |
| 314 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 315 |
|
| 316 |
mock( ).expectOneCall("foo").withParameter("parameter", 100.0, 5.0); |
| 317 |
mock( ).actualCall("foo").withParameter("parameter", 106.0); |
| 318 |
|
| 319 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
TEST(MockParameterTest, expectOneStringParameterAndValue) |
| 324 |
{ |
| 325 |
mock().expectOneCall("foo").withParameter("parameter", "string"); |
| 326 |
mock().actualCall("foo").withParameter("parameter", "string"); |
| 327 |
|
| 328 |
mock().checkExpectations(); |
| 329 |
} |
| 330 |
|
| 331 |
TEST(MockParameterTest, expectOnePointerParameterAndValue) |
| 332 |
{ |
| 333 |
mock().expectOneCall("foo").withParameter("parameter", (void*) 0x01); |
| 334 |
mock().actualCall("foo").withParameter("parameter", (void*) 0x01); |
| 335 |
|
| 336 |
mock().checkExpectations(); |
| 337 |
} |
| 338 |
|
| 339 |
TEST(MockParameterTest, expectOneConstPointerParameterAndValue) |
| 340 |
{ |
| 341 |
mock().expectOneCall("foo").withParameter("parameter", (const void*) 0x01); |
| 342 |
mock().actualCall("foo").withParameter("parameter", (const void*) 0x01); |
| 343 |
|
| 344 |
mock().checkExpectations(); |
| 345 |
} |
| 346 |
|
| 347 |
TEST(MockParameterTest, expectOneFunctionPointerParameterAndValue) |
| 348 |
{ |
| 349 |
mock().expectOneCall("foo").withParameter("parameter", (void(*)()) 0x01); |
| 350 |
mock().actualCall("foo").withParameter("parameter", (void(*)()) 0x01); |
| 351 |
|
| 352 |
mock().checkExpectations(); |
| 353 |
} |
| 354 |
|
| 355 |
TEST(MockParameterTest, expectOneMemBufferParameterAndValue) |
| 356 |
{ |
| 357 |
unsigned char memBuffer1[] = { 0x12, 0x15, 0xFF }; |
| 358 |
unsigned char memBuffer2[] = { 0x12, 0x15, 0xFF }; |
| 359 |
mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1)); |
| 360 |
mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2)); |
| 361 |
|
| 362 |
mock().checkExpectations(); |
| 363 |
} |
| 364 |
|
| 365 |
TEST(MockParameterTest, expectOneMemBufferParameterAndValueFailsDueToContents) |
| 366 |
{ |
| 367 |
MockFailureReporterInstaller failureReporterInstaller; |
| 368 |
|
| 369 |
unsigned char memBuffer1[] = { 0x12, 0x15, 0xFF }; |
| 370 |
unsigned char memBuffer2[] = { 0x12, 0x05, 0xFF }; |
| 371 |
MockExpectedCallsListForTest expectations; |
| 372 |
expectations.addFunction("foo")->withParameter("parameter", memBuffer1, sizeof(memBuffer1)); |
| 373 |
MockNamedValue parameter("parameter"); |
| 374 |
parameter.setMemoryBuffer( memBuffer2, sizeof(memBuffer2) ); |
| 375 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 376 |
|
| 377 |
mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1)); |
| 378 |
mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2)); |
| 379 |
|
| 380 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 381 |
} |
| 382 |
|
| 383 |
TEST(MockParameterTest, expectOneMemBufferParameterAndValueFailsDueToSize) |
| 384 |
{ |
| 385 |
MockFailureReporterInstaller failureReporterInstaller; |
| 386 |
|
| 387 |
unsigned char memBuffer1[] = { 0x12, 0x15, 0xFF }; |
| 388 |
unsigned char memBuffer2[] = { 0x12, 0x15, 0xFF, 0x90 }; |
| 389 |
|
| 390 |
MockExpectedCallsListForTest expectations; |
| 391 |
expectations.addFunction("foo")->withParameter("parameter", memBuffer1, sizeof(memBuffer1)); |
| 392 |
MockNamedValue parameter("parameter"); |
| 393 |
parameter.setMemoryBuffer( memBuffer2, sizeof(memBuffer2) ); |
| 394 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 395 |
|
| 396 |
mock().expectOneCall("foo").withParameter("parameter", memBuffer1, sizeof(memBuffer1)); |
| 397 |
mock().actualCall("foo").withParameter("parameter", memBuffer2, sizeof(memBuffer2)); |
| 398 |
|
| 399 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 400 |
} |
| 401 |
|
| 402 |
TEST(MockParameterTest, expectOneStringParameterAndValueFails) |
| 403 |
{ |
| 404 |
MockFailureReporterInstaller failureReporterInstaller; |
| 405 |
|
| 406 |
MockExpectedCallsListForTest expectations; |
| 407 |
expectations.addFunction("foo")->withParameter("parameter", "string"); |
| 408 |
MockNamedValue parameter("parameter"); |
| 409 |
parameter.setValue("different"); |
| 410 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 411 |
|
| 412 |
mock().expectOneCall("foo").withParameter("parameter", "string"); |
| 413 |
mock().actualCall("foo").withParameter("parameter", "different"); |
| 414 |
|
| 415 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 416 |
} |
| 417 |
|
| 418 |
TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndFailsDueToParameterName) |
| 419 |
{ |
| 420 |
MockFailureReporterInstaller failureReporterInstaller; |
| 421 |
|
| 422 |
unsigned int value = 7; |
| 423 |
MockExpectedCallsListForTest expectations; |
| 424 |
expectations.addFunction("foo")->withParameter("parameter", value); |
| 425 |
MockNamedValue parameter("different"); |
| 426 |
parameter.setValue(value); |
| 427 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 428 |
|
| 429 |
mock().expectOneCall("foo").withParameter("parameter", value); |
| 430 |
mock().actualCall("foo").withParameter("different", value); |
| 431 |
|
| 432 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 433 |
} |
| 434 |
|
| 435 |
TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToParameterName) |
| 436 |
{ |
| 437 |
MockFailureReporterInstaller failureReporterInstaller; |
| 438 |
|
| 439 |
MockExpectedCallsListForTest expectations; |
| 440 |
expectations.addFunction("foo")->withParameter("parameter", 10); |
| 441 |
MockNamedValue parameter("different"); |
| 442 |
parameter.setValue(10); |
| 443 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 444 |
|
| 445 |
mock().expectOneCall("foo").withParameter("parameter", 10); |
| 446 |
mock().actualCall("foo").withParameter("different", 10); |
| 447 |
|
| 448 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 449 |
} |
| 450 |
|
| 451 |
TEST(MockParameterTest, expectOneUnsignedIntegerParameterAndFailsDueToValue) |
| 452 |
{ |
| 453 |
MockFailureReporterInstaller failureReporterInstaller; |
| 454 |
|
| 455 |
unsigned int actual_value = 8; |
| 456 |
unsigned int expected_value = actual_value + 1; |
| 457 |
MockExpectedCallsListForTest expectations; |
| 458 |
expectations.addFunction("foo")->withParameter("parameter", expected_value); |
| 459 |
MockNamedValue parameter("parameter"); |
| 460 |
parameter.setValue(actual_value); |
| 461 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 462 |
|
| 463 |
mock().expectOneCall("foo").withParameter("parameter", expected_value); |
| 464 |
mock().actualCall("foo").withParameter("parameter", actual_value); |
| 465 |
|
| 466 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 467 |
} |
| 468 |
|
| 469 |
TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToValue) |
| 470 |
{ |
| 471 |
MockFailureReporterInstaller failureReporterInstaller; |
| 472 |
|
| 473 |
MockExpectedCallsListForTest expectations; |
| 474 |
expectations.addFunction("foo")->withParameter("parameter", 10); |
| 475 |
MockNamedValue parameter("parameter"); |
| 476 |
parameter.setValue(8); |
| 477 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 478 |
|
| 479 |
mock().expectOneCall("foo").withParameter("parameter", 10); |
| 480 |
mock().actualCall("foo").withParameter("parameter", 8); |
| 481 |
|
| 482 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 483 |
} |
| 484 |
|
| 485 |
TEST(MockParameterTest, expectOneIntegerParameterAndFailsDueToTypes) |
| 486 |
{ |
| 487 |
MockFailureReporterInstaller failureReporterInstaller; |
| 488 |
|
| 489 |
MockExpectedCallsListForTest expectations; |
| 490 |
expectations.addFunction("foo")->withParameter("parameter", 10); |
| 491 |
MockNamedValue parameter("parameter"); |
| 492 |
parameter.setValue("heh"); |
| 493 |
MockUnexpectedInputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 494 |
|
| 495 |
mock().expectOneCall("foo").withParameter("parameter", 10); |
| 496 |
mock().actualCall("foo").withParameter("parameter", "heh"); |
| 497 |
|
| 498 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 499 |
} |
| 500 |
|
| 501 |
TEST(MockParameterTest, expectMultipleCallsWithDifferentParametersThatHappenOutOfOrder) |
| 502 |
{ |
| 503 |
mock().expectOneCall("foo").withParameter("p1", 1); |
| 504 |
mock().expectOneCall("foo").withParameter("p1", 2); |
| 505 |
mock().actualCall("foo").withParameter("p1", 2); |
| 506 |
mock().actualCall("foo").withParameter("p1", 1); |
| 507 |
|
| 508 |
mock().checkExpectations(); |
| 509 |
} |
| 510 |
|
| 511 |
TEST(MockParameterTest, expectMultipleCallsWithMultipleDifferentParametersThatHappenOutOfOrder) |
| 512 |
{ |
| 513 |
mock().expectOneCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 514 |
mock().expectOneCall("foo").withParameter("p1", 1).withParameter("p2", 20); |
| 515 |
|
| 516 |
mock().actualCall("foo").withParameter("p1", 1).withParameter("p2", 20); |
| 517 |
mock().actualCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 518 |
|
| 519 |
mock().checkExpectations(); |
| 520 |
} |
| 521 |
|
| 522 |
TEST(MockParameterTest, twiceCalledWithSameParameters) |
| 523 |
{ |
| 524 |
mock().expectOneCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 525 |
mock().expectOneCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 526 |
mock().actualCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 527 |
mock().actualCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 528 |
|
| 529 |
mock().checkExpectations(); |
| 530 |
} |
| 531 |
|
| 532 |
TEST(MockParameterTest, calledWithoutParameters) |
| 533 |
{ |
| 534 |
MockFailureReporterInstaller failureReporterInstaller; |
| 535 |
|
| 536 |
MockExpectedCallsListForTest expectations; |
| 537 |
expectations.addFunction("foo")->withParameter("p1", 1); |
| 538 |
MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations); |
| 539 |
|
| 540 |
mock().expectOneCall("foo").withParameter("p1", 1); |
| 541 |
mock().actualCall("foo"); |
| 542 |
|
| 543 |
mock().checkExpectations(); |
| 544 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 545 |
} |
| 546 |
|
| 547 |
TEST(MockParameterTest, ignoreOtherParameters) |
| 548 |
{ |
| 549 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters(); |
| 550 |
mock().actualCall("foo").withParameter("p1", 1).withParameter("p2", 2); |
| 551 |
|
| 552 |
mock().checkExpectations(); |
| 553 |
} |
| 554 |
|
| 555 |
TEST(MockParameterTest, ignoreOtherParametersButStillPassAll) |
| 556 |
{ |
| 557 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters(); |
| 558 |
mock().actualCall("foo").withParameter("p1", 1); |
| 559 |
|
| 560 |
mock().checkExpectations(); |
| 561 |
} |
| 562 |
|
| 563 |
TEST(MockParameterTest, ignoreOtherParametersButExpectedParameterDidntHappen) |
| 564 |
{ |
| 565 |
MockFailureReporterInstaller failureReporterInstaller; |
| 566 |
|
| 567 |
MockExpectedCallsListForTest expectations; |
| 568 |
expectations.addFunction("foo")->withParameter("p1", 1).ignoreOtherParameters(); |
| 569 |
MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations); |
| 570 |
|
| 571 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters(); |
| 572 |
mock().actualCall("foo").withParameter("p2", 2).withParameter("p3", 3).withParameter("p4", 4); |
| 573 |
|
| 574 |
mock().checkExpectations(); |
| 575 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 576 |
} |
| 577 |
|
| 578 |
TEST(MockParameterTest, ignoreOtherParametersMultipleCalls) |
| 579 |
{ |
| 580 |
mock().expectOneCall("foo").ignoreOtherParameters(); |
| 581 |
mock().expectOneCall("foo").ignoreOtherParameters(); |
| 582 |
mock().actualCall("foo").withParameter("p2", 2).withParameter("p3", 3).withParameter("p4", 4); |
| 583 |
LONGS_EQUAL(1, mock().expectedCallsLeft()); |
| 584 |
mock().actualCall("foo").withParameter("p2", 2).withParameter("p3", 3).withParameter("p4", 4); |
| 585 |
|
| 586 |
mock().checkExpectations(); |
| 587 |
} |
| 588 |
|
| 589 |
TEST(MockParameterTest, ignoreOtherParametersMultipleCallsButOneDidntHappen) |
| 590 |
{ |
| 591 |
MockFailureReporterInstaller failureReporterInstaller; |
| 592 |
|
| 593 |
MockExpectedCallsListForTest expectations; |
| 594 |
MockCheckedExpectedCall* call = expectations.addFunction("boo"); |
| 595 |
call->ignoreOtherParameters(); |
| 596 |
call->callWasMade(1); |
| 597 |
call->finalizeActualCallMatch(); |
| 598 |
call->ignoreOtherParameters(); |
| 599 |
expectations.addFunction("boo")->ignoreOtherParameters(); |
| 600 |
MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations); |
| 601 |
|
| 602 |
mock().expectOneCall("boo").ignoreOtherParameters(); |
| 603 |
mock().expectOneCall("boo").ignoreOtherParameters(); |
| 604 |
mock().actualCall("boo"); |
| 605 |
|
| 606 |
mock().checkExpectations(); |
| 607 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 608 |
} |
| 609 |
|
| 610 |
TEST(MockParameterTest, newCallStartsWhileNotAllParametersWerePassed) |
| 611 |
{ |
| 612 |
MockFailureReporterInstaller failureReporterInstaller; |
| 613 |
|
| 614 |
MockExpectedCallsListForTest expectations; |
| 615 |
expectations.addFunction("foo")->withParameter("p1", 1); |
| 616 |
MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations); |
| 617 |
|
| 618 |
mock().expectOneCall("foo").withParameter("p1", 1); |
| 619 |
mock().actualCall("foo"); |
| 620 |
mock().actualCall("foo").withParameter("p1", 1); |
| 621 |
|
| 622 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 623 |
} |
| 624 |
|
| 625 |
TEST(MockParameterTest, outputParameterSucceeds) |
| 626 |
{ |
| 627 |
int param = 1; |
| 628 |
int retval = 2; |
| 629 |
|
| 630 |
mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval, sizeof(retval)); |
| 631 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m); |
| 632 |
|
| 633 |
CHECK_EQUAL(param, 2); |
| 634 |
CHECK_EQUAL(retval, 2); |
| 635 |
mock().checkExpectations(); |
| 636 |
} |
| 637 |
|
| 638 |
TEST(MockParameterTest, unmodifiedOutputParameterSucceeds) |
| 639 |
{ |
| 640 |
int param = 1; |
| 641 |
|
| 642 |
mock().expectOneCall("function").withUnmodifiedOutputParameter("parameterName"); |
| 643 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m); |
| 644 |
|
| 645 |
CHECK_EQUAL(param, 1); |
| 646 |
mock().checkExpectations(); |
| 647 |
} |
| 648 |
|
| 649 |
TEST(MockParameterTest, noActualCallForOutputParameter) |
| 650 |
{ |
| 651 |
MockFailureReporterInstaller failureReporterInstaller; |
| 652 |
|
| 653 |
int output; |
| 654 |
MockExpectedCallsListForTest expectations; |
| 655 |
mock().expectOneCall("foo").withOutputParameterReturning("output", &output, sizeof(output)); |
| 656 |
|
| 657 |
expectations.addFunction("foo")->withOutputParameterReturning("output", &output, sizeof(output)); |
| 658 |
MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations); |
| 659 |
|
| 660 |
mock().checkExpectations(); |
| 661 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 662 |
} |
| 663 |
|
| 664 |
TEST(MockParameterTest, noActualCallForUnmodifiedOutputParameter) |
| 665 |
{ |
| 666 |
MockFailureReporterInstaller failureReporterInstaller; |
| 667 |
|
| 668 |
MockExpectedCallsListForTest expectations; |
| 669 |
mock().expectOneCall("foo").withUnmodifiedOutputParameter("output"); |
| 670 |
|
| 671 |
expectations.addFunction("foo")->withUnmodifiedOutputParameter("output"); |
| 672 |
MockExpectedCallsDidntHappenFailure expectedFailure(mockFailureTest(), expectations); |
| 673 |
|
| 674 |
mock().checkExpectations(); |
| 675 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 676 |
} |
| 677 |
|
| 678 |
TEST(MockParameterTest, unexpectedOutputParameter) |
| 679 |
{ |
| 680 |
MockFailureReporterInstaller failureReporterInstaller; |
| 681 |
|
| 682 |
int param; |
| 683 |
MockExpectedCallsListForTest expectations; |
| 684 |
mock().expectOneCall("foo"); |
| 685 |
mock().actualCall("foo").withOutputParameter("parameterName", ¶m); |
| 686 |
|
| 687 |
expectations.addFunction("foo"); |
| 688 |
MockNamedValue parameter("parameterName"); |
| 689 |
parameter.setValue(¶m); |
| 690 |
MockUnexpectedOutputParameterFailure expectedFailure(mockFailureTest(), "foo", parameter, expectations); |
| 691 |
|
| 692 |
mock().checkExpectations(); |
| 693 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 694 |
} |
| 695 |
|
| 696 |
TEST(MockParameterTest, outputParameterMissing) |
| 697 |
{ |
| 698 |
MockFailureReporterInstaller failureReporterInstaller; |
| 699 |
|
| 700 |
int output; |
| 701 |
MockExpectedCallsListForTest expectations; |
| 702 |
mock().expectOneCall("foo").withOutputParameterReturning("output", &output, sizeof(output)); |
| 703 |
mock().actualCall("foo"); |
| 704 |
|
| 705 |
expectations.addFunction("foo")->withOutputParameterReturning("output", &output, sizeof(output)); |
| 706 |
MockExpectedParameterDidntHappenFailure expectedFailure(mockFailureTest(), "foo", expectations); |
| 707 |
|
| 708 |
mock().checkExpectations(); |
| 709 |
CHECK_EXPECTED_MOCK_FAILURE(expectedFailure); |
| 710 |
} |
| 711 |
|
| 712 |
TEST(MockParameterTest, twoOutputParameters) |
| 713 |
{ |
| 714 |
int param1 = 55; |
| 715 |
int retval1 = 1; |
| 716 |
int param2 = 77; |
| 717 |
int retval2 = 2; |
| 718 |
|
| 719 |
mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval1, sizeof(retval1)).withParameter("id", 1); |
| 720 |
mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval2, sizeof(retval2)).withParameter("id", 2); |
| 721 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m1).withParameter("id", 1); |
| 722 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m2).withParameter("id", 2); |
| 723 |
|
| 724 |
CHECK_EQUAL(retval1, param1); |
| 725 |
CHECK_EQUAL(retval2, param2); |
| 726 |
mock().checkExpectations(); |
| 727 |
} |
| 728 |
|
| 729 |
TEST(MockParameterTest, twoInterleavedOutputParameters) |
| 730 |
{ |
| 731 |
int param1 = 55; |
| 732 |
int retval1 = 1; |
| 733 |
int param2 = 77; |
| 734 |
int retval2 = 2; |
| 735 |
|
| 736 |
mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval1, sizeof(retval1)).withParameter("id", 1); |
| 737 |
mock().expectOneCall("function").withOutputParameterReturning("parameterName", &retval2, sizeof(retval2)).withParameter("id", 2); |
| 738 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m2).withParameter("id", 2); |
| 739 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m1).withParameter("id", 1); |
| 740 |
|
| 741 |
CHECK_EQUAL(retval1, param1); |
| 742 |
CHECK_EQUAL(retval2, param2); |
| 743 |
mock().checkExpectations(); |
| 744 |
} |
| 745 |
|
| 746 |
TEST(MockParameterTest, twoDifferentOutputParametersInSameFunctionCallSucceeds) |
| 747 |
{ |
| 748 |
int param1 = 1; |
| 749 |
int param2 = 1; |
| 750 |
int retval1 = 2; |
| 751 |
int retval2 = 3; |
| 752 |
|
| 753 |
mock().expectOneCall("foo") |
| 754 |
.withOutputParameterReturning("bar", &retval1, sizeof(retval1)) |
| 755 |
.withOutputParameterReturning("foobar", &retval2, sizeof(retval2)); |
| 756 |
mock().actualCall("foo") |
| 757 |
.withOutputParameter("bar", ¶m1) |
| 758 |
.withOutputParameter("foobar", ¶m2); |
| 759 |
|
| 760 |
CHECK_EQUAL(2, retval1); |
| 761 |
CHECK_EQUAL(2, param1); |
| 762 |
CHECK_EQUAL(3, retval2); |
| 763 |
CHECK_EQUAL(3, param2); |
| 764 |
mock().checkExpectations(); |
| 765 |
} |
| 766 |
|
| 767 |
TEST(MockParameterTest, outputAndIntParametersOfSameNameInDifferentFunctionCallsOfSameFunctionSucceeds) |
| 768 |
{ |
| 769 |
int param = 1; |
| 770 |
int retval = 2; |
| 771 |
|
| 772 |
mock().expectOneCall("foo").withOutputParameterReturning("bar", &retval, sizeof(retval)); |
| 773 |
mock().expectOneCall("foo").withIntParameter("bar", 25); |
| 774 |
mock().actualCall("foo").withOutputParameter("bar", ¶m); |
| 775 |
mock().actualCall("foo").withIntParameter("bar", 25); |
| 776 |
|
| 777 |
CHECK_EQUAL(2, retval); |
| 778 |
CHECK_EQUAL(2, param); |
| 779 |
mock().checkExpectations(); |
| 780 |
} |
| 781 |
|
| 782 |
TEST(MockParameterTest, twoOutputParameterOfSameNameInDifferentFunctionCallsOfSameFunctionSucceeds) |
| 783 |
{ |
| 784 |
int param1 = 1; |
| 785 |
int param2 = 1; |
| 786 |
int retval1 = 2; |
| 787 |
int retval2 = 3; |
| 788 |
|
| 789 |
mock().expectOneCall("foo").withOutputParameterReturning("bar", &retval1, sizeof(retval1)); |
| 790 |
mock().expectOneCall("foo").withOutputParameterReturning("bar", &retval2, sizeof(retval2)); |
| 791 |
mock().actualCall("foo").withOutputParameter("bar", ¶m1); |
| 792 |
mock().actualCall("foo").withOutputParameter("bar", ¶m2); |
| 793 |
|
| 794 |
CHECK_EQUAL(2, retval1); |
| 795 |
CHECK_EQUAL(2, param1); |
| 796 |
CHECK_EQUAL(3, retval2); |
| 797 |
CHECK_EQUAL(3, param2); |
| 798 |
mock().checkExpectations(); |
| 799 |
} |
| 800 |
|
| 801 |
TEST(MockParameterTest, twoOutputParametersOfSameNameInDifferentFunctionsSucceeds) |
| 802 |
{ |
| 803 |
int param = 1; |
| 804 |
int retval = 2; |
| 805 |
|
| 806 |
mock().expectOneCall("foo1").withOutputParameterReturning("bar", &retval, sizeof(retval)); |
| 807 |
mock().expectOneCall("foo2").withIntParameter("bar", 25); |
| 808 |
mock().actualCall("foo1").withOutputParameter("bar", ¶m); |
| 809 |
mock().actualCall("foo2").withIntParameter("bar", 25); |
| 810 |
|
| 811 |
CHECK_EQUAL(2, retval); |
| 812 |
CHECK_EQUAL(2, param); |
| 813 |
mock().checkExpectations(); |
| 814 |
} |
| 815 |
|
| 816 |
TEST(MockParameterTest, outputAndInputParameter) |
| 817 |
{ |
| 818 |
int return_value = 5; |
| 819 |
int returned_value = 7; |
| 820 |
|
| 821 |
mock().expectOneCall("foo").withParameter("bar", 10).withOutputParameterReturning("bar", &return_value, sizeof(return_value)); |
| 822 |
mock().actualCall("foo").withParameter("bar", 10).withOutputParameter("bar", &returned_value); |
| 823 |
|
| 824 |
LONGS_EQUAL(5, returned_value); |
| 825 |
mock().checkExpectations(); |
| 826 |
} |
| 827 |
|
| 828 |
TEST(MockParameterTest, outputParameterTraced) |
| 829 |
{ |
| 830 |
mock().tracing(true); |
| 831 |
|
| 832 |
int param = 1; |
| 833 |
mock().actualCall("someFunc").withOutputParameter("someParameter", ¶m); |
| 834 |
mock().checkExpectations(); |
| 835 |
STRCMP_CONTAINS("Function name:someFunc someParameter:", mock().getTraceOutput()); |
| 836 |
|
| 837 |
mock().checkExpectations(); |
| 838 |
} |
| 839 |
|
| 840 |
TEST(MockParameterTest, outputParameterThatIsIgnoredShouldNotFail) |
| 841 |
{ |
| 842 |
int param; |
| 843 |
mock().expectOneCall("function").ignoreOtherParameters(); |
| 844 |
mock().actualCall("function").withOutputParameter("parameterName", ¶m); |
| 845 |
|
| 846 |
mock().checkExpectations(); |
| 847 |
} |
| 848 |
|
| 849 |
TEST(MockParameterTest, outputParameterWithIgnoredParameters) |
| 850 |
{ |
| 851 |
int param = 1; |
| 852 |
int retval = 2; |
| 853 |
|
| 854 |
mock().expectOneCall("foo").withOutputParameterReturning("bar", ¶m, sizeof(param)).ignoreOtherParameters(); |
| 855 |
mock().actualCall("foo").withOutputParameter("bar", &retval).withParameter("other", 1); |
| 856 |
|
| 857 |
LONGS_EQUAL(param, retval); |
| 858 |
|
| 859 |
mock().checkExpectations(); |
| 860 |
} |
| 861 |
|
| 862 |
/* |
| 863 |
* This test checks that the proper output parameters are copied when multiple calls to the same |
| 864 |
* function are expected. |
| 865 |
*/ |
| 866 |
TEST(MockParameterTest, properOutputParametersAreCopied) |
| 867 |
{ |
| 868 |
int expectedValue1 = 1; |
| 869 |
int expectedValue2 = 2; |
| 870 |
mock().expectOneCall("foo").withOutputParameterReturning("param", &expectedValue1, sizeof(expectedValue1)).ignoreOtherParameters(); |
| 871 |
mock().expectOneCall("foo").withOutputParameterReturning("param", &expectedValue2, sizeof(expectedValue2)); |
| 872 |
|
| 873 |
int returnedValue1 = 0; |
| 874 |
int returnedValue2 = 0; |
| 875 |
mock().actualCall("foo").withOutputParameter("param", &returnedValue1); |
| 876 |
mock().actualCall("foo").withOutputParameter("param", &returnedValue2).withParameter("optional", 50); |
| 877 |
|
| 878 |
CHECK_EQUAL_TEXT(expectedValue2, returnedValue1, "Wrong output value in 1st call"); |
| 879 |
CHECK_EQUAL_TEXT(expectedValue1, returnedValue2, "Wrong output value in 2nd call"); |
| 880 |
|
| 881 |
mock().checkExpectations(); |
| 882 |
} |
| 883 |
|
| 884 |
TEST(MockParameterTest, ignoreOtherCallsIgnoresWithAllKindsOfParameters) |
| 885 |
{ |
| 886 |
mock().ignoreOtherCalls(); |
| 887 |
mock().actualCall("boo") |
| 888 |
.withParameter("umm", true) |
| 889 |
.withParameter("bar", 1u) |
| 890 |
.withParameter("foo", 1l) |
| 891 |
.withParameter("hey", 1ul) |
| 892 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 893 |
.withParameter("ick", 1ll) |
| 894 |
.withParameter("grr", 1ull) |
| 895 |
#endif |
| 896 |
.withParameter("duh", 1.0) |
| 897 |
.withParameter("yoo", (const void*) NULLPTR) |
| 898 |
.withParameter("func", (void(*)()) NULLPTR) |
| 899 |
.withParameter("mem", (const unsigned char*) NULLPTR, 0) |
| 900 |
.withParameterOfType("hoo", "int", (const void*) NULLPTR) |
| 901 |
.withOutputParameter("gah", (void*) NULLPTR) |
| 902 |
.withOutputParameterOfType("goo", "int", (void*) NULLPTR); |
| 903 |
|
| 904 |
mock().checkExpectations(); |
| 905 |
} |
| 906 |
|
| 907 |
TEST(MockParameterTest, expectMultipleCallsWithParameters) |
| 908 |
{ |
| 909 |
int expected_int = -7; |
| 910 |
unsigned int expected_uint = 7; |
| 911 |
|
| 912 |
mock().expectNCalls(2, "boo").withParameter("double", 1.0).withParameter("int", expected_int). |
| 913 |
withParameter("string", "string").withParameter("uint", expected_uint); |
| 914 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", expected_int).withParameter("string", "string"). |
| 915 |
withParameter("uint", expected_uint); |
| 916 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", expected_int).withParameter("string", "string"). |
| 917 |
withParameter("uint", expected_uint); |
| 918 |
|
| 919 |
mock().checkExpectations(); |
| 920 |
} |
| 921 |
|
| 922 |
TEST(MockParameterTest, expectMultipleMultipleCallsWithParameters) |
| 923 |
{ |
| 924 |
mock().expectNCalls(2, "boo").withParameter("double", 1.0).ignoreOtherParameters(); |
| 925 |
mock().expectNCalls(2, "boo").withParameter("double", 1.0).ignoreOtherParameters(); |
| 926 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", 1).withParameter("string", "string"); |
| 927 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", 1).withParameter("string", "string"); |
| 928 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", 1).withParameter("string", "string"); |
| 929 |
mock().actualCall("boo").withParameter("double", 1.0).withParameter("int", 1).withParameter("string", "string"); |
| 930 |
|
| 931 |
mock().checkExpectations(); |
| 932 |
} |
| 933 |
|