Fake PR to test CI
[platform/upstream/coreclr.git] / tests / src / Interop / StructMarshalling / PInvoke / Helper.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class Helper
5 {
6     #region methods for InnerSequential struct
7     // Return new InnerSequential instance 
8     public static InnerSequential NewInnerSequential(int f1, float f2, string f3)
9     {
10         InnerSequential inner_seq = new InnerSequential();
11         inner_seq.f1 = f1;
12         inner_seq.f2 = f2;
13         inner_seq.f3 = f3;
14         return inner_seq;
15     }
16     //  Prints InnerSequential  
17     public static void PrintInnerSequential(InnerSequential inner_seq, string name)
18     {
19         Console.WriteLine("\t{0}.f1 = {1}", name, inner_seq.f1);
20         Console.WriteLine("\t{0}.f2 = {1}", name, inner_seq.f2);
21         Console.WriteLine("\t{0}.f3 = {1}", name, inner_seq.f3);
22     }
23     public static bool ValidateInnerSequential(InnerSequential s1, InnerSequential s2, string methodName)
24     {
25         if (s1.f1 != s2.f1 || s1.f2 != s2.f2 || s1.f3 != s2.f3)
26         {
27             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
28             Console.WriteLine("\tThe Actual is...");
29             PrintInnerSequential(s1, s1.ToString());
30             Console.WriteLine("\tThe Expected is...");
31             PrintInnerSequential(s2, s2.ToString());
32             return false;
33         }
34         else
35         {
36             Console.WriteLine("\tPASSED!");
37             return true;
38         }
39     }
40     #endregion
41
42     
43     #region methods for INNER2 struct
44     // Return new INNER2 instance 
45     public static INNER2 NewINNER2(int f1, float f2, string f3)
46     {
47         INNER2 inner = new INNER2();
48         inner.f1 = f1;
49         inner.f2 = f2;
50         inner.f3 = f3;
51         return inner;
52     }
53     //  Prints INNER2  
54     public static void PrintINNER2(INNER2 inner, string name)
55     {
56         Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1);
57         Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2);
58         Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3);
59     }
60     public static bool ValidateINNER2(INNER2 inner1, INNER2 inner2, string methodName)
61     {
62         if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3)
63         {
64             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
65             Console.WriteLine("\tThe Actual is...");
66             PrintINNER2(inner1, inner1.ToString());
67             Console.WriteLine("\tThe Expected is...");
68             PrintINNER2(inner2, inner2.ToString());
69             return false;
70         }
71         else
72         {
73             Console.WriteLine("\tPASSED!");
74             return true;
75         }
76     }
77
78     #endregion
79     
80     #region methods for InnerExplicit struct
81     // Return new InnerExplicit instance 
82     public static InnerExplicit NewInnerExplicit(int f1, float f2, string f3)
83     {
84         InnerExplicit inner = new InnerExplicit();
85         inner.f1 = f1;
86         inner.f2 = f2;
87         inner.f3 = f3;
88         return inner;
89     }
90     //  Prints InnerExplicit  
91     public static void PrintInnerExplicit(InnerExplicit inner, string name)
92     {
93         Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1);
94         Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2);
95         Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3);
96     }
97     public static bool ValidateInnerExplicit(InnerExplicit inner1, InnerExplicit inner2, string methodName)
98     {
99         if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3)
100         {
101             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
102             Console.WriteLine("\tThe Actual is...");
103             PrintInnerExplicit(inner1, inner1.ToString());
104             Console.WriteLine("\tThe Expected is...");
105             PrintInnerExplicit(inner2, inner2.ToString());
106             return false;
107         }
108         else
109         {
110             Console.WriteLine("\tPASSED!");
111             return true;
112         }
113     }
114
115     #endregion
116     
117     #region methods for InnerArraySequential struct
118     //  Returns new OUTER instance; the params are the fields of INNER; 
119     //  all the INNER elements have the same field values
120     public static InnerArraySequential NewInnerArraySequential(int f1, float f2, string f3)
121     {
122         InnerArraySequential outer = new InnerArraySequential();
123         outer.arr = new InnerSequential[Common.NumArrElements];
124         for (int i = 0; i < Common.NumArrElements; i++)
125         {
126             outer.arr[i].f1 = f1;
127             outer.arr[i].f2 = f2;
128             outer.arr[i].f3 = f3;
129         }
130         return outer;
131     }
132     //  Prints InnerArraySequential
133     public static void PrintInnerArraySequential(InnerArraySequential outer, string name)
134     {
135         for (int i = 0; i < Common.NumArrElements; i++)
136         {
137             Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
138             Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
139             Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
140         }
141     }
142     //  Returns true if the two params have the same fields
143     public static bool ValidateInnerArraySequential(InnerArraySequential outer1, InnerArraySequential outer2, string methodName)
144     {
145         for (int i = 0; i < Common.NumArrElements; i++)
146         {
147             if (outer1.arr[i].f1 != outer2.arr[i].f1 ||
148                 outer1.arr[i].f2 != outer2.arr[i].f2 ||
149                 outer1.arr[i].f3 != outer2.arr[i].f3)
150             {
151                 Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
152                 Console.WriteLine("\tThe Actual is...");
153                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
154                 Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2);
155                 Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3);
156                 Console.WriteLine("\tThe Expected is...");
157                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer2.ToString(), i, outer2.arr[i].f1);
158                 Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer2.ToString(), i, outer2.arr[i].f2);
159                 Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer2.ToString(), i, outer2.arr[i].f3);
160                 return false;
161             }
162         }
163         Console.WriteLine("\tPASSED!");
164         return true;
165     }
166     #endregion
167     
168     #region methods for InnerArrayExplicit struct
169     //  Returns new InnerArrayExplicit instance; the params are the fields of INNER; 
170     //  all the INNER elements have the same field values
171     public static InnerArrayExplicit NewInnerArrayExplicit(int f1, float f2, string f3, string f4)
172     {
173         InnerArrayExplicit outer = new InnerArrayExplicit();
174         outer.arr = new InnerSequential[Common.NumArrElements];
175         for (int i = 0; i < Common.NumArrElements; i++)
176         {
177             outer.arr[i].f1 = f1;
178             outer.arr[i].f2 = f2;
179             outer.arr[i].f3 = f3;
180         }
181         outer.f4 = f4;
182         return outer;
183     }
184     //  Prints InnerArrayExplicit
185     public static void PrintInnerArrayExplicit(InnerArrayExplicit outer, string name)
186     {
187         for (int i = 0; i < Common.NumArrElements; i++)
188         {
189             Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
190             Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
191             Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
192         }
193         Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4);
194     }
195     //  Returns true if the two params have the same fields
196     public static bool ValidateInnerArrayExplicit(InnerArrayExplicit outer1, InnerArrayExplicit InnerArrayExplicit, string methodName)
197     {
198         for (int i = 0; i < Common.NumArrElements; i++)
199         {
200             if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1)
201             {
202                 Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
203                 Console.WriteLine("\tThe Actual f1 field is...");
204                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
205                 Console.WriteLine("\tThe Expected f1 field is...");
206                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1);
207                 return false;
208             }
209         }
210         if (outer1.f4 != InnerArrayExplicit.f4)
211         {
212             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
213             Console.WriteLine("\tThe Actual f4 field is...");
214             Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4);
215             Console.WriteLine("\tThe Expected f4 field is...");
216             Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4);
217             return false;
218         }
219         Console.WriteLine("\tPASSED!");
220         return true;
221     }
222     #endregion
223     
224     #region methods for OUTER3 struct
225     //  Returns new OUTER3 instance; the params are the fields of INNER; 
226     //  all the INNER elements have the same field values
227     public static OUTER3 NewOUTER3(int f1, float f2, string f3, string f4)
228     {
229         OUTER3 outer = new OUTER3();
230         outer.arr = new InnerSequential[Common.NumArrElements];
231         for (int i = 0; i < Common.NumArrElements; i++)
232         {
233             outer.arr[i].f1 = f1;
234             outer.arr[i].f2 = f2;
235             outer.arr[i].f3 = f3;
236         }
237         outer.f4 = f4;
238         return outer;
239     }
240     //  Prints OUTER3
241     public static void PrintOUTER3(OUTER3 outer, string name)
242     {
243         for (int i = 0; i < Common.NumArrElements; i++)
244         {
245             Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1);
246             Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2);
247             Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3);
248         }
249         Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4);
250     }
251     //  Returns true if the two params have the same fields
252     public static bool ValidateOUTER3(OUTER3 outer1, OUTER3 InnerArrayExplicit, string methodName)
253     {
254         for (int i = 0; i < Common.NumArrElements; i++)
255         {
256             if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1 ||
257                 outer1.arr[i].f2 != InnerArrayExplicit.arr[i].f2 ||
258                 outer1.arr[i].f3 != InnerArrayExplicit.arr[i].f3)
259             {
260                 Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
261                 Console.WriteLine("\tThe Actual is...");
262                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1);
263                 Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2);
264                 Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3);
265                 Console.WriteLine("\tThe Expected is...");
266                 Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1);
267                 Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f2);
268                 Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f3);
269                 return false;
270             }
271         }
272         if (outer1.f4 != InnerArrayExplicit.f4)
273         {
274             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
275             Console.WriteLine("\tThe Actual f4 field is...");
276             Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4);
277             Console.WriteLine("\tThe Expected f4 field is...");
278             Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4);
279             return false;
280         }
281         Console.WriteLine("\tPASSED!");
282         return true;
283     }
284     #endregion
285      
286     #region methods for CharSetAnsiSequential struct
287     //return CharSetAnsiSequential struct instance
288     public static CharSetAnsiSequential NewCharSetAnsiSequential(string f1, char f2)
289     {
290         CharSetAnsiSequential str1 = new CharSetAnsiSequential();
291         str1.f1 = f1;
292         str1.f2 = f2;
293         return str1;
294     }
295     //print the struct CharSetAnsiSequential element
296     public static void PrintCharSetAnsiSequential(CharSetAnsiSequential str1, string name)
297     {
298         Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1);
299         Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2);
300     }
301     //  Returns true if the two params have the same fields
302     public static bool ValidateCharSetAnsiSequential(CharSetAnsiSequential str1, CharSetAnsiSequential str2, string methodName)
303     {
304         if (str1.f1 != str2.f1 || str1.f2 != str2.f2)
305         {
306             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
307             Console.WriteLine("\tThe Actual is...");
308             PrintCharSetAnsiSequential(str1, str1.ToString());
309             Console.WriteLine("\tThe Expected is...");
310             PrintCharSetAnsiSequential(str2, str2.ToString());
311             return false;
312         }
313         else
314         {
315             Console.WriteLine("\tPASSED!");
316             return true;
317         }
318     }
319
320     #endregion
321     
322     #region methods for CharSetUnicodeSequential struct
323     //return the struct CharSetUnicodeSequential instance
324     public static CharSetUnicodeSequential NewCharSetUnicodeSequential(string f1, char f2)
325     {
326         CharSetUnicodeSequential str1 = new CharSetUnicodeSequential();
327         str1.f1 = f1;
328         str1.f2 = f2;
329         return str1;
330     }
331     //print the struct CharSetUnicodeSequential element
332     public static void PrintCharSetUnicodeSequential(CharSetUnicodeSequential str1, string name)
333     {
334         Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1);
335         Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2);
336     }
337     //  Returns true if the two params have the same fields
338     public static bool ValidateCharSetUnicodeSequential(CharSetUnicodeSequential str1, CharSetUnicodeSequential str2, string methodName)
339     {
340         if (str1.f1 != str2.f1 || str1.f2 != str2.f2)
341         {
342             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
343             Console.WriteLine("\tThe Actual is...");
344             PrintCharSetUnicodeSequential(str1, str1.ToString());
345             Console.WriteLine("\tThe Expected is...");
346             PrintCharSetUnicodeSequential(str2, str2.ToString());
347             return false;
348         }
349         else
350         {
351             Console.WriteLine("\tPASSED!");
352             return true;
353         }
354     }
355     #endregion
356     
357     #region methods for NumberSequential struct
358     public static NumberSequential NewNumberSequential(int i32, uint ui32, short s1, ushort us1, Byte b, SByte sb, 
359         Int16 i16, UInt16 ui16, Int64 i64, UInt64 ui64, Single sgl, Double d)
360     {
361         NumberSequential str1 = new NumberSequential();
362         str1.i32 = i32;
363         str1.ui32 = ui32;
364         str1.s1 = s1;
365         str1.us1 = us1;
366         str1.b = b;
367         str1.sb = sb;
368         str1.i16 = i16;
369         str1.ui16 = ui16;
370         str1.i64 = i64;
371         str1.ui64 = ui64;
372         str1.sgl = sgl;
373         str1.d = d;
374         return str1;
375     }
376     public static void PrintNumberSequential(NumberSequential str1, string name)
377     {
378         Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
379         Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
380         Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1);
381         Console.WriteLine("\t{0}.us1 = {1}", name, str1.us1);
382         Console.WriteLine("\t{0}.b = {1}", name, str1.b);
383         Console.WriteLine("\t{0}.sb = {1}", name, str1.sb);
384         Console.WriteLine("\t{0}.i16 = {1}", name, str1.i16);
385         Console.WriteLine("\t{0}.ui16 = {1}", name, str1.ui16);
386         Console.WriteLine("\t{0}.i64 = {1}", name, str1.i64);
387         Console.WriteLine("\t{0}.ui64 = {1}", name, str1.ui64);
388         Console.WriteLine("\t{0}.sgl = {1}", name, str1.sgl);
389         Console.WriteLine("\t{0}.d = {1}", name, str1.d);
390     }
391     public static bool ValidateNumberSequential(NumberSequential str1, NumberSequential str2, string methodName)
392     {
393         if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.s1 != str2.s1 ||
394             str1.us1 != str2.us1 || str1.b != str2.b || str1.sb != str2.sb || str1.i16 != str2.i16 ||
395             str1.ui16 != str2.ui16 || str1.i64 != str2.i64 || str1.ui64 != str2.ui64 ||
396             str1.sgl != str2.sgl || str1.d != str2.d)
397         {
398             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
399             Console.WriteLine("\tThe Actual is...");
400             PrintNumberSequential(str1, str1.ToString());
401             Console.WriteLine("\tThe Expected is...");
402             PrintNumberSequential(str2, str2.ToString());
403             return false;
404         }
405         else
406         {
407             Console.WriteLine("\tPASSED!");
408             return true;
409         }
410     }
411     #endregion 
412     
413     #region methods for S3 struct
414     public static void InitialArray(int[] iarr, int[] icarr)
415     {
416         for (int i = 0; i < iarr.Length; i++)
417         {
418             iarr[i] = i;
419         }
420
421         for (int i = 1; i < icarr.Length + 1; i++)
422         {
423             icarr[i - 1] = i;
424         }
425     }
426
427
428     public static S3 NewS3(bool flag, string str, int[] vals)
429     {
430         S3 str1 = new S3();
431         str1.flag = flag;
432         str1.str = str;
433         str1.vals = vals;
434         return str1;
435     }
436     public static void PrintS3(S3 str1, string name)
437     {
438         Console.WriteLine("\t{0}.flag = {1}", name, str1.flag);
439         Console.WriteLine("\t{0}.flag = {1}", name, str1.str);
440         for (int i = 0; i < str1.vals.Length; i++)
441         {
442             Console.WriteLine("\t{0}.vals[{1}] = {2}", name, i, str1.vals[i]);
443         }
444     }
445     public static bool ValidateS3(S3 str1, S3 str2, string methodName)
446     {
447         int iflag = 0;
448         if (str1.flag != str2.flag || str1.str != str2.str)
449         {
450             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
451             Console.WriteLine("\tThe Actual flag field is...");
452             Console.WriteLine("\t{0}.flag = {1}", str1.ToString(), str1.flag);
453             Console.WriteLine("\t{0}.str = {1}", str1.ToString(), str1.str);
454             Console.WriteLine("\tThe Expected is...");
455             Console.WriteLine("\t{0}.flag = {1}", str2.ToString(), str2.flag);
456             Console.WriteLine("\t{0}.str = {1}", str2.ToString(), str2.str);
457             return false;
458         }
459         for (int i = 0; i < 256; i++)
460         {
461             if (str1.vals[i] != str2.vals[i])
462             {
463                 Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
464                 Console.WriteLine("\tThe Actual vals field is...");
465                 Console.WriteLine("\t{0}.vals[{1}] = {2}", str1.ToString(), i, str1.vals[i]);
466                 Console.WriteLine("\tThe Expected vals field is...");
467                 Console.WriteLine("\t{0}.vals[{1}] = {2}", str2.ToString(), i, str2.vals[i]);
468                 iflag++;
469             }
470         }
471         if (iflag != 0)
472         {
473             return false;
474         }
475         Console.WriteLine("\tPASSED!");
476         return true;
477     }
478     #endregion
479     
480     #region methods for S5 struct
481     public static S5 NewS5(int age, string name,Enum1 ef)
482     {
483         S4 s4 = new S4();
484         s4.age = age;
485         s4.name = name;
486
487         S5 s5 = new S5();
488         s5.s4 = s4;
489         s5.ef = ef;
490
491         return s5;
492     }
493     public static void PrintS5(S5 str1, string name)
494     {
495         Console.WriteLine("\t{0}.s4.age = {1}", str1.s4.age);
496         Console.WriteLine("\t{0}.s4.name = {1}", str1.s4.name);
497         Console.WriteLine("\t{0}.ef = {1}", str1.ef.ToString());
498     }
499     public static bool ValidateS5(S5 str1, S5 str2, string methodName)
500     {
501         if (str1.s4.age != str2.s4.age || str1.s4.name != str2.s4.name)
502         {
503             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
504             Console.WriteLine("\tThe Actual s4 field is...");
505             Console.WriteLine("\t{0}.s4.age = {1}", str1.ToString(), str1.s4.age);
506             Console.WriteLine("\t{0}.s4.name = {1}", str1.ToString(), str1.s4.name);
507             Console.WriteLine("\tThe Expected s4 field is...");
508             Console.WriteLine("\t{0}.s4.age = {1}", str2.ToString(), str2.s4.age);
509             Console.WriteLine("\t{0}.s4.name = {1}", str2.ToString(), str2.s4.name);
510             return false;
511         }
512         if (str1.ef != str2.ef)
513         {
514             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
515             Console.WriteLine("\tThe Actual ef field is...");
516             Console.WriteLine("\t{0}.ef = {1}", str1.ToString(), str1.ef);
517             Console.WriteLine("\tThe Expected s4 field is...");
518             Console.WriteLine("\t{0}.ef = {1}", str2.ToString(), str2.ef);
519             return false;
520         }
521         Console.WriteLine("\tPASSED!");
522         return true;
523     }
524     #endregion
525     
526     #region methods for StringStructSequentialAnsi struct
527     public static StringStructSequentialAnsi NewStringStructSequentialAnsi(string first, string last)
528     {
529         StringStructSequentialAnsi s6 = new StringStructSequentialAnsi();
530         s6.first = first;
531         s6.last = last;
532
533         return s6;
534     }
535     public static void PrintStringStructSequentialAnsi(StringStructSequentialAnsi str1, string name)
536     {
537         Console.WriteLine("\t{0}.first = {1}", name, str1.first);
538         Console.WriteLine("\t{0}.last = {1}", name, str1.last);
539     }
540     public static bool ValidateStringStructSequentialAnsi(StringStructSequentialAnsi str1, StringStructSequentialAnsi str2, string methodName)
541     {
542         if (str1.first != str2.first || str1.last != str2.last)
543         {
544             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
545             Console.WriteLine("\tThe Actual is...");
546             PrintStringStructSequentialAnsi(str1, str1.ToString());
547             Console.WriteLine("\tThe Expected is...");
548             PrintStringStructSequentialAnsi(str2, str2.ToString());
549             return false;
550         }
551         else
552         {
553             Console.WriteLine("\tPASSED!");
554             return true;
555         }
556     }
557     #endregion
558     
559     #region methods for StringStructSequentialUnicode struct
560     public static StringStructSequentialUnicode NewStringStructSequentialUnicode(string first, string last)
561     {
562         StringStructSequentialUnicode s7 = new StringStructSequentialUnicode();
563         s7.first = first;
564         s7.last = last;
565
566         return s7;
567     }
568     public static void PrintStringStructSequentialUnicode(StringStructSequentialUnicode str1, string name)
569     {
570         Console.WriteLine("\t{0}.first = {1}", name, str1.first);
571         Console.WriteLine("\t{0}.last = {1}", name, str1.last);
572     }
573     public static bool ValidateStringStructSequentialUnicode(StringStructSequentialUnicode str1, StringStructSequentialUnicode str2, string methodName)
574     {
575         if (str1.first != str2.first || str1.last != str2.last)
576         {
577             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
578             Console.WriteLine("\tThe Actual is...");
579             PrintStringStructSequentialUnicode(str1, str1.ToString());
580             Console.WriteLine("\tThe Expected is...");
581             PrintStringStructSequentialUnicode(str2, str2.ToString());
582             return false;
583         }
584         else
585         {
586             Console.WriteLine("\tPASSED!");
587             return true;
588         }
589     }
590     #endregion
591     
592     #region methods for S8 struct
593     public static S8 NewS8(string name, bool gender, UInt16 jobNum, int i32, uint ui32, sbyte mySByte)
594     {
595         S8 s8 = new S8();
596         s8.name = name;
597         s8.gender = gender;
598         s8.i32 = i32;
599         s8.ui32 = ui32;
600         s8.jobNum = jobNum;
601         s8.mySByte = mySByte;
602         return s8;
603     }
604     public static void PrintS8(S8 str1, string name)
605     {
606         Console.WriteLine("\t{0}.name = {1}", name, str1.name);
607         Console.WriteLine("\t{0}.gender = {1}", name, str1.gender);
608         Console.WriteLine("\t{0}.jobNum = {1}", name, str1.jobNum);
609         Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
610         Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
611         Console.WriteLine("\t{0}.mySByte = {1}", name, str1.mySByte);
612     }
613     public static bool ValidateS8(S8 str1, S8 str2, string methodName)
614     {
615         if (str1.name != str2.name || str1.gender != str2.gender ||
616             str1.jobNum != str2.jobNum ||
617             str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.mySByte != str2.mySByte)
618         {
619             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
620             Console.WriteLine("\tThe Actual is...");
621             PrintS8(str1, str1.ToString());
622             Console.WriteLine("\tThe Expected is...");
623             PrintS8(str2, str2.ToString());
624             return false;
625         }
626         Console.WriteLine("\tPASSED!");
627         return true;
628
629     }
630
631     #endregion
632     
633     #region methods for S9 struct
634     public static S9 NewS9(int i32, TestDelegate1 testDel1)
635     {
636         S9 s9 = new S9();
637         s9.i32 = i32;
638         s9.myDelegate1 = testDel1;
639         return s9;
640     }
641     public static bool ValidateS9(S9 str1, S9 str2, string methodName)
642     {
643         if (str1.i32 != str2.i32 || str1.myDelegate1 != str2.myDelegate1)
644         {
645             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
646             Console.WriteLine("\tThe Actual is...");
647             Console.WriteLine("\t{0}.i32 = {1}", str1.ToString(), str1.i32);
648             Console.WriteLine("\t{0}.myDelegate1 = {1}", str1.ToString(), str1.myDelegate1);
649             Console.WriteLine("\tThe Expected is...");
650             Console.WriteLine("\t{0}.i32 = {1}", str2.ToString(), str2.i32);
651             Console.WriteLine("\t{0}.myDelegate1 = {1}", str2.ToString(), str2.myDelegate1);
652             return false;
653         }
654         Console.WriteLine("\tPASSED!");
655         return true;
656     }
657     #endregion
658     
659     #region methods for IncludeOuterIntergerStructSequential struct
660     public static IncludeOuterIntergerStructSequential NewIncludeOuterIntergerStructSequential(int i321, int i322)
661     {
662         IncludeOuterIntergerStructSequential s10 = new IncludeOuterIntergerStructSequential();
663         s10.s.s_int.i = i321;
664         s10.s.i = i322;
665         return s10;
666     }
667     public static void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, string name)
668     {
669         Console.WriteLine("\t{0}.s.s_int.i = {1}", name, str1.s.s_int.i);
670         Console.WriteLine("\t{0}.s.i = {1}", name, str1.s.i);
671     }
672     public static bool ValidateIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, IncludeOuterIntergerStructSequential str2, string methodName)
673     {
674         if (str1.s.s_int.i != str2.s.s_int.i || str1.s.i != str2.s.i)
675         {
676             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
677             Console.WriteLine("\tThe Actual is...");
678             PrintIncludeOuterIntergerStructSequential(str1, str1.ToString());
679             Console.WriteLine("\tThe Expected is...");
680             PrintIncludeOuterIntergerStructSequential(str2, str2.ToString());
681             return false;
682         }
683         else
684         {
685             Console.WriteLine("\tPASSED!");
686             return true;
687         }
688     }
689     #endregion
690     
691     #region methods for S11 struct
692     unsafe public static void PrintS11(S11 str1, string name)
693     {
694         Console.WriteLine("\t{0}.i32 = {1}", name, (int)(str1.i32));
695         Console.WriteLine("\t{0}.i = {1}", name, str1.i);
696     }
697     unsafe public static S11 NewS11(int* i32, int i)
698     {
699         S11 s11 = new S11();
700         s11.i32 = i32;
701         s11.i = i;
702         return s11;
703     }
704     unsafe public static bool ValidateS11(S11 str1, S11 str2, string methodName)
705     {
706         if (str1.i32 != str2.i32 || str1.i != str2.i)
707         {
708             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
709             Console.WriteLine("\tThe Actual is...");
710             PrintS11(str1, str1.ToString());
711             Console.WriteLine("\tThe Expected is...");
712             PrintS11(str2, str2.ToString());
713             return false;
714         }
715         Console.WriteLine("\tPASSED!");
716         return true;
717     }
718     #endregion
719     
720     #region methods for U struct
721     public static U NewU(int i32, uint ui32, IntPtr iPtr, UIntPtr uiPtr, short s, ushort us, byte b, sbyte sb, long l, ulong ul, float f, double d)
722     {
723         U u = new U();
724         u.i32 = i32;
725         u.ui32 = ui32;
726         u.iPtr = iPtr;
727         u.uiPtr = uiPtr;
728         u.s = s;
729         u.us = us;
730         u.b = b;
731         u.sb = sb;
732         u.l = l;
733         u.ul = ul;
734         u.f = f;
735         u.d = d;
736
737         return u;
738     }
739     public static void PrintU(U str1, string name)
740     {
741         Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32);
742         Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32);
743         Console.WriteLine("\t{0}.iPtr = {1}", name, str1.iPtr);
744         Console.WriteLine("\t{0}.uiPtr = {1}", name, str1.uiPtr);
745         Console.WriteLine("\t{0}.s = {1}", name, str1.s);
746         Console.WriteLine("\t{0}.us = {1}", name, str1.us);
747         Console.WriteLine("\t{0}.b = {1}", name, str1.b);
748         Console.WriteLine("\t{0}.sb = {1}", name, str1.sb);
749         Console.WriteLine("\t{0}.l = {1}", name, str1.l);
750         Console.WriteLine("\t{0}.ul = {1}", name, str1.ul);
751         Console.WriteLine("\t{0}.f = {1}", name, str1.f);
752         Console.WriteLine("\t{0}.d = {1}", name, str1.d);
753     }
754     public static bool ValidateU(U str1, U str2, string methodName)
755     {
756         if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.iPtr != str2.iPtr ||
757             str1.uiPtr != str2.uiPtr || str1.s != str2.s || str1.us != str2.us ||
758             str1.b != str2.b || str1.sb != str2.sb || str1.l != str2.l || str1.ul != str2.ul ||
759             str1.f != str2.f || str1.d != str2.d)
760         {
761             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
762             Console.WriteLine("\tThe Actual is...");
763             PrintU(str1, str1.ToString());
764             Console.WriteLine("\tThe Expected is...");
765             PrintU(str2, str2.ToString());
766             return false;
767         }
768         Console.WriteLine("\tPASSED!");
769         return true;
770     }
771     #endregion
772     
773     #region methods for ByteStructPack2Explicit struct
774     public static ByteStructPack2Explicit NewByteStructPack2Explicit(byte b1, byte b2)
775     {
776         ByteStructPack2Explicit u1 = new ByteStructPack2Explicit();
777         u1.b1 = b1;
778         u1.b2 = b2;
779
780         return u1;
781     }
782     public static void PrintByteStructPack2Explicit(ByteStructPack2Explicit str1, string name)
783     {
784         Console.WriteLine("\t{0}.b1 = {1}", name, str1.b1);
785         Console.WriteLine("\t{0}.b2 = {1}", name, str1.b2);
786     }
787     public static bool ValidateByteStructPack2Explicit(ByteStructPack2Explicit str1, ByteStructPack2Explicit str2, string methodName)
788     {
789         if (str1.b1 != str2.b1 || str1.b2 != str2.b2)
790         {
791             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
792             Console.WriteLine("\tThe Actual is...");
793             PrintByteStructPack2Explicit(str1, str1.ToString());
794             Console.WriteLine("\tThe Expected is...");
795             PrintByteStructPack2Explicit(str2, str2.ToString());
796             return false;
797         }
798         else
799         {
800             Console.WriteLine("\tPASSED!");
801             return true;
802         }
803     }
804     #endregion
805     
806     #region methods for ShortStructPack4Explicit struct
807     public static ShortStructPack4Explicit NewShortStructPack4Explicit(short s1, short s2)
808     {
809         ShortStructPack4Explicit u2 = new ShortStructPack4Explicit();
810         u2.s1 = s1;
811         u2.s2 = s2;
812
813         return u2;
814     }
815     public static void PrintShortStructPack4Explicit(ShortStructPack4Explicit str1, string name)
816     {
817         Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1);
818         Console.WriteLine("\t{0}.s2 = {1}", name, str1.s2);
819     }
820     public static bool ValidateShortStructPack4Explicit(ShortStructPack4Explicit str1, ShortStructPack4Explicit str2, string methodName)
821     {
822         if (str1.s1 != str2.s1 || str1.s2 != str2.s2)
823         {
824             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
825             Console.WriteLine("\tThe Actual is...");
826             PrintShortStructPack4Explicit(str1, str1.ToString());
827             Console.WriteLine("\tThe Expected is...");
828             PrintShortStructPack4Explicit(str2, str2.ToString());
829             return false;
830         }
831         else
832         {
833             Console.WriteLine("\tPASSED!");
834             return true;
835         }
836     }
837     #endregion
838     
839     #region methods for IntStructPack8Explicit struct
840     public static IntStructPack8Explicit NewIntStructPack8Explicit(int i1, int i2)
841     {
842         IntStructPack8Explicit u3 = new IntStructPack8Explicit();
843         u3.i1 = i1;
844         u3.i2 = i2;
845
846         return u3;
847     }
848     public static void PrintIntStructPack8Explicit(IntStructPack8Explicit str1, string name)
849     {
850         Console.WriteLine("\t{0}.i1 = {1}", name, str1.i1);
851         Console.WriteLine("\t{0}.i2 = {1}", name, str1.i2);
852     }
853     public static bool ValidateIntStructPack8Explicit(IntStructPack8Explicit str1, IntStructPack8Explicit str2, string methodName)
854     {
855         if (str1.i1 != str2.i1 || str1.i2 != str2.i2)
856         {
857             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
858             Console.WriteLine("\tThe Actual is...");
859             PrintIntStructPack8Explicit(str1, str1.ToString());
860             Console.WriteLine("\tThe Expected is...");
861             PrintIntStructPack8Explicit(str2, str2.ToString());
862             return false;
863         }
864         else
865         {
866             Console.WriteLine("\tPASSED!");
867             return true;
868         }
869     }
870     #endregion
871  
872     #region methods for LongStructPack16Explicit struct
873     public static LongStructPack16Explicit NewLongStructPack16Explicit(long l1, long l2)
874     {
875         LongStructPack16Explicit u4 = new LongStructPack16Explicit();
876         u4.l1 = l1;
877         u4.l2 = l2;
878
879         return u4;
880     }
881     public static void PrintLongStructPack16Explicit(LongStructPack16Explicit str1, string name)
882     {
883         Console.WriteLine("\t{0}.l1 = {1}", name, str1.l1);
884         Console.WriteLine("\t{0}.l2 = {1}", name, str1.l2);
885     }
886     public static bool ValidateLongStructPack16Explicit(LongStructPack16Explicit str1, LongStructPack16Explicit str2, string methodName)
887     {
888         if (str1.l1 != str2.l1 || str1.l2 != str2.l2)
889         {
890             Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
891             Console.WriteLine("\tThe Actual is...");
892             PrintLongStructPack16Explicit(str1, str1.ToString());
893             Console.WriteLine("\tThe Expected is...");
894             PrintLongStructPack16Explicit(str2, str2.ToString());
895             return false;
896         }
897         else
898         {
899             Console.WriteLine("\tPASSED!");
900             return true;
901         }
902     }
903     #endregion
904     
905 }