| 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 "CppUTest/TestOutput.h" |
| 30 | #include "CppUTest/TestTestingFixture.h" |
| 31 | |
| 32 | #define CHECK_TEST_FAILS_PROPER_WITH_TEXT(text) fixture.checkTestFailsWithProperTestLocation(text, __FILE__, __LINE__) |
| 33 | |
| 34 | // Mainly this is for Visual C++, but we'll define it for any system that has the same behavior |
| 35 | // of a 32-bit long on a 64-bit system |
| 36 | #if defined(CPPUTEST_64BIT) && defined(CPPUTEST_64BIT_32BIT_LONGS) |
| 37 | // Forcing the value to be unsigned long long means that there's no sign-extension to perform |
| 38 | #define to_void_pointer(x) ((void *)x##ULL) |
| 39 | #define to_func_pointer(x) ((void (*)())x##ULL) |
| 40 | #else |
| 41 | // Probably not needed, but let's guarantee that the value is an unsigned long |
| 42 | #define to_void_pointer(x) ((void *)x##UL) |
| 43 | #define to_func_pointer(x) ((void (*)())x##UL) |
| 44 | #endif |
| 45 | |
| 46 | TEST_GROUP(UnitTestMacros) |
| 47 | { |
| 48 | TestTestingFixture fixture; |
| 49 | }; |
| 50 | |
| 51 | static void _failingTestMethodWithFAIL() |
| 52 | { |
| 53 | FAIL("This test fails"); |
| 54 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 55 | } // LCOV_EXCL_LINE |
| 56 | |
| 57 | TEST(UnitTestMacros, FAILMakesTheTestFailPrintsTheRightResultAndStopsExecuting) |
| 58 | { |
| 59 | fixture.runTestWithMethod(_failingTestMethodWithFAIL); |
| 60 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("This test fails"); |
| 61 | } |
| 62 | |
| 63 | TEST(UnitTestMacros, FAILWillPrintTheFileThatItFailed) |
| 64 | { |
| 65 | fixture.runTestWithMethod(_failingTestMethodWithFAIL); |
| 66 | CHECK_TEST_FAILS_PROPER_WITH_TEXT(__FILE__); |
| 67 | } |
| 68 | |
| 69 | TEST(UnitTestMacros, FAILBehavesAsAProperMacro) |
| 70 | { |
| 71 | if (false) FAIL(""); |
| 72 | else CHECK(true); |
| 73 | |
| 74 | if (true) CHECK(true); |
| 75 | else FAIL(""); |
| 76 | } |
| 77 | |
| 78 | IGNORE_TEST(UnitTestMacros, FAILworksInAnIgnoredTest) |
| 79 | { |
| 80 | FAIL("die!"); // LCOV_EXCL_LINE |
| 81 | } // LCOV_EXCL_LINE |
| 82 | |
| 83 | static void _UNSIGNED_LONGS_EQUALTestMethod() |
| 84 | { |
| 85 | UNSIGNED_LONGS_EQUAL(1, 1); |
| 86 | UNSIGNED_LONGS_EQUAL(1, 0); |
| 87 | } // LCOV_EXCL_LINE |
| 88 | |
| 89 | TEST(UnitTestMacros, TestUNSIGNED_LONGS_EQUAL) |
| 90 | { |
| 91 | fixture.runTestWithMethod(_UNSIGNED_LONGS_EQUALTestMethod); |
| 92 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 93 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 94 | } |
| 95 | |
| 96 | TEST(UnitTestMacros, UNSIGNED_LONGS_EQUALBehavesAsProperMacro) |
| 97 | { |
| 98 | if (false) UNSIGNED_LONGS_EQUAL(1, 0); |
| 99 | else UNSIGNED_LONGS_EQUAL(1, 1); |
| 100 | } |
| 101 | |
| 102 | IGNORE_TEST(UnitTestMacros, UNSIGNED_LONGS_EQUALWorksInAnIgnoredTest) |
| 103 | { |
| 104 | UNSIGNED_LONGS_EQUAL(1, 0); // LCOV_EXCL_LINE |
| 105 | } // LCOV_EXCL_LINE |
| 106 | |
| 107 | static void _UNSIGNED_LONGS_EQUAL_TEXTTestMethod() |
| 108 | { |
| 109 | UNSIGNED_LONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 110 | } // LCOV_EXCL_LINE |
| 111 | |
| 112 | TEST(UnitTestMacros, TestUNSIGNED_LONGS_EQUAL_TEXT) |
| 113 | { |
| 114 | fixture.runTestWithMethod(_UNSIGNED_LONGS_EQUAL_TEXTTestMethod); |
| 115 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 116 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 117 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 118 | } |
| 119 | |
| 120 | TEST(UnitTestMacros, UNSIGNED_LONGS_EQUAL_TEXTBehavesAsProperMacro) |
| 121 | { |
| 122 | if (false) UNSIGNED_LONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 123 | else UNSIGNED_LONGS_EQUAL_TEXT(1, 1, "Failed because it failed"); |
| 124 | } |
| 125 | |
| 126 | IGNORE_TEST(UnitTestMacros, UNSIGNED_LONGS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 127 | { |
| 128 | UNSIGNED_LONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); // LCOV_EXCL_LINE |
| 129 | } // LCOV_EXCL_LINE |
| 130 | |
| 131 | #ifdef CPPUTEST_USE_LONG_LONG |
| 132 | |
| 133 | static void _LONGLONGS_EQUALTestMethod() |
| 134 | { |
| 135 | LONGLONGS_EQUAL(1, 1); |
| 136 | LONGLONGS_EQUAL(1, 0); |
| 137 | } // LCOV_EXCL_LINE |
| 138 | |
| 139 | TEST(UnitTestMacros, TestLONGLONGS_EQUAL) |
| 140 | { |
| 141 | fixture.runTestWithMethod(_LONGLONGS_EQUALTestMethod); |
| 142 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 143 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 144 | } |
| 145 | |
| 146 | TEST(UnitTestMacros, LONGLONGS_EQUALBehavesAsProperMacro) |
| 147 | { |
| 148 | if (false) LONGLONGS_EQUAL(1, 0); |
| 149 | else LONGLONGS_EQUAL(1, 1); |
| 150 | } |
| 151 | |
| 152 | IGNORE_TEST(UnitTestMacros, LONGLONGS_EQUALWorksInAnIgnoredTest) |
| 153 | { |
| 154 | LONGLONGS_EQUAL(1, 0); // LCOV_EXCL_LINE |
| 155 | } // LCOV_EXCL_LINE |
| 156 | |
| 157 | static void _LONGLONGS_EQUAL_TEXTTestMethod() |
| 158 | { |
| 159 | LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 160 | } // LCOV_EXCL_LINE |
| 161 | |
| 162 | TEST(UnitTestMacros, TestLONGLONGS_EQUAL_TEXT) |
| 163 | { |
| 164 | fixture.runTestWithMethod(_LONGLONGS_EQUAL_TEXTTestMethod); |
| 165 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 166 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 167 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 168 | } |
| 169 | |
| 170 | TEST(UnitTestMacros, LONGLONGS_EQUAL_TEXTBehavesAsProperMacro) |
| 171 | { |
| 172 | if (false) LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 173 | else LONGLONGS_EQUAL_TEXT(1, 1, "Failed because it failed"); |
| 174 | } |
| 175 | |
| 176 | IGNORE_TEST(UnitTestMacros, LONGLONGS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 177 | { |
| 178 | LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); // LCOV_EXCL_LINE |
| 179 | } // LCOV_EXCL_LINE |
| 180 | |
| 181 | static void _UNSIGNED_LONGLONGS_EQUALTestMethod() |
| 182 | { |
| 183 | UNSIGNED_LONGLONGS_EQUAL(1, 1); |
| 184 | UNSIGNED_LONGLONGS_EQUAL(1, 0); |
| 185 | } // LCOV_EXCL_LINE |
| 186 | |
| 187 | TEST(UnitTestMacros, TestUNSIGNED_LONGLONGS_EQUAL) |
| 188 | { |
| 189 | fixture.runTestWithMethod(_UNSIGNED_LONGLONGS_EQUALTestMethod); |
| 190 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 191 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 192 | } |
| 193 | |
| 194 | TEST(UnitTestMacros, UNSIGNED_LONGLONGS_EQUALBehavesAsProperMacro) |
| 195 | { |
| 196 | if (false) UNSIGNED_LONGLONGS_EQUAL(1, 0); |
| 197 | else UNSIGNED_LONGLONGS_EQUAL(1, 1); |
| 198 | } |
| 199 | |
| 200 | IGNORE_TEST(UnitTestMacros, UNSIGNED_LONGLONGS_EQUALWorksInAnIgnoredTest) |
| 201 | { |
| 202 | UNSIGNED_LONGLONGS_EQUAL(1, 0); // LCOV_EXCL_LINE |
| 203 | } // LCOV_EXCL_LINE |
| 204 | |
| 205 | static void _UNSIGNED_LONGLONGS_EQUAL_TEXTTestMethod() |
| 206 | { |
| 207 | UNSIGNED_LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 208 | } // LCOV_EXCL_LINE |
| 209 | |
| 210 | TEST(UnitTestMacros, TestUNSIGNED_LONGLONGS_EQUAL_TEXT) |
| 211 | { |
| 212 | fixture.runTestWithMethod(_UNSIGNED_LONGLONGS_EQUAL_TEXTTestMethod); |
| 213 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 214 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0 (0x0)>"); |
| 215 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 216 | } |
| 217 | |
| 218 | TEST(UnitTestMacros, UNSIGNED_LONGLONGS_EQUAL_TEXTBehavesAsProperMacro) |
| 219 | { |
| 220 | if (false) UNSIGNED_LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); |
| 221 | else UNSIGNED_LONGLONGS_EQUAL_TEXT(1, 1, "Failed because it failed"); |
| 222 | } |
| 223 | |
| 224 | IGNORE_TEST(UnitTestMacros, UNSIGNED_LONGLONGS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 225 | { |
| 226 | UNSIGNED_LONGLONGS_EQUAL_TEXT(1, 0, "Failed because it failed"); // LCOV_EXCL_LINE |
| 227 | } // LCOV_EXCL_LINE |
| 228 | |
| 229 | #else |
| 230 | |
| 231 | static void _LONGLONGS_EQUALFailsWithUnsupportedFeatureTestMethod() |
| 232 | { |
| 233 | LONGLONGS_EQUAL(1, 1); |
| 234 | } // LCOV_EXCL_LINE |
| 235 | |
| 236 | static void _UNSIGNED_LONGLONGS_EQUALFailsWithUnsupportedFeatureTestMethod() |
| 237 | { |
| 238 | UNSIGNED_LONGLONGS_EQUAL(1, 1); |
| 239 | } // LCOV_EXCL_LINE |
| 240 | |
| 241 | TEST(UnitTestMacros, LONGLONGS_EQUALFailsWithUnsupportedFeature) |
| 242 | { |
| 243 | fixture.runTestWithMethod(_LONGLONGS_EQUALFailsWithUnsupportedFeatureTestMethod); |
| 244 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("\"CPPUTEST_USE_LONG_LONG\" is not supported"); |
| 245 | } |
| 246 | |
| 247 | TEST(UnitTestMacros, UNSIGNED_LONGLONGS_EQUALFailsWithUnsupportedFeature) |
| 248 | { |
| 249 | fixture.runTestWithMethod(_UNSIGNED_LONGLONGS_EQUALFailsWithUnsupportedFeatureTestMethod); |
| 250 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("\"CPPUTEST_USE_LONG_LONG\" is not supported"); |
| 251 | } |
| 252 | |
| 253 | #endif /* CPPUTEST_USE_LONG_LONG */ |
| 254 | |
| 255 | static void _failingTestMethodWithCHECK() |
| 256 | { |
| 257 | CHECK(false); |
| 258 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 259 | } // LCOV_EXCL_LINE |
| 260 | |
| 261 | TEST(UnitTestMacros, FailureWithCHECK) |
| 262 | { |
| 263 | fixture.runTestWithMethod(_failingTestMethodWithCHECK); |
| 264 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK(false) failed"); |
| 265 | } |
| 266 | |
| 267 | TEST(UnitTestMacros, CHECKBehavesAsProperMacro) |
| 268 | { |
| 269 | if (false) CHECK(false); |
| 270 | else CHECK(true); |
| 271 | } |
| 272 | |
| 273 | IGNORE_TEST(UnitTestMacros, CHECKWorksInAnIgnoredTest) |
| 274 | { |
| 275 | CHECK(false); // LCOV_EXCL_LINE |
| 276 | } // LCOV_EXCL_LINE |
| 277 | |
| 278 | static void _failingTestMethodWithCHECK_TEXT() |
| 279 | { |
| 280 | CHECK_TEXT(false, "Failed because it failed"); |
| 281 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 282 | } // LCOV_EXCL_LINE |
| 283 | |
| 284 | TEST(UnitTestMacros, FailureWithCHECK_TEXT) |
| 285 | { |
| 286 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_TEXT); |
| 287 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK(false) failed"); |
| 288 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 289 | } |
| 290 | |
| 291 | TEST(UnitTestMacros, CHECK_TEXTBehavesAsProperMacro) |
| 292 | { |
| 293 | if (false) CHECK_TEXT(false, "false"); |
| 294 | else CHECK_TEXT(true, "true"); |
| 295 | } |
| 296 | |
| 297 | IGNORE_TEST(UnitTestMacros, CHECK_TEXTWorksInAnIgnoredTest) |
| 298 | { |
| 299 | CHECK_TEXT(false, "false"); // LCOV_EXCL_LINE |
| 300 | } // LCOV_EXCL_LINE |
| 301 | |
| 302 | static void _failingTestMethodWithCHECK_TRUE() |
| 303 | { |
| 304 | CHECK_TRUE(false); |
| 305 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 306 | } // LCOV_EXCL_LINE |
| 307 | |
| 308 | TEST(UnitTestMacros, FailureWithCHECK_TRUE) |
| 309 | { |
| 310 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_TRUE); |
| 311 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_TRUE(false) failed"); |
| 312 | } |
| 313 | |
| 314 | TEST(UnitTestMacros, CHECK_TRUEBehavesAsProperMacro) |
| 315 | { |
| 316 | if (false) CHECK_TRUE(false); |
| 317 | else CHECK_TRUE(true); |
| 318 | } |
| 319 | |
| 320 | IGNORE_TEST(UnitTestMacros, CHECK_TRUEWorksInAnIgnoredTest) |
| 321 | { |
| 322 | CHECK_TRUE(false); // LCOV_EXCL_LINE |
| 323 | } // LCOV_EXCL_LINE |
| 324 | |
| 325 | static void _failingTestMethodWithCHECK_TRUE_TEXT() |
| 326 | { |
| 327 | CHECK_TRUE_TEXT(false, "Failed because it failed"); |
| 328 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 329 | } // LCOV_EXCL_LINE |
| 330 | |
| 331 | TEST(UnitTestMacros, FailureWithCHECK_TRUE_TEXT) |
| 332 | { |
| 333 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_TRUE_TEXT); |
| 334 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_TRUE(false) failed"); |
| 335 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 336 | } |
| 337 | |
| 338 | TEST(UnitTestMacros, CHECK_TRUE_TEXTBehavesAsProperMacro) |
| 339 | { |
| 340 | if (false) CHECK_TRUE_TEXT(false, "Failed because it failed"); |
| 341 | else CHECK_TRUE_TEXT(true, "Failed because it failed"); |
| 342 | } |
| 343 | |
| 344 | IGNORE_TEST(UnitTestMacros, CHECK_TRUE_TEXTWorksInAnIgnoredTest) |
| 345 | { |
| 346 | CHECK_TRUE_TEXT(false, "Failed because it failed"); // LCOV_EXCL_LINE |
| 347 | } // LCOV_EXCL_LINE |
| 348 | |
| 349 | static void _failingTestMethodWithCHECK_FALSE() |
| 350 | { |
| 351 | CHECK_FALSE(true); |
| 352 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 353 | } // LCOV_EXCL_LINE |
| 354 | |
| 355 | TEST(UnitTestMacros, FailureWithCHECK_FALSE) |
| 356 | { |
| 357 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_FALSE); |
| 358 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_FALSE(true) failed"); |
| 359 | } |
| 360 | |
| 361 | TEST(UnitTestMacros, CHECK_FALSEBehavesAsProperMacro) |
| 362 | { |
| 363 | if (false) CHECK_FALSE(true); |
| 364 | else CHECK_FALSE(false); |
| 365 | } |
| 366 | |
| 367 | IGNORE_TEST(UnitTestMacros, CHECK_FALSEWorksInAnIgnoredTest) |
| 368 | { |
| 369 | CHECK_FALSE(true); // LCOV_EXCL_LINE |
| 370 | } // LCOV_EXCL_LINE |
| 371 | |
| 372 | static void _failingTestMethodWithCHECK_FALSE_TEXT() |
| 373 | { |
| 374 | CHECK_FALSE_TEXT(true, "Failed because it failed"); |
| 375 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 376 | } // LCOV_EXCL_LINE |
| 377 | |
| 378 | TEST(UnitTestMacros, FailureWithCHECK_FALSE_TEXT) |
| 379 | { |
| 380 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_FALSE_TEXT); |
| 381 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_FALSE(true)"); |
| 382 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 383 | } |
| 384 | |
| 385 | TEST(UnitTestMacros, CHECK_FALSE_TEXTBehavesAsProperMacro) |
| 386 | { |
| 387 | if (false) CHECK_FALSE_TEXT(true, "Failed because it failed"); |
| 388 | else CHECK_FALSE_TEXT(false, "Failed because it failed"); |
| 389 | } |
| 390 | |
| 391 | IGNORE_TEST(UnitTestMacros, CHECK_FALSE_TEXTWorksInAnIgnoredTest) |
| 392 | { |
| 393 | CHECK_FALSE_TEXT(true, "Failed because it failed"); // LCOV_EXCL_LINE |
| 394 | } // LCOV_EXCL_LINE |
| 395 | |
| 396 | static void _failingTestMethodWithCHECK_EQUAL() |
| 397 | { |
| 398 | CHECK_EQUAL(1, 2); |
| 399 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 400 | } // LCOV_EXCL_LINE |
| 401 | |
| 402 | TEST(UnitTestMacros, FailureWithCHECK_EQUAL) |
| 403 | { |
| 404 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_EQUAL); |
| 405 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 406 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <2>"); |
| 407 | } |
| 408 | |
| 409 | static void _failingTestMethodWithCHECK_COMPARE() |
| 410 | { |
| 411 | double small = 0.5, big = 0.8; |
| 412 | CHECK_COMPARE(small, >=, big); |
| 413 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 414 | } // LCOV_EXCL_LINE |
| 415 | |
| 416 | TEST(UnitTestMacros, FailureWithCHECK_COMPARE) |
| 417 | { |
| 418 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_COMPARE); |
| 419 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_COMPARE(0.5 >= 0.8)"); |
| 420 | } |
| 421 | |
| 422 | TEST(UnitTestMacros, CHECK_COMPAREBehavesAsProperMacro) |
| 423 | { |
| 424 | if (false) CHECK_COMPARE(1, >, 2); |
| 425 | else CHECK_COMPARE(1, <, 2); |
| 426 | } |
| 427 | |
| 428 | IGNORE_TEST(UnitTestMacros, CHECK_COMPAREWorksInAnIgnoredTest) |
| 429 | { |
| 430 | CHECK_COMPARE(1, >, 2); // LCOV_EXCL_LINE |
| 431 | } // LCOV_EXCL_LINE |
| 432 | |
| 433 | static void _failingTestMethodWithCHECK_COMPARE_TEXT() |
| 434 | { |
| 435 | double small = 0.5, big = 0.8; |
| 436 | CHECK_COMPARE_TEXT(small, >=, big, "small bigger than big"); |
| 437 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 438 | } // LCOV_EXCL_LINE |
| 439 | |
| 440 | TEST(UnitTestMacros, FailureWithCHECK_COMPARE_TEXT) |
| 441 | { |
| 442 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_COMPARE_TEXT); |
| 443 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("CHECK_COMPARE(0.5 >= 0.8)"); |
| 444 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("small bigger than big"); |
| 445 | } |
| 446 | |
| 447 | TEST(UnitTestMacros, CHECK_COMPARE_TEXTBehavesAsProperMacro) |
| 448 | { |
| 449 | if (false) CHECK_COMPARE_TEXT(1, >, 2, "1 bigger than 2"); |
| 450 | else CHECK_COMPARE_TEXT(1, <, 2, "1 smaller than 2"); |
| 451 | } |
| 452 | |
| 453 | IGNORE_TEST(UnitTestMacros, CHECK_COMPARE_TEXTWorksInAnIgnoredTest) |
| 454 | { |
| 455 | CHECK_COMPARE_TEXT(1, >, 2, "1 smaller than 2"); // LCOV_EXCL_LINE |
| 456 | } // LCOV_EXCL_LINE |
| 457 | |
| 458 | static int countInCountingMethod; |
| 459 | static int _countingMethod() |
| 460 | { |
| 461 | return countInCountingMethod++; |
| 462 | } |
| 463 | |
| 464 | TEST(UnitTestMacros, LONGS_EQUAL_macroExpressionSafety) |
| 465 | { |
| 466 | LONGS_EQUAL(1, 0.4 + 0.7); |
| 467 | LONGS_EQUAL(0.4 + 0.7, 1); |
| 468 | LONGS_EQUAL_TEXT(1, 0.4 + 0.7, "-Wconversion=great"); |
| 469 | LONGS_EQUAL_TEXT(0.4 + 0.7, 1, "-Wconversion=great"); |
| 470 | } |
| 471 | |
| 472 | TEST(UnitTestMacros, UNSIGNED_LONGS_EQUAL_macroExpressionSafety) |
| 473 | { |
| 474 | UNSIGNED_LONGS_EQUAL(1, 0.4 + 0.7); |
| 475 | UNSIGNED_LONGS_EQUAL(0.4 + 0.7, 1); |
| 476 | UNSIGNED_LONGS_EQUAL_TEXT(1, 0.4 + 0.7, "-Wconversion=great"); |
| 477 | UNSIGNED_LONGS_EQUAL_TEXT(0.4 + 0.7, 1, "-Wconversion=great"); |
| 478 | } |
| 479 | |
| 480 | TEST(UnitTestMacros, passingCheckEqualWillNotBeEvaluatedMultipleTimesWithCHECK_EQUAL) |
| 481 | { |
| 482 | countInCountingMethod = 0; |
| 483 | CHECK_EQUAL(0, _countingMethod()); |
| 484 | |
| 485 | LONGS_EQUAL(1, countInCountingMethod); |
| 486 | } |
| 487 | |
| 488 | static void _failing_CHECK_EQUAL_WithActualBeingEvaluatesMultipleTimesWillGiveAWarning() |
| 489 | { |
| 490 | CHECK_EQUAL(12345, _countingMethod()); |
| 491 | } // LCOV_EXCL_LINE |
| 492 | |
| 493 | TEST(UnitTestMacros, failing_CHECK_EQUAL_WithActualBeingEvaluatesMultipleTimesWillGiveAWarning) |
| 494 | { |
| 495 | fixture.runTestWithMethod(_failing_CHECK_EQUAL_WithActualBeingEvaluatesMultipleTimesWillGiveAWarning); |
| 496 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("WARNING:\n\tThe \"Actual Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect."); |
| 497 | } |
| 498 | |
| 499 | static void _failing_CHECK_EQUAL_WithExpectedBeingEvaluatesMultipleTimesWillGiveAWarning() |
| 500 | { |
| 501 | CHECK_EQUAL(_countingMethod(), 12345); |
| 502 | } // LCOV_EXCL_LINE |
| 503 | |
| 504 | TEST(UnitTestMacros, failing_CHECK_EQUAL_WithExpectedBeingEvaluatesMultipleTimesWillGiveAWarning) |
| 505 | { |
| 506 | fixture.runTestWithMethod(_failing_CHECK_EQUAL_WithExpectedBeingEvaluatesMultipleTimesWillGiveAWarning); |
| 507 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("WARNING:\n\tThe \"Expected Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect."); |
| 508 | } |
| 509 | |
| 510 | TEST(UnitTestMacros, failing_CHECK_EQUAL_withParamatersThatDontChangeWillNotGiveAnyWarning) |
| 511 | { |
| 512 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_EQUAL); |
| 513 | fixture.assertPrintContainsNot("WARNING"); |
| 514 | } |
| 515 | |
| 516 | TEST(UnitTestMacros, CHECK_EQUALBehavesAsProperMacro) |
| 517 | { |
| 518 | if (false) CHECK_EQUAL(1, 2); |
| 519 | else CHECK_EQUAL(1, 1); |
| 520 | } |
| 521 | |
| 522 | IGNORE_TEST(UnitTestMacros, CHECK_EQUALWorksInAnIgnoredTest) |
| 523 | { |
| 524 | CHECK_EQUAL(1, 2); // LCOV_EXCL_LINE |
| 525 | } // LCOV_EXCL_LINE |
| 526 | |
| 527 | static void _failingTestMethodWithCHECK_EQUAL_TEXT() |
| 528 | { |
| 529 | CHECK_EQUAL_TEXT(1, 2, "Failed because it failed"); |
| 530 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 531 | } // LCOV_EXCL_LINE |
| 532 | |
| 533 | TEST(UnitTestMacros, FailureWithCHECK_EQUAL_TEXT) |
| 534 | { |
| 535 | fixture.runTestWithMethod(_failingTestMethodWithCHECK_EQUAL_TEXT); |
| 536 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 537 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <2>"); |
| 538 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 539 | } |
| 540 | |
| 541 | TEST(UnitTestMacros, CHECK_EQUAL_TEXTBehavesAsProperMacro) |
| 542 | { |
| 543 | if (false) CHECK_EQUAL_TEXT(1, 2, "Failed because it failed"); |
| 544 | else CHECK_EQUAL_TEXT(1, 1, "Failed because it failed"); |
| 545 | } |
| 546 | |
| 547 | IGNORE_TEST(UnitTestMacros, CHECK_EQUAL_TEXTWorksInAnIgnoredTest) |
| 548 | { |
| 549 | CHECK_EQUAL_TEXT(1, 2, "Failed because it failed"); // LCOV_EXCL_LINE; |
| 550 | } // LCOV_EXCL_LINE |
| 551 | |
| 552 | static void _failingTestMethodWithLONGS_EQUAL() |
| 553 | { |
| 554 | LONGS_EQUAL(1, 0xff); |
| 555 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 556 | } // LCOV_EXCL_LINE |
| 557 | |
| 558 | TEST(UnitTestMacros, FailureWithLONGS_EQUALS) |
| 559 | { |
| 560 | fixture.runTestWithMethod(_failingTestMethodWithLONGS_EQUAL); |
| 561 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected < 1 (0x1)>"); |
| 562 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <255 (0xff)>"); |
| 563 | } |
| 564 | |
| 565 | static void _failingTestMethodWithLONGS_EQUALWithSymbolicParameters() |
| 566 | { |
| 567 | #define _MONDAY 1 |
| 568 | int day_of_the_week = _MONDAY+1; |
| 569 | LONGS_EQUAL(_MONDAY, day_of_the_week); |
| 570 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 571 | } // LCOV_EXCL_LINE |
| 572 | |
| 573 | TEST(UnitTestMacros, FailureWithLONGS_EQUALShowsSymbolicParameters) |
| 574 | { |
| 575 | fixture.runTestWithMethod(_failingTestMethodWithLONGS_EQUALWithSymbolicParameters); |
| 576 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("LONGS_EQUAL(_MONDAY, day_of_the_week) failed"); |
| 577 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1 (0x1)>"); |
| 578 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <2 (0x2)>"); |
| 579 | CHECK_FALSE(fixture.getOutput().contains("Message: ")); |
| 580 | } |
| 581 | |
| 582 | TEST(UnitTestMacros, LONGS_EQUALBehavesAsProperMacro) |
| 583 | { |
| 584 | if (false) LONGS_EQUAL(1, 2); |
| 585 | else LONGS_EQUAL(10, 10); |
| 586 | } |
| 587 | |
| 588 | IGNORE_TEST(UnitTestMacros, LONGS_EQUALWorksInAnIgnoredTest) |
| 589 | { |
| 590 | LONGS_EQUAL(11, 22); // LCOV_EXCL_LINE |
| 591 | } // LCOV_EXCL_LINE |
| 592 | |
| 593 | static void _failingTestMethodWithLONGS_EQUAL_TEXT() |
| 594 | { |
| 595 | LONGS_EQUAL_TEXT(1, 0xff, "Failed because it failed"); |
| 596 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 597 | } // LCOV_EXCL_LINE |
| 598 | |
| 599 | TEST(UnitTestMacros, FailureWithLONGS_EQUALS_TEXT) |
| 600 | { |
| 601 | fixture.runTestWithMethod(_failingTestMethodWithLONGS_EQUAL_TEXT); |
| 602 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected < 1 (0x1)>"); |
| 603 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <255 (0xff)>"); |
| 604 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 605 | } |
| 606 | |
| 607 | TEST(UnitTestMacros, LONGS_EQUAL_TEXTBehavesAsProperMacro) |
| 608 | { |
| 609 | if (false) LONGS_EQUAL_TEXT(1, 2, "Failed because it failed"); |
| 610 | else LONGS_EQUAL_TEXT(10, 10, "Failed because it failed"); |
| 611 | } |
| 612 | |
| 613 | IGNORE_TEST(UnitTestMacros, LONGS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 614 | { |
| 615 | LONGS_EQUAL_TEXT(11, 22, "Failed because it failed"); // LCOV_EXCL_LINE |
| 616 | } // LCOV_EXCL_LINE |
| 617 | |
| 618 | static void _failingTestMethodWithBYTES_EQUAL() |
| 619 | { |
| 620 | BYTES_EQUAL('a', 'b'); |
| 621 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 622 | } |
| 623 | |
| 624 | TEST(UnitTestMacros, FailureWithBYTES_EQUAL) |
| 625 | { |
| 626 | fixture.runTestWithMethod(_failingTestMethodWithBYTES_EQUAL); |
| 627 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <97 (0x61)>"); |
| 628 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <98 (0x62)>"); |
| 629 | } |
| 630 | |
| 631 | TEST(UnitTestMacros, BYTES_EQUALBehavesAsProperMacro) |
| 632 | { |
| 633 | if (false) BYTES_EQUAL('a', 'b'); |
| 634 | else BYTES_EQUAL('c', 'c'); |
| 635 | } |
| 636 | |
| 637 | IGNORE_TEST(UnitTestMacros, BYTES_EQUALWorksInAnIgnoredTest) |
| 638 | { |
| 639 | BYTES_EQUAL('q', 'w'); // LCOV_EXCL_LINE; |
| 640 | } // LCOV_EXCL_LINE |
| 641 | |
| 642 | static void _failingTestMethodWithBYTES_EQUAL_TEXT() |
| 643 | { |
| 644 | BYTES_EQUAL_TEXT('a', 'b', "Failed because it failed"); |
| 645 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 646 | } |
| 647 | |
| 648 | TEST(UnitTestMacros, FailureWithBYTES_EQUAL_TEXT) |
| 649 | { |
| 650 | fixture.runTestWithMethod(_failingTestMethodWithBYTES_EQUAL_TEXT); |
| 651 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <97 (0x61)>"); |
| 652 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <98 (0x62)>"); |
| 653 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 654 | } |
| 655 | |
| 656 | TEST(UnitTestMacros, BYTES_EQUAL_TEXTBehavesAsProperMacro) |
| 657 | { |
| 658 | if (false) BYTES_EQUAL_TEXT('a', 'b', "Failed because it failed"); |
| 659 | else BYTES_EQUAL_TEXT('c', 'c', "Failed because it failed"); |
| 660 | } |
| 661 | |
| 662 | IGNORE_TEST(UnitTestMacros, BYTES_EQUAL_TEXTWorksInAnIgnoredTest) |
| 663 | { |
| 664 | BYTES_EQUAL_TEXT('q', 'w', "Failed because it failed"); // LCOV_EXCL_LINE; |
| 665 | } // LCOV_EXCL_LINE |
| 666 | |
| 667 | static void _failingTestMethodWithSIGNED_BYTES_EQUAL() |
| 668 | { |
| 669 | SIGNED_BYTES_EQUAL(-1, -2); |
| 670 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 671 | } |
| 672 | |
| 673 | TEST(UnitTestMacros, FailureWithSIGNED_BYTES_EQUAL) |
| 674 | { |
| 675 | fixture.runTestWithMethod(_failingTestMethodWithSIGNED_BYTES_EQUAL); |
| 676 | #if CPPUTEST_CHAR_BIT == 16 |
| 677 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <-1 (0xffff)>"); |
| 678 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <-2 (0xfffe)>"); |
| 679 | #else |
| 680 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <-1 (0xff)>"); |
| 681 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <-2 (0xfe)>"); |
| 682 | #endif |
| 683 | } |
| 684 | |
| 685 | TEST(UnitTestMacros, CHARS_EQUALBehavesAsProperMacro) |
| 686 | { |
| 687 | if (false) SIGNED_BYTES_EQUAL(-1, -2); |
| 688 | else SIGNED_BYTES_EQUAL(-3, -3); |
| 689 | } |
| 690 | |
| 691 | IGNORE_TEST(UnitTestMacros, CHARS_EQUALWorksInAnIgnoredTest) |
| 692 | { |
| 693 | SIGNED_BYTES_EQUAL(-7, 19); // LCOV_EXCL_LINE; |
| 694 | } // LCOV_EXCL_LINE |
| 695 | |
| 696 | static void _failingTestMethodWithSIGNED_BYTES_EQUAL_TEXT() |
| 697 | { |
| 698 | SIGNED_BYTES_EQUAL_TEXT(-127, -126, "Failed because it failed"); |
| 699 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 700 | } |
| 701 | |
| 702 | TEST(UnitTestMacros, FailureWithSIGNED_BYTES_EQUAL_TEXT) |
| 703 | { |
| 704 | fixture.runTestWithMethod(_failingTestMethodWithSIGNED_BYTES_EQUAL_TEXT); |
| 705 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <-127 (0x81)>"); |
| 706 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <-126 (0x82)>"); |
| 707 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 708 | } |
| 709 | |
| 710 | TEST(UnitTestMacros, CHARS_EQUAL_TEXTBehavesAsProperMacro) |
| 711 | { |
| 712 | if (false) SIGNED_BYTES_EQUAL_TEXT(-1, -2, "Failed because it failed"); |
| 713 | else SIGNED_BYTES_EQUAL_TEXT(-3, -3, "Failed because it failed"); |
| 714 | } |
| 715 | |
| 716 | IGNORE_TEST(UnitTestMacros, SIGNED_BYTES_EQUAL_TEXTWorksInAnIgnoredTest) |
| 717 | { |
| 718 | SIGNED_BYTES_EQUAL_TEXT(-7, 19, "Failed because it failed"); // LCOV_EXCL_LINE |
| 719 | } // LCOV_EXCL_LINE |
| 720 | |
| 721 | static void _failingTestMethodWithPOINTERS_EQUAL() |
| 722 | { |
| 723 | POINTERS_EQUAL((void*)0xa5a5, (void*)0xf0f0); |
| 724 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 725 | } // LCOV_EXCL_LINE |
| 726 | |
| 727 | TEST(UnitTestMacros, FailureWithPOINTERS_EQUAL) |
| 728 | { |
| 729 | fixture.runTestWithMethod(_failingTestMethodWithPOINTERS_EQUAL); |
| 730 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0xa5a5>"); |
| 731 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0xf0f0>"); |
| 732 | } |
| 733 | |
| 734 | TEST(UnitTestMacros, POINTERS_EQUALBehavesAsProperMacro) |
| 735 | { |
| 736 | if (false) POINTERS_EQUAL(NULLPTR, to_void_pointer(0xbeefbeef)); |
| 737 | else POINTERS_EQUAL(to_void_pointer(0xdeadbeef), to_void_pointer(0xdeadbeef)); |
| 738 | } |
| 739 | |
| 740 | IGNORE_TEST(UnitTestMacros, POINTERS_EQUALWorksInAnIgnoredTest) |
| 741 | { |
| 742 | POINTERS_EQUAL((void*) 0xbeef, (void*) 0xdead); // LCOV_EXCL_LINE |
| 743 | } // LCOV_EXCL_LINE |
| 744 | |
| 745 | static void _failingTestMethodWithPOINTERS_EQUAL_TEXT() |
| 746 | { |
| 747 | POINTERS_EQUAL_TEXT((void*)0xa5a5, (void*)0xf0f0, "Failed because it failed"); |
| 748 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 749 | } // LCOV_EXCL_LINE |
| 750 | |
| 751 | TEST(UnitTestMacros, FailureWithPOINTERS_EQUAL_TEXT) |
| 752 | { |
| 753 | fixture.runTestWithMethod(_failingTestMethodWithPOINTERS_EQUAL_TEXT); |
| 754 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0xa5a5>"); |
| 755 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0xf0f0>"); |
| 756 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 757 | } |
| 758 | |
| 759 | TEST(UnitTestMacros, POINTERS_EQUAL_TEXTBehavesAsProperMacro) |
| 760 | { |
| 761 | if (false) POINTERS_EQUAL_TEXT(NULLPTR, to_void_pointer(0xbeefbeef), "Failed because it failed"); |
| 762 | else POINTERS_EQUAL_TEXT(to_void_pointer(0xdeadbeef), to_void_pointer(0xdeadbeef), "Failed because it failed"); |
| 763 | } |
| 764 | |
| 765 | IGNORE_TEST(UnitTestMacros, POINTERS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 766 | { |
| 767 | POINTERS_EQUAL_TEXT((void*) 0xbeef, (void*) 0xdead, "Failed because it failed"); // LCOV_EXCL_LINE |
| 768 | } // LCOV_EXCL_LINE |
| 769 | |
| 770 | |
| 771 | static void _failingTestMethodWithFUNCTIONPOINTERS_EQUAL() |
| 772 | { |
| 773 | FUNCTIONPOINTERS_EQUAL((void (*)())0xa5a5, (void (*)())0xf0f0); |
| 774 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 775 | } // LCOV_EXCL_LINE |
| 776 | |
| 777 | TEST(UnitTestMacros, FailureWithFUNCTIONPOINTERS_EQUAL) |
| 778 | { |
| 779 | fixture.runTestWithMethod(_failingTestMethodWithFUNCTIONPOINTERS_EQUAL); |
| 780 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0xa5a5>"); |
| 781 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0xf0f0>"); |
| 782 | } |
| 783 | |
| 784 | TEST(UnitTestMacros, FUNCTIONPOINTERS_EQUALBehavesAsProperMacro) |
| 785 | { |
| 786 | if (false) FUNCTIONPOINTERS_EQUAL(NULLPTR, to_func_pointer(0xbeefbeef)); |
| 787 | else FUNCTIONPOINTERS_EQUAL(to_func_pointer(0xdeadbeef), to_func_pointer(0xdeadbeef)); |
| 788 | } |
| 789 | |
| 790 | IGNORE_TEST(UnitTestMacros, FUNCTIONPOINTERS_EQUALWorksInAnIgnoredTest) |
| 791 | { |
| 792 | FUNCTIONPOINTERS_EQUAL((void (*)())0xbeef, (void (*)())0xdead); // LCOV_EXCL_LINE |
| 793 | } // LCOV_EXCL_LINE |
| 794 | |
| 795 | static void _failingTestMethodWithFUNCTIONPOINTERS_EQUAL_TEXT() |
| 796 | { |
| 797 | FUNCTIONPOINTERS_EQUAL_TEXT((void (*)())0xa5a5, (void (*)())0xf0f0, "Failed because it failed"); |
| 798 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 799 | } // LCOV_EXCL_LINE |
| 800 | |
| 801 | TEST(UnitTestMacros, FailureWithFUNCTIONPOINTERS_EQUAL_TEXT) |
| 802 | { |
| 803 | fixture.runTestWithMethod(_failingTestMethodWithFUNCTIONPOINTERS_EQUAL_TEXT); |
| 804 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0xa5a5>"); |
| 805 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0xf0f0>"); |
| 806 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 807 | } |
| 808 | |
| 809 | TEST(UnitTestMacros, FUNCTIONPOINTERS_EQUAL_TEXTBehavesAsProperMacro) |
| 810 | { |
| 811 | if (false) FUNCTIONPOINTERS_EQUAL_TEXT(NULLPTR, to_func_pointer(0xbeefbeef), "Failed because it failed"); |
| 812 | else FUNCTIONPOINTERS_EQUAL_TEXT(to_func_pointer(0xdeadbeef), to_func_pointer(0xdeadbeef), "Failed because it failed"); |
| 813 | } |
| 814 | |
| 815 | IGNORE_TEST(UnitTestMacros, FUNCTIONPOINTERS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 816 | { |
| 817 | FUNCTIONPOINTERS_EQUAL_TEXT((void (*)())0xbeef, (void (*)())0xdead, "Failed because it failed"); // LCOV_EXCL_LINE |
| 818 | } // LCOV_EXCL_LINE |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | static void _failingTestMethodWithDOUBLES_EQUAL() |
| 824 | { |
| 825 | DOUBLES_EQUAL(0.12, 44.1, 0.3); |
| 826 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 827 | } // LCOV_EXCL_LINE |
| 828 | |
| 829 | TEST(UnitTestMacros, FailureWithDOUBLES_EQUAL) |
| 830 | { |
| 831 | fixture.runTestWithMethod(_failingTestMethodWithDOUBLES_EQUAL); |
| 832 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0.12>"); |
| 833 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <44.1>"); |
| 834 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("threshold used was <0.3>"); |
| 835 | } |
| 836 | |
| 837 | TEST(UnitTestMacros, DOUBLES_EQUALBehavesAsProperMacro) |
| 838 | { |
| 839 | if (false) DOUBLES_EQUAL(0.0, 1.1, 0.0005); |
| 840 | else DOUBLES_EQUAL(0.1, 0.2, 0.2); |
| 841 | } |
| 842 | |
| 843 | IGNORE_TEST(UnitTestMacros, DOUBLES_EQUALWorksInAnIgnoredTest) |
| 844 | { |
| 845 | DOUBLES_EQUAL(100.0, 0.0, 0.2); // LCOV_EXCL_LINE; |
| 846 | } // LCOV_EXCL_LINE |
| 847 | |
| 848 | static void _failingTestMethodWithDOUBLES_EQUAL_TEXT() |
| 849 | { |
| 850 | DOUBLES_EQUAL_TEXT(0.12, 44.1, 0.3, "Failed because it failed"); |
| 851 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 852 | } // LCOV_EXCL_LINE |
| 853 | |
| 854 | TEST(UnitTestMacros, FailureWithDOUBLES_EQUAL_TEXT) |
| 855 | { |
| 856 | fixture.runTestWithMethod(_failingTestMethodWithDOUBLES_EQUAL_TEXT); |
| 857 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <0.12>"); |
| 858 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <44.1>"); |
| 859 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("threshold used was <0.3>"); |
| 860 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 861 | } |
| 862 | |
| 863 | TEST(UnitTestMacros, DOUBLES_EQUAL_TEXTBehavesAsProperMacro) |
| 864 | { |
| 865 | if (false) DOUBLES_EQUAL_TEXT(0.0, 1.1, 0.0005, "Failed because it failed"); |
| 866 | else DOUBLES_EQUAL_TEXT(0.1, 0.2, 0.2, "Failed because it failed"); |
| 867 | } |
| 868 | |
| 869 | IGNORE_TEST(UnitTestMacros, DOUBLES_EQUAL_TEXTWorksInAnIgnoredTest) |
| 870 | { |
| 871 | DOUBLES_EQUAL_TEXT(100.0, 0.0, 0.2, "Failed because it failed"); // LCOV_EXCL_LINE |
| 872 | } // LCOV_EXCL_LINE |
| 873 | |
| 874 | static bool lineOfCodeExecutedAfterCheck = false; |
| 875 | |
| 876 | static void _passingTestMethod() |
| 877 | { |
| 878 | CHECK(true); |
| 879 | lineOfCodeExecutedAfterCheck = true; |
| 880 | } |
| 881 | |
| 882 | TEST(UnitTestMacros, SuccessPrintsNothing) |
| 883 | { |
| 884 | fixture.runTestWithMethod(_passingTestMethod); |
| 885 | |
| 886 | LONGS_EQUAL(0, fixture.getFailureCount()); |
| 887 | fixture.assertPrintContains(".\nOK (1 tests"); |
| 888 | CHECK(lineOfCodeExecutedAfterCheck); |
| 889 | } |
| 890 | |
| 891 | static void _methodThatOnlyPrints() |
| 892 | { |
| 893 | UT_PRINT("Hello World!"); |
| 894 | } |
| 895 | |
| 896 | TEST(UnitTestMacros, PrintPrintsWhateverPrintPrints) |
| 897 | { |
| 898 | fixture.runTestWithMethod(_methodThatOnlyPrints); |
| 899 | |
| 900 | LONGS_EQUAL(0, fixture.getFailureCount()); |
| 901 | fixture.assertPrintContains("Hello World!"); |
| 902 | fixture.assertPrintContains(__FILE__); |
| 903 | } |
| 904 | |
| 905 | static void _methodThatOnlyPrintsUsingSimpleStringFromFormat() |
| 906 | { |
| 907 | UT_PRINT(StringFromFormat("Hello %s %d", "World!", 2009)); |
| 908 | } |
| 909 | |
| 910 | TEST(UnitTestMacros, PrintPrintsSimpleStringsForExampleThoseReturnedByFromString) |
| 911 | { |
| 912 | fixture.runTestWithMethod(_methodThatOnlyPrintsUsingSimpleStringFromFormat); |
| 913 | fixture.assertPrintContains("Hello World! 2009"); |
| 914 | } |
| 915 | |
| 916 | static int functionThatReturnsAValue() |
| 917 | { |
| 918 | CHECK(0 == 0); |
| 919 | CHECK_TEXT(0 == 0, "Shouldn't fail"); |
| 920 | CHECK_TRUE(0 == 0); |
| 921 | CHECK_TRUE_TEXT(0 == 0, "Shouldn't fail"); |
| 922 | CHECK_FALSE(0 != 0); |
| 923 | CHECK_FALSE_TEXT(0 != 0, "Shouldn't fail"); |
| 924 | LONGS_EQUAL(1,1); |
| 925 | LONGS_EQUAL_TEXT(1, 1, "Shouldn't fail"); |
| 926 | BYTES_EQUAL(0xab,0xab); |
| 927 | BYTES_EQUAL_TEXT(0xab, 0xab, "Shouldn't fail"); |
| 928 | CHECK_EQUAL(100,100); |
| 929 | CHECK_EQUAL_TEXT(100, 100, "Shouldn't fail"); |
| 930 | STRCMP_EQUAL("THIS", "THIS"); |
| 931 | STRCMP_EQUAL_TEXT("THIS", "THIS", "Shouldn't fail"); |
| 932 | DOUBLES_EQUAL(1.0, 1.0, .01); |
| 933 | DOUBLES_EQUAL_TEXT(1.0, 1.0, .01, "Shouldn't fail"); |
| 934 | POINTERS_EQUAL(NULLPTR, NULLPTR); |
| 935 | POINTERS_EQUAL_TEXT(NULLPTR, NULLPTR, "Shouldn't fail"); |
| 936 | MEMCMP_EQUAL("THIS", "THIS", 5); |
| 937 | MEMCMP_EQUAL_TEXT("THIS", "THIS", 5, "Shouldn't fail"); |
| 938 | BITS_EQUAL(0x01, (unsigned char )0x01, 0xFF); |
| 939 | BITS_EQUAL(0x0001, (unsigned short )0x0001, 0xFFFF); |
| 940 | BITS_EQUAL(0x00000001, (unsigned long )0x00000001, 0xFFFFFFFF); |
| 941 | BITS_EQUAL_TEXT(0x01, (unsigned char )0x01, 0xFF, "Shouldn't fail"); |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | TEST(UnitTestMacros, allMacrosFromFunctionThatReturnsAValue) |
| 946 | { |
| 947 | functionThatReturnsAValue(); |
| 948 | } |
| 949 | |
| 950 | TEST(UnitTestMacros, MEMCMP_EQUALBehavesAsAProperMacro) |
| 951 | { |
| 952 | if (false) MEMCMP_EQUAL("TEST", "test", 5); |
| 953 | else MEMCMP_EQUAL("TEST", "TEST", 5); |
| 954 | } |
| 955 | |
| 956 | IGNORE_TEST(UnitTestMacros, MEMCMP_EQUALWorksInAnIgnoredTest) |
| 957 | { |
| 958 | MEMCMP_EQUAL("TEST", "test", 5); // LCOV_EXCL_LINE |
| 959 | } // LCOV_EXCL_LINE |
| 960 | |
| 961 | static void _MEMCMP_EQUALFailingTestMethodWithUnequalInput() |
| 962 | { |
| 963 | unsigned char expectedData[] = { 0x00, 0x01, 0x02, 0x03 }; |
| 964 | unsigned char actualData[] = { 0x00, 0x01, 0x03, 0x03 }; |
| 965 | |
| 966 | MEMCMP_EQUAL(expectedData, actualData, sizeof(expectedData)); |
| 967 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 968 | } // LCOV_EXCL_LINE |
| 969 | |
| 970 | TEST(UnitTestMacros, MEMCMP_EQUALFailureWithUnequalInput) |
| 971 | { |
| 972 | fixture.runTestWithMethod(_MEMCMP_EQUALFailingTestMethodWithUnequalInput); |
| 973 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <00 01 02 03>"); |
| 974 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <00 01 03 03>"); |
| 975 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("difference starts at position 2"); |
| 976 | } |
| 977 | |
| 978 | static void _MEMCMP_EQUALFailingTestMethodWithNullExpected() |
| 979 | { |
| 980 | unsigned char actualData[] = { 0x00, 0x01, 0x02, 0x03 }; |
| 981 | |
| 982 | MEMCMP_EQUAL(NULLPTR, actualData, sizeof(actualData)); |
| 983 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 984 | } // LCOV_EXCL_LINE |
| 985 | |
| 986 | TEST(UnitTestMacros, MEMCMP_EQUALFailureWithNullExpected) |
| 987 | { |
| 988 | fixture.runTestWithMethod(_MEMCMP_EQUALFailingTestMethodWithNullExpected); |
| 989 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <(null)>"); |
| 990 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <00 01 02 03>"); |
| 991 | } |
| 992 | |
| 993 | static void _MEMCMP_EQUALFailingTestMethodWithNullActual() |
| 994 | { |
| 995 | unsigned char expectedData[] = { 0x00, 0x01, 0x02, 0x03 }; |
| 996 | |
| 997 | MEMCMP_EQUAL(expectedData, NULLPTR, sizeof(expectedData)); |
| 998 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 999 | } // LCOV_EXCL_LINE |
| 1000 | |
| 1001 | TEST(UnitTestMacros, MEMCMP_EQUALFailureWithNullActual) |
| 1002 | { |
| 1003 | fixture.runTestWithMethod(_MEMCMP_EQUALFailingTestMethodWithNullActual); |
| 1004 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <00 01 02 03>"); |
| 1005 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <(null)>"); |
| 1006 | } |
| 1007 | |
| 1008 | TEST(UnitTestMacros, MEMCMP_EQUALNullExpectedNullActual) |
| 1009 | { |
| 1010 | MEMCMP_EQUAL(NULLPTR, NULLPTR, 0); |
| 1011 | MEMCMP_EQUAL(NULLPTR, NULLPTR, 1024); |
| 1012 | } |
| 1013 | |
| 1014 | TEST(UnitTestMacros, MEMCMP_EQUALNullPointerIgnoredInExpectationWhenSize0) |
| 1015 | { |
| 1016 | unsigned char actualData[] = { 0x00, 0x01, 0x03, 0x03 }; |
| 1017 | MEMCMP_EQUAL(NULLPTR, actualData, 0); |
| 1018 | } |
| 1019 | |
| 1020 | TEST(UnitTestMacros, MEMCMP_EQUALNullPointerIgnoredInActualWhenSize0) |
| 1021 | { |
| 1022 | unsigned char expectedData[] = { 0x00, 0x01, 0x02, 0x03 }; |
| 1023 | MEMCMP_EQUAL(expectedData, NULLPTR, 0); |
| 1024 | } |
| 1025 | |
| 1026 | static void _failingTestMethodWithMEMCMP_EQUAL_TEXT() |
| 1027 | { |
| 1028 | unsigned char expectedData[] = { 0x00, 0x01, 0x02, 0x03 }; |
| 1029 | unsigned char actualData[] = { 0x00, 0x01, 0x03, 0x03 }; |
| 1030 | |
| 1031 | MEMCMP_EQUAL_TEXT(expectedData, actualData, sizeof(expectedData), "Failed because it failed"); |
| 1032 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1033 | } // LCOV_EXCL_LINE |
| 1034 | |
| 1035 | TEST(UnitTestMacros, FailureWithMEMCMP_EQUAL_TEXT) |
| 1036 | { |
| 1037 | fixture.runTestWithMethod(_failingTestMethodWithMEMCMP_EQUAL_TEXT); |
| 1038 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <00 01 02 03>"); |
| 1039 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <00 01 03 03>"); |
| 1040 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("difference starts at position 2"); |
| 1041 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 1042 | } |
| 1043 | |
| 1044 | TEST(UnitTestMacros, MEMCMP_EQUAL_TEXTBehavesAsAProperMacro) |
| 1045 | { |
| 1046 | if (false) MEMCMP_EQUAL_TEXT("TEST", "test", 5, "Failed because it failed"); |
| 1047 | else MEMCMP_EQUAL_TEXT("TEST", "TEST", 5, "Failed because it failed"); |
| 1048 | } |
| 1049 | |
| 1050 | IGNORE_TEST(UnitTestMacros, MEMCMP_EQUAL_TEXTWorksInAnIgnoredTest) |
| 1051 | { |
| 1052 | MEMCMP_EQUAL_TEXT("TEST", "test", 5, "Failed because it failed"); // LCOV_EXCL_LINE |
| 1053 | } // LCOV_EXCL_LINE |
| 1054 | |
| 1055 | TEST(UnitTestMacros, BITS_EQUALBehavesAsAProperMacro) |
| 1056 | { |
| 1057 | if (false) BITS_EQUAL(0x00, 0xFF, 0xFF); |
| 1058 | else BITS_EQUAL(0x00, 0x00, 0xFF); |
| 1059 | } |
| 1060 | |
| 1061 | IGNORE_TEST(UnitTestMacros, BITS_EQUALWorksInAnIgnoredTest) |
| 1062 | { |
| 1063 | BITS_EQUAL(0x00, 0xFF, 0xFF); // LCOV_EXCL_LINE |
| 1064 | } // LCOV_EXCL_LINE |
| 1065 | |
| 1066 | static void _BITS_EQUALFailingTestMethodWithUnequalInput() |
| 1067 | { |
| 1068 | BITS_EQUAL(0x00, 0xFF, 0xFF); |
| 1069 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1070 | } // LCOV_EXCL_LINE |
| 1071 | |
| 1072 | TEST(UnitTestMacros, BITS_EQUALFailureWithUnequalInput) |
| 1073 | { |
| 1074 | fixture.runTestWithMethod(_BITS_EQUALFailingTestMethodWithUnequalInput); |
| 1075 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("00000000>"); |
| 1076 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("11111111>"); |
| 1077 | } |
| 1078 | |
| 1079 | TEST(UnitTestMacros, BITS_EQUALZeroMaskEqual) |
| 1080 | { |
| 1081 | BITS_EQUAL(0x00, 0xFF, 0x00); |
| 1082 | } |
| 1083 | |
| 1084 | static void _failingTestMethodWithBITS_EQUAL_TEXT() |
| 1085 | { |
| 1086 | BITS_EQUAL_TEXT(0x00, 0xFFFFFFFF, 0xFF, "Failed because it failed"); |
| 1087 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1088 | } // LCOV_EXCL_LINE |
| 1089 | |
| 1090 | TEST(UnitTestMacros, FailureWithBITS_EQUAL_TEXT) |
| 1091 | { |
| 1092 | fixture.runTestWithMethod(_failingTestMethodWithBITS_EQUAL_TEXT); |
| 1093 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <xxxxxxxx xxxxxxxx xxxxxxxx 00000000>"); |
| 1094 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <xxxxxxxx xxxxxxxx xxxxxxxx 11111111>"); |
| 1095 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 1096 | } |
| 1097 | |
| 1098 | TEST(UnitTestMacros, BITS_EQUAL_TEXTBehavesAsAProperMacro) |
| 1099 | { |
| 1100 | if (false) BITS_EQUAL_TEXT(0x00, 0xFF, 0xFF, "Failed because it failed"); |
| 1101 | else BITS_EQUAL_TEXT(0x00, 0x00, 0xFF, "Failed because it failed"); |
| 1102 | } |
| 1103 | |
| 1104 | IGNORE_TEST(UnitTestMacros, BITS_EQUAL_TEXTWorksInAnIgnoredTest) |
| 1105 | { |
| 1106 | BITS_EQUAL_TEXT(0x00, 0xFF, 0xFF, "Failed because it failed"); // LCOV_EXCL_LINE |
| 1107 | } // LCOV_EXCL_LINE |
| 1108 | |
| 1109 | #if defined(__cplusplus) && __cplusplus >= 201103L |
| 1110 | enum class ScopedIntEnum { |
| 1111 | A, B |
| 1112 | }; |
| 1113 | |
| 1114 | static void _ENUMS_EQUAL_INTWithScopedIntEnumTestMethod() |
| 1115 | { |
| 1116 | ENUMS_EQUAL_INT(ScopedIntEnum::B, ScopedIntEnum::B); |
| 1117 | ENUMS_EQUAL_INT(ScopedIntEnum::B, ScopedIntEnum::A); |
| 1118 | } // LCOV_EXCL_LINE |
| 1119 | |
| 1120 | TEST(UnitTestMacros, TestENUMS_EQUAL_INTWithScopedIntEnum) |
| 1121 | { |
| 1122 | fixture.runTestWithMethod(_ENUMS_EQUAL_INTWithScopedIntEnumTestMethod); |
| 1123 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1124 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1125 | } |
| 1126 | |
| 1127 | TEST(UnitTestMacros, ENUMS_EQUAL_INTWithScopedIntEnumBehavesAsProperMacro) |
| 1128 | { |
| 1129 | if (false) ENUMS_EQUAL_INT(ScopedIntEnum::B, ScopedIntEnum::A); |
| 1130 | else ENUMS_EQUAL_INT(ScopedIntEnum::B, ScopedIntEnum::B); |
| 1131 | } |
| 1132 | |
| 1133 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_INTWithScopedIntEnumWorksInAnIgnoredTest) |
| 1134 | { |
| 1135 | ENUMS_EQUAL_INT(ScopedIntEnum::B, ScopedIntEnum::A); // LCOV_EXCL_LINE |
| 1136 | } // LCOV_EXCL_LINE |
| 1137 | |
| 1138 | static void _ENUMS_EQUAL_INT_TEXTWithScopedIntEnumTestMethod() |
| 1139 | { |
| 1140 | ENUMS_EQUAL_INT_TEXT(ScopedIntEnum::B, ScopedIntEnum::A, "Failed because it failed"); |
| 1141 | } // LCOV_EXCL_LINE |
| 1142 | |
| 1143 | TEST(UnitTestMacros, TestENUMS_EQUAL_INT_TEXTWithScopedIntEnum) |
| 1144 | { |
| 1145 | fixture.runTestWithMethod(_ENUMS_EQUAL_INT_TEXTWithScopedIntEnumTestMethod); |
| 1146 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1147 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1148 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 1149 | } |
| 1150 | |
| 1151 | TEST(UnitTestMacros, ENUMS_EQUAL_INT_TEXTWithScopedIntEnumBehavesAsProperMacro) |
| 1152 | { |
| 1153 | if (false) ENUMS_EQUAL_INT_TEXT(ScopedIntEnum::B, ScopedIntEnum::A, "Failed because it failed"); |
| 1154 | else ENUMS_EQUAL_INT_TEXT(ScopedIntEnum::B, ScopedIntEnum::B, "Failed because it failed"); |
| 1155 | } |
| 1156 | |
| 1157 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_EQUAL_INT_TEXTWithScopedIntEnumWorksInAnIgnoredTest) |
| 1158 | { |
| 1159 | ENUMS_EQUAL_INT_TEXT(ScopedIntEnum::B, ScopedIntEnum::A, "Failed because it failed"); // LCOV_EXCL_LINE |
| 1160 | } // LCOV_EXCL_LINE |
| 1161 | |
| 1162 | enum class ScopedLongEnum : long { |
| 1163 | A, B |
| 1164 | }; |
| 1165 | |
| 1166 | static void _ENUMS_EQUAL_TYPEWithScopedLongEnumTestMethod() |
| 1167 | { |
| 1168 | ENUMS_EQUAL_TYPE(long, ScopedLongEnum::B, ScopedLongEnum::B); |
| 1169 | ENUMS_EQUAL_TYPE(long, ScopedLongEnum::B, ScopedLongEnum::A); |
| 1170 | } // LCOV_EXCL_LINE |
| 1171 | |
| 1172 | TEST(UnitTestMacros, TestENUMS_EQUAL_TYPEWithScopedLongEnum) |
| 1173 | { |
| 1174 | fixture.runTestWithMethod(_ENUMS_EQUAL_TYPEWithScopedLongEnumTestMethod); |
| 1175 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1176 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1177 | } |
| 1178 | |
| 1179 | TEST(UnitTestMacros, ENUMS_EQUAL_TYPEWithScopedLongEnumBehavesAsProperMacro) |
| 1180 | { |
| 1181 | if (false) ENUMS_EQUAL_TYPE(long, ScopedLongEnum::B, ScopedLongEnum::A); |
| 1182 | else ENUMS_EQUAL_TYPE(long, ScopedLongEnum::B, ScopedLongEnum::B); |
| 1183 | } |
| 1184 | |
| 1185 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_TYPEWithScopedLongEnumWorksInAnIgnoredTest) |
| 1186 | { |
| 1187 | ENUMS_EQUAL_TYPE(long, ScopedLongEnum::B, ScopedLongEnum::A); // LCOV_EXCL_LINE |
| 1188 | } // LCOV_EXCL_LINE |
| 1189 | |
| 1190 | static void _ENUMS_EQUAL_TYPE_TEXTWithScopedLongEnumTestMethod() |
| 1191 | { |
| 1192 | ENUMS_EQUAL_TYPE_TEXT(long, ScopedLongEnum::B, ScopedLongEnum::A, "Failed because it failed"); |
| 1193 | } // LCOV_EXCL_LINE |
| 1194 | |
| 1195 | TEST(UnitTestMacros, TestENUMS_EQUAL_TYPE_TEXTWithScopedLongEnum) |
| 1196 | { |
| 1197 | fixture.runTestWithMethod(_ENUMS_EQUAL_TYPE_TEXTWithScopedLongEnumTestMethod); |
| 1198 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1199 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1200 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 1201 | } |
| 1202 | |
| 1203 | TEST(UnitTestMacros, ENUMS_EQUAL_TYPE_TEXTWithScopedLongEnumBehavesAsProperMacro) |
| 1204 | { |
| 1205 | if (false) ENUMS_EQUAL_TYPE_TEXT(long, ScopedLongEnum::B, ScopedLongEnum::A, "Failed because it failed"); |
| 1206 | else ENUMS_EQUAL_TYPE_TEXT(long, ScopedLongEnum::B, ScopedLongEnum::B, "Failed because it failed"); |
| 1207 | } |
| 1208 | |
| 1209 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_EQUAL_TYPE_TEXTWithScopedLongEnumWorksInAnIgnoredTest) |
| 1210 | { |
| 1211 | ENUMS_EQUAL_TYPE_TEXT(long, ScopedLongEnum::B, ScopedLongEnum::A, "Failed because it failed"); // LCOV_EXCL_LINE |
| 1212 | } // LCOV_EXCL_LINE |
| 1213 | |
| 1214 | #endif |
| 1215 | |
| 1216 | enum UnscopedEnum { |
| 1217 | UNSCOPED_ENUM_A, UNSCOPED_ENUM_B |
| 1218 | }; |
| 1219 | |
| 1220 | static void _ENUMS_EQUAL_INTWithUnscopedEnumTestMethod() |
| 1221 | { |
| 1222 | ENUMS_EQUAL_INT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_B); |
| 1223 | ENUMS_EQUAL_INT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A); |
| 1224 | } // LCOV_EXCL_LINE |
| 1225 | |
| 1226 | TEST(UnitTestMacros, TestENUMS_EQUAL_INTWithUnscopedEnum) |
| 1227 | { |
| 1228 | fixture.runTestWithMethod(_ENUMS_EQUAL_INTWithUnscopedEnumTestMethod); |
| 1229 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1230 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1231 | } |
| 1232 | |
| 1233 | TEST(UnitTestMacros, ENUMS_EQUAL_INTWithUnscopedEnumBehavesAsProperMacro) |
| 1234 | { |
| 1235 | if (false) ENUMS_EQUAL_INT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A); |
| 1236 | else ENUMS_EQUAL_INT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_B); |
| 1237 | } |
| 1238 | |
| 1239 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_INTWithUnscopedEnumWorksInAnIgnoredTest) |
| 1240 | { |
| 1241 | ENUMS_EQUAL_INT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A); // LCOV_EXCL_LINE |
| 1242 | } // LCOV_EXCL_LINE |
| 1243 | |
| 1244 | static void _ENUMS_EQUAL_INT_TEXTWithUnscopedEnumTestMethod() |
| 1245 | { |
| 1246 | ENUMS_EQUAL_INT_TEXT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A, "Failed because it failed"); |
| 1247 | } // LCOV_EXCL_LINE |
| 1248 | |
| 1249 | TEST(UnitTestMacros, TestENUMS_EQUAL_INT_TEXTWithUnscopedEnum) |
| 1250 | { |
| 1251 | fixture.runTestWithMethod(_ENUMS_EQUAL_INT_TEXTWithUnscopedEnumTestMethod); |
| 1252 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected <1>"); |
| 1253 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but was <0>"); |
| 1254 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Failed because it failed"); |
| 1255 | } |
| 1256 | |
| 1257 | TEST(UnitTestMacros, ENUMS_EQUAL_INT_TEXTWithUnscopedEnumBehavesAsProperMacro) |
| 1258 | { |
| 1259 | if (false) ENUMS_EQUAL_INT_TEXT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A, "Failed because it failed"); |
| 1260 | else ENUMS_EQUAL_INT_TEXT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_B, "Failed because it failed"); |
| 1261 | } |
| 1262 | |
| 1263 | IGNORE_TEST(UnitTestMacros, ENUMS_EQUAL_EQUAL_INT_TEXTWithUnscopedEnumWorksInAnIgnoredTest) |
| 1264 | { |
| 1265 | ENUMS_EQUAL_INT_TEXT(UNSCOPED_ENUM_B, UNSCOPED_ENUM_A, "Failed because it failed"); // LCOV_EXCL_LINE |
| 1266 | } // LCOV_EXCL_LINE |
| 1267 | |
| 1268 | #if CPPUTEST_USE_STD_CPP_LIB |
| 1269 | static void _failingTestMethod_NoThrowWithCHECK_THROWS() |
| 1270 | { |
| 1271 | CHECK_THROWS(int, (void) (1+2)); |
| 1272 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1273 | } // LCOV_EXCL_LINE |
| 1274 | |
| 1275 | TEST(UnitTestMacros, FailureWithCHECK_THROWS_whenDoesntThrow) |
| 1276 | { |
| 1277 | fixture.runTestWithMethod(_failingTestMethod_NoThrowWithCHECK_THROWS); |
| 1278 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected to throw int"); |
| 1279 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but threw nothing"); |
| 1280 | LONGS_EQUAL(1, fixture.getCheckCount()); |
| 1281 | } |
| 1282 | |
| 1283 | static void _succeedingTestMethod_CorrectThrowWithCHECK_THROWS() |
| 1284 | { |
| 1285 | CHECK_THROWS(int, throw 4); |
| 1286 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1287 | } |
| 1288 | |
| 1289 | TEST(UnitTestMacros, SuccessWithCHECK_THROWS) |
| 1290 | { |
| 1291 | fixture.runTestWithMethod(_succeedingTestMethod_CorrectThrowWithCHECK_THROWS); |
| 1292 | LONGS_EQUAL(1, fixture.getCheckCount()); |
| 1293 | } |
| 1294 | |
| 1295 | static void _failingTestMethod_WrongThrowWithCHECK_THROWS() |
| 1296 | { |
| 1297 | CHECK_THROWS(int, throw 4.3); |
| 1298 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 1299 | } // LCOV_EXCL_LINE |
| 1300 | |
| 1301 | TEST(UnitTestMacros, FailureWithCHECK_THROWS_whenWrongThrow) |
| 1302 | { |
| 1303 | fixture.runTestWithMethod(_failingTestMethod_WrongThrowWithCHECK_THROWS); |
| 1304 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("expected to throw int"); |
| 1305 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("but threw a different type"); |
| 1306 | LONGS_EQUAL(1, fixture.getCheckCount()); |
| 1307 | } |
| 1308 | |
| 1309 | TEST(UnitTestMacros, MultipleCHECK_THROWS_inOneScope) |
| 1310 | { |
| 1311 | CHECK_THROWS(int, throw 4); |
| 1312 | CHECK_THROWS(int, throw 4); |
| 1313 | } |
| 1314 | #endif |