Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / gtest-fixedbuffer-01.cs
1 // Compiler options: -unsafe -r:gtest-fixedbuffer-01-lib.dll
2
3 // Fixed buffers tests
4
5 using System;
6 using System.Runtime.InteropServices;
7
8 [module: DefaultCharSet (CharSet.Ansi)]
9
10 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
11 public unsafe struct TestNew {
12         private fixed char test_1 [128];
13         public fixed bool test2 [4];
14         
15         public fixed int T [2];
16         public fixed bool test20 [4], test21 [40];
17         
18         private int foo, foo2;
19         public void SetTest () {
20                 fixed (char* c = test_1) {
21                         *c = 'g';
22                 }
23         }
24 }
25
26 struct Struct2 {
27         public unsafe fixed byte Pad[64];
28 }
29
30 public class C {
31         unsafe static int Test () {
32                 TestNew tt = new TestNew ();
33                 tt.SetTest ();
34                 tt.test2 [2] = false;
35                 tt.T [1] = 5544;
36                 if (tt.T [1] != 5544)
37                         return 2;
38         
39                 ExternalStruct es = new ExternalStruct ();
40                 es.double_buffer [1] = 999999.8888;
41                 es.double_buffer [0] = es.double_buffer [1];
42
43                 // Attributes test
44                 if (Attribute.GetCustomAttribute (typeof (TestNew).GetField ("test2"), typeof (System.Runtime.CompilerServices.FixedBufferAttribute)) == null)
45                         return 3;
46
47                 
48                 if (typeof (TestNew).GetNestedTypes ().Length != 5)
49                         return 5;
50
51                 foreach (Type t in typeof (TestNew).GetNestedTypes ()) {
52                         if (Attribute.GetCustomAttribute (t, typeof (System.Runtime.CompilerServices.CompilerGeneratedAttribute)) == null)
53                                 return 40;
54                                 
55                         if (Attribute.GetCustomAttribute (t, typeof (System.Runtime.CompilerServices.UnsafeValueTypeAttribute)) == null)
56                                 return 41;
57                                 
58                         if (!t.IsUnicodeClass)
59                                 return 42;
60                 }
61
62                 Console.WriteLine ("OK");
63                 return 0;
64         }
65     
66         public static int Main () {
67                 return Test ();
68         }
69 }