Merge pull request #2720 from mono/fix-39325
[mono.git] / mcs / class / corlib / Test / System / UIntPtrTest.cs
1 // 
2 // System.UIntPtrTest.cs - Unit test for UIntPtr
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 UIntPtrTest  {
17
18                 [Test]
19                 [ExpectedException (typeof (OverflowException))]
20                 public void Test64on32 () 
21                 {
22                         if (UIntPtr.Size > 4)
23                                 throw new OverflowException ("Test only applicable to 32bits machines");
24
25                         ulong addr = UInt32.MaxValue;
26                         UIntPtr p = new UIntPtr (addr + 1);
27                 }
28
29                 [Test]
30                 public void TestUlongOn32 ()
31                 {
32                         // int64 can be used (as a type) with a 32bits address
33                         ulong max32 = UInt32.MaxValue;
34                         UIntPtr p32max = new UIntPtr (max32);
35
36                         ulong min32 = UInt32.MinValue;
37                         UIntPtr p32min = new UIntPtr (min32);
38                 }
39
40                 [Test]
41                 public void Test64on64 () 
42                 {
43                         // for 64 bits machines
44                         if (UIntPtr.Size > 4) {
45                                 UIntPtr pmax = new UIntPtr (UInt64.MaxValue);
46                                 Assert.AreEqual (UInt64.MaxValue, (ulong) pmax, "Max");
47
48                                 UIntPtr pmin = new UIntPtr (UInt64.MinValue);
49                                 Assert.AreEqual (UInt64.MinValue, (ulong) pmin, "Min");
50                         }
51                 }
52
53                 [Test]
54                 public void ToString () 
55                 {
56                         // for 64 bits machines
57                         if (UIntPtr.Size > 4) {
58                                 Assert.AreEqual (UInt64.MaxValue.ToString (), new UIntPtr (UInt64.MaxValue).ToString (), "#1");
59                         }
60                         else {
61                                 Assert.AreEqual (UInt32.MaxValue.ToString (), new UIntPtr (UInt32.MaxValue).ToString (), "#2");
62                         }
63                 }
64         }
65 }