In Test/System.Runtime.CompilerServices:
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 15 Oct 2009 14:36:12 +0000 (14:36 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 15 Oct 2009 14:36:12 +0000 (14:36 -0000)
2009-10-15  Sebastien Pouliot  <sebastien@ximian.com>

* RuntimeHelpersTest.cs: Add more test cases for validations

In System.Runtime.CompilerServices:
2009-10-15  Sebastien Pouliot  <sebastien@ximian.com>

* RuntimeHelpers.cs: Add missing validations

svn path=/trunk/mcs/; revision=144208

mcs/class/corlib/System.Runtime.CompilerServices/ChangeLog
mcs/class/corlib/System.Runtime.CompilerServices/RuntimeHelpers.cs
mcs/class/corlib/Test/System.Runtime.CompilerServices/ChangeLog
mcs/class/corlib/Test/System.Runtime.CompilerServices/RuntimeHelpersTest.cs

index 9c2a21343607e9f27c6430a3e2fba41482b95010..38da981d8dfcf4009eaba3968ddfeb39f261371c 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-15  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * RuntimeHelpers.cs: Add missing validations
+
 2009-09-23  Marek Safar  <marek.safar@gmail.com>
 
        * MethodImplOptions.cs: Add NoOptimization.
index 11a193b73df611cbf2206ad8afe191fcf9bcf76f..02184229878245550a5324a69b705fcdaa866ec1 100644 (file)
@@ -55,6 +55,9 @@ namespace System.Runtime.CompilerServices
 
                public static void InitializeArray (Array array, RuntimeFieldHandle fldHandle)
                {
+                       if ((array == null) || (fldHandle.Value == IntPtr.Zero))
+                               throw new ArgumentNullException ();
+
                        InitializeArray (array, fldHandle.Value);
                }
 
@@ -92,6 +95,9 @@ namespace System.Runtime.CompilerServices
 
                public static void RunClassConstructor (RuntimeTypeHandle type)
                {
+                       if (type.Value == IntPtr.Zero)
+                               throw new ArgumentException ("Handle is not initialized.", "type");
+
                        RunClassConstructor (type.Value);
                }
 
index 2fd257b7c34f98d1a27099f0338333cca34e17e4..1d90c1db9130eb2d149753c840275cecc1db78cb 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-15  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * RuntimeHelpersTest.cs: Add more test cases for validations
+
 2009-06-20  Zoltan Varga  <vargaz@gmail.com>
 
        * *.cs: Convert all tests to new-style nunit classes/methods.
index a05aee17e9cf21751453d8934cb86021f98e98a9..e7e91990b99ce8fc54d0dbfb5eb4942b81a3034c 100644 (file)
@@ -85,6 +85,74 @@ namespace MonoTests.System.Runtime.CompilerServices {
                        Assert.AreEqual (FooClass.counter, 1);
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void RunClassConstructor_Default ()
+               {
+                       RuntimeTypeHandle rth = new RuntimeTypeHandle ();
+                       Assert.AreEqual (IntPtr.Zero, rth.Value, "Value");
+                       RuntimeHelpers.RunClassConstructor (rth);
+               }
+
+               static RuntimeTypeHandle handle;
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void RunClassConstructor_Uninitialized ()
+               {
+                       RuntimeHelpers.RunClassConstructor (handle);
+               }
+
+               class Thrower {
+                       static Thrower ()
+                       {
+                               throw new NotFiniteNumberException ();
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (TypeInitializationException))]
+               public void RunClassConstructor_Throw ()
+               {
+                       RuntimeHelpers.RunClassConstructor (typeof (Thrower).TypeHandle);
+               }
+
+               class Fielder {
+                       public byte [] array = new byte [1];
+               }
+
+               static RuntimeFieldHandle rfh = typeof (Fielder).GetField ("array").FieldHandle;
+               static RuntimeFieldHandle static_rfh;
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void InitializeArray_Null ()
+               {
+                       RuntimeHelpers.InitializeArray (null, rfh);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void InitializeArray_Default ()
+               {
+                       RuntimeFieldHandle h = new RuntimeFieldHandle ();
+                       RuntimeHelpers.InitializeArray (new Fielder ().array, h);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void InitializeArray_Uninitialized ()
+               {
+                       RuntimeHelpers.InitializeArray (new Fielder ().array, static_rfh);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InitializeArray ()
+               {
+                       RuntimeHelpers.InitializeArray (new Fielder ().array, rfh);
+               }
+
 #if NET_1_1
                public void TestGetHashCode ()
                {