[xbuild] Throw ArgumentNullException if target name is null
[mono.git] / mono / tests / marshalbool.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class marshalbool
5 {
6         [DllImport ("libtest")]
7         static extern int mono_test_marshal_bool_in (int arg, uint expected,
8                                                      bool bDefaultMarsh,
9                                                      [MarshalAs (UnmanagedType.Bool)] bool bBoolCustMarsh,
10                                                      [MarshalAs (UnmanagedType.I1)] bool bI1CustMarsh,
11                                                      [MarshalAs (UnmanagedType.U1)] bool bU1CustMarsh,
12                                                      [MarshalAs (UnmanagedType.VariantBool)] bool bVBCustMarsh);
13
14         [DllImport ("libtest")]
15         static extern int mono_test_marshal_bool_out (int arg, uint testVal,
16                                                      out bool bDefaultMarsh,
17                                                      [MarshalAs (UnmanagedType.Bool)] out bool bBoolCustMarsh,
18                                                      [MarshalAs (UnmanagedType.I1)] out bool bI1CustMarsh,
19                                                      [MarshalAs (UnmanagedType.U1)] out bool bU1CustMarsh,
20                                                      [MarshalAs (UnmanagedType.VariantBool)] out bool bVBCustMarsh);
21
22         [DllImport ("libtest")]
23         static extern int mono_test_marshal_bool_ref (int arg, uint expected, uint testVal,
24                                                      ref bool bDefaultMarsh,
25                                                      [MarshalAs (UnmanagedType.Bool)] ref bool bBoolCustMarsh,
26                                                      [MarshalAs (UnmanagedType.I1)] ref bool bI1CustMarsh,
27                                                      [MarshalAs (UnmanagedType.U1)] ref bool bU1CustMarsh,
28                                                      [MarshalAs (UnmanagedType.VariantBool)] ref bool bVBCustMarsh);
29
30         delegate int MarshalBoolInDelegate (int arg, uint expected,
31                                             bool bDefaultMarsh,
32                                             [MarshalAs (UnmanagedType.Bool)] bool bBoolCustMarsh,
33                                             [MarshalAs (UnmanagedType.I1)] bool bI1CustMarsh,
34                                             [MarshalAs (UnmanagedType.U1)] bool bU1CustMarsh,
35                                             [MarshalAs (UnmanagedType.VariantBool)] bool bVBCustMarsh);
36
37         delegate int MarshalBoolOutDelegate (int arg, uint testVal,
38                                              out bool bDefaultMarsh,
39                                              [MarshalAs (UnmanagedType.Bool)] out bool bBoolCustMarsh,
40                                              [MarshalAs (UnmanagedType.I1)] out bool bI1CustMarsh,
41                                              [MarshalAs (UnmanagedType.U1)] out bool bU1CustMarsh,
42                                              [MarshalAs (UnmanagedType.VariantBool)] out bool bVBCustMarsh);
43
44         delegate int MarshalBoolRefDelegate (int arg, uint expected, uint testVal,
45                                              ref bool bDefaultMarsh,
46                                              [MarshalAs (UnmanagedType.Bool)] ref bool bBoolCustMarsh,
47                                              [MarshalAs (UnmanagedType.I1)] ref bool bI1CustMarsh,
48                                              [MarshalAs (UnmanagedType.U1)] ref bool bU1CustMarsh,
49                                              [MarshalAs (UnmanagedType.VariantBool)] ref bool bVBCustMarsh);
50
51         [DllImport ("libtest")]
52         static extern int mono_test_managed_marshal_bool_in (int arg, uint expected, uint testVal, MarshalBoolInDelegate fcn);
53
54         [DllImport ("libtest")]
55         static extern int mono_test_managed_marshal_bool_out (int arg, uint expected, uint testVal, MarshalBoolOutDelegate fcn);
56
57         [DllImport ("libtest")]
58         static extern int mono_test_managed_marshal_bool_ref (int arg, uint expected, uint testVal,
59                                                               uint outExpected, uint outTestVal, MarshalBoolRefDelegate fcn);
60
61         static int Main (string[] args)
62         {
63                 return TestDriver.RunTests (typeof (marshalbool), args);
64         }
65
66         unsafe public static int test_0_Default_In_Native ()
67         {
68                 int ret;
69
70                 ret = mono_test_marshal_bool_in (1, 0, false, false, false, false, false);
71                 if (ret != 0)
72                         return 0x0100 + ret;
73                 ret = mono_test_marshal_bool_in (1, 1, true, false, false, false, false);
74                 if (ret != 0)
75                         return 0x0200 + ret;
76
77                 bool testVal = false;
78                 bool* ptestVal = &testVal;
79
80                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
81                 ret = mono_test_marshal_bool_in (1, 1, testVal, false, false, false, false);
82                 if (ret != 0)
83                         return 0x0300 + ret;
84
85                 return 0;
86         }
87
88         unsafe public static int test_0_Bool_In_Native ()
89         {
90                 int ret;
91
92                 ret = mono_test_marshal_bool_in (2, 0, false, false, false, false, false);
93                 if (ret != 0)
94                         return 0x0100 + ret;
95                 ret = mono_test_marshal_bool_in (2, 1, false, true, false, false, false);
96                 if (ret != 0)
97                         return 0x0200 + ret;
98
99                 bool testVal = false;
100                 bool* ptestVal = &testVal;
101
102                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
103                 ret = mono_test_marshal_bool_in (2, 1, false, testVal, false, false, false);
104                 if (ret != 0)
105                         return 0x0300 + ret;
106
107                 return 0;
108         }
109
110         unsafe public static int test_0_I1_In_Native ()
111         {
112                 int ret;
113
114                 ret = mono_test_marshal_bool_in (3, 0, false, false, false, false, false);
115                 if (ret != 0)
116                         return 0x0100 + ret;
117                 ret = mono_test_marshal_bool_in (3, 1, false, false, true, false, false);
118                 if (ret != 0)
119                         return 0x0200 + ret;
120
121                 bool testVal = false;
122                 bool* ptestVal = &testVal;
123
124                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
125                 ret = mono_test_marshal_bool_in (3, 1, false, false, testVal, false, false);
126                 if (ret != 0)
127                         return 0x0300 + ret;
128
129                 return 0;
130         }
131
132         unsafe public static int test_0_U1_In_Native ()
133         {
134                 int ret;
135
136                 ret = mono_test_marshal_bool_in (4, 0, false, false, false, false, false);
137                 if (ret != 0)
138                         return 0x0100 + ret;
139                 ret = mono_test_marshal_bool_in (4, 1, false, false, false, true, false);
140                 if (ret != 0)
141                         return 0x0200 + ret;
142
143                 bool testVal = false;
144                 bool* ptestVal = &testVal;
145
146                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
147                 ret = mono_test_marshal_bool_in (4, 1, false, false, false, testVal, false);
148                 if (ret != 0)
149                         return 0x0300 + ret;
150
151                 return 0;
152         }
153
154         unsafe public static int test_0_VariantBool_In_Native ()
155         {
156                 int ret;
157                 int m1 = -1;
158
159                 ret = mono_test_marshal_bool_in (5, 0, false, false, false, false, false);
160                 if (ret != 0)
161                         return 0x0100 + ret;
162                 ret = mono_test_marshal_bool_in (5, (uint)m1, false, false, false, false, true);
163                 if (ret != 0)
164                         return 0x0200 + ret;
165
166                 bool testVal = false;
167                 bool* ptestVal = &testVal;
168
169                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
170                 ret = mono_test_marshal_bool_in (5, (uint)m1, false, false, false, false, testVal);
171                 if (ret != 0)
172                         return 0x0300 + ret;
173
174                 return 0;
175         }
176
177         unsafe public static int test_0_Default_Out_Native ()
178         {
179                 bool testVal = false;
180                 bool* ptestVal = &testVal;
181                 bool d = false;
182                 int ret;
183
184                 ret = mono_test_marshal_bool_out (1, 0, out testVal, out d, out d, out d, out d);
185                 if (ret != 0)
186                         return 0x0100 + ret;
187                 if (testVal)
188                         return 0x0200;
189
190                 ret = mono_test_marshal_bool_out (1, 1, out testVal, out d, out d, out d, out d);
191                 if (ret != 0)
192                         return 0x0300 + ret;
193                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
194                         return 0x0400;
195
196                 ret = mono_test_marshal_bool_out (1, 0x22000000, out testVal, out d, out d, out d, out d);
197                 if (ret != 0)
198                         return 0x0500 + ret;
199                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
200                         return 0x0600;
201
202                 return 0;
203         }
204
205         unsafe public static int test_0_Bool_Out_Native ()
206         {
207                 bool testVal = false;
208                 bool* ptestVal = &testVal;
209                 bool d = false;
210                 int ret;
211
212                 ret = mono_test_marshal_bool_out (2, 0, out d, out testVal, out d, out d, out d);
213                 if (ret != 0)
214                         return 0x0100 + ret;
215                 if (testVal)
216                         return 0x0200;
217
218                 ret = mono_test_marshal_bool_out (2, 1, out d, out testVal, out d, out d, out d);
219                 if (ret != 0)
220                         return 0x0300 + ret;
221                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
222                         return 0x0400;
223
224                 ret = mono_test_marshal_bool_out (2, 0x22000000, out d, out testVal, out d, out d, out d);
225                 if (ret != 0)
226                         return 0x0500 + ret;
227                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
228                         return 0x0600;
229
230                 return 0;
231         }
232
233         unsafe public static int test_0_I1_Out_Native ()
234         {
235                 bool testVal = false;
236                 bool* ptestVal = &testVal;
237                 bool d = false;
238                 int ret;
239
240                 ret = mono_test_marshal_bool_out (3, 0, out d, out d, out testVal, out d, out d);
241                 if (ret != 0)
242                         return 0x0100 + ret;
243                 if (testVal)
244                         return 0x0200;
245
246                 ret = mono_test_marshal_bool_out (3, 1, out d, out d, out testVal, out d, out d);
247                 if (ret != 0)
248                         return 0x0300 + ret;
249                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
250                         return 0x0400;
251
252                 ret = mono_test_marshal_bool_out (3, 0x22, out d, out d, out testVal, out d, out d);
253                 if (ret != 0)
254                         return 0x0500 + ret;
255                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
256                         return 0x0600;
257
258                 return 0;
259         }
260
261         unsafe public static int test_0_U1_Out_Native ()
262         {
263                 bool testVal = false;
264                 bool* ptestVal = &testVal;
265                 bool d = false;
266                 int ret;
267
268                 ret = mono_test_marshal_bool_out (4, 0, out d, out d, out d, out testVal, out d);
269                 if (ret != 0)
270                         return 0x0100 + ret;
271                 if (testVal)
272                         return 0x0200;
273
274                 ret = mono_test_marshal_bool_out (4, 1, out d, out d, out d, out testVal, out d);
275                 if (ret != 0)
276                         return 0x0300 + ret;
277                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
278                         return 0x0400;
279
280                 ret = mono_test_marshal_bool_out (4, 0x22, out d, out d, out d, out testVal, out d);
281                 if (ret != 0)
282                         return 0x0500 + ret;
283                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
284                         return 0x0600;
285
286                 return 0;
287         }
288
289         unsafe public static int test_0_VariantBool_Out_Native ()
290         {
291                 bool testVal = false;
292                 bool* ptestVal = &testVal;
293                 bool d = false;
294                 int ret;
295
296                 ret = mono_test_marshal_bool_out (5, 0, out d, out d, out d, out d, out testVal);
297                 if (ret != 0)
298                         return 0x0100 + ret;
299                 if (testVal)
300                         return 0x0200;
301
302                 ret = mono_test_marshal_bool_out (5, 1, out d, out d, out d, out d, out testVal);
303                 if (ret != 0)
304                         return 0x0100 + ret;
305                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
306                         return 0x0200;
307
308                 ret = mono_test_marshal_bool_out (5, 0x2200, out d, out d, out d, out d, out testVal);
309                 if (ret != 0)
310                         return 0x0100 + ret;
311                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
312                         return 0x0200;
313
314                 return 0;
315         }
316
317         unsafe public static int test_0_Default_Ref_Native ()
318         {
319                 bool testVal = false;
320                 bool* ptestVal = &testVal;
321                 bool d = false;
322                 int ret;
323
324                 ret = mono_test_marshal_bool_ref (1, 0, 0, ref testVal, ref d, ref d, ref d, ref d);
325                 if (ret != 0)
326                         return 0x0100 + ret;
327                 if (testVal)
328                         return 0x0200;
329
330                 ret = mono_test_marshal_bool_ref (1, 0, 1, ref testVal, ref d, ref d, ref d, ref d);
331                 if (ret != 0)
332                         return 0x0300 + ret;
333                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
334                         return 0x0400;
335
336                 ret = mono_test_marshal_bool_ref (1, 1, 0, ref testVal, ref d, ref d, ref d, ref d);
337                 if (ret != 0)
338                         return 0x0500 + ret;
339                 if (testVal)
340                         return 0x0600;
341
342                 testVal = true;
343                 ret = mono_test_marshal_bool_ref (1, 1, 1, ref testVal, ref d, ref d, ref d, ref d);
344                 if (ret != 0)
345                         return 0x0700 + ret;
346                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
347                         return 0x08800;
348
349                 testVal = false;
350                 ret = mono_test_marshal_bool_ref (1, 0, 0x22000000, ref testVal, ref d, ref d, ref d, ref d);
351                 if (ret != 0)
352                         return 0x0900 + ret;
353                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
354                         return 0x1000;
355
356                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
357                 ret = mono_test_marshal_bool_ref (1, 1, 0, ref testVal, ref d, ref d, ref d, ref d);
358                 if (ret != 0)
359                         return 0x1100 + ret;
360                 if (testVal)
361                         return 0x1200;
362
363                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
364                 ret = mono_test_marshal_bool_ref (1, 1, 0x22000000, ref testVal, ref d, ref d, ref d, ref d);
365                 if (ret != 0)
366                         return 0x1300 + ret;
367                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
368                         return 0x1400;
369
370                 return 0;
371         }
372
373         unsafe public static int test_0_Bool_Ref_Native ()
374         {
375                 bool testVal = false;
376                 bool* ptestVal = &testVal;
377                 bool d = false;
378                 int ret;
379
380                 ret = mono_test_marshal_bool_ref (2, 0, 0, ref d, ref testVal, ref d, ref d, ref d);
381                 if (ret != 0)
382                         return 0x0100 + ret;
383                 if (testVal)
384                         return 0x0200;
385
386                 ret = mono_test_marshal_bool_ref (2, 0, 1, ref d, ref testVal, ref d, ref d, ref d);
387                 if (ret != 0)
388                         return 0x0300 + ret;
389                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
390                         return 0x0400;
391
392                 ret = mono_test_marshal_bool_ref (2, 1, 0, ref d, ref testVal, ref d, ref d, ref d);
393                 if (ret != 0)
394                         return 0x0500 + ret;
395                 if (testVal)
396                         return 0x0600;
397
398                 testVal = true;
399                 ret = mono_test_marshal_bool_ref (2, 1, 1, ref d, ref testVal, ref d, ref d, ref d);
400                 if (ret != 0)
401                         return 0x0700 + ret;
402                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
403                         return 0x0800;
404
405                 testVal = false;
406                 ret = mono_test_marshal_bool_ref (2, 0, 0x22000000, ref d, ref testVal, ref d, ref d, ref d);
407                 if (ret != 0)
408                         return 0x0900 + ret;
409                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
410                         return 0x1000;
411
412                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
413                 ret = mono_test_marshal_bool_ref (2, 1, 0, ref d, ref testVal, ref d, ref d, ref d);
414                 if (ret != 0)
415                         return 0x1100 + ret;
416                 if (testVal)
417                         return 0x1200;
418
419                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
420                 ret = mono_test_marshal_bool_ref (2, 1, 0x22000000, ref d, ref testVal, ref d, ref d, ref d);
421                 if (ret != 0)
422                         return 0x1300 + ret;
423                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
424                         return 0x1400;
425
426                 return 0;
427         }
428
429         unsafe public static int test_0_I1_Ref_Native ()
430         {
431                 bool testVal = false;
432                 bool* ptestVal = &testVal;
433                 bool d = false;
434                 int ret;
435
436                 ret = mono_test_marshal_bool_ref (3, 0, 0, ref d, ref d, ref testVal, ref d, ref d);
437                 if (ret != 0)
438                         return 0x0100 + ret;
439                 if (testVal)
440                         return 0x0200;
441
442                 ret = mono_test_marshal_bool_ref (3, 0, 1, ref d, ref d, ref testVal, ref d, ref d);
443                 if (ret != 0)
444                         return 0x0300 + ret;
445                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
446                         return 0x0400;
447
448                 ret = mono_test_marshal_bool_ref (3, 1, 0, ref d, ref d, ref testVal, ref d, ref d);
449                 if (ret != 0)
450                         return 0x0500 + ret;
451                 if (testVal)
452                         return 0x0600;
453
454                 testVal = true;
455                 ret = mono_test_marshal_bool_ref (3, 1, 1, ref d, ref d, ref testVal, ref d, ref d);
456                 if (ret != 0)
457                         return 0x0700 + ret;
458                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
459                         return 0x0800;
460
461                 testVal = false;
462                 ret = mono_test_marshal_bool_ref (3, 0, 0x22, ref d, ref d, ref testVal, ref d, ref d);
463                 if (ret != 0)
464                         return 0x0900 + ret;
465                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
466                         return 0x1000;
467
468                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
469                 ret = mono_test_marshal_bool_ref (3, 1, 0, ref d, ref d, ref testVal, ref d, ref d);
470                 if (ret != 0)
471                         return 0x1100 + ret;
472                 if (testVal)
473                         return 0x1200;
474
475                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
476                 ret = mono_test_marshal_bool_ref (3, 1, 0x22, ref d, ref d, ref testVal, ref d, ref d);
477                 if (ret != 0)
478                         return 0x1300 + ret;
479                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
480                         return 0x1400;
481
482                 return 0;
483         }
484
485         unsafe public static int test_0_U1_Ref_Native ()
486         {
487                 bool testVal = false;
488                 bool* ptestVal = &testVal;
489                 bool d = false;
490                 int ret;
491
492                 ret = mono_test_marshal_bool_ref (4, 0, 0, ref d, ref d, ref d, ref testVal, ref d);
493                 if (ret != 0)
494                         return 0x0100 + ret;
495                 if (testVal)
496                         return 0x0200;
497
498                 ret = mono_test_marshal_bool_ref (4, 0, 1, ref d, ref d, ref d, ref testVal, ref d);
499                 if (ret != 0)
500                         return 0x0300 + ret;
501                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
502                         return 0x0400;
503
504                 ret = mono_test_marshal_bool_ref (4, 1, 0, ref d, ref d, ref d, ref testVal, ref d);
505                 if (ret != 0)
506                         return 0x0500 + ret;
507                 if (testVal)
508                         return 0x0600;
509
510                 testVal = true;
511                 ret = mono_test_marshal_bool_ref (4, 1, 1, ref d, ref d, ref d, ref testVal, ref d);
512                 if (ret != 0)
513                         return 0x0700 + ret;
514                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
515                         return 0x0800;
516
517                 testVal = false;
518                 ret = mono_test_marshal_bool_ref (4, 0, 0x22, ref d, ref d, ref d, ref testVal, ref d);
519                 if (ret != 0)
520                         return 0x0900 + ret;
521                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
522                         return 0x1000;
523
524                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
525                 ret = mono_test_marshal_bool_ref (4, 1, 0, ref d, ref d, ref d, ref testVal, ref d);
526                 if (ret != 0)
527                         return 0x1100 + ret;
528                 if (testVal)
529                         return 0x1200;
530
531                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
532                 ret = mono_test_marshal_bool_ref (4, 1, 0x22, ref d, ref d, ref d, ref testVal, ref d);
533                 if (ret != 0)
534                         return 0x1300 + ret;
535                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
536                         return 0x1400;
537
538                 return 0;
539         }
540
541         unsafe public static int test_0_VariantBool_Ref_Native ()
542         {
543                 bool testVal = false;
544                 bool* ptestVal = &testVal;
545                 bool d = false;
546                 int ret;
547
548                 ret = mono_test_marshal_bool_ref (5, 0, 0, ref d, ref d, ref d, ref d, ref testVal);
549                 if (ret != 0)
550                         return 0x0100 + ret;
551                 if (testVal)
552                         return 0x0200;
553
554                 ret = mono_test_marshal_bool_ref (5, 0, 1, ref d, ref d, ref d, ref d, ref testVal);
555                 if (ret != 0)
556                         return 0x0300 + ret;
557                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
558                         return 0x0400;
559
560                 ret = mono_test_marshal_bool_ref (5, 0xFFFF, 0, ref d, ref d, ref d, ref d, ref testVal);
561                 if (ret != 0)
562                         return 0x0500 + ret;
563                 if (testVal)
564                         return 0x0600;
565
566                 testVal = true;
567                 ret = mono_test_marshal_bool_ref (5, 0xFFFF, 1, ref d, ref d, ref d, ref d, ref testVal);
568                 if (ret != 0)
569                         return 0x0700 + ret;
570                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
571                         return 0x0800;
572
573                 testVal = false;
574                 ret = mono_test_marshal_bool_ref (5, 0, 0x2200, ref d, ref d, ref d, ref d, ref testVal);
575                 if (ret != 0)
576                         return 0x0900 + ret;
577                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
578                         return 0x1000;
579
580                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
581                 ret = mono_test_marshal_bool_ref (5, 0xFFFF, 0, ref d, ref d, ref d, ref d, ref testVal);
582                 if (ret != 0)
583                         return 0x1100 + ret;
584                 if (testVal)
585                         return 0x1200;
586
587                 Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
588                 ret = mono_test_marshal_bool_ref (5, 0xFFFF, 0x2200, ref d, ref d, ref d, ref d, ref testVal);
589                 if (ret != 0)
590                         return 0x1300 + ret;
591                 if (1 != Marshal.ReadByte ((IntPtr)ptestVal))
592                         return 0x1400;
593
594                 return 0;
595         }
596
597         public static int test_0_Default_In_Managed ()
598         {
599                 MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
600                 int ret;
601
602                 ret = mono_test_managed_marshal_bool_in (1, 0, 0, fcn);
603                 if (ret != 0)
604                         return 0x0100 + ret;
605                 ret =  mono_test_managed_marshal_bool_in (1, 1, 1, fcn);
606                 if (ret != 0)
607                         return 0x0200 + ret;
608                 ret =  mono_test_managed_marshal_bool_in (1, 1, 0x22000000, fcn);
609                 if (ret != 0)
610                         return 0x0300 + ret;
611                 return 0;
612         }
613
614         public static int test_0_Bool_In_Managed ()
615         {
616                 MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
617                 int ret;
618
619                 ret = mono_test_managed_marshal_bool_in (2, 0, 0, fcn);
620                 if (ret != 0)
621                         return 0x0100 + ret;
622                 ret =  mono_test_managed_marshal_bool_in (2, 1, 1, fcn);
623                 if (ret != 0)
624                         return 0x0200 + ret;
625                 ret =  mono_test_managed_marshal_bool_in (2, 1, 0x22000000, fcn);
626                 if (ret != 0)
627                         return 0x0300 + ret;
628                 return 0;
629         }
630
631         public static int test_0_I1_In_Managed ()
632         {
633                 MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
634                 int ret;
635
636                 ret = mono_test_managed_marshal_bool_in (3, 0, 0, fcn);
637                 if (ret != 0)
638                         return 0x0100 + ret;
639                 ret =  mono_test_managed_marshal_bool_in (3, 1, 1, fcn);
640                 if (ret != 0)
641                         return 0x0200 + ret;
642                 ret =  mono_test_managed_marshal_bool_in (3, 1, 0x22, fcn);
643                 if (ret != 0)
644                         return 0x0300 + ret;
645                 return 0;
646         }
647
648         public static int test_0_U1_In_Managed ()
649         {
650                 MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
651                 int ret;
652
653                 ret = mono_test_managed_marshal_bool_in (4, 0, 0, fcn);
654                 if (ret != 0)
655                         return 0x0100 + ret;
656                 ret = mono_test_managed_marshal_bool_in (4, 1, 1, fcn);
657                 if (ret != 0)
658                         return 0x0200 + ret;
659                 ret = mono_test_managed_marshal_bool_in (4, 1, 0x22, fcn);
660                 if (ret != 0)
661                         return 0x0300 + ret;
662                 return 0;
663         }
664
665         public static int test_0_VariantBool_In_Managed ()
666         {
667                 MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
668                 int ret;
669
670                 ret = mono_test_managed_marshal_bool_in (5, 0, 0, fcn);
671                 if (ret != 0)
672                         return 0x0100 + ret;
673                 ret = mono_test_managed_marshal_bool_in (5, 1, 0xFFFF, fcn);
674                 if (ret != 0)
675                         return 0x0200 + ret;
676                 ret = mono_test_managed_marshal_bool_in (5, 1, 0x22, fcn);
677                 if (ret != 0)
678                         return 0x0300 + ret;
679                 return 0;
680         }
681
682         public static int test_0_Default_Out_Managed ()
683         {
684                 MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
685                 int ret;
686
687                 ret = mono_test_managed_marshal_bool_out (1, 0, 0, fcn);
688                 if (ret != 0)
689                         return 0x010000 + ret; 
690                 ret = mono_test_managed_marshal_bool_out (1, 1, 1, fcn);
691                 if (ret != 0)
692                         return 0x020000 + ret;
693                 ret = mono_test_managed_marshal_bool_out (1, 1, 0x22, fcn);
694                 if (ret != 0)
695                         return 0x030000 + ret;
696                 return 0;
697         }
698
699         public static int test_0_Bool_Out_Managed ()
700         {
701                 MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
702                 int ret;
703                 
704                 ret = mono_test_managed_marshal_bool_out (2, 0, 0, fcn);
705                 if (ret != 0)
706                         return 0x010000 + ret; 
707                 ret = mono_test_managed_marshal_bool_out (2, 1, 1, fcn);
708                 if (ret != 0)
709                         return 0x020000 + ret;
710                 ret = mono_test_managed_marshal_bool_out (2, 1, 0x22, fcn);
711                 if (ret != 0)
712                         return 0x030000 + ret;
713                 return 0;
714         }
715
716         public static int test_0_I1_Out_Managed ()
717         {
718                 MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
719                 int ret;
720                 
721                 ret = mono_test_managed_marshal_bool_out (3, 0, 0, fcn);
722                 if (ret != 0)
723                         return 0x010000 + ret; 
724                 ret = mono_test_managed_marshal_bool_out (3, 1, 1, fcn);
725                 if (ret != 0)
726                         return 0x020000 + ret;
727                 ret = mono_test_managed_marshal_bool_out (3, 1, 0x22, fcn);
728                 if (ret != 0)
729                         return 0x030000 + ret;
730                 return 0;
731         }
732
733         public static int test_0_U1_Out_Managed ()
734         {
735                 MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
736                 int ret;
737                 
738                 ret = mono_test_managed_marshal_bool_out (4, 0, 0, fcn);
739                 if (ret != 0)
740                         return 0x010000 + ret; 
741                 ret = mono_test_managed_marshal_bool_out (4, 1, 1, fcn);
742                 if (ret != 0)
743                         return 0x020000 + ret;
744                 ret = mono_test_managed_marshal_bool_out (4, 1, 0x22, fcn);
745                 if (ret != 0)
746                         return 0x030000 + ret;
747                 return 0;
748         }
749
750         public static int test_0_VariantBool_Out_Managed ()
751         {
752                 MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
753                 int ret;
754                 
755                 ret = mono_test_managed_marshal_bool_out (5, 0, 0, fcn);
756                 if (ret != 0)
757                         return 0x010000 + ret; 
758                 ret = mono_test_managed_marshal_bool_out (5, 0xFFFF, 1, fcn);
759                 if (ret != 0)
760                         return 0x020000 + ret;
761                 ret = mono_test_managed_marshal_bool_out (5, 0xFFFF, 0x22, fcn);
762                 if (ret != 0)
763                         return 0x030000 + ret;
764                 return 0;
765         }
766
767         public static int test_0_Default_Ref_Managed ()
768         {
769                 MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
770                 int ret;
771
772                 ret = mono_test_managed_marshal_bool_ref (1, 0, 0, 0, 0, fcn);
773                 if (ret != 0)
774                         return 0x010000 + ret; 
775                 ret = mono_test_managed_marshal_bool_ref (1, 1, 1, 0, 0, fcn);
776                 if (ret != 0)
777                         return 0x020000 + ret; 
778                 ret = mono_test_managed_marshal_bool_ref (1, 0, 0, 1, 1, fcn);
779                 if (ret != 0)
780                         return 0x030000 + ret; 
781                 ret = mono_test_managed_marshal_bool_ref (1, 1, 1, 1, 1, fcn);
782                 if (ret != 0)
783                         return 0x040000 + ret; 
784                 ret = mono_test_managed_marshal_bool_ref (1, 1, 0x22000000, 0, 0, fcn);
785                 if (ret != 0)
786                         return 0x050000 + ret; 
787                 ret = mono_test_managed_marshal_bool_ref (1, 0, 0, 1, 0x22, fcn);
788                 if (ret != 0)
789                         return 0x060000 + ret; 
790                 ret = mono_test_managed_marshal_bool_ref (1, 1, 0x22000000, 1, 0x22, fcn);
791                 if (ret != 0)
792                         return 0x070000 + ret; 
793                 return 0;
794         }
795
796         public static int test_0_Bool_Ref_Managed ()
797         {
798                 MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
799                 int ret;
800
801                 ret = mono_test_managed_marshal_bool_ref (2, 0, 0, 0, 0, fcn);
802                 if (ret != 0)
803                         return 0x010000 + ret; 
804                 ret = mono_test_managed_marshal_bool_ref (2, 1, 1, 0, 0, fcn);
805                 if (ret != 0)
806                         return 0x020000 + ret; 
807                 ret = mono_test_managed_marshal_bool_ref (2, 0, 0, 1, 1, fcn);
808                 if (ret != 0)
809                         return 0x030000 + ret; 
810                 ret = mono_test_managed_marshal_bool_ref (2, 1, 1, 1, 1, fcn);
811                 if (ret != 0)
812                         return 0x040000 + ret; 
813                 ret = mono_test_managed_marshal_bool_ref (2, 1, 0x22000000, 0, 0, fcn);
814                 if (ret != 0)
815                         return 0x050000 + ret; 
816                 ret = mono_test_managed_marshal_bool_ref (2, 0, 0, 1, 0x22, fcn);
817                 if (ret != 0)
818                         return 0x060000 + ret; 
819                 ret = mono_test_managed_marshal_bool_ref (2, 1, 0x22000000, 1, 0x22, fcn);
820                 if (ret != 0)
821                         return 0x070000 + ret; 
822                 return 0;
823         }
824
825         public static int test_0_I1_Ref_Managed ()
826         {
827                 MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
828                 int ret;
829
830                 ret = mono_test_managed_marshal_bool_ref (3, 0, 0, 0, 0, fcn);
831                 if (ret != 0)
832                         return 0x010000 + ret; 
833                 ret = mono_test_managed_marshal_bool_ref (3, 1, 1, 0, 0, fcn);
834                 if (ret != 0)
835                         return 0x020000 + ret; 
836                 ret = mono_test_managed_marshal_bool_ref (3, 0, 0, 1, 1, fcn);
837                 if (ret != 0)
838                         return 0x030000 + ret; 
839                 ret = mono_test_managed_marshal_bool_ref (3, 1, 1, 1, 1, fcn);
840                 if (ret != 0)
841                         return 0x040000 + ret; 
842                 ret = mono_test_managed_marshal_bool_ref (3, 1, 0x22, 0, 0, fcn);
843                 if (ret != 0)
844                         return 0x050000 + ret; 
845                 ret = mono_test_managed_marshal_bool_ref (3, 0, 0, 1, 0x22, fcn);
846                 if (ret != 0)
847                         return 0x060000 + ret; 
848                 ret = mono_test_managed_marshal_bool_ref (3, 1, 0x22, 1, 0x22, fcn);
849                 if (ret != 0)
850                         return 0x070000 + ret; 
851                 return 0;
852         }
853
854         public static int test_0_U1_Ref_Managed ()
855         {
856                 MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
857                 int ret;
858
859                 ret = mono_test_managed_marshal_bool_ref (4, 0, 0, 0, 0, fcn);
860                 if (ret != 0)
861                         return 0x010000 + ret; 
862                 ret = mono_test_managed_marshal_bool_ref (4, 1, 1, 0, 0, fcn);
863                 if (ret != 0)
864                         return 0x020000 + ret; 
865                 ret = mono_test_managed_marshal_bool_ref (4, 0, 0, 1, 1, fcn);
866                 if (ret != 0)
867                         return 0x030000 + ret; 
868                 ret = mono_test_managed_marshal_bool_ref (4, 1, 1, 1, 1, fcn);
869                 if (ret != 0)
870                         return 0x040000 + ret; 
871                 ret = mono_test_managed_marshal_bool_ref (4, 1, 0x22, 0, 0, fcn);
872                 if (ret != 0)
873                         return 0x050000 + ret; 
874                 ret = mono_test_managed_marshal_bool_ref (4, 0, 0, 1, 0x22, fcn);
875                 if (ret != 0)
876                         return 0x060000 + ret; 
877                 ret = mono_test_managed_marshal_bool_ref (4, 1, 0x22, 1, 0x22, fcn);
878                 if (ret != 0)
879                         return 0x070000 + ret; 
880                 return 0;
881         }
882
883         public static int test_0_VariantBool_Ref_Managed ()
884         {
885                 MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
886                 int ret;
887
888                 ret = mono_test_managed_marshal_bool_ref (5, 0, 0, 0, 0, fcn);
889                 if (ret != 0)
890                         return 0x010000 + ret; 
891                 ret = mono_test_managed_marshal_bool_ref (5, 1, 0xFFFF, 0, 0, fcn);
892                 if (ret != 0)
893                         return 0x020000 + ret; 
894                 ret = mono_test_managed_marshal_bool_ref (5, 0, 0, 0xFFFF, 1, fcn);
895                 if (ret != 0)
896                         return 0x030000 + ret; 
897                 ret = mono_test_managed_marshal_bool_ref (5, 1, 0xFFFF, 0xFFFF, 1, fcn);
898                 if (ret != 0)
899                         return 0x040000 + ret; 
900                 ret = mono_test_managed_marshal_bool_ref (5, 1, 0x2200, 0, 0, fcn);
901                 if (ret != 0)
902                         return 0x050000 + ret; 
903                 ret = mono_test_managed_marshal_bool_ref (5, 0, 0, 0xFFFF, 0x22, fcn);
904                 if (ret != 0)
905                         return 0x060000 + ret; 
906                 ret = mono_test_managed_marshal_bool_ref (5, 1, 0x2200, 0xFFFF, 0x22, fcn);
907                 if (ret != 0)
908                         return 0x070000 + ret; 
909                 return 0;
910         }
911
912 ///////////////////////////////////////////////////////////////////
913
914         unsafe int MarshalBoolInHelper (int arg, uint expected, bool bDefaultMarsh, bool bBoolCustMarsh, bool bI1CustMarsh,
915                                         bool bU1CustMarsh, bool bVBCustMarsh)
916         {
917                 bool* ptestVal;
918                 switch (arg) {
919                 case 1 :
920                         ptestVal = &bDefaultMarsh;
921                         if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
922                                 return 1;
923                         break;
924                 case 2 :
925                         ptestVal = &bBoolCustMarsh;
926                         if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
927                                 return 2;
928                         break;
929                 case 3 :
930                         ptestVal = &bI1CustMarsh;
931                         if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
932                                 return 3;
933                         break;
934                 case 4 :
935                         ptestVal = &bU1CustMarsh;
936                         if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
937                                 return 4;
938                         break;
939                 case 5 :
940                         ptestVal = &bVBCustMarsh;
941                         if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
942                                 return 5;
943                         break;
944                 default :
945                         return 99;      
946                 }
947                 return 0;
948         }
949
950         unsafe int MarshalBoolOutHelper (int arg, uint testVal, out bool bDefaultMarsh, out bool bBoolCustMarsh,
951                                          out bool bI1CustMarsh, out bool bU1CustMarsh, out bool bVBCustMarsh)
952         {
953                 bDefaultMarsh = bBoolCustMarsh = bI1CustMarsh = bU1CustMarsh = bVBCustMarsh = false;
954                 switch (arg) {
955                 case 1:
956                         fixed (bool*ptestVal = &bDefaultMarsh)
957                         {
958                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
959                         }
960                         break;
961                 case 2:
962                         fixed (bool*ptestVal = &bBoolCustMarsh)
963                         {
964                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
965                         }
966                         break;
967                 case 3:
968                         fixed (bool*ptestVal = &bI1CustMarsh)
969                         {
970                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
971                         }
972                         break;
973                 case 4:
974                         fixed (bool*ptestVal = &bU1CustMarsh)
975                         {
976                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
977                         }
978                         break;
979                 case 5:
980                         fixed (bool*ptestVal = &bVBCustMarsh)
981                         {
982                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
983                         }
984                         break;
985                 default :
986                         return 99;
987                 }
988                 return 0;
989         }
990
991         unsafe int MarshalBoolRefHelper (int arg, uint expected, uint testVal, ref bool bDefaultMarsh, ref bool bBoolCustMarsh,
992                                          ref bool bI1CustMarsh, ref bool bU1CustMarsh, ref bool bVBCustMarsh)
993         {
994                 switch (arg) {
995                 case 1:
996                         fixed (bool*ptestVal = &bDefaultMarsh)
997                         {
998                                 if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
999                                         return 1;
1000                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
1001                         }
1002                         break;
1003                 case 2:
1004                         fixed (bool*ptestVal = &bBoolCustMarsh)
1005                         {
1006                                 if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
1007                                         return 2;
1008                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
1009                         }
1010                         break;
1011                 case 3:
1012                         fixed (bool*ptestVal = &bI1CustMarsh)
1013                         {
1014                                 if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
1015                                         return 3;
1016                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
1017                         }
1018                         break;
1019                 case 4:
1020                         fixed (bool*ptestVal = &bU1CustMarsh)
1021                         {
1022                                 if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
1023                                         return 4;
1024                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
1025                         }
1026                         break;
1027                 case 5:
1028                         fixed (bool*ptestVal = &bVBCustMarsh)
1029                         {
1030                                 if (expected != Marshal.ReadByte ((IntPtr)ptestVal))
1031                                         return 5;
1032                                 Marshal.WriteByte ((IntPtr)ptestVal, (byte)testVal);
1033                         }
1034                         break;
1035                 default :
1036                         return 99;
1037                 }
1038                 return 0;
1039         }
1040
1041 }
1042