| 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 |
|
| 6 |
using namespace std; |
| 7 |
//------------------------------------------------------------------------------------------------------------------------------ |
| 8 |
// Tests TOC |
| 9 |
//------------------------------------------------------------------------------------------------------------------------------ |
| 10 |
// - Stringify NULL arguments |
| 11 |
// TEST_FUNCTION(MicroMock_TFS102616_NULL_Const_wchar_Pointer_Does_Not_Trigger_Exceptions) |
| 12 |
// TEST_FUNCTION(MicroMock_TFS102616_NULL_Const_char_Pointer_Does_Not_Trigger_Exceptions) |
| 13 |
// TEST_FUNCTION(MicroMock_TFS102616_NULL_wchar_Pointer_Does_Not_Trigger_Exceptions) |
| 14 |
// TEST_FUNCTION(MicroMock_TFS102616_NULL_char_Pointer_Does_Not_Trigger_Exceptions) |
| 15 |
// - Stringify non-NULL arguments |
| 16 |
// TEST_FUNCTION(MicroMock_TFS102616_Const_wchar_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 17 |
// TEST_FUNCTION(MicroMock_TFS102616_Const_char_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 18 |
// TEST_FUNCTION(MicroMock_TFS102616_wchar_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 19 |
// TEST_FUNCTION(MicroMock_TFS102616_char_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 20 |
//------------------------------------------------------------------------------------------------------------------------------ |
| 21 |
|
| 22 |
|
| 23 |
TYPED_MOCK_CLASS(CSomeMocks, CGlobalMock) |
| 24 |
{ |
| 25 |
public: |
| 26 |
MOCK_STATIC_METHOD_1(,void, XAA_wchar_const, const wchar_t*, p) |
| 27 |
MOCK_VOID_METHOD_END() |
| 28 |
|
| 29 |
MOCK_STATIC_METHOD_1(, void, XAA_char_const, const char*, p) |
| 30 |
MOCK_VOID_METHOD_END() |
| 31 |
|
| 32 |
MOCK_STATIC_METHOD_1(, void, XAA_wchar, wchar_t*, p) |
| 33 |
MOCK_VOID_METHOD_END() |
| 34 |
|
| 35 |
MOCK_STATIC_METHOD_1(, void, XAA_char, char*, p) |
| 36 |
MOCK_VOID_METHOD_END() |
| 37 |
}; |
| 38 |
DECLARE_GLOBAL_MOCK_METHOD_1(CSomeMocks, , void, XAA_wchar_const, const wchar_t*, p) |
| 39 |
DECLARE_GLOBAL_MOCK_METHOD_1(CSomeMocks, , void, XAA_char_const, const char*, p) |
| 40 |
DECLARE_GLOBAL_MOCK_METHOD_1(CSomeMocks, , void, XAA_wchar, wchar_t*, p) |
| 41 |
DECLARE_GLOBAL_MOCK_METHOD_1(CSomeMocks, , void, XAA_char, char*, p) |
| 42 |
|
| 43 |
template<> |
| 44 |
bool operator==<char*>(const CMockValue<char*>& lhs, const CMockValue<char*>& rhs) |
| 45 |
{ |
| 46 |
bool result = false; |
| 47 |
if (lhs.GetValue() == rhs.GetValue()) |
| 48 |
{ |
| 49 |
result = true; |
| 50 |
} else |
| 51 |
{ |
| 52 |
if ((NULL != lhs.GetValue()) && |
| 53 |
(NULL != rhs.GetValue()) && |
| 54 |
(strcmp(lhs.GetValue(), rhs.GetValue()) == 0)) |
| 55 |
{ |
| 56 |
result = true; |
| 57 |
} |
| 58 |
} |
| 59 |
return result; |
| 60 |
} |
| 61 |
|
| 62 |
static int tstring_Compare(const std::tstring& a, const std::tstring&b) |
| 63 |
{ |
| 64 |
return strcmp(a.c_str(), b.c_str()); |
| 65 |
} |
| 66 |
static void tstring_ToString(char* string, size_t bufferSize, std::tstring val) |
| 67 |
{ |
| 68 |
size_t val_size = strlen(val.c_str()); |
| 69 |
strncpy(string, val.c_str(), (val_size >= bufferSize) ? (bufferSize - 1) : val_size); |
| 70 |
} |
| 71 |
|
| 72 |
static MICROMOCK_MUTEX_HANDLE g_testByTest; |
| 73 |
static MICROMOCK_GLOBAL_SEMAPHORE_HANDLE g_dllByDll; |
| 74 |
|
| 75 |
BEGIN_TEST_SUITE(NULLArgsStringificationTests) |
| 76 |
|
| 77 |
TEST_SUITE_INITIALIZE(TestClassInitialize) |
| 78 |
{ |
| 79 |
g_testByTest = MicroMockCreateMutex(); |
| 80 |
ASSERT_IS_NOT_NULL(g_testByTest); |
| 81 |
} |
| 82 |
|
| 83 |
TEST_SUITE_CLEANUP(TestClassCleanup) |
| 84 |
{ |
| 85 |
MicroMockDestroyMutex(g_testByTest); |
| 86 |
} |
| 87 |
|
| 88 |
TEST_FUNCTION_INITIALIZE(TestMethodInitialize) |
| 89 |
{ |
| 90 |
if (!MicroMockAcquireMutex(g_testByTest)) |
| 91 |
{ |
| 92 |
ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework"); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
TEST_FUNCTION_CLEANUP(TestMethodCleanup) |
| 97 |
{ |
| 98 |
if (!MicroMockReleaseMutex(g_testByTest)) |
| 99 |
{ |
| 100 |
ASSERT_FAIL("failure in test framework at ReleaseMutex"); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/*http://webvstf:8080/tfs/web/wi.aspx?pcguid=8947f9e3-3622-497e-ab87-a27e01082a6c&id=102616*/ |
| 105 |
TEST_FUNCTION(MicroMock_TFS102616_NULL_Const_wchar_Pointer_Does_Not_Trigger_Exceptions) |
| 106 |
{ |
| 107 |
// arrange |
| 108 |
CSomeMocks testMock; |
| 109 |
|
| 110 |
STRICT_EXPECTED_CALL(testMock, XAA_wchar_const(NULL)) |
| 111 |
.NeverInvoked(); |
| 112 |
|
| 113 |
// act |
| 114 |
XAA_wchar_const(NULL); |
| 115 |
|
| 116 |
// assert |
| 117 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_wchar_const(NULL)]")), testMock.CompareActualAndExpectedCalls(), |
| 118 |
_T("An unexpected call with NULL argument should be reported")); |
| 119 |
} |
| 120 |
|
| 121 |
TEST_FUNCTION(MicroMock_TFS102616_NULL_Const_char_Pointer_Does_Not_Trigger_Exceptions) |
| 122 |
{ |
| 123 |
// arrange |
| 124 |
CSomeMocks testMock; |
| 125 |
|
| 126 |
STRICT_EXPECTED_CALL(testMock, XAA_char_const(NULL)) |
| 127 |
.NeverInvoked(); |
| 128 |
|
| 129 |
// act |
| 130 |
XAA_char_const(NULL); |
| 131 |
|
| 132 |
// assert |
| 133 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_char_const(NULL)]")), testMock.CompareActualAndExpectedCalls(), |
| 134 |
_T("An unexpected call with NULL argument should be reported")); |
| 135 |
} |
| 136 |
|
| 137 |
TEST_FUNCTION(MicroMock_TFS102616_NULL_wchar_Pointer_Does_Not_Trigger_Exceptions) |
| 138 |
{ |
| 139 |
// arrange |
| 140 |
CSomeMocks testMock; |
| 141 |
|
| 142 |
STRICT_EXPECTED_CALL(testMock, XAA_wchar(NULL)) |
| 143 |
.NeverInvoked(); |
| 144 |
|
| 145 |
// act |
| 146 |
XAA_wchar(NULL); |
| 147 |
|
| 148 |
// assert |
| 149 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_wchar(NULL)]")), testMock.CompareActualAndExpectedCalls(), |
| 150 |
_T("An unexpected call with NULL argument should be reported")); |
| 151 |
} |
| 152 |
|
| 153 |
TEST_FUNCTION(MicroMock_TFS102616_NULL_char_Pointer_Does_Not_Trigger_Exceptions) |
| 154 |
{ |
| 155 |
// arrange |
| 156 |
CSomeMocks testMock; |
| 157 |
|
| 158 |
STRICT_EXPECTED_CALL(testMock, XAA_char(NULL)) |
| 159 |
.NeverInvoked(); |
| 160 |
|
| 161 |
// act |
| 162 |
XAA_char(NULL); |
| 163 |
|
| 164 |
// assert |
| 165 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_char(NULL)]")), testMock.CompareActualAndExpectedCalls(), |
| 166 |
_T("An unexpected call with NULL argument should be reported")); |
| 167 |
} |
| 168 |
|
| 169 |
TEST_FUNCTION(MicroMock_TFS102616_Const_wchar_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 170 |
{ |
| 171 |
// arrange |
| 172 |
CSomeMocks testMock; |
| 173 |
wchar_t val1[] = L"oink"; |
| 174 |
wchar_t val2[] = L"oink"; |
| 175 |
|
| 176 |
STRICT_EXPECTED_CALL(testMock, XAA_wchar_const(val1)) |
| 177 |
.NeverInvoked(); |
| 178 |
|
| 179 |
// act |
| 180 |
XAA_wchar_const(val2); |
| 181 |
|
| 182 |
// assert |
| 183 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_wchar_const(oink)]")), testMock.CompareActualAndExpectedCalls(), |
| 184 |
_T("An unexpected call with NULL argument should be reported")); |
| 185 |
} |
| 186 |
|
| 187 |
TEST_FUNCTION(MicroMock_TFS102616_Const_char_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 188 |
{ |
| 189 |
// arrange |
| 190 |
CSomeMocks testMock; |
| 191 |
char val1[] = "oink"; |
| 192 |
char val2[] = "oink"; |
| 193 |
|
| 194 |
STRICT_EXPECTED_CALL(testMock, XAA_char_const(val1)) |
| 195 |
.NeverInvoked(); |
| 196 |
|
| 197 |
// act |
| 198 |
XAA_char_const(val2); |
| 199 |
|
| 200 |
// assert |
| 201 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_char_const(oink)]")), testMock.CompareActualAndExpectedCalls(), |
| 202 |
_T("An unexpected call with NULL argument should be reported")); |
| 203 |
} |
| 204 |
|
| 205 |
TEST_FUNCTION(MicroMock_TFS102616_wchar_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 206 |
{ |
| 207 |
// arrange |
| 208 |
CSomeMocks testMock; |
| 209 |
wchar_t val1[] = L"oink"; |
| 210 |
wchar_t val2[] = L"oink"; |
| 211 |
|
| 212 |
STRICT_EXPECTED_CALL(testMock, XAA_wchar(val1)) |
| 213 |
.NeverInvoked(); |
| 214 |
|
| 215 |
// act |
| 216 |
XAA_wchar(val2); |
| 217 |
|
| 218 |
// assert |
| 219 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_wchar(oink)]")), testMock.CompareActualAndExpectedCalls(), |
| 220 |
_T("An unexpected call with NULL argument should be reported")); |
| 221 |
} |
| 222 |
|
| 223 |
TEST_FUNCTION(MicroMock_TFS102616_char_String_Is_Printed_As_Such_In_Unexpected_Call) |
| 224 |
{ |
| 225 |
// arrange |
| 226 |
CSomeMocks testMock; |
| 227 |
char val1[] = "oink"; |
| 228 |
char val2[] = "oink"; |
| 229 |
|
| 230 |
STRICT_EXPECTED_CALL(testMock, XAA_char(val1)) |
| 231 |
.NeverInvoked(); |
| 232 |
|
| 233 |
// act |
| 234 |
XAA_char(val2); |
| 235 |
|
| 236 |
// assert |
| 237 |
ASSERT_ARE_EQUAL_WITH_MSG(tstring, tstring(_T("[Actual:XAA_char(oink)]")), testMock.CompareActualAndExpectedCalls(), |
| 238 |
_T("An unexpected call with NULL argument should be reported")); |
| 239 |
} |
| 240 |
END_TEST_SUITE(NULLArgsStringificationTests) |
| 241 |
|