* MethodBuilderTest.cs: Move from Assertion to Assert. Added tests
[mono.git] / mcs / tests / test-67.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 [StructLayout (LayoutKind.Sequential)]
5 public class MySystemTime {
6         public ushort Year; 
7         public ushort Month;
8         public ushort DayOfWeek; 
9         public ushort Day; 
10         public ushort Hour; 
11         public ushort Minute; 
12         public ushort Second; 
13         public ushort Milliseconds; 
14 }
15
16 [StructLayout (LayoutKind.Sequential)]
17 public struct Point {
18         public int x;
19         public int y;
20 }
21
22 [StructLayout (LayoutKind.Explicit)]
23 public struct Rect {    
24         [FieldOffset (0)] public int left;
25         [FieldOffset (4)] public int top;
26         [FieldOffset (8)] public int right;
27         [FieldOffset (12)] public int bottom;
28 }
29
30 [StructLayout (LayoutKind.Explicit)]
31 struct A {
32         [FieldOffset (0)]
33         public int a;
34         [FieldOffset (0)]
35         public byte b1;
36         [FieldOffset (1)]
37         public byte b2;
38         [FieldOffset (2)]
39         public byte b3;
40         [FieldOffset (3)]
41         public byte b4;
42 }
43
44 public class Blah {
45
46         [DllImport ("Kernel32.dll")]
47         public static extern void GetSystemTime (MySystemTime st);
48
49         [DllImport ("User32.dll")]
50         public static extern bool PtInRect (ref Rect r, Point p);       
51
52         public static int Main () {
53
54                 MySystemTime st = new MySystemTime ();
55
56                 GetSystemTime (st);
57
58                 Console.WriteLine ("Today's date is : {0:0000}-{1:00}-{2:00}", st.Year, st.Month, st.Day);
59                 Console.WriteLine ("The time now is : {0:00}:{1:00}:{2:00}", st.Hour, st.Minute, st.Second);
60
61                 Rect r = new Rect ();
62
63                 r.left = 10;
64                 r.top  = 12;
65                 r.right = 30;
66                 r.bottom = 30;
67
68                 Point p = new Point ();
69
70                 p.x = 15;
71                 p.y = 20;
72
73                 if (!PtInRect (ref r, p))
74                         return 1;
75
76                 A a = new A ();
77
78                 a.a = 0x12345678;
79
80                 if (a.b1 != 0x78)
81                         return 2;
82                 if (a.b2 != 0x56)
83                         return 3;
84                 if (a.b3 != 0x34)
85                         return 4;
86                 if (a.b4 != 0x12)
87                         return 5;
88                 
89                 Console.WriteLine ("Point lies inside rect");
90                 Console.WriteLine ("Test passes");
91                 return 0;
92         }
93 }