In ilasm/tests:
[mcs.git] / tests / test-67.cs
blob7eb792ae690d37610e8ef3635c4596d71ff1c866
1 using System;
2 using System.Runtime.InteropServices;
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;
16 [StructLayout (LayoutKind.Sequential)]
17 public struct Point {
18 public int x;
19 public int y;
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;
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;
44 public class Blah {
46 [DllImport ("Kernel32.dll")]
47 public static extern void GetSystemTime (MySystemTime st);
49 [DllImport ("User32.dll")]
50 public static extern bool PtInRect (ref Rect r, Point p);
52 public static int Main () {
54 MySystemTime st = new MySystemTime ();
56 GetSystemTime (st);
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);
61 Rect r = new Rect ();
63 r.left = 10;
64 r.top = 12;
65 r.right = 30;
66 r.bottom = 30;
68 Point p = new Point ();
70 p.x = 15;
71 p.y = 20;
73 if (!PtInRect (ref r, p))
74 return 1;
76 A a = new A ();
78 a.a = 0x12345678;
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;
89 Console.WriteLine ("Point lies inside rect");
90 Console.WriteLine ("Test passes");
91 return 0;