|
3 | 3 | #include "multiple_translation_units_stub.h" |
4 | 4 |
|
5 | 5 | using namespace fakeit; |
| 6 | +using namespace multiple_tu; |
6 | 7 |
|
7 | 8 | struct MultipleTranslationUnitsStub : tpunit::TestFixture { |
8 | | - MultipleTranslationUnitsStub() |
9 | | - : tpunit::TestFixture( |
10 | | - TEST(MultipleTranslationUnitsStub::NoCollidingIds) |
11 | | - ) |
12 | | - {} |
13 | 9 |
|
14 | | - void NoCollidingIds() { |
| 10 | + MultipleTranslationUnitsStub() : |
| 11 | + tpunit::TestFixture( |
| 12 | + TEST(MultipleTranslationUnitsStub::NoCollidingIdsBasics), |
| 13 | + TEST(MultipleTranslationUnitsStub::NoCollidingIdsAlternateBasics), |
| 14 | + TEST(MultipleTranslationUnitsStub::NoCollidingIdsMoreFunctionsMocked), |
| 15 | + TEST(MultipleTranslationUnitsStub::NoCollidingIdsWhenOverridingMocks) |
| 16 | + ) |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + void NoCollidingIdsBasics() |
| 21 | + { |
| 22 | + Mock<SomeInterface> mock; |
| 23 | + |
| 24 | + stubFunc(mock); |
| 25 | + When(Method(mock, func2)).Return("Something"); |
| 26 | + |
| 27 | + SomeInterface &i = mock.get(); |
| 28 | + |
| 29 | + // Uncatchable write access violation if ids collide. |
| 30 | + EXPECT_EQUAL(i.func(5), 5); |
| 31 | + EXPECT_EQUAL(i.func2(5), "Something"); |
| 32 | + |
| 33 | + Verify(Method(mock, func).Using(5)).Exactly(1); |
| 34 | + Verify(Method(mock, func2).Using(5)).Exactly(1); |
| 35 | + } |
| 36 | + |
| 37 | + void NoCollidingIdsAlternateBasics() |
| 38 | + { |
| 39 | + Mock<SomeInterface> mock; |
| 40 | + |
| 41 | + When(Method(mock, func)).Return(100); |
| 42 | + stubFunc2(mock); |
| 43 | + |
| 44 | + SomeInterface &i = mock.get(); |
| 45 | + |
| 46 | + // Uncatchable write access violation if ids collide. |
| 47 | + EXPECT_EQUAL(i.func(5), 100); |
| 48 | + EXPECT_EQUAL(i.func2(5), "String"); |
| 49 | + |
| 50 | + Verify(Method(mock, func).Using(5)).Exactly(1); |
| 51 | + Verify(Method(mock, func2).Using(5)).Exactly(1); |
| 52 | + } |
| 53 | + |
| 54 | + void NoCollidingIdsMoreFunctionsMocked() |
| 55 | + { |
15 | 56 | Mock<SomeInterface> mock; |
| 57 | + |
| 58 | + stubFunc(mock); |
| 59 | + stubFunc2(mock); |
| 60 | + |
| 61 | + When(Method(mock, func).Using(20)).Return(20); |
| 62 | + When(Method(mock, func).Using(50)).Return(50); |
| 63 | + |
| 64 | + When(Method(mock, func2).Using(20)).Return("Something-20"); |
| 65 | + When(Method(mock, func2).Using(50)).Return("Something-50"); |
| 66 | + |
| 67 | + stubMoreFunc(mock); |
| 68 | + stubMoreFunc2(mock); |
| 69 | + |
16 | 70 | SomeInterface &i = mock.get(); |
17 | | - |
| 71 | + |
| 72 | + // Uncatchable write access violation if ids collide. |
| 73 | + EXPECT_EQUAL(i.func(1), 10); |
| 74 | + EXPECT_EQUAL(i.func(2), 20); |
| 75 | + EXPECT_EQUAL(i.func(5), 5); |
| 76 | + EXPECT_EQUAL(i.func(20), 20); |
| 77 | + EXPECT_EQUAL(i.func(50), 50); |
| 78 | + EXPECT_EQUAL(i.func2(1), "String1"); |
| 79 | + EXPECT_EQUAL(i.func2(2), "String2"); |
| 80 | + EXPECT_EQUAL(i.func2(5), "String"); |
| 81 | + EXPECT_EQUAL(i.func2(20), "Something-20"); |
| 82 | + EXPECT_EQUAL(i.func2(50), "Something-50"); |
| 83 | + |
| 84 | + Verify(Method(mock, func).Using(1)).Exactly(1); |
| 85 | + Verify(Method(mock, func).Using(2)).Exactly(1); |
| 86 | + Verify(Method(mock, func).Using(5)).Exactly(1); |
| 87 | + Verify(Method(mock, func).Using(20)).Exactly(1); |
| 88 | + Verify(Method(mock, func).Using(50)).Exactly(1); |
| 89 | + Verify(Method(mock, func2).Using(1)).Exactly(1); |
| 90 | + Verify(Method(mock, func2).Using(2)).Exactly(1); |
| 91 | + Verify(Method(mock, func2).Using(5)).Exactly(1); |
| 92 | + Verify(Method(mock, func2).Using(20)).Exactly(1); |
| 93 | + Verify(Method(mock, func2).Using(50)).Exactly(1); |
| 94 | + } |
| 95 | + |
| 96 | + void NoCollidingIdsWhenOverridingMocks() |
| 97 | + { |
| 98 | + Mock<SomeInterface> mock; |
| 99 | + |
| 100 | + stubFunc(mock); |
| 101 | + When(Method(mock, func)).Return(123); |
| 102 | + When(Method(mock, func2)).Return("Something"); |
18 | 103 | stubFunc2(mock); |
19 | | - When(Method(mock, func)).Return<int>(1); |
20 | 104 |
|
21 | | - mock.get().func2(); // Uncatchable write access violation if ids collide |
| 105 | + SomeInterface &i = mock.get(); |
| 106 | + |
| 107 | + EXPECT_EQUAL(i.func(0), 123); |
| 108 | + EXPECT_EQUAL(i.func2(0), "String"); |
| 109 | + |
| 110 | + try { |
| 111 | + i.func(0); |
| 112 | + FAIL(); |
| 113 | + } catch (const UnexpectedMethodCallException&) { |
| 114 | + // There was only one action in the mock for this function. |
| 115 | + } |
| 116 | + |
| 117 | + try { |
| 118 | + i.func2(0); |
| 119 | + FAIL(); |
| 120 | + } catch (const UnexpectedMethodCallException&) { |
| 121 | + // There was only one action in the mock for this function. |
| 122 | + } |
| 123 | + |
| 124 | + Verify(Method(mock, func)).Exactly(2); |
| 125 | + Verify(Method(mock, func)).Exactly(2); |
22 | 126 | } |
23 | 127 |
|
24 | 128 | } __MultipleTranslationUnitsStub; |
0 commit comments