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. |
4 | |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | #include <string.h> |
8 | #include <xplatform.h> |
9 | |
10 | const int NumArrElements = 2; |
11 | struct InnerSequential |
12 | { |
13 | int f1; |
14 | float f2; |
15 | LPCSTR f3; |
16 | }; |
17 | |
18 | void PrintInnerSequential(InnerSequential* p, const char* name) |
19 | { |
20 | printf("\t%s.f1 = %d\n" , name, p->f1); |
21 | printf("\t%s.f2 = %f\n" , name, p->f2); |
22 | printf("\t%s.f3 = %s\n" , name, p->f3); |
23 | } |
24 | |
25 | void ChangeInnerSequential(InnerSequential* p) |
26 | { |
27 | p->f1 = 77; |
28 | p->f2 = 77.0; |
29 | |
30 | const char* lpstr = "changed string" ; |
31 | size_t size = sizeof(char) * (strlen(lpstr) + 1); |
32 | LPSTR temp = (LPSTR)CoreClrAlloc( size ); |
33 | memset(temp, 0, size); |
34 | if(temp) |
35 | { |
36 | strcpy_s((char*)temp,size,lpstr); |
37 | p->f3 = temp; |
38 | } |
39 | else |
40 | { |
41 | printf("Memory Allocated Failed!" ); |
42 | } |
43 | } |
44 | |
45 | bool IsCorrectInnerSequential(InnerSequential* p) |
46 | { |
47 | if(p->f1 != 1) |
48 | return false; |
49 | if(p->f2 != 1.0) |
50 | return false; |
51 | if( strcmp((char*)p->f3,"some string" ) != 0 ) |
52 | return false; |
53 | return true; |
54 | } |
55 | |
56 | struct INNER2 // size = 12 bytes |
57 | { |
58 | INT f1; |
59 | FLOAT f2; |
60 | LPCSTR f3; |
61 | }; |
62 | |
63 | void ChangeINNER2(INNER2* p) |
64 | { |
65 | p->f1 = 77; |
66 | p->f2 = 77.0; |
67 | const char* temp = "changed string" ; |
68 | size_t len = strlen(temp); |
69 | LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) ); |
70 | strcpy_s((char*)str,len+1,temp); |
71 | p->f3 = str; |
72 | } |
73 | |
74 | void PrintINNER2(INNER2* p, const char* name) |
75 | { |
76 | printf("\t%s.f1 = %d\n" , name, p->f1); |
77 | printf("\t%s.f2 = %f\n" , name, p->f2); |
78 | printf("\t%s.f3 = %s\n" , name, p->f3); |
79 | } |
80 | |
81 | bool IsCorrectINNER2(INNER2* p) |
82 | { |
83 | if(p->f1 != 1) |
84 | return false; |
85 | if(p->f2 != 1.0) |
86 | return false; |
87 | if(memcmp(p->f3, "some string" ,11*sizeof(char)) != 0 ) |
88 | return false; |
89 | return true; |
90 | } |
91 | |
92 | struct InnerExplicit |
93 | { |
94 | #ifdef WINDOWS |
95 | union |
96 | { |
97 | INT f1; |
98 | FLOAT f2; |
99 | }; |
100 | CHAR _unused0[4]; |
101 | LPCSTR f3; |
102 | #else |
103 | union |
104 | { |
105 | INT f1; |
106 | FLOAT f2; |
107 | }; |
108 | INT _unused0; |
109 | LPCSTR f3; |
110 | #endif |
111 | }; |
112 | |
113 | void PrintInnerExplicit(InnerExplicit* p, const char* name) |
114 | { |
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); |
118 | } |
119 | |
120 | void ChangeInnerExplicit(InnerExplicit* p) |
121 | { |
122 | p->f1 = 77; |
123 | |
124 | const char* temp = "changed string" ; |
125 | size_t len = strlen(temp); |
126 | LPCSTR str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) ); |
127 | strcpy_s((char*)str,len+1,temp); |
128 | p->f3 = str; |
129 | } |
130 | |
131 | struct InnerArraySequential |
132 | { |
133 | InnerSequential arr[NumArrElements]; |
134 | }; |
135 | |
136 | void PrintInnerArraySequential(InnerArraySequential* p, const char* name) |
137 | { |
138 | for(int i = 0; i < NumArrElements; i++) |
139 | { |
140 | printf("\t%s.arr[%d].f1 = %d\n" , name, i, (p->arr)[i].f1); |
141 | printf("\t%s.arr[%d].f2 = %f\n" , name, i, (p->arr)[i].f2); |
142 | printf("\t%s.arr[%d].f2 = %s\n" , name, i, (p->arr)[i].f3); |
143 | } |
144 | } |
145 | |
146 | void ChangeInnerArraySequential(InnerArraySequential* p) |
147 | { |
148 | const char* lpstr = "changed string" ; |
149 | LPSTR temp; |
150 | for(int i = 0; i < NumArrElements; i++) |
151 | { |
152 | (p->arr)[i].f1 = 77; |
153 | (p->arr)[i].f2 = 77.0; |
154 | |
155 | size_t size = sizeof(char) * (strlen(lpstr) + 1); |
156 | temp = (LPSTR)CoreClrAlloc( size ); |
157 | memset(temp, 0, size); |
158 | if(temp) |
159 | { |
160 | strcpy_s((char*)temp,size,lpstr); |
161 | (p->arr)[i].f3 = temp; |
162 | } |
163 | else |
164 | { |
165 | printf("Memory Allocated Failed!" ); |
166 | } |
167 | } |
168 | } |
169 | |
170 | bool IsCorrectInnerArraySequential(InnerArraySequential* p) |
171 | { |
172 | for(int i = 0; i < NumArrElements; i++) |
173 | { |
174 | if( (p->arr)[i].f1 != 1 ) |
175 | return false; |
176 | if( (p->arr)[i].f2 != 1.0 ) |
177 | return false; |
178 | } |
179 | return true; |
180 | } |
181 | |
182 | #ifdef WINDOWS |
183 | #ifdef _WIN64 |
184 | union OUTER3 // size = 32 bytes |
185 | { |
186 | struct InnerSequential arr[2]; |
187 | struct |
188 | { |
189 | CHAR _unused0[24]; |
190 | LPCSTR f4; |
191 | }; |
192 | }; |
193 | #else |
194 | struct OUTER3 // size = 28 bytes |
195 | { |
196 | struct InnerSequential arr[2]; |
197 | LPCSTR f4; |
198 | }; |
199 | #endif |
200 | #else |
201 | struct OUTER3 // size = 28 bytes |
202 | { |
203 | struct InnerSequential arr[2]; |
204 | LPCSTR f4; |
205 | }; |
206 | #endif |
207 | |
208 | void PrintOUTER3(OUTER3* p, const char* name) |
209 | { |
210 | for(int i = 0; i < NumArrElements; i++) |
211 | { |
212 | printf("\t%s.arr[%d].f1 = %d\n" , name, i, (p->arr)[i].f1); |
213 | printf("\t%s.arr[%d].f2 = %f\n" , name, i, (p->arr)[i].f2); |
214 | printf("\t%s.arr[%d].f3 = %s\n" , name, i, (p->arr)[i].f3); |
215 | } |
216 | printf("\t%s.f4 = %s\n" ,name,p->f4); |
217 | } |
218 | |
219 | void ChangeOUTER3(OUTER3* p) |
220 | { |
221 | const char* temp = "changed string" ; |
222 | size_t len = strlen(temp); |
223 | LPCSTR str = NULL; |
224 | for(int i = 0; i < NumArrElements; i++) |
225 | { |
226 | (p->arr)[i].f1 = 77; |
227 | (p->arr)[i].f2 = 77.0; |
228 | |
229 | str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) ); |
230 | strcpy_s((char*)str,len+1,temp); |
231 | (p->arr)[i].f3 = str; |
232 | } |
233 | |
234 | str = (LPCSTR)CoreClrAlloc( sizeof(char)*(len+1) ); |
235 | strcpy_s((char*)str,len+1,temp); |
236 | p->f4 = str; |
237 | } |
238 | |
239 | bool IsCorrectOUTER3(OUTER3* p) |
240 | { |
241 | for(int i = 0; i < NumArrElements; i++) |
242 | { |
243 | if( (p->arr)[i].f1 != 1 ) |
244 | return false; |
245 | if( (p->arr)[i].f2 != 1.0 ) |
246 | return false; |
247 | if( memcmp((p->arr)[i].f3, "some string" ,11*sizeof(char)) != 0 ) |
248 | return false; |
249 | } |
250 | if(memcmp(p->f4,"some string" ,11*sizeof(char)) != 0) |
251 | { |
252 | return false; |
253 | } |
254 | return true; |
255 | } |
256 | |
257 | struct CharSetAnsiSequential |
258 | { |
259 | LPCSTR f1; |
260 | char f2; |
261 | }; |
262 | |
263 | void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, const char* name) |
264 | { |
265 | printf("\t%s.f1 = %s\n" , name, p->f1); |
266 | printf("\t%s.f2 = %c\n" , name, p->f2); |
267 | } |
268 | |
269 | void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p) |
270 | { |
271 | const char* strSource = "change string" ; |
272 | size_t size = strlen(strSource) + 1; |
273 | LPSTR temp = (LPSTR)CoreClrAlloc(size); |
274 | if(temp != NULL) |
275 | { |
276 | strcpy_s((char*)temp,size,strSource); |
277 | p->f1 = temp; |
278 | p->f2 = 'n'; |
279 | } |
280 | else |
281 | { |
282 | printf("Memory Allocated Failed!" ); |
283 | } |
284 | } |
285 | |
286 | bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p) |
287 | { |
288 | if(strcmp((char*)p->f1, (char*)"some string" ) != 0 ) |
289 | return false; |
290 | if(p->f2 != 'c') |
291 | return false; |
292 | return true; |
293 | } |
294 | |
295 | |
296 | struct CharSetUnicodeSequential |
297 | { |
298 | LPCWSTR f1; |
299 | WCHAR f2; |
300 | }; |
301 | |
302 | void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, const char* name) |
303 | { |
304 | #ifdef _WIN32 |
305 | wprintf(L"\t%S.first = %s\n" , name, p->f1); |
306 | wprintf(L"\t%S.last = %c\n" , name, p->f2); |
307 | #else |
308 | wprintf(L"\t%s.first = %s\n" , name, p->f1); |
309 | wprintf(L"\t%s.last = %c\n" , name, p->f2); |
310 | #endif |
311 | } |
312 | |
313 | void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p) |
314 | { |
315 | LPCWSTR strSource = W("change string" ); |
316 | size_t len = wcslen(strSource); |
317 | LPCWSTR temp = (LPCWSTR)CoreClrAlloc(sizeof(WCHAR)*(len+1)); |
318 | if(temp != NULL) |
319 | { |
320 | wcscpy_s((WCHAR*)temp, (len+1), strSource); |
321 | p->f1 = temp; |
322 | p->f2 = L'n'; |
323 | } |
324 | else |
325 | { |
326 | printf("Memory Allocated Failed!" ); |
327 | } |
328 | } |
329 | |
330 | bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p) |
331 | { |
332 | LPCWSTR expected= W("some string" ); |
333 | LPCWSTR actual = p->f1; |
334 | if(0 != wcscmp(actual, expected)) |
335 | { |
336 | return false; |
337 | } |
338 | if(p->f2 != L'c') |
339 | { |
340 | return false; |
341 | } |
342 | return true; |
343 | } |
344 | |
345 | struct NumberSequential // size = 64 bytes |
346 | { |
347 | LONG64 i64; |
348 | ULONG64 ui64; |
349 | DOUBLE d; |
350 | INT i32; |
351 | UINT ui32; |
352 | SHORT s1; |
353 | WORD us1; |
354 | SHORT i16; |
355 | WORD ui16; |
356 | FLOAT sgl; |
357 | BYTE b; |
358 | CHAR sb; |
359 | }; |
360 | |
361 | void PrintNumberSequential(NumberSequential* str, const char* name) |
362 | { |
363 | printf("\t%s.i32 = %d\n" , name, str->i32); |
364 | printf("\t%s.ui32 = %d\n" , name, str->ui32); |
365 | printf("\t%s.s1 = %d\n" , name, str->s1); |
366 | printf("\t%s.us1 = %u\n" , name, str->us1); |
367 | printf("\t%s.b = %u\n" , name, str->b); |
368 | printf("\t%s.sb = %d\n" , name, str->sb); |
369 | printf("\t%s.i16 = %d\n" , name, str->i16); |
370 | printf("\t%s.ui16 = %u\n" , name, str->ui16); |
371 | printf("\t%s.i64 = %lld\n" , name, str->i64); |
372 | printf("\t%s.ui64 = %llu\n" , name, str->ui64); |
373 | printf("\t%s.sgl = %f\n" , name, str->sgl); |
374 | printf("\t%s.d = %f\n" ,name, str->d); |
375 | } |
376 | |
377 | void ChangeNumberSequential(NumberSequential* p) |
378 | { |
379 | p->i32 = 0; |
380 | p->ui32 = 32; |
381 | p->s1 = 0; |
382 | p->us1 = 16; |
383 | p->b = 0; |
384 | p->sb = 8; |
385 | p->i16 = 0; |
386 | p->ui16 = 16; |
387 | p->i64 = 0; |
388 | p->ui64 = 64; |
389 | p->sgl = 64.0; |
390 | p->d = 6.4; |
391 | } |
392 | |
393 | bool IsCorrectNumberSequential(NumberSequential* p) |
394 | { |
395 | if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || |
396 | p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 || |
397 | p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2) |
398 | { |
399 | return false; |
400 | } |
401 | return true; |
402 | } |
403 | |
404 | struct S3 // size = 1032 bytes |
405 | { |
406 | BOOL flag; |
407 | LPCSTR str; |
408 | INT vals[256]; |
409 | }; |
410 | |
411 | void PrintS3(S3* str, const char* name) |
412 | { |
413 | printf("\t%s.flag = %d\n" , name, str->flag); |
414 | printf("\t%s.str = %s\n" , name, str->str); |
415 | for(int i = 0; i<256 ;i++) |
416 | { |
417 | printf("\t%s.vals[%d] = %d\n" ,name,i,str->vals[i]); |
418 | } |
419 | } |
420 | |
421 | void ChangeS3(S3* p) |
422 | { |
423 | p->flag = false; |
424 | |
425 | const char* strSource = "change string" ; |
426 | size_t len = strlen(strSource); |
427 | LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*(len+1)); |
428 | if(temp != NULL) |
429 | { |
430 | memset((LPVOID)temp,0,len+1); |
431 | strncpy_s((char*)temp,len+1,strSource,len); |
432 | p->str = temp; |
433 | } |
434 | for(int i = 1;i<257;i++) |
435 | { |
436 | p->vals[i-1] = i; |
437 | } |
438 | } |
439 | |
440 | bool IsCorrectS3(S3* p) |
441 | { |
442 | int iflag = 0; |
443 | if(!p->flag || strcmp((char*)p->str,"some string" ) != 0) |
444 | return false; |
445 | for (int i = 0; i < 256; i++) |
446 | { |
447 | if (p->vals[i] != i) |
448 | { |
449 | printf("\tThe Index of %i is not expected" ,i); |
450 | iflag++; |
451 | } |
452 | } |
453 | if (iflag != 0) |
454 | { |
455 | return false; |
456 | } |
457 | return true; |
458 | } |
459 | |
460 | struct S4 // size = 8 bytes |
461 | { |
462 | INT age; |
463 | LPCSTR name; |
464 | }; |
465 | |
466 | enum Enum1 |
467 | { |
468 | e1 = 1, |
469 | e2 = 3 |
470 | }; |
471 | |
472 | struct S5 // size = 8 bytes |
473 | { |
474 | struct S4 s4; |
475 | Enum1 ef; |
476 | }; |
477 | |
478 | void PrintS5(S5* str, const char* name) |
479 | { |
480 | printf("\t%s.s4.age = %d" , name, str->s4.age); |
481 | printf("\t%s.s4.name = %s" , name, str->s4.name); |
482 | printf("\t%s.ef = %d" , name, str->ef); |
483 | } |
484 | |
485 | void ChangeS5(S5* str) |
486 | { |
487 | Enum1 eInstance = e2; |
488 | const char* strSource = "change string" ; |
489 | size_t len = strlen(strSource); |
490 | LPCSTR temp = (LPCSTR)CoreClrAlloc(sizeof(char)*(len+1)); |
491 | if(temp != NULL) |
492 | { |
493 | memset((LPVOID)temp,0,len+1); |
494 | strncpy_s((char*)temp,len+1,strSource,len); |
495 | str->s4.name = temp; |
496 | } |
497 | str->s4.age = 64; |
498 | str->ef = eInstance; |
499 | } |
500 | |
501 | bool IsCorrectS5(S5* str) |
502 | { |
503 | Enum1 eInstance = e1; |
504 | if(str->s4.age != 32 || strcmp((char*)str->s4.name,"some string" ) != 0) |
505 | return false; |
506 | if(str->ef != eInstance) |
507 | { |
508 | return false; |
509 | } |
510 | return true; |
511 | } |
512 | |
513 | struct StringStructSequentialAnsi // size = 8 bytes |
514 | { |
515 | LPCSTR first; |
516 | LPCSTR last; |
517 | }; |
518 | |
519 | void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, const char* name) |
520 | { |
521 | printf("\t%s.first = %s\n" , name, str->first); |
522 | printf("\t%s.last = %s\n" , name, str->last); |
523 | } |
524 | |
525 | bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str) |
526 | { |
527 | char strOne[512]; |
528 | char strTwo[512]; |
529 | for(int i = 0;i<512;i++) |
530 | { |
531 | strOne[i] = 'a'; |
532 | strTwo[i] = 'b'; |
533 | } |
534 | |
535 | if(memcmp(str->first,strOne,512)!= 0) |
536 | return false; |
537 | |
538 | if(memcmp(str->last,strTwo,512)!= 0) |
539 | return false; |
540 | |
541 | return true; |
542 | } |
543 | |
544 | void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str) |
545 | { |
546 | char* newFirst = (char*)CoreClrAlloc(sizeof(char)*513); |
547 | char* newLast = (char*)CoreClrAlloc(sizeof(char)*513); |
548 | for (int i = 0; i < 512; ++i) |
549 | { |
550 | newFirst[i] = 'b'; |
551 | newLast[i] = 'a'; |
552 | } |
553 | newFirst[512] = '\0'; |
554 | newLast[512] = '\0'; |
555 | |
556 | str->first = newFirst; |
557 | str->last = newLast; |
558 | } |
559 | |
560 | struct StringStructSequentialUnicode // size = 8 bytes |
561 | { |
562 | LPCWSTR first; |
563 | LPCWSTR last; |
564 | }; |
565 | |
566 | void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, const char* name) |
567 | { |
568 | #ifdef _WIN32 |
569 | wprintf(L"\t%S.first = %s\n" , name, str->first); |
570 | wprintf(L"\t%S.last = %s\n" , name, str->last); |
571 | #else |
572 | wprintf(L"\t%s.first = %s\n" , name, str->first); |
573 | wprintf(L"\t%s.last = %s\n" , name, str->last); |
574 | #endif |
575 | } |
576 | |
577 | bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str) |
578 | { |
579 | WCHAR strOne[256+1]; |
580 | WCHAR strTwo[256+1]; |
581 | |
582 | for(int i = 0;i<256;++i) |
583 | { |
584 | strOne[i] = L'a'; |
585 | strTwo[i] = L'b'; |
586 | } |
587 | strOne[256] = L'\0'; |
588 | strTwo[256] = L'\0'; |
589 | |
590 | if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0) |
591 | return false; |
592 | if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0) |
593 | return false; |
594 | return true; |
595 | } |
596 | |
597 | void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str) |
598 | { |
599 | WCHAR* newFirst = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257); |
600 | WCHAR* newLast = (WCHAR*)CoreClrAlloc(sizeof(WCHAR)*257); |
601 | for (int i = 0; i < 256; ++i) |
602 | { |
603 | newFirst[i] = L'b'; |
604 | newLast[i] = L'a'; |
605 | } |
606 | newFirst[256] = L'\0'; |
607 | newLast[256] = L'\0'; |
608 | str->first = (const WCHAR*)newFirst; |
609 | str->last = (const WCHAR*)newLast; |
610 | } |
611 | |
612 | struct S8 // size = 32 bytes |
613 | { |
614 | LPCSTR name; |
615 | BOOL gender; |
616 | HRESULT i32; |
617 | HRESULT ui32; |
618 | WORD jobNum; |
619 | CHAR mySByte; |
620 | }; |
621 | |
622 | void PrintS8(S8* str, const char* name) |
623 | { |
624 | printf("\t%s.name = %s\n" ,name, str->name); |
625 | printf("\t%s.gender = %d\n" , name, str->gender); |
626 | printf("\t%s.jobNum = %d\n" ,name, str->jobNum); |
627 | printf("\t%s.i32 = %d\n" , name, (int)(str->i32)); |
628 | printf("\t%s.ui32 = %u\n" , name, (unsigned int)(str->ui32)); |
629 | printf("\t%s.mySByte = %c\n" , name, str->mySByte); |
630 | } |
631 | |
632 | bool IsCorrectS8(S8* str) |
633 | { |
634 | if(memcmp( str->name,"hello" , strlen("hello" )*sizeof(char)+1 )!= 0) |
635 | return false; |
636 | if(!str->gender) |
637 | return false; |
638 | if(str->jobNum != 10) |
639 | return false; |
640 | if(str->i32!= 128 || str->ui32 != 128) |
641 | return false; |
642 | if(str->mySByte != 32) |
643 | return false; |
644 | return true; |
645 | } |
646 | |
647 | void ChangeS8(S8* str) |
648 | { |
649 | const char* lpstr = "world" ; |
650 | size_t size = sizeof(char) * (strlen(lpstr) + 1); |
651 | LPSTR temp = (LPSTR)CoreClrAlloc( size ); |
652 | memset(temp, 0, size); |
653 | if(temp) |
654 | { |
655 | strcpy_s((char*)temp,size,lpstr); |
656 | str->name = temp; |
657 | } |
658 | else |
659 | { |
660 | printf("Memory Allocated Failed!" ); |
661 | } |
662 | str->gender = false; |
663 | str->jobNum = 1; |
664 | str->i32 = 256; |
665 | str->ui32 = 256; |
666 | str->mySByte = 64; |
667 | } |
668 | |
669 | #pragma pack (8) |
670 | struct IntergerStructSequential // size = 4 bytes |
671 | { |
672 | INT i; |
673 | }; |
674 | |
675 | struct S9; |
676 | typedef void (*TestDelegate1)(struct S9 myStruct); |
677 | |
678 | struct S9 // size = 8 bytes |
679 | { |
680 | HRESULT i32; |
681 | TestDelegate1 myDelegate1; |
682 | }; |
683 | |
684 | struct OuterIntergerStructSequential // size = 8 bytes |
685 | { |
686 | INT i; |
687 | struct IntergerStructSequential s_int; |
688 | }; |
689 | |
690 | struct IncludeOuterIntergerStructSequential // size = 8 bytes |
691 | { |
692 | struct OuterIntergerStructSequential s; |
693 | }; |
694 | |
695 | void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str, const char* name) |
696 | { |
697 | printf("\t%s.s.s_int.i = %d\n" , name, str->s.s_int.i); |
698 | printf("\t%s.s.i = %d\n" , name, str->s.i); |
699 | } |
700 | |
701 | bool IsCorrectIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str) |
702 | { |
703 | if(str->s.s_int.i != 32) |
704 | return false; |
705 | if(str->s.i != 32) |
706 | return false; |
707 | return true; |
708 | } |
709 | |
710 | void ChangeIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential* str) |
711 | { |
712 | str->s.s_int.i = 64; |
713 | str->s.i = 64; |
714 | } |
715 | |
716 | #ifndef WINDOWS |
717 | typedef int* LPINT; |
718 | #endif |
719 | |
720 | struct S11 // size = 8 bytes |
721 | { |
722 | LPINT i32; |
723 | INT i; |
724 | }; |
725 | |
726 | union U // size = 8 bytes |
727 | { |
728 | INT i32; |
729 | UINT ui32; |
730 | LPVOID iPtr; |
731 | LPVOID uiPtr; |
732 | SHORT s; |
733 | WORD us; |
734 | BYTE b; |
735 | CHAR sb; |
736 | LONG64 l; |
737 | ULONG64 ul; |
738 | FLOAT f; |
739 | DOUBLE d; |
740 | }; |
741 | |
742 | void PrintU(U* str, const char* name) |
743 | { |
744 | printf("\t%s.i32 = %d\n" , name, str->i32); |
745 | printf("\t%s.ui32 = %u\n" , name, str->ui32); |
746 | printf("\t%s.iPtr = %zu\n" , name, (size_t)(str->iPtr)); |
747 | printf("\t%s.uiPtr = %zu\n" , name, (size_t)(str->uiPtr)); |
748 | printf("\t%s.s = %d\n" , name, str->s); |
749 | printf("\t%s.us = %u\n" , name, str->us); |
750 | printf("\t%s.b = %u\n" , name, str->b); |
751 | printf("\t%s.sb = %d\n" , name, str->sb); |
752 | printf("\t%s.l = %lld\n" , name, str->l); |
753 | printf("\t%s.ul = %llu\n" , name, str->ul); |
754 | printf("\t%s.f = %f\n" , name, str->f); |
755 | printf("\t%s.d = %f\n" , name, str->d); |
756 | } |
757 | |
758 | void ChangeU(U* p) |
759 | { |
760 | p->i32 = 2147483647; |
761 | p->ui32 = 0; |
762 | p->iPtr = (LPVOID)(-64); |
763 | p->uiPtr = (LPVOID)(64); |
764 | p->s = 32767; |
765 | p->us = 0; |
766 | p->b = 255; |
767 | p->sb = -128; |
768 | p->l = -1234567890; |
769 | p->ul = 0; |
770 | p->f = 64.0; |
771 | p->d = 6.4; |
772 | } |
773 | |
774 | bool IsCorrectU(U* p) |
775 | { |
776 | if(p->d != 3.2) |
777 | { |
778 | return false; |
779 | } |
780 | return true; |
781 | } |
782 | |
783 | struct ByteStructPack2Explicit // size = 2 bytes |
784 | { |
785 | BYTE b1; |
786 | BYTE b2; |
787 | }; |
788 | |
789 | void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, const char* name) |
790 | { |
791 | printf("\t%s.b1 = %d" , name, str->b1); |
792 | printf("\t%s.b2 = %d" , name, str->b2); |
793 | } |
794 | |
795 | void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p) |
796 | { |
797 | p->b1 = 64; |
798 | p->b2 = 64; |
799 | } |
800 | |
801 | bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p) |
802 | { |
803 | if(p->b1 != 32 || p->b2 != 32) |
804 | return false; |
805 | return true; |
806 | } |
807 | |
808 | struct ShortStructPack4Explicit // size = 4 bytes |
809 | { |
810 | SHORT s1; |
811 | SHORT s2; |
812 | }; |
813 | |
814 | void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, const char* name) |
815 | { |
816 | printf("\t%s.s1 = %d" , name, str->s1); |
817 | printf("\t%s.s2 = %d" , name, str->s2); |
818 | } |
819 | |
820 | void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p) |
821 | { |
822 | p->s1 = 64; |
823 | p->s2 = 64; |
824 | } |
825 | |
826 | bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p) |
827 | { |
828 | if(p->s1 != 32 || p->s2 != 32) |
829 | return false; |
830 | return true; |
831 | } |
832 | |
833 | struct IntStructPack8Explicit // size = 8 bytes |
834 | { |
835 | INT i1; |
836 | INT i2; |
837 | }; |
838 | |
839 | void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, const char* name) |
840 | { |
841 | printf("\t%s.i1 = %d" , name, str->i1); |
842 | printf("\t%s.i2 = %d" , name, str->i2); |
843 | } |
844 | |
845 | void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p) |
846 | { |
847 | p->i1 = 64; |
848 | p->i2 = 64; |
849 | } |
850 | |
851 | bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p) |
852 | { |
853 | if(p->i1 != 32 || p->i2 != 32) |
854 | return false; |
855 | return true; |
856 | } |
857 | |
858 | struct LongStructPack16Explicit // size = 16 bytes |
859 | { |
860 | LONG64 l1; |
861 | LONG64 l2; |
862 | }; |
863 | |
864 | void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, const char* name) |
865 | { |
866 | printf("\t%s.l1 = %lld" , name, str->l1); |
867 | printf("\t%s.l2 = %lld" , name, str->l2); |
868 | } |
869 | |
870 | void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p) |
871 | { |
872 | p->l1 = 64; |
873 | p->l2 = 64; |
874 | } |
875 | |
876 | bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p) |
877 | { |
878 | if(p->l1 != 32 || p->l2 != 32) |
879 | return false; |
880 | return true; |
881 | } |
882 | |