2 // System.IntPtrTest.cs - Unit test for IntPtr
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004 Novell (http://www.novell.com)
11 using NUnit.Framework;
13 namespace MonoTests.System {
16 public class IntPtrTest {
18 // The corresponding fix was reverted (r136567)
20 [Category ("NotWorking")]
21 [ExpectedException (typeof (OverflowException))]
22 public void Test64on32 ()
25 throw new OverflowException ("Test only applicable to 32bits machines");
27 long addr = Int32.MaxValue;
28 IntPtr p = new IntPtr (addr + 1);
32 public void TestLongOn32 ()
34 // int64 can be used (as a type) with a 32bits address
35 long max32 = Int32.MaxValue;
36 IntPtr p32max = new IntPtr (max32);
38 long min32 = Int32.MinValue;
39 IntPtr p32min = new IntPtr (min32);
43 public void Test64on64 ()
45 // for 64 bits machines
46 if (IntPtr.Size > 4) {
47 IntPtr pmax = new IntPtr (Int64.MaxValue);
48 Assert.AreEqual (Int64.MaxValue, (long) pmax, "Max");
50 IntPtr pmin = new IntPtr (Int64.MinValue);
51 Assert.AreEqual (Int64.MinValue, (long) pmin, "Min");
56 public void ToStringWithFormat ()
58 Assert.AreEqual ("0", IntPtr.Zero.ToString ("x"), "#1");
59 Assert.AreEqual ("3b9aca00", new IntPtr (1000000000).ToString ("x"), "#2");