2004-05-23 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / Test / System / IntPtrTest.cs
1 // 
2 // System.IntPtrTest.cs - Unit test for IntPtr
3 //
4 // Author
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 //
9
10 using System;
11 using NUnit.Framework;
12
13 namespace MonoTests.System  {
14
15         [TestFixture]
16         public class IntPtrTest : Assertion {
17
18                 [Test]
19                 [ExpectedException (typeof (OverflowException))]
20                 public void Test64on32 () 
21                 {
22                         if (IntPtr.Size > 4)
23                                 throw new OverflowException ("Test only applicable to 32bits machines");
24
25                         long addr = Int32.MaxValue;
26                         IntPtr p = new IntPtr (addr + 1);
27                 }
28
29                 [Test]
30                 public void TestLongOn32 ()
31                 {
32                         // int64 can be used (as a type) with a 32bits address
33                         long max32 = Int32.MaxValue;
34                         IntPtr p32max = new IntPtr (max32);
35
36                         long min32 = Int32.MinValue;
37                         IntPtr p32min = new IntPtr (min32);
38                 }
39
40                 [Test]
41                 public void Test64on64 () 
42                 {
43                         // for 64 bits machines
44                         if (IntPtr.Size > 4) {
45                                 IntPtr pmax = new IntPtr (Int64.MaxValue);
46                                 AssertEquals ("Max", Int64.MaxValue, (long) pmax);
47
48                                 IntPtr pmin = new IntPtr (Int64.MinValue);
49                                 AssertEquals ("Min", Int64.MinValue, (long) pmin);
50                         }
51                 }
52         }
53 }