1 #include <platformdefines.h>
4 inline char* CoStrDup(const char* str)
6 size_t size = strlen(str) + 1;
7 char* dup = (char *)CoreClrAlloc(size);
10 strcpy_s(dup, size, str);
15 const int NumArrElements = 2;
16 struct InnerSequential
22 void PrintInnerSequential(InnerSequential* p, char const * name)
24 printf("\t%s.f1 = %d\n", name, p->f1);
25 printf("\t%s.f2 = %f\n", name, p->f2);
26 printf("\t%s.f3 = %s\n", name, p->f3);
29 void ChangeInnerSequential(InnerSequential* p)
33 p->f3 = CoStrDup("changed string");
36 bool IsCorrectInnerSequential(InnerSequential* p)
42 if(strcmp(p->f3, "") != 0)
50 typedef unsigned int UINT;
53 typedef unsigned short WORD;
56 typedef double DOUBLE;
59 struct INNER2 // size = 12 bytes
65 void ChangeINNER2(INNER2* p)
69 p->f3 = CoStrDup("changed string");
71 void PrintINNER2(INNER2* p, char const * name)
73 printf("\t%s.f1 = %d\n", name, p->f1);
74 printf("\t%s.f2 = %f\n", name, p->f2);
75 printf("\t%s.f3 = %s\n", name, p->f3);
77 bool IsCorrectINNER2(INNER2* p)
83 if(memcmp(p->f3, "some string",11*sizeof(char)) != 0 )
113 void PrintInnerExplicit(InnerExplicit* p, char const * name)
115 printf("\t%s.f1 = %d\n", name, p->f1);
116 printf("\t%s.f2 = %f\n", name, p->f2);
117 printf("\t%s.f3 = %s\n", name, p->f3);
120 void ChangeInnerExplicit(InnerExplicit* p)
123 p->f3 = CoStrDup("changed string");
126 struct InnerArraySequential
128 InnerSequential arr[NumArrElements];
131 void PrintInnerArraySequential(InnerArraySequential* p, char const * name)
133 for(int i = 0; i < NumArrElements; i++)
135 printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
136 printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
137 printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
141 void ChangeInnerArraySequential(InnerArraySequential* p)
143 for(int i = 0; i < NumArrElements; i++)
146 (p->arr)[i].f2 = 77.0;
147 (p->arr)[i].f3 = CoStrDup("changed string");
151 bool IsCorrectInnerArraySequential(InnerArraySequential* p)
153 for(int i = 0; i < NumArrElements; i++)
155 if( (p->arr)[i].f1 != 1 )
157 if( (p->arr)[i].f2 != 1.0 )
164 union InnerArrayExplicit // size = 32 bytes
166 struct InnerSequential arr[2];
177 #pragma warning(push)
178 #pragma warning(disable: 4201) // nonstandard extension used: nameless struct/union
179 union OUTER3 // size = 32 bytes
181 struct InnerSequential arr[2];
190 struct OUTER3 // size = 28 bytes
192 struct InnerSequential arr[2];
199 struct OUTER3 // size = 28 bytes
201 struct InnerSequential arr[2];
206 void PrintOUTER3(OUTER3* p, char const * name)
208 for(int i = 0; i < NumArrElements; i++)
210 printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1);
211 printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2);
212 printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3);
214 printf("\t%s.f4 = %s\n",name,p->f4);
216 void ChangeOUTER3(OUTER3* p)
218 for(int i = 0; i < NumArrElements; i++)
221 (p->arr)[i].f2 = 77.0;
222 (p->arr)[i].f3 = CoStrDup("changed string");
225 p->f4 = CoStrDup("changed string");
227 bool IsCorrectOUTER3(OUTER3* p)
229 for(int i = 0; i < NumArrElements; i++)
231 if( (p->arr)[i].f1 != 1 )
233 if( (p->arr)[i].f2 != 1.0 )
235 if( memcmp((p->arr)[i].f3, "some string",11*sizeof(char)) != 0 )
238 if(memcmp(p->f4,"some string",11*sizeof(char)) != 0)
245 struct CharSetAnsiSequential
251 void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, char const * name)
253 printf("\t%s.f1 = %s\n", name, p->f1);
254 printf("\t%s.f2 = %c\n", name, p->f2);
257 void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p)
259 p->f1 = CoStrDup("change string");
263 bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p)
265 if(strcmp((char*)p->f1, (char*)"some string") != 0 )
273 struct CharSetUnicodeSequential
278 void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, char const * name)
281 wprintf(L"\t%S.f1 = %s\n", name, p->f1);
283 wprintf(L"\t%s.f1 = %S\n", name, p->f1);
285 printf("\t%s.f2 = %c\n", name, p->f2);
288 void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p)
291 LPCWSTR strSource = L"change string";
293 LPCWSTR strSource = u"change string";
295 size_t len = TP_slen(strSource);
296 LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1));
299 TP_scpy_s((WCHAR*)temp, (len+1), strSource);
305 printf("Memory Allocated Failed!");
309 bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p)
312 LPCWSTR expected= L"some string";
314 LPCWSTR expected= u"some string";
316 LPCWSTR actual = p->f1;
317 if(0 != TP_wcmp_s((WCHAR*)actual, (WCHAR*)expected))
329 struct NumberSequential // size = 64 bytes
344 void PrintNumberSequential(NumberSequential* str, char const * name)
346 printf("\t%s.i32 = %d\n", name, str->i32);
347 printf("\t%s.ui32 = %d\n", name, str->ui32);
348 printf("\t%s.s1 = %d\n", name, str->s1);
349 printf("\t%s.us1 = %u\n", name, str->us1);
350 printf("\t%s.b = %u\n", name, str->b);
351 printf("\t%s.sb = %d\n", name, str->sb);
352 printf("\t%s.i16 = %d\n", name, str->i16);
353 printf("\t%s.ui16 = %u\n", name, str->ui16);
354 printf("\t%s.i64 = %lld\n", name, str->i64);
355 printf("\t%s.ui64 = %llu\n", name, str->ui64);
356 printf("\t%s.sgl = %f\n", name, str->sgl);
357 printf("\t%s.d = %f\n",name, str->d);
359 void ChangeNumberSequential(NumberSequential* p)
375 bool IsCorrectNumberSequential(NumberSequential* p)
377 if(p->i32 != (-0x7fffffff - 1) || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
378 p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
379 p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
386 struct S3 // size = 1032 bytes
393 void PrintS3(S3* str, char const * name)
395 printf("\t%s.flag = %d\n", name, str->flag);
396 printf("\t%s.str = %s\n", name, str->str);
397 for(int i = 0; i<256 ;i++)
399 printf("\t%s.vals[%d] = %d\n",name,i,str->vals[i]);
407 /*CoreClrFree((void *)p->str);*/
408 p->str = CoStrDup("change string");
410 for(int i = 1;i<257;i++)
416 bool IsCorrectS3(S3* p)
420 if (!p->flag || strcmp(p->str, "") != 0)
422 for (int i = 0; i < 256; i++)
426 printf("\tThe Index of %i is not expected",i);
437 struct S4 // size = 8 bytes
447 struct S5 // size = 8 bytes
453 void PrintS5(S5* str, char const * name)
455 printf("\t%s.s4.age = %d", name, str->s4.age);
456 printf("\t%s.s4.name = %s", name, str->s4.name);
457 printf("\t%s.ef = %d", name, str->ef);
459 void ChangeS5(S5* str)
461 str->s4.name = CoStrDup("change string");
465 bool IsCorrectS5(S5* str)
467 if(str->s4.age != 32 || strcmp(str->s4.name, "") != 0)
474 struct StringStructSequentialAnsi // size = 8 bytes
480 void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, char const * name)
482 printf("\t%s.first = %s\n", name, str->first);
483 printf("\t%s.last = %s\n", name, str->last);
486 bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str)
490 for(int i = 0;i<512;i++)
496 if(memcmp(str->first,strOne,512)!= 0)
499 if(memcmp(str->last,strTwo,512)!= 0)
505 void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str)
507 char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513);
508 char* newLast = (char*)CoreClrAlloc(sizeof(char)*513);
509 for (int i = 0; i < 512; ++i)
514 newFirst[512] = '\0';
517 str->first = newFirst;
521 struct StringStructSequentialUnicode // size = 8 bytes
527 void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, char const * name)
530 wprintf(L"\t%S.first = %s\n", name, str->first);
531 wprintf(L"\t%S.last = %s\n", name, str->last);
533 wprintf(L"\t%s.first = %s\n", name, str->first);
534 wprintf(L"\t%s.last = %s\n", name, str->last);
538 bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str)
543 for(int i = 0;i<256;++i)
551 if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0)
553 if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0)
558 void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str)
560 WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
561 WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257);
562 for (int i = 0; i < 256; ++i)
567 newFirst[256] = L'\0';
568 newLast[256] = L'\0';
569 str->first = (const WCHAR*)newFirst;
570 str->last = (const WCHAR*)newLast;
574 struct S8 // size = 32 bytes
583 void PrintS8(S8* str, char const * name)
585 printf("\t%s.name = %s\n",name, str->name);
586 printf("\t%s.gender = %d\n", name, str->gender);
587 printf("\t%s.jobNum = %d\n",name, str->jobNum);
588 printf("\t%s.i32 = %d\n", name, str->i32);
589 printf("\t%s.ui32 = %u\n", name, str->ui32);
590 printf("\t%s.mySByte = %c\n", name, str->mySByte);
592 bool IsCorrectS8(S8* str)
594 if(memcmp( str->name,"hello", strlen("hello")*sizeof(char)+1 )!= 0)
598 if(str->jobNum != 10)
600 if(str->i32!= 128 || str->ui32 != 128)
602 if(str->mySByte != 32)
607 void ChangeS8(S8* str)
609 str->name = CoStrDup("world");
617 struct S_int // size = 4 bytes
623 typedef void (*TestDelegate1)(struct S9 myStruct);
625 struct S9 // size = 8 bytes
628 TestDelegate1 myDelegate1;
631 struct S101 // size = 8 bytes
637 struct S10 // size = 8 bytes
641 void PrintS10(S10* str, char const * name)
643 printf("\t%s.s.s_int.i = %d\n", name, str->s.s_int.i);
644 printf("\t%s.s.i = %d\n", name, str->s.i);
646 bool IsCorrectS10(S10* str)
648 if(str->s.s_int.i != 32)
654 void ChangeS10(S10* str)
664 struct S11 // size = 8 bytes
670 union U // size = 8 bytes
686 void PrintU(U* str, char const * name)
688 printf("\t%s.i32 = %d\n", name, str->i32);
689 printf("\t%s.ui32 = %u\n", name, str->ui32);
690 printf("\t%s.iPtr = %p\n", name, str->iPtr);
691 printf("\t%s.uiPtr = %p\n", name, str->uiPtr);
692 printf("\t%s.s = %d\n", name, str->s);
693 printf("\t%s.us = %u\n", name, str->us);
694 printf("\t%s.b = %u\n", name, str->b);
695 printf("\t%s.sb = %d\n", name, str->sb);
696 printf("\t%s.l = %lld\n", name, str->l);
697 printf("\t%s.ul = %llu\n", name, str->ul);
698 printf("\t%s.f = %f\n", name, str->f);
699 printf("\t%s.d = %f\n", name, str->d);
706 p->iPtr = (LPVOID)(-64);
707 p->uiPtr = (LPVOID)(64);
718 bool IsCorrectU(U* p)
727 struct ByteStructPack2Explicit // size = 2 bytes
732 void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, char const * name)
734 printf("\t%s.b1 = %d", name, str->b1);
735 printf("\t%s.b2 = %d", name, str->b2);
738 void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p)
743 bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p)
745 if(p->b1 != 32 || p->b2 != 32)
752 struct ShortStructPack4Explicit // size = 4 bytes
758 void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, char const * name)
760 printf("\t%s.s1 = %d", name, str->s1);
761 printf("\t%s.s2 = %d", name, str->s2);
763 void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p)
768 bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p)
770 if(p->s1 != 32 || p->s2 != 32)
776 struct IntStructPack8Explicit // size = 8 bytes
782 void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, char const * name)
784 printf("\t%s.i1 = %d", name, str->i1);
785 printf("\t%s.i2 = %d", name, str->i2);
787 void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p)
792 bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p)
794 if(p->i1 != 32 || p->i2 != 32)
799 struct LongStructPack16Explicit // size = 16 bytes
805 void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, char const * name)
807 printf("\t%s.l1 = %lld", name, str->l1);
808 printf("\t%s.l2 = %lld", name, str->l2);
810 void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p)
815 bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p)
817 if(p->l1 != 32 || p->l2 != 32)
869 struct IntWithInnerSequential
872 InnerSequential sequential;
875 struct SequentialWrapper
877 InnerSequential sequential;
880 struct SequentialDoubleWrapper
882 SequentialWrapper wrapper;
885 struct AggregateSequentialWrapper
887 SequentialWrapper wrapper1;
888 InnerSequential sequential;
889 SequentialWrapper wrapper2;