1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 #include <stdlib.h> // required by itoa
9 #include "platformdefines.h"
11 //////////////////////////////////////////////////////////////////////////////
13 //////////////////////////////////////////////////////////////////////////////
14 #define ARRAY_SIZE 100
18 #define COUNTOF(__arr) sizeof(__arr) / sizeof(__arr[0])
19 #define ELEM_PER_ROW_2D(__arr) (&(__arr[1][0]) - &(__arr[0][0]))
20 #define ROWS_2D(__arr) sizeof(__arr) / (ELEM_PER_ROW_2D(__arr) * sizeof(__arr[0][0]))
22 #define ENTERFUNC() printf("============ [%s]\t ============\n", __FUNCTION__)
24 #define CHECK_PARAM_NOT_EMPTY(__p) \
26 if ( (__p) == NULL ) \
28 printf("[%s] Error: parameter actual is NULL\n", __FUNCTION__); \
32 #define CHECK_PARAM_EMPTY(__p) \
36 printf("[%s] Error: parameter ppActual is not NULL\n", __FUNCTION__); \
40 #define VERIFY_ERROR(__expect, __actual) \
41 std::cout << '[' << __FUNCSIG__ << "] EXPECT: " << (__expect) << ", ACTUAL: " << (__actual) << std::endl
43 #define TRACE(__msg) \
44 std::cout << __msg << std::endl
46 #define VERIFY_ERROR_MSG(__msg, __expect, __actual) \
47 printf("["##__FUNCSIG__##"] "##__msg, (__expect), (__actual))
49 //////////////////////////////////////////////////////////////////////////////
50 // Verify helper methods
51 //////////////////////////////////////////////////////////////////////////////
54 bool IsObjectEquals(const T& o1, const T& o2)
60 bool IsObjectEquals(const LPSTR& o1, const LPSTR& o2)
71 size_t cLen1 = strlen(o1);
72 size_t cLen2 = strlen(o2);
76 printf("Not equals in %s\n",__FUNCTION__);
80 return strncmp(o1, o2, cLen1) == 0;
84 bool IsObjectEquals(const LPCSTR& o1, const LPCSTR& o2)
95 size_t cLen1 = strlen(o1);
96 size_t cLen2 = strlen(o2);
100 printf("Not equals in %s\n",__FUNCTION__);
104 return strncmp(o1, o2, cLen1) == 0;
109 bool IsObjectEquals(const BSTR& o1, const BSTR& o2)
120 UINT uLen1 = SysStringLen(o1);
121 UINT uLen2 = SysStringLen(o2);
125 printf("Not equals in %s\n",__FUNCTION__);
129 return memcmp(o1, o2, uLen1 * sizeof(*o1)) == 0;
133 //////////////////////////////////////////////////////////////////////////////
134 // Test Data Structure
135 //////////////////////////////////////////////////////////////////////////////
137 LPSTR ToString(int i)
139 CHAR *pBuffer = (CHAR *)CoreClrAlloc(10 * sizeof(CHAR)); // 10 is enough for our case
140 _itoa_s(i, pBuffer, 10, 10);
149 VarBstrFromI4(i, 0, 0, &bstrRet);
165 inline TestStruct(int v)
178 inline bool operator==(const TestStruct &other) const
180 return IsObjectEquals(x, other.x) &&
181 IsObjectEquals(d, other.d) &&
182 IsObjectEquals(l, other.l) &&
183 IsObjectEquals(str, other.str);
203 //////////////////////////////////////////////////////////////////////////////
205 //////////////////////////////////////////////////////////////////////////////
208 // Do not output variants, and suppress the boring template compile warning
209 std::ostream &operator<<(std::ostream &ostr, VARIANT &v)
214 std::ostream &operator<<(std::ostream &ostr, BSTR &b)
221 //////////////////////////////////method for struct S2////////////////////////////////////////////////
222 void InstanceS2(S2 * pREC, int i32,UINT ui32,SHORT s1,WORD us1,BYTE b,CHAR sb,SHORT i16,WORD ui16,
223 LONG64 i64,ULONG64 ui64,FLOAT sgl,DOUBLE d)
239 bool ValidateS2LPArray(S2 * pREC, S2 * pRECCorrect, int numArrElement)
241 for(int i = 0; i<numArrElement;i++)
243 if(pREC[i].i32 != pRECCorrect[i].i32)
245 printf("\t The field of int is not the expected!");
246 printf("\t\tpREC[%d].i32 = %d\n", i, pREC[i].i32);
247 printf("\t\tpRECCorrect[%d].i32 = %d\n", i, pRECCorrect[i].i32);
250 else if(pREC[i].ui32 != pRECCorrect[i].ui32)
252 printf("\t The field of UInt32 is not the expected!");
253 printf("\t\tpREC[%d].ui32 = %d\n", i, pREC[i].ui32);
254 printf("\t\tpRECCorrect[%d].ui32 = %u\n", i, pRECCorrect[i].ui32);
257 else if(pREC[i].s1 != pRECCorrect[i].s1)
259 printf("\t The field of short is not the expected!");
260 printf("\t\tpREC[%d].s1 = %d\n", i, pREC[i].s1);
261 printf("\t\tpRECCorrect[%d].s1 = %d\n", i, pRECCorrect[i].s1);
264 else if(pREC[i].us1 != pRECCorrect[i].us1)
266 printf("\t The field of ushort is not the expected!");
267 printf("\t\tpREC[%d].us1 = %d\n", i, pREC[i].us1);
268 printf("\t\tpRECCorrect[%d].us1 = %u\n", i, pRECCorrect[i].us1);
271 else if(pREC[i].b != pRECCorrect[i].b)
273 printf("\t The field of byte is not the expected!");
274 printf("\t\tpREC[%d].b = %d\n", i, pREC[i].b);
275 printf("\t\tpRECCorrect[%d].b = %d\n", i, pRECCorrect[i].b);
278 else if(pREC[i].sb != pRECCorrect[i].sb)
280 printf("\t The field of sbyte is not the expected!");
281 printf("\t\tpREC[%d].sb = %d\n", i, pREC[i].sb);
282 printf("\t\tpRECCorrect[%d].sb = %u\n", i, pRECCorrect[i].sb);
285 else if(pREC[i].i16 != pRECCorrect[i].i16)
287 printf("\t The field of Int16 is not the expected!");
288 printf("\t\tpREC[%d].i16 = %d\n", i, pREC[i].i16);
289 printf("\t\tpRECCorrect[%d].i16 = %d\n", i, pRECCorrect[i].i16);
292 else if(pREC[i].ui16 != pRECCorrect[i].ui16)
294 printf("\t The field of UInt16 is not the expected!");
295 printf("\t\tpREC[%d].ui16 = %d\n", i, pREC[i].ui16);
296 printf("\t\tpRECCorrect[%d].ui16 = %u\n", i, pRECCorrect[i].ui16);
299 else if(pREC[i].i64 != pRECCorrect[i].i64)
301 printf("\t The field of Int64 is not the expected!");
302 printf("\t\tpREC[%d].i64 = %lld\n", i, pREC[i].i64);
303 printf("\t\tpRECCorrect[%d].i64 = %lld\n", i, pRECCorrect[i].i64);
306 else if(pREC[i].ui64 != pRECCorrect[i].ui64)
308 printf("\t The field of UInt64 is not the expected!");
309 printf("\t\tpREC[%d].ui64 = %llu\n", i, pREC[i].ui64);
310 printf("\t\tpRECCorrect[%d].ui64 = %llu\n", i, pRECCorrect[i].ui64);
313 else if(pREC[i].sgl != pRECCorrect[i].sgl)
315 printf("\t The field of single is not the expected!");
316 printf("\t\tpREC[%d].sgl = %f\n", i, pREC[i].sgl);
317 printf("\t\tpRECCorrect[%d].sgl = %f\n", i, pRECCorrect[i].sgl);
320 else if(pREC[i].d != pRECCorrect[i].d)
322 printf("\t The field of double is not the expected!");
323 printf("\t\tpREC[%d].d = %f\n", i, pREC[i].d);
324 printf("\t\tpRECCorrect[%d].d = %f\n", i, pRECCorrect[i].d);