| 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 | #include "CppUTestExt/MockCheckedActualCall.h" |
| 32 | #include "CppUTestExt/MockCheckedExpectedCall.h" |
| 33 | #include "CppUTestExt/MockExpectedCallsList.h" |
| 34 | #include "CppUTestExt/MockFailure.h" |
| 35 | #include "MockFailureReporterForTest.h" |
| 36 | |
| 37 | |
| 38 | TEST_GROUP(FakeLongLongs) |
| 39 | { |
| 40 | TestTestingFixture fixture; |
| 41 | }; |
| 42 | |
| 43 | #ifndef CPPUTEST_USE_LONG_LONG |
| 44 | |
| 45 | #define CHECK_TEST_FAILS_PROPER_WITH_TEXT(text) fixture.checkTestFailsWithProperTestLocation(text, __FILE__, __LINE__) |
| 46 | |
| 47 | static void _actualCallWithFakeLongLongParameter() |
| 48 | { |
| 49 | cpputest_longlong value = {0}; |
| 50 | |
| 51 | mock().expectOneCall("foo").withParameter("bar", 0); |
| 52 | mock().actualCall("foo").withParameter("bar", value); |
| 53 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 54 | } // LCOV_EXCL_LINE |
| 55 | |
| 56 | TEST(FakeLongLongs, ActualCallWithFakeLongLongParameterFAILS) |
| 57 | { |
| 58 | fixture.runTestWithMethod(_actualCallWithFakeLongLongParameter); |
| 59 | mock().clear(); |
| 60 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Long Long type is not supported"); |
| 61 | } |
| 62 | |
| 63 | static void _actualCallWithFakeUnsignedLongLongParameter() |
| 64 | { |
| 65 | cpputest_ulonglong value = {0}; |
| 66 | |
| 67 | mock().expectOneCall("foo").withParameter("bar", 0); |
| 68 | mock().actualCall("foo").withParameter("bar", value); |
| 69 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 70 | } // LCOV_EXCL_LINE |
| 71 | |
| 72 | TEST(FakeLongLongs, ActualCallWithFakeUnsignedLongLongParameterFAILS) |
| 73 | { |
| 74 | fixture.runTestWithMethod(_actualCallWithFakeUnsignedLongLongParameter); |
| 75 | mock().clear(); |
| 76 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Unsigned Long Long type is not supported"); |
| 77 | } |
| 78 | |
| 79 | static void _actualCallWithFakeLongLongReturn() |
| 80 | { |
| 81 | mock().expectOneCall("foo").andReturnValue(0); |
| 82 | mock().actualCall("foo").returnLongLongIntValue(); |
| 83 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 84 | } // LCOV_EXCL_LINE |
| 85 | |
| 86 | TEST(FakeLongLongs, ActualCallWithFakeLongLongReturnFAILS) |
| 87 | { |
| 88 | fixture.runTestWithMethod(_actualCallWithFakeLongLongReturn); |
| 89 | mock().clear(); |
| 90 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Long Long type is not supported"); |
| 91 | } |
| 92 | |
| 93 | static void _actualCallWithFakeUnsignedLongLongReturn() |
| 94 | { |
| 95 | mock().expectOneCall("foo").andReturnValue(0); |
| 96 | mock().actualCall("foo").returnUnsignedLongLongIntValue(); |
| 97 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 98 | } // LCOV_EXCL_LINE |
| 99 | |
| 100 | TEST(FakeLongLongs, ActualCallWithFakeUnsignedLongLongReturnFAILS) |
| 101 | { |
| 102 | fixture.runTestWithMethod(_actualCallWithFakeUnsignedLongLongReturn); |
| 103 | mock().clear(); |
| 104 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Unsigned Long Long type is not supported"); |
| 105 | } |
| 106 | |
| 107 | static void _expectOneCallWithFakeLongLongParameter() |
| 108 | { |
| 109 | cpputest_longlong value = {0}; |
| 110 | |
| 111 | mock().expectOneCall("foo").withParameter("bar", value); |
| 112 | mock().actualCall("foo").withParameter("bar", 0); |
| 113 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 114 | } // LCOV_EXCL_LINE |
| 115 | |
| 116 | TEST(FakeLongLongs, ExpectedCallWithFakeLongLongParameterFAILS) |
| 117 | { |
| 118 | fixture.runTestWithMethod(_expectOneCallWithFakeLongLongParameter); |
| 119 | mock().clear(); |
| 120 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Long Long type is not supported"); |
| 121 | } |
| 122 | |
| 123 | static void _expectOneCallWithFakeUnsignedLongLongParameter() |
| 124 | { |
| 125 | cpputest_ulonglong value = {0}; |
| 126 | |
| 127 | mock().expectOneCall("foo").withParameter("bar", value); |
| 128 | mock().actualCall("foo").withParameter("bar", 0); |
| 129 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 130 | } // LCOV_EXCL_LINE |
| 131 | |
| 132 | TEST(FakeLongLongs, ExpectedCallWithFakeUnsignedLongLongParameterFAILS) |
| 133 | { |
| 134 | fixture.runTestWithMethod(_expectOneCallWithFakeUnsignedLongLongParameter); |
| 135 | mock().clear(); |
| 136 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Unsigned Long Long type is not supported"); |
| 137 | } |
| 138 | |
| 139 | static void _expectOneCallWithFakeLongLongReturn() |
| 140 | { |
| 141 | cpputest_longlong value = {0}; |
| 142 | |
| 143 | mock().expectOneCall("foo").andReturnValue(value); |
| 144 | mock().actualCall("foo").returnIntValue(); |
| 145 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 146 | } // LCOV_EXCL_LINE |
| 147 | |
| 148 | TEST(FakeLongLongs, ExpectedCallWithFakeLongLongReturnFAILS) |
| 149 | { |
| 150 | fixture.runTestWithMethod(_expectOneCallWithFakeLongLongReturn); |
| 151 | mock().clear(); |
| 152 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Long Long type is not supported"); |
| 153 | } |
| 154 | |
| 155 | static void _expectOneCallWithFakeUnsignedLongLongReturn() |
| 156 | { |
| 157 | cpputest_ulonglong value = {0}; |
| 158 | |
| 159 | mock().expectOneCall("foo").andReturnValue(value); |
| 160 | mock().actualCall("foo").returnIntValue(); |
| 161 | TestTestingFixture::lineExecutedAfterCheck(); // LCOV_EXCL_LINE |
| 162 | } // LCOV_EXCL_LINE |
| 163 | |
| 164 | TEST(FakeLongLongs, ExpectedCallWithFakeUnsignedLongLongReturnFAILS) |
| 165 | { |
| 166 | fixture.runTestWithMethod(_expectOneCallWithFakeUnsignedLongLongReturn); |
| 167 | mock().clear(); |
| 168 | CHECK_TEST_FAILS_PROPER_WITH_TEXT("Unsigned Long Long type is not supported"); |
| 169 | } |
| 170 | |
| 171 | #endif |