Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Driesen <drieseng@users.sourceforge.net>2009-06-06 21:07:34 +0400
committerGert Driesen <drieseng@users.sourceforge.net>2009-06-06 21:07:34 +0400
commit3ee30c68d12c8989ea663fcbe294b8b21742abb8 (patch)
tree8e6a2323fd8617639d4ed362ecd388727a4c2229 /mcs/class/System/Test
parentbf070eecb16eae2d70844b7e182073a571a0b2c0 (diff)
* ContextStack.cs: Added argument check to Type indexer, avoiding a
NRE. Modify System.Int32 indexer to throw ArgumentOutOfRangeException instead of ArgumentException. Reduce number of times that item count must be obtained. * ContextStackTest.cs: Added unit tests for indexers, and argument (null) checks. svn path=/trunk/mcs/; revision=135596
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r--mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog5
-rw-r--r--mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs166
2 files changed, 155 insertions, 16 deletions
diff --git a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog
index c3c2934174e..07a95feb0c7 100644
--- a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog
+++ b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog
@@ -1,3 +1,8 @@
+2009-06-06 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * ContextStackTest.cs: Added unit tests for indexers, and argument
+ (null) checks.
+
2007-08-20 Gert Driesen <drieseng@users.sourceforge.net>
* ContextStackTest.cs: Fix build of unit tests on 1.0 profile.
diff --git a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs
index 250f0d73920..4808a3b9334 100644
--- a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs
+++ b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs
@@ -27,10 +27,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using NUnit.Framework;
-
+using System;
using System.ComponentModel.Design.Serialization;
+using NUnit.Framework;
+
namespace MonoTests.System.ComponentModel.Design.Serialization
{
[TestFixture]
@@ -45,30 +46,163 @@ namespace MonoTests.System.ComponentModel.Design.Serialization
string two = "two";
stack.Push (two);
stack.Push (one);
- Assert.AreEqual (one, stack[typeof (string)], "#1");
- Assert.AreEqual (one, stack[0], "#2");
- Assert.AreEqual (one, stack.Current, "#3");
+ Assert.AreSame (one, stack [typeof (string)], "#1");
+ Assert.AreSame (one, stack [0], "#2");
+ Assert.AreSame (one, stack.Current, "#3");
- Assert.AreEqual (one, stack.Pop (), "#4");
+ Assert.AreSame (one, stack.Pop (), "#4");
- Assert.AreEqual (two, stack[typeof (string)], "#5");
- Assert.AreEqual (two, stack[0], "#6");
- Assert.AreEqual (two, stack.Current, "#7");
+ Assert.AreSame (two, stack [typeof (string)], "#5");
+ Assert.AreSame (two, stack [0], "#6");
+ Assert.AreSame (two, stack.Current, "#7");
#if NET_2_0
string three = "three";
stack.Append (three);
- Assert.AreEqual (two, stack[typeof (string)], "#8");
- Assert.AreEqual (two, stack[0], "#9");
- Assert.AreEqual (two, stack.Current, "#10");
+ Assert.AreSame (two, stack[typeof (string)], "#8");
+ Assert.AreSame (two, stack[0], "#9");
+ Assert.AreSame (two, stack.Current, "#10");
- Assert.AreEqual (two, stack.Pop (), "#11");
+ Assert.AreSame (two, stack.Pop (), "#11");
- Assert.AreEqual (three, stack[typeof (string)], "#12");
- Assert.AreEqual (three, stack[0], "#13");
- Assert.AreEqual (three, stack.Current, "#14");
+ Assert.AreSame (three, stack[typeof (string)], "#12");
+ Assert.AreSame (three, stack[0], "#13");
+ Assert.AreSame (three, stack.Current, "#14");
+ Assert.AreSame (three, stack.Pop (), "#15");
+#else
+ Assert.AreSame (two, stack.Pop (), "#15");
+#endif
+
+ Assert.IsNull (stack.Pop (), "#16");
+ Assert.IsNull (stack.Current, "#17");
+ }
+
+#if NET_2_0
+ [Test]
+ public void Append_Context_Null ()
+ {
+ ContextStack stack = new ContextStack ();
+ try {
+ stack.Append (null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("context", ex.ParamName, "#5");
+ }
+ }
#endif
+
+ [Test] // Item (Int32)
+ public void Indexer1 ()
+ {
+ ContextStack stack = new ContextStack ();
+ string one = "one";
+ string two = "two";
+
+ stack.Push (one);
+ stack.Push (two);
+
+ Assert.AreSame (two, stack [0], "#1");
+ Assert.AreSame (one, stack [1], "#2");
+ Assert.IsNull (stack [2], "#3");
+ Assert.AreSame (two, stack.Pop (), "#4");
+ Assert.AreSame (one, stack [0], "#5");
+ Assert.IsNull (stack [1], "#6");
+ Assert.AreSame (one, stack.Pop (), "#7");
+ Assert.IsNull (stack [0], "#8");
+ Assert.IsNull (stack [1], "#9");
+ }
+
+ [Test] // Item (Int32)
+ public void Indexer1_Level_Negative ()
+ {
+ ContextStack stack = new ContextStack ();
+ stack.Push (new Foo ());
+
+ try {
+ object context = stack [-1];
+ Assert.Fail ("#A1:" + context);
+ } catch (ArgumentOutOfRangeException ex) {
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#A4");
+ Assert.AreEqual ("level", ex.ParamName, "#A5");
+ }
+
+ try {
+ object context = stack [-5];
+ Assert.Fail ("#B1:" + context);
+ } catch (ArgumentOutOfRangeException ex) {
+ Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.AreEqual (new ArgumentOutOfRangeException ("level").Message, ex.Message, "#B4");
+ Assert.AreEqual ("level", ex.ParamName, "#B5");
+ }
+ }
+
+ [Test] // Item (Type)
+ public void Indexer2 ()
+ {
+ ContextStack stack = new ContextStack ();
+
+ Foo foo = new Foo ();
+ FooBar foobar = new FooBar ();
+
+ stack.Push (foobar);
+ stack.Push (foo);
+ Assert.AreSame (foo, stack [typeof (Foo)], "#1");
+ Assert.AreSame (foo, stack [typeof (IFoo)], "#2");
+ Assert.AreSame (foo, stack.Pop (), "#3");
+ Assert.AreSame (foobar, stack [typeof (Foo)], "#4");
+ Assert.AreSame (foobar, stack [typeof (FooBar)], "#5");
+ Assert.AreSame (foobar, stack [typeof (IFoo)], "#6");
+ Assert.IsNull (stack [typeof (string)], "#7");
+ }
+
+ [Test] // Item (Type)
+ public void Indexer2_Type_Null ()
+ {
+ ContextStack stack = new ContextStack ();
+ stack.Push (new Foo ());
+ try {
+ object context = stack [(Type) null];
+ Assert.Fail ("#1:" + context);
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("type", ex.ParamName, "#5");
+ }
+ }
+
+ [Test]
+ public void Push_Context_Null ()
+ {
+ ContextStack stack = new ContextStack ();
+ try {
+ stack.Push (null);
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("context", ex.ParamName, "#5");
+ }
+ }
+
+ public interface IFoo
+ {
+ }
+
+ public class Foo : IFoo
+ {
+ }
+
+ public class FooBar : Foo
+ {
}
}
}