Merge pull request #3600 from henricm/fix-win-network-info-tests
[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  {
17
18                 // The corresponding fix was reverted (r136567)
19                 [Test]
20                 [Category ("NotWorking")]
21                 [ExpectedException (typeof (OverflowException))]
22                 public void Test64on32 () 
23                 {
24                         if (IntPtr.Size > 4)
25                                 throw new OverflowException ("Test only applicable to 32bits machines");
26
27                         long addr = Int32.MaxValue;
28                         IntPtr p = new IntPtr (addr + 1);
29                 }
30
31                 [Test]
32                 public void TestLongOn32 ()
33                 {
34                         // int64 can be used (as a type) with a 32bits address
35                         long max32 = Int32.MaxValue;
36                         IntPtr p32max = new IntPtr (max32);
37
38                         long min32 = Int32.MinValue;
39                         IntPtr p32min = new IntPtr (min32);
40                 }
41
42                 [Test]
43                 public void Test64on64 () 
44                 {
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");
49
50                                 IntPtr pmin = new IntPtr (Int64.MinValue);
51                                 Assert.AreEqual (Int64.MinValue, (long) pmin, "Min");
52                         }
53                 }
54
55                 [Test]
56                 public void ToStringWithFormat ()
57                 {
58                         Assert.AreEqual ("0", IntPtr.Zero.ToString ("x"), "#1");
59                         Assert.AreEqual ("3b9aca00", new IntPtr (1000000000).ToString ("x"), "#2");
60                 }
61         }
62 }