Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / pack-bug.cs
1 using System;
2 using System.Collections;
3 using System.Runtime.InteropServices;
4 // bug #77788
5
6 [StructLayout(LayoutKind.Sequential , Pack = 1)]
7 struct Bogus {
8         public byte b;
9         public string str;
10
11         public Bogus (int a) {
12                 b = (byte)a;
13                 str = "hello-" + a.ToString ();
14         }
15 }
16
17 class T {
18
19         static void test (Bogus[] arr) {
20                 for (int i = 0; i < 256; ++i) {
21                         if (arr [i].b != (byte)i)
22                                 throw new Exception ("wrong b at " + i);
23                         if (arr [i].str != "hello-" + i.ToString ())
24                                 throw new Exception ("wrong str at " + i);
25                 }
26         }
27         static void Main () {
28                 Bogus[] arr = new Bogus [256];
29                 int i;
30                 for (i = 0; i < 256; ++i) {
31                         arr [i] = new Bogus (i);
32                 }
33                 test (arr);
34                 for (i = 0; i < 10000; ++i) {
35                         ArrayList l = new ArrayList ();
36                         l.Add (i);
37                 }
38                 
39                 GC.Collect ();
40                 test (arr);
41         }
42 }
43