| 1 |
/* |
| 2 |
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions are met: |
| 7 |
* * Redistributions of source code must retain the above copyright |
| 8 |
* notice, this list of conditions and the following disclaimer. |
| 9 |
* * Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* * Neither the name of the <organization> nor the |
| 13 |
* names of its contributors may be used to endorse or promote products |
| 14 |
* derived from this software without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY |
| 17 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
| 20 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "CppUTest/TestHarness.h" |
| 29 |
#include "MockFailureReporterForTest.h" |
| 30 |
|
| 31 |
TEST_GROUP(MockReturnValueTest) |
| 32 |
{ |
| 33 |
void teardown() |
| 34 |
{ |
| 35 |
mock().checkExpectations(); |
| 36 |
mock().clear(); |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
TEST(MockReturnValueTest, hasReturnValue) |
| 41 |
{ |
| 42 |
CHECK(!mock().hasReturnValue()); |
| 43 |
mock().expectOneCall("foo"); |
| 44 |
CHECK(!mock().actualCall("foo").hasReturnValue()); |
| 45 |
CHECK(!mock().hasReturnValue()); |
| 46 |
|
| 47 |
mock().expectOneCall("foo2").andReturnValue(1); |
| 48 |
CHECK(mock().actualCall("foo2").hasReturnValue()); |
| 49 |
CHECK(mock().hasReturnValue()); |
| 50 |
} |
| 51 |
|
| 52 |
TEST(MockReturnValueTest, UnsignedIntegerReturnValue) |
| 53 |
{ |
| 54 |
unsigned int expected_value = 7; |
| 55 |
|
| 56 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 57 |
|
| 58 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 59 |
|
| 60 |
LONGS_EQUAL(expected_value, actual_call.returnValue().getUnsignedIntValue()); |
| 61 |
LONGS_EQUAL(expected_value, actual_call.returnUnsignedIntValue()); |
| 62 |
|
| 63 |
LONGS_EQUAL(expected_value, mock().returnValue().getUnsignedIntValue()); |
| 64 |
LONGS_EQUAL(expected_value, mock().unsignedIntReturnValue()); |
| 65 |
} |
| 66 |
|
| 67 |
TEST(MockReturnValueTest, PositiveIntReturnValueCanBeRetrievedAsUnsignedInt) |
| 68 |
{ |
| 69 |
int expected_value = 7; |
| 70 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 71 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedIntValue()); |
| 72 |
} |
| 73 |
|
| 74 |
TEST(MockReturnValueTest, IntReturnValueCanBeRetrievedAsLongInt) |
| 75 |
{ |
| 76 |
int expected_value = 7; |
| 77 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 78 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongIntValue()); |
| 79 |
} |
| 80 |
|
| 81 |
TEST(MockReturnValueTest, UnsignedIntReturnValueCanBeRetrievedAsLongInt) |
| 82 |
{ |
| 83 |
unsigned int expected_value = 7; |
| 84 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 85 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongIntValue()); |
| 86 |
} |
| 87 |
|
| 88 |
TEST(MockReturnValueTest, PositiveIntReturnValueCanBeRetrievedAsUnsignedLongInt) |
| 89 |
{ |
| 90 |
int expected_value = 7; |
| 91 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 92 |
UNSIGNED_LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongIntValue()); |
| 93 |
} |
| 94 |
|
| 95 |
TEST(MockReturnValueTest, PositiveLongIntReturnValueCanBeRetrievedAsUnsignedLongInt) |
| 96 |
{ |
| 97 |
long int expected_value = 7; |
| 98 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 99 |
UNSIGNED_LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongIntValue()); |
| 100 |
} |
| 101 |
|
| 102 |
TEST(MockReturnValueTest, UnsignedIntReturnValueCanBeRetrievedAsUnsignedLongInt) |
| 103 |
{ |
| 104 |
unsigned int expected_value = 7; |
| 105 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 106 |
UNSIGNED_LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongIntValue()); |
| 107 |
} |
| 108 |
|
| 109 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 110 |
|
| 111 |
TEST(MockReturnValueTest, PositiveIntReturnValueCanBeRetrievedAsUnsignedLongLongInt) |
| 112 |
{ |
| 113 |
int expected_value = 7; |
| 114 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 115 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 116 |
} |
| 117 |
|
| 118 |
TEST(MockReturnValueTest, PositiveLongIntReturnValueCanBeRetrievedAsUnsignedLongLongInt) |
| 119 |
{ |
| 120 |
long int expected_value = 7; |
| 121 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 122 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 123 |
} |
| 124 |
|
| 125 |
TEST(MockReturnValueTest, PositiveLongLongIntReturnValueCanBeRetrievedAsUnsignedLongLongInt) |
| 126 |
{ |
| 127 |
long long int expected_value = 7; |
| 128 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 129 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 130 |
} |
| 131 |
|
| 132 |
TEST(MockReturnValueTest, UnsignedIntReturnValueCanBeRetrievedAsUnsignedLongLongInt) |
| 133 |
{ |
| 134 |
unsigned int expected_value = 7; |
| 135 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 136 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 137 |
} |
| 138 |
|
| 139 |
TEST(MockReturnValueTest, UnsignedLongIntReturnValueCanBeRetrievedAsUnsignedLongLongInt) |
| 140 |
{ |
| 141 |
unsigned long int expected_value = 7; |
| 142 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 143 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 144 |
} |
| 145 |
|
| 146 |
TEST(MockReturnValueTest, UnsignedLongLongIntReturnValueCanBeRetrieved) |
| 147 |
{ |
| 148 |
unsigned long long int expected_value = ULLONG_MAX; |
| 149 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 150 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 151 |
} |
| 152 |
|
| 153 |
TEST(MockReturnValueTest, PositiveIntReturnValueCanBeRetrievedAsLongLongInt) |
| 154 |
{ |
| 155 |
int expected_value = 7; |
| 156 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 157 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 158 |
} |
| 159 |
|
| 160 |
TEST(MockReturnValueTest, PositiveLongIntReturnValueCanBeRetrievedAsLongLongInt) |
| 161 |
{ |
| 162 |
long int expected_value = 7; |
| 163 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 164 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 165 |
} |
| 166 |
|
| 167 |
TEST(MockReturnValueTest, UnsignedIntReturnValueCanBeRetrievedAsLongLongInt) |
| 168 |
{ |
| 169 |
unsigned int expected_value = 7; |
| 170 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 171 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 172 |
} |
| 173 |
|
| 174 |
TEST(MockReturnValueTest, UnsignedLongIntReturnValueCanBeRetrievedAsLongLongInt) |
| 175 |
{ |
| 176 |
unsigned long int expected_value = 7; |
| 177 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 178 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 179 |
} |
| 180 |
|
| 181 |
TEST(MockReturnValueTest, LongLongIntReturnValueCanBeRetrieved) |
| 182 |
{ |
| 183 |
long long int expected_value = LLONG_MAX; |
| 184 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 185 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 186 |
} |
| 187 |
|
| 188 |
#endif |
| 189 |
|
| 190 |
TEST(MockReturnValueTest, UnsignedIntegerReturnValueSetsDifferentValues) |
| 191 |
{ |
| 192 |
unsigned int expected_value = 1; |
| 193 |
unsigned int another_expected_value = 2; |
| 194 |
|
| 195 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 196 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 197 |
|
| 198 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedIntValue()); |
| 199 |
LONGS_EQUAL(expected_value, mock().returnValue().getUnsignedIntValue()); |
| 200 |
LONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getUnsignedIntValue()); |
| 201 |
LONGS_EQUAL(another_expected_value, mock().returnValue().getUnsignedIntValue()); |
| 202 |
} |
| 203 |
|
| 204 |
TEST(MockReturnValueTest, UnsignedIntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 205 |
{ |
| 206 |
unsigned int ret_value = 1; |
| 207 |
unsigned int another_ret_value = 2; |
| 208 |
|
| 209 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 210 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 211 |
|
| 212 |
LONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedIntValue()); |
| 213 |
LONGS_EQUAL(ret_value, mock().returnValue().getUnsignedIntValue()); |
| 214 |
LONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedIntValue()); |
| 215 |
LONGS_EQUAL(another_ret_value, mock().returnValue().getUnsignedIntValue()); |
| 216 |
} |
| 217 |
|
| 218 |
TEST(MockReturnValueTest, WhenADoubleReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 219 |
{ |
| 220 |
double default_return_value = 10.7; |
| 221 |
double expected_return_value = default_return_value + 1.3; |
| 222 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 223 |
|
| 224 |
DOUBLES_EQUAL(expected_return_value, mock().actualCall("foo").returnDoubleValueOrDefault(default_return_value), 0.05); |
| 225 |
DOUBLES_EQUAL(expected_return_value, mock().returnDoubleValueOrDefault(default_return_value), 0.05); |
| 226 |
} |
| 227 |
|
| 228 |
TEST(MockReturnValueTest, WhenNoDoubleReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 229 |
{ |
| 230 |
double default_return_value = 7.7; |
| 231 |
mock().expectOneCall("foo"); |
| 232 |
DOUBLES_EQUAL(default_return_value, mock().actualCall("foo").returnDoubleValueOrDefault(default_return_value), 0.05); |
| 233 |
DOUBLES_EQUAL(default_return_value, mock().returnDoubleValueOrDefault(default_return_value), 0.05); |
| 234 |
} |
| 235 |
|
| 236 |
TEST(MockReturnValueTest, WhenAUnsignedIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 237 |
{ |
| 238 |
unsigned int default_return_value = 10; |
| 239 |
unsigned int expected_return_value = default_return_value + 1; |
| 240 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 241 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnUnsignedIntValueOrDefault(default_return_value)); |
| 242 |
LONGS_EQUAL(expected_return_value, mock().returnUnsignedIntValueOrDefault(default_return_value)); |
| 243 |
} |
| 244 |
|
| 245 |
TEST(MockReturnValueTest, WhenNoUnsignedIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 246 |
{ |
| 247 |
unsigned int default_return_value = 10; |
| 248 |
mock().expectOneCall("foo"); |
| 249 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnUnsignedIntValueOrDefault(default_return_value)); |
| 250 |
LONGS_EQUAL(default_return_value, mock().returnUnsignedIntValueOrDefault(default_return_value)); |
| 251 |
} |
| 252 |
|
| 253 |
TEST(MockReturnValueTest, WhenAUnsignedLongIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 254 |
{ |
| 255 |
unsigned long int default_return_value = 121487; |
| 256 |
unsigned long int expected_return_value = default_return_value + 1; |
| 257 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 258 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnUnsignedLongIntValueOrDefault(default_return_value)); |
| 259 |
LONGS_EQUAL(expected_return_value, mock().returnUnsignedLongIntValueOrDefault(default_return_value)); |
| 260 |
} |
| 261 |
|
| 262 |
TEST(MockReturnValueTest, WhenNoUnsignedLongIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 263 |
{ |
| 264 |
unsigned long int default_return_value = 7710144; |
| 265 |
mock().expectOneCall("foo"); |
| 266 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnUnsignedLongIntValueOrDefault(default_return_value)); |
| 267 |
LONGS_EQUAL(default_return_value, mock().returnUnsignedLongIntValueOrDefault(default_return_value)); |
| 268 |
} |
| 269 |
|
| 270 |
TEST(MockReturnValueTest, WhenALongIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 271 |
{ |
| 272 |
long int default_return_value = 748797; |
| 273 |
long int expected_return_value = default_return_value + 1; |
| 274 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 275 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnLongIntValueOrDefault(default_return_value)); |
| 276 |
LONGS_EQUAL(expected_return_value, mock().returnLongIntValueOrDefault(default_return_value)); |
| 277 |
} |
| 278 |
|
| 279 |
TEST(MockReturnValueTest, WhenNoLongIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 280 |
{ |
| 281 |
long int default_return_value = 123659; |
| 282 |
mock().expectOneCall("foo"); |
| 283 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnLongIntValueOrDefault(default_return_value)); |
| 284 |
LONGS_EQUAL(default_return_value, mock().returnLongIntValueOrDefault(default_return_value)); |
| 285 |
} |
| 286 |
|
| 287 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 288 |
|
| 289 |
TEST(MockReturnValueTest, WhenAUnsignedLongLongIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 290 |
{ |
| 291 |
unsigned long long int default_return_value = ULLONG_MAX; |
| 292 |
unsigned long long int expected_return_value = default_return_value - 1; |
| 293 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 294 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnUnsignedLongLongIntValueOrDefault(default_return_value)); |
| 295 |
LONGS_EQUAL(expected_return_value, mock().returnUnsignedLongLongIntValueOrDefault(default_return_value)); |
| 296 |
} |
| 297 |
|
| 298 |
TEST(MockReturnValueTest, WhenNoUnsignedLongLongIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 299 |
{ |
| 300 |
unsigned long long int default_return_value = ULLONG_MAX; |
| 301 |
mock().expectOneCall("foo"); |
| 302 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnUnsignedLongLongIntValueOrDefault(default_return_value)); |
| 303 |
LONGS_EQUAL(default_return_value, mock().returnUnsignedLongLongIntValueOrDefault(default_return_value)); |
| 304 |
} |
| 305 |
|
| 306 |
TEST(MockReturnValueTest, WhenALongLongIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 307 |
{ |
| 308 |
long long int default_return_value = LLONG_MAX; |
| 309 |
long long int expected_return_value = default_return_value - 1; |
| 310 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 311 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnLongLongIntValueOrDefault(default_return_value)); |
| 312 |
LONGS_EQUAL(expected_return_value, mock().returnLongLongIntValueOrDefault(default_return_value)); |
| 313 |
} |
| 314 |
|
| 315 |
TEST(MockReturnValueTest, WhenNoLongLongIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 316 |
{ |
| 317 |
long long int default_return_value = LLONG_MAX; |
| 318 |
mock().expectOneCall("foo"); |
| 319 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnLongLongIntValueOrDefault(default_return_value)); |
| 320 |
LONGS_EQUAL(default_return_value, mock().returnLongLongIntValueOrDefault(default_return_value)); |
| 321 |
} |
| 322 |
|
| 323 |
#endif |
| 324 |
|
| 325 |
TEST(MockReturnValueTest, WhenABooleanReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 326 |
{ |
| 327 |
bool default_return_value = true; |
| 328 |
bool expected_return_value = false; |
| 329 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 330 |
CHECK_EQUAL(expected_return_value, mock().actualCall("foo").returnBoolValueOrDefault(default_return_value)); |
| 331 |
CHECK_EQUAL(expected_return_value, mock().returnBoolValueOrDefault(default_return_value)); |
| 332 |
} |
| 333 |
|
| 334 |
TEST(MockReturnValueTest, WhenNoBooleanReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 335 |
{ |
| 336 |
bool default_return_value = true; |
| 337 |
mock().expectOneCall("foo"); |
| 338 |
CHECK_EQUAL(default_return_value, mock().actualCall("foo").returnBoolValueOrDefault(default_return_value)); |
| 339 |
CHECK_EQUAL(default_return_value, mock().returnBoolValueOrDefault(default_return_value)); |
| 340 |
} |
| 341 |
|
| 342 |
TEST(MockReturnValueTest, WhenAIntegerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 343 |
{ |
| 344 |
int default_return_value = 777; |
| 345 |
int expected_return_value = default_return_value + 1; |
| 346 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 347 |
LONGS_EQUAL(expected_return_value, mock().actualCall("foo").returnIntValueOrDefault(default_return_value)); |
| 348 |
LONGS_EQUAL(expected_return_value, mock().returnIntValueOrDefault(default_return_value)); |
| 349 |
} |
| 350 |
|
| 351 |
TEST(MockReturnValueTest, WhenNoIntegerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 352 |
{ |
| 353 |
int default_return_value = 777; |
| 354 |
mock().expectOneCall("foo"); |
| 355 |
LONGS_EQUAL(default_return_value, mock().actualCall("foo").returnIntValueOrDefault(default_return_value)); |
| 356 |
LONGS_EQUAL(default_return_value, mock().returnIntValueOrDefault(default_return_value)); |
| 357 |
} |
| 358 |
|
| 359 |
TEST(MockReturnValueTest, BooleanReturnValue) |
| 360 |
{ |
| 361 |
bool expected_value = true; |
| 362 |
mock().expectOneCall("foo").andReturnValue(true); |
| 363 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 364 |
|
| 365 |
CHECK_EQUAL(expected_value, actual_call.returnValue().getBoolValue()); |
| 366 |
CHECK_EQUAL(expected_value, actual_call.returnBoolValue()); |
| 367 |
|
| 368 |
CHECK_EQUAL(expected_value, mock().returnValue().getBoolValue()); |
| 369 |
CHECK_EQUAL(expected_value, mock().boolReturnValue()); |
| 370 |
} |
| 371 |
|
| 372 |
TEST(MockReturnValueTest, BooleanReturnValueSetsDifferentValues) |
| 373 |
{ |
| 374 |
bool expected_value = true; |
| 375 |
bool another_expected_value = false; |
| 376 |
|
| 377 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 378 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 379 |
|
| 380 |
CHECK_EQUAL(expected_value, mock().actualCall("foo").returnValue().getBoolValue()); |
| 381 |
CHECK_EQUAL(expected_value, mock().returnValue().getBoolValue()); |
| 382 |
CHECK_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getBoolValue()); |
| 383 |
CHECK_EQUAL(another_expected_value, mock().returnValue().getBoolValue()); |
| 384 |
} |
| 385 |
|
| 386 |
TEST(MockReturnValueTest, BooleanReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 387 |
{ |
| 388 |
bool ret_value = true; |
| 389 |
bool another_ret_value = false; |
| 390 |
|
| 391 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 392 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 393 |
|
| 394 |
CHECK_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getBoolValue()); |
| 395 |
CHECK_EQUAL(ret_value, mock().returnValue().getBoolValue()); |
| 396 |
CHECK_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getBoolValue()); |
| 397 |
CHECK_EQUAL(another_ret_value, mock().returnValue().getBoolValue()); |
| 398 |
} |
| 399 |
|
| 400 |
TEST(MockReturnValueTest, IntegerReturnValue) |
| 401 |
{ |
| 402 |
int expected_value = 1; |
| 403 |
mock().expectOneCall("foo").andReturnValue(1); |
| 404 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 405 |
|
| 406 |
LONGS_EQUAL(expected_value, actual_call.returnValue().getIntValue()); |
| 407 |
LONGS_EQUAL(expected_value, actual_call.returnIntValue()); |
| 408 |
|
| 409 |
LONGS_EQUAL(expected_value, mock().returnValue().getIntValue()); |
| 410 |
LONGS_EQUAL(expected_value, mock().intReturnValue()); |
| 411 |
} |
| 412 |
|
| 413 |
TEST(MockReturnValueTest, IntegerReturnValueSetsDifferentValues) |
| 414 |
{ |
| 415 |
int expected_value = 1; |
| 416 |
int another_expected_value = -1; |
| 417 |
|
| 418 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 419 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 420 |
|
| 421 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getIntValue()); |
| 422 |
LONGS_EQUAL(expected_value, mock().returnValue().getIntValue()); |
| 423 |
LONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getIntValue()); |
| 424 |
LONGS_EQUAL(another_expected_value, mock().returnValue().getIntValue()); |
| 425 |
} |
| 426 |
|
| 427 |
TEST(MockReturnValueTest, IntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 428 |
{ |
| 429 |
int ret_value = 1; |
| 430 |
int another_ret_value = -1; |
| 431 |
|
| 432 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 433 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 434 |
|
| 435 |
LONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getIntValue()); |
| 436 |
LONGS_EQUAL(ret_value, mock().returnValue().getIntValue()); |
| 437 |
LONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getIntValue()); |
| 438 |
LONGS_EQUAL(another_ret_value, mock().returnValue().getIntValue()); |
| 439 |
} |
| 440 |
|
| 441 |
TEST(MockReturnValueTest, LongIntegerReturnValue) |
| 442 |
{ |
| 443 |
long int expected_value = 7; |
| 444 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 445 |
|
| 446 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 447 |
LONGS_EQUAL(expected_value, actual_call.returnValue().getLongIntValue()); |
| 448 |
LONGS_EQUAL(expected_value, actual_call.returnLongIntValue()); |
| 449 |
LONGS_EQUAL(expected_value, mock().returnValue().getLongIntValue()); |
| 450 |
LONGS_EQUAL(expected_value, mock().longIntReturnValue()); |
| 451 |
} |
| 452 |
|
| 453 |
TEST(MockReturnValueTest, LongIntegerReturnValueSetsDifferentValues) |
| 454 |
{ |
| 455 |
long int expected_value = 1; |
| 456 |
long int another_expected_value = 2; |
| 457 |
|
| 458 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 459 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 460 |
|
| 461 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongIntValue()); |
| 462 |
LONGS_EQUAL(expected_value, mock().returnValue().getLongIntValue()); |
| 463 |
LONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getLongIntValue()); |
| 464 |
LONGS_EQUAL(another_expected_value, mock().returnValue().getLongIntValue()); |
| 465 |
} |
| 466 |
|
| 467 |
TEST(MockReturnValueTest, LongIntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 468 |
{ |
| 469 |
long int ret_value = 1; |
| 470 |
long int another_ret_value = 2; |
| 471 |
|
| 472 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 473 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 474 |
|
| 475 |
LONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getLongIntValue()); |
| 476 |
LONGS_EQUAL(ret_value, mock().returnValue().getLongIntValue()); |
| 477 |
LONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getLongIntValue()); |
| 478 |
LONGS_EQUAL(another_ret_value, mock().returnValue().getLongIntValue()); |
| 479 |
} |
| 480 |
|
| 481 |
TEST(MockReturnValueTest, UnsignedLongIntegerReturnValue) |
| 482 |
{ |
| 483 |
unsigned long int expected_value = 7; |
| 484 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 485 |
|
| 486 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 487 |
LONGS_EQUAL(expected_value, actual_call.returnValue().getUnsignedLongIntValue()); |
| 488 |
LONGS_EQUAL(expected_value, actual_call.returnUnsignedLongIntValue()); |
| 489 |
LONGS_EQUAL(expected_value, mock().returnValue().getUnsignedLongIntValue()); |
| 490 |
LONGS_EQUAL(expected_value, mock().unsignedLongIntReturnValue()); |
| 491 |
} |
| 492 |
|
| 493 |
TEST(MockReturnValueTest, UnsignedLongIntegerReturnValueSetsDifferentValues) |
| 494 |
{ |
| 495 |
unsigned long int expected_value = 1; |
| 496 |
unsigned long int another_expected_value = 2; |
| 497 |
|
| 498 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 499 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 500 |
|
| 501 |
LONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongIntValue()); |
| 502 |
LONGS_EQUAL(expected_value, mock().returnValue().getUnsignedLongIntValue()); |
| 503 |
LONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getUnsignedLongIntValue()); |
| 504 |
LONGS_EQUAL(another_expected_value, mock().returnValue().getUnsignedLongIntValue()); |
| 505 |
} |
| 506 |
|
| 507 |
TEST(MockReturnValueTest, UnsignedLongIntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 508 |
{ |
| 509 |
unsigned long int ret_value = 1; |
| 510 |
unsigned long int another_ret_value = 2; |
| 511 |
|
| 512 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 513 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 514 |
|
| 515 |
LONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedLongIntValue()); |
| 516 |
LONGS_EQUAL(ret_value, mock().returnValue().getUnsignedLongIntValue()); |
| 517 |
LONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedLongIntValue()); |
| 518 |
LONGS_EQUAL(another_ret_value, mock().returnValue().getUnsignedLongIntValue()); |
| 519 |
} |
| 520 |
|
| 521 |
#ifdef CPPUTEST_USE_LONG_LONG |
| 522 |
|
| 523 |
TEST(MockReturnValueTest, LongLongIntegerReturnValue) |
| 524 |
{ |
| 525 |
long long int expected_value = 7; |
| 526 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 527 |
|
| 528 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 529 |
LONGLONGS_EQUAL(expected_value, actual_call.returnValue().getLongLongIntValue()); |
| 530 |
LONGLONGS_EQUAL(expected_value, actual_call.returnLongLongIntValue()); |
| 531 |
LONGLONGS_EQUAL(expected_value, mock().returnValue().getLongLongIntValue()); |
| 532 |
LONGLONGS_EQUAL(expected_value, mock().longLongIntReturnValue()); |
| 533 |
} |
| 534 |
|
| 535 |
TEST(MockReturnValueTest, LongLongIntegerReturnValueSetsDifferentValues) |
| 536 |
{ |
| 537 |
long long int expected_value = 1; |
| 538 |
long long int another_expected_value = 2; |
| 539 |
|
| 540 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 541 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 542 |
|
| 543 |
LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 544 |
LONGLONGS_EQUAL(expected_value, mock().returnValue().getLongLongIntValue()); |
| 545 |
LONGLONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getLongLongIntValue()); |
| 546 |
LONGLONGS_EQUAL(another_expected_value, mock().returnValue().getLongLongIntValue()); |
| 547 |
} |
| 548 |
|
| 549 |
TEST(MockReturnValueTest, LongLongIntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 550 |
{ |
| 551 |
long long int ret_value = 1; |
| 552 |
long long int another_ret_value = 2; |
| 553 |
|
| 554 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 555 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 556 |
|
| 557 |
LONGLONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getLongLongIntValue()); |
| 558 |
LONGLONGS_EQUAL(ret_value, mock().returnValue().getLongLongIntValue()); |
| 559 |
LONGLONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getLongLongIntValue()); |
| 560 |
LONGLONGS_EQUAL(another_ret_value, mock().returnValue().getLongLongIntValue()); |
| 561 |
} |
| 562 |
|
| 563 |
TEST(MockReturnValueTest, UnsignedLongLongIntegerReturnValue) |
| 564 |
{ |
| 565 |
unsigned long long int expected_value = 7; |
| 566 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 567 |
|
| 568 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 569 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, actual_call.returnValue().getUnsignedLongLongIntValue()); |
| 570 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, actual_call.returnUnsignedLongLongIntValue()); |
| 571 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().returnValue().getUnsignedLongLongIntValue()); |
| 572 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().unsignedLongLongIntReturnValue()); |
| 573 |
} |
| 574 |
|
| 575 |
TEST(MockReturnValueTest, UnsignedLongLongIntegerReturnValueSetsDifferentValues) |
| 576 |
{ |
| 577 |
unsigned long long int expected_value = 1; |
| 578 |
unsigned long long int another_expected_value = 2; |
| 579 |
|
| 580 |
mock().expectOneCall("foo").andReturnValue(expected_value); |
| 581 |
mock().expectOneCall("foo").andReturnValue(another_expected_value); |
| 582 |
|
| 583 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 584 |
UNSIGNED_LONGLONGS_EQUAL(expected_value, mock().returnValue().getUnsignedLongLongIntValue()); |
| 585 |
UNSIGNED_LONGLONGS_EQUAL(another_expected_value, mock().actualCall("foo").returnValue().getUnsignedLongLongIntValue()); |
| 586 |
UNSIGNED_LONGLONGS_EQUAL(another_expected_value, mock().returnValue().getUnsignedLongLongIntValue()); |
| 587 |
} |
| 588 |
|
| 589 |
TEST(MockReturnValueTest, UnsignedLongLongIntegerReturnValueSetsDifferentValuesWhileParametersAreIgnored) |
| 590 |
{ |
| 591 |
unsigned long long int ret_value = 1; |
| 592 |
unsigned long long int another_ret_value = 2; |
| 593 |
|
| 594 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(ret_value); |
| 595 |
mock().expectOneCall("foo").withParameter("p1", 1).ignoreOtherParameters().andReturnValue(another_ret_value); |
| 596 |
|
| 597 |
UNSIGNED_LONGLONGS_EQUAL(ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedLongLongIntValue()); |
| 598 |
UNSIGNED_LONGLONGS_EQUAL(ret_value, mock().returnValue().getUnsignedLongLongIntValue()); |
| 599 |
UNSIGNED_LONGLONGS_EQUAL(another_ret_value, mock().actualCall("foo").withParameter("p1", 1).returnValue().getUnsignedLongLongIntValue()); |
| 600 |
UNSIGNED_LONGLONGS_EQUAL(another_ret_value, mock().returnValue().getUnsignedLongLongIntValue()); |
| 601 |
} |
| 602 |
|
| 603 |
#endif |
| 604 |
|
| 605 |
TEST(MockReturnValueTest, MatchingReturnValueOnWhileSignature) |
| 606 |
{ |
| 607 |
mock().expectOneCall("foo").withParameter("p1", 1).andReturnValue(1); |
| 608 |
mock().expectOneCall("foo").withParameter("p1", 2).andReturnValue(2); |
| 609 |
mock().expectOneCall("foo").withParameter("p1", 3).andReturnValue(3); |
| 610 |
mock().expectOneCall("foo").ignoreOtherParameters().andReturnValue(4); |
| 611 |
|
| 612 |
LONGS_EQUAL(3, mock().actualCall("foo").withParameter("p1", 3).returnValue().getIntValue()); |
| 613 |
LONGS_EQUAL(4, mock().actualCall("foo").withParameter("p1", 4).returnValue().getIntValue()); |
| 614 |
LONGS_EQUAL(1, mock().actualCall("foo").withParameter("p1", 1).returnValue().getIntValue()); |
| 615 |
LONGS_EQUAL(2, mock().actualCall("foo").withParameter("p1", 2).returnValue().getIntValue()); |
| 616 |
} |
| 617 |
|
| 618 |
TEST(MockReturnValueTest, WhenAStringReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 619 |
{ |
| 620 |
const char * default_return_value = "default"; |
| 621 |
const char * expected_return_value = "expected"; |
| 622 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 623 |
STRCMP_EQUAL(expected_return_value, mock().actualCall("foo").returnStringValueOrDefault(default_return_value)); |
| 624 |
STRCMP_EQUAL(expected_return_value, mock().returnStringValueOrDefault(default_return_value)); |
| 625 |
} |
| 626 |
|
| 627 |
TEST(MockReturnValueTest, WhenNoStringReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 628 |
{ |
| 629 |
const char * default_return_value = "default"; |
| 630 |
mock().expectOneCall("foo"); |
| 631 |
STRCMP_EQUAL(default_return_value, mock().actualCall("foo").returnStringValueOrDefault(default_return_value)); |
| 632 |
STRCMP_EQUAL(default_return_value, mock().returnStringValueOrDefault(default_return_value)); |
| 633 |
} |
| 634 |
|
| 635 |
TEST(MockReturnValueTest, StringReturnValue) |
| 636 |
{ |
| 637 |
mock().expectOneCall("foo").andReturnValue("hello world"); |
| 638 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 639 |
|
| 640 |
STRCMP_EQUAL("hello world", actual_call.returnValue().getStringValue()); |
| 641 |
STRCMP_EQUAL("hello world", actual_call.returnStringValue()); |
| 642 |
STRCMP_EQUAL("hello world", mock().stringReturnValue()); |
| 643 |
} |
| 644 |
|
| 645 |
TEST(MockReturnValueTest, DoubleReturnValue) |
| 646 |
{ |
| 647 |
double expected_return_value = 7.8; |
| 648 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 649 |
|
| 650 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 651 |
DOUBLES_EQUAL(expected_return_value, actual_call.returnValue().getDoubleValue(), 0.05); |
| 652 |
DOUBLES_EQUAL(expected_return_value, actual_call.returnDoubleValue(), 0.05); |
| 653 |
DOUBLES_EQUAL(expected_return_value, mock().doubleReturnValue(), 0.05); |
| 654 |
} |
| 655 |
|
| 656 |
TEST(MockReturnValueTest, WhenAConstPointerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 657 |
{ |
| 658 |
const void * default_return_value = (void*) 0x7778; |
| 659 |
const void * expected_return_value = (void*) 0x144010; |
| 660 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 661 |
POINTERS_EQUAL(expected_return_value, mock().actualCall("foo").returnConstPointerValueOrDefault(default_return_value)); |
| 662 |
POINTERS_EQUAL(expected_return_value, mock().returnConstPointerValueOrDefault(default_return_value)); |
| 663 |
} |
| 664 |
|
| 665 |
TEST(MockReturnValueTest, WhenNoConstPointerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 666 |
{ |
| 667 |
const void * default_return_value = (void*) 0x11; |
| 668 |
mock().expectOneCall("foo"); |
| 669 |
POINTERS_EQUAL(default_return_value, mock().actualCall("foo").returnConstPointerValueOrDefault(default_return_value)); |
| 670 |
POINTERS_EQUAL(default_return_value, mock().returnConstPointerValueOrDefault(default_return_value)); |
| 671 |
} |
| 672 |
|
| 673 |
TEST(MockReturnValueTest, WhenAPointerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 674 |
{ |
| 675 |
void * default_return_value = (void*) 0x777; |
| 676 |
void * expected_return_value = (void*) 0x144000; |
| 677 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 678 |
POINTERS_EQUAL(expected_return_value, mock().actualCall("foo").returnPointerValueOrDefault(default_return_value)); |
| 679 |
POINTERS_EQUAL(expected_return_value, mock().returnPointerValueOrDefault(default_return_value)); |
| 680 |
} |
| 681 |
|
| 682 |
TEST(MockReturnValueTest, WhenNoPointerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 683 |
{ |
| 684 |
void * default_return_value = (void*) 0x10; |
| 685 |
mock().expectOneCall("foo"); |
| 686 |
POINTERS_EQUAL(default_return_value, mock().actualCall("foo").returnPointerValueOrDefault(default_return_value)); |
| 687 |
POINTERS_EQUAL(default_return_value, mock().returnPointerValueOrDefault(default_return_value)); |
| 688 |
} |
| 689 |
|
| 690 |
TEST(MockReturnValueTest, WhenAFunctionPointerReturnValueIsExpectedAndAlsoThereIsADefaultShouldlIgnoreTheDefault) |
| 691 |
{ |
| 692 |
void (*default_return_value)() = (void(*)()) 0x777; |
| 693 |
void (*expected_return_value)() = (void(*)()) 0x144000; |
| 694 |
mock().expectOneCall("foo").andReturnValue(expected_return_value); |
| 695 |
FUNCTIONPOINTERS_EQUAL(expected_return_value, mock().actualCall("foo").returnFunctionPointerValueOrDefault(default_return_value)); |
| 696 |
FUNCTIONPOINTERS_EQUAL(expected_return_value, mock().returnFunctionPointerValueOrDefault(default_return_value)); |
| 697 |
} |
| 698 |
|
| 699 |
TEST(MockReturnValueTest, WhenNoFunctionPointerReturnValueIsExpectedButThereIsADefaultShouldlUseTheDefaultValue) |
| 700 |
{ |
| 701 |
void (*default_return_value)() = (void(*)()) 0x10; |
| 702 |
mock().expectOneCall("foo"); |
| 703 |
FUNCTIONPOINTERS_EQUAL(default_return_value, mock().actualCall("foo").returnFunctionPointerValueOrDefault(default_return_value)); |
| 704 |
FUNCTIONPOINTERS_EQUAL(default_return_value, mock().returnFunctionPointerValueOrDefault(default_return_value)); |
| 705 |
} |
| 706 |
|
| 707 |
TEST(MockReturnValueTest, PointerReturnValue) |
| 708 |
{ |
| 709 |
void* ptr = (void*) 0x00107; |
| 710 |
mock().expectOneCall("foo").andReturnValue(ptr); |
| 711 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 712 |
|
| 713 |
POINTERS_EQUAL(ptr, actual_call.returnValue().getPointerValue()); |
| 714 |
POINTERS_EQUAL(ptr, actual_call.returnPointerValue()); |
| 715 |
POINTERS_EQUAL(ptr, mock().pointerReturnValue()); |
| 716 |
} |
| 717 |
|
| 718 |
TEST(MockReturnValueTest, ConstPointerReturnValue) |
| 719 |
{ |
| 720 |
const void* ptr = (const void*) 0x001074; |
| 721 |
mock().expectOneCall("foo").andReturnValue(ptr); |
| 722 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 723 |
POINTERS_EQUAL(ptr, actual_call.returnValue().getConstPointerValue()); |
| 724 |
POINTERS_EQUAL(ptr, actual_call.returnConstPointerValue()); |
| 725 |
POINTERS_EQUAL(ptr, mock().constPointerReturnValue()); |
| 726 |
} |
| 727 |
|
| 728 |
TEST(MockReturnValueTest, FunctionPointerReturnValue) |
| 729 |
{ |
| 730 |
void (*ptr)() = (void(*)()) 0x00107; |
| 731 |
mock().expectOneCall("foo").andReturnValue(ptr); |
| 732 |
MockActualCall& actual_call = mock().actualCall("foo"); |
| 733 |
|
| 734 |
FUNCTIONPOINTERS_EQUAL(ptr, actual_call.returnValue().getFunctionPointerValue()); |
| 735 |
FUNCTIONPOINTERS_EQUAL(ptr, actual_call.returnFunctionPointerValue()); |
| 736 |
FUNCTIONPOINTERS_EQUAL(ptr, mock().functionPointerReturnValue()); |
| 737 |
} |
| 738 |
|
| 739 |
TEST(MockReturnValueTest, whenCallingDisabledOrIgnoredActualCallsThenTheyDontReturnPreviousCallsValues) |
| 740 |
{ |
| 741 |
mock().expectOneCall("boo").ignoreOtherParameters().andReturnValue(10); |
| 742 |
mock().ignoreOtherCalls(); |
| 743 |
mock().actualCall("boo"); |
| 744 |
mock().actualCall("An Ignored Call"); |
| 745 |
|
| 746 |
CHECK(!mock().hasReturnValue()); |
| 747 |
} |
| 748 |
|