Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/unittests/micromocktest/micromockcallcomparisonunittests.cpp

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #include "stdafx.h"
5 using namespace std;
6 TYPED_MOCK_CLASS(CTestAllArgsMock, CMock)
7 {
8 public:
9 MOCK_METHOD_0(, UINT8, TestFunctionWithNoArgs);
10 MOCK_METHOD_END(UINT8, 0)
11
12 MOCK_METHOD_1(, UINT8, TestFunctionWith1Arg, UINT8, arg1);
13 MOCK_METHOD_END(UINT8, 0)
14
15 MOCK_METHOD_2(, UINT8, TestFunctionWith2Args, UINT8, arg1, UINT8, arg2);
16 MOCK_METHOD_END(UINT8, 0)
17
18 MOCK_METHOD_3(, UINT8, TestFunctionWith3Args, UINT8, arg1, UINT8, arg2, UINT8, arg3);
19 MOCK_METHOD_END(UINT8, 0)
20
21 MOCK_METHOD_4(, UINT8, TestFunctionWith4Args, UINT8, arg1, UINT8, arg2, UINT8, arg3, UINT8, arg4);
22 MOCK_METHOD_END(UINT8, 0)
23
24 MOCK_METHOD_5(, UINT8, TestFunctionWith5Args, UINT8, arg1, UINT8, arg2, UINT8, arg3, UINT8, arg4, UINT8, arg5);
25 MOCK_METHOD_END(UINT8, 0)
26
27 MOCK_METHOD_6(, UINT8, TestFunctionWith6Args, UINT8, arg1, UINT8, arg2, UINT8, arg3, UINT8, arg4, UINT8, arg5, UINT8, arg6);
28 MOCK_METHOD_END(UINT8, 0)
29 };
30
31 static MICROMOCK_MUTEX_HANDLE g_testByTest;
32 static MICROMOCK_GLOBAL_SEMAPHORE_HANDLE g_dllByDll;
33
34 BEGIN_TEST_SUITE(MicroMockCallComparisonUnitTests)
35
36 // GetUnexpectedCalls
37
38 TEST_SUITE_INITIALIZE(TestClassInitialize)
39 {
40 g_testByTest = MicroMockCreateMutex();
41 ASSERT_IS_NOT_NULL(g_testByTest);
42 }
43
44 TEST_SUITE_CLEANUP(TestClassCleanup)
45 {
46 MicroMockDestroyMutex(g_testByTest);
47 }
48
49 TEST_FUNCTION_INITIALIZE(TestMethodInitialize)
50 {
51 if (!MicroMockAcquireMutex(g_testByTest))
52 {
53 ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
54 }
55 }
56
57 TEST_FUNCTION_CLEANUP(TestMethodCleanup)
58 {
59 if (!MicroMockReleaseMutex(g_testByTest))
60 {
61 ASSERT_FAIL("failure in test framework at ReleaseMutex");
62 }
63 }
64
65 TEST_FUNCTION(MicroMock_GetUnexpectedCalls_When_No_Actual_Call_Is_Made_Returns_An_Empty_String)
66 {
67 // arrange
68 CTestAllArgsMock testMock;
69
70 // act
71
72 // assert
73 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetUnexpectedCalls().c_str(),
74 _T("Incorrect actual calls"));
75 }
76
77 TEST_FUNCTION(MicroMock_GetUnexpectedCalls_Returns_Unexpected_Calls)
78 {
79 // arrange
80 CTestAllArgsMock testMock;
81
82 // act
83 testMock.TestFunctionWithNoArgs();
84
85 // assert
86 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("[TestFunctionWithNoArgs()]")).c_str(), testMock.GetUnexpectedCalls().c_str(),
87 _T("Incorrect actual calls"));
88 }
89
90 TEST_FUNCTION(MicroMock_GetUnexpectedCalls_When_An_Expected_Call_And_An_Actual_Call_Match_Returns_Empty_String)
91 {
92 // arrange
93 CTestAllArgsMock testMock;
94
95 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
96
97 // act
98 testMock.TestFunctionWithNoArgs();
99
100 // assert
101 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetUnexpectedCalls().c_str(),
102 _T("Incorrect actual calls"));
103 }
104
105 TEST_FUNCTION(MicroMock_GetUnexpectedCalls_When_Only_The_Expected_Call_Happens_Returns_Empty_String)
106 {
107 // arrange
108 CTestAllArgsMock testMock;
109
110 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
111
112 // act
113
114 // assert
115 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetUnexpectedCalls().c_str(),
116 _T("Incorrect actual calls"));
117 }
118
119 TEST_FUNCTION(MicroMock_GetUnexpectedCalls_When_More_Than_One_Unexpected_Calls_Are_Made_Reports_All_Calls)
120 {
121 // arrange
122 CTestAllArgsMock testMock;
123
124 // act
125 testMock.TestFunctionWithNoArgs();
126 testMock.TestFunctionWithNoArgs();
127
128 // assert
129 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("[TestFunctionWithNoArgs()][TestFunctionWithNoArgs()]")).c_str(), testMock.GetUnexpectedCalls().c_str(),
130 _T("Incorrect actual calls"));
131 }
132
133 // GetMissingCalls
134
135 TEST_FUNCTION(MicroMock_GetMissingCalls_When_No_Expected_Call_Is_Programmed_Returns_An_Empty_String)
136 {
137 // arrange
138 CTestAllArgsMock testMock;
139
140 // act
141
142 // assert
143 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetMissingCalls().c_str(),
144 _T("Incorrect actual calls"));
145 }
146
147 TEST_FUNCTION(MicroMock_GetMissingCalls_Returns_MissingCalls)
148 {
149 // arrange
150 CTestAllArgsMock testMock;
151
152 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
153
154 // act
155
156 // assert
157 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("[TestFunctionWithNoArgs()]")).c_str(), testMock.GetMissingCalls().c_str(),
158 _T("Incorrect actual calls"));
159 }
160
161 TEST_FUNCTION(MicroMock_GetMissingCalls_When_An_Expected_Call_And_An_Actual_Call_Match_Returns_Empty_String)
162 {
163 // arrange
164 CTestAllArgsMock testMock;
165
166 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
167
168 // act
169 testMock.TestFunctionWithNoArgs();
170
171 // assert
172 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetMissingCalls().c_str(),
173 _T("Incorrect actual calls"));
174 }
175
176 TEST_FUNCTION(MicroMock_GetMissingCalls_When_Only_The_Actual_Call_Happens_Returns_Empty_String)
177 {
178 // arrange
179 CTestAllArgsMock testMock;
180
181 // act
182 testMock.TestFunctionWithNoArgs();
183
184 // assert
185 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("")).c_str(), testMock.GetMissingCalls().c_str(),
186 _T("Incorrect actual calls"));
187 }
188
189 TEST_FUNCTION(MicroMock_GetMissingCalls_When_More_Than_One_Missing_Calls_Exists_Reports_All_Missing_Calls)
190 {
191 // arrange
192 CTestAllArgsMock testMock;
193
194 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
195 STRICT_EXPECTED_CALL(testMock, TestFunctionWithNoArgs());
196
197 // act
198
199 // assert
200 ASSERT_ARE_EQUAL_WITH_MSG(char_ptr, tstring(_T("[TestFunctionWithNoArgs()][TestFunctionWithNoArgs()]")).c_str(), testMock.GetMissingCalls().c_str(),
201 _T("Incorrect actual calls"));
202 }
203 END_TEST_SUITE(MicroMockCallComparisonUnitTests);