diff options
author | Ivan Zlatev <ivan@ivanz.com> | 2007-08-19 12:24:16 +0400 |
---|---|---|
committer | Ivan Zlatev <ivan@ivanz.com> | 2007-08-19 12:24:16 +0400 |
commit | 917ec97a49ae9a122ee5ee54618b234bae13afd1 (patch) | |
tree | 4db52a5e6cc4be6324b5a1aa92cf284440ef6cd9 /mcs | |
parent | 3b31446cee715207543a757960c24693ee3b665c (diff) |
2007-08-19 Ivan N. Zlatev <contact@i-nz.net>
* ContextStack.cs: Update to 2.0.
* ContextStackTest.cs: New unit tests for ContextStack.
svn path=/trunk/mcs/; revision=84369
Diffstat (limited to 'mcs')
4 files changed, 116 insertions, 19 deletions
diff --git a/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog b/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog index 6ffcb96cf92..232cce24a2d 100644 --- a/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog +++ b/mcs/class/System/System.ComponentModel.Design.Serialization/ChangeLog @@ -1,3 +1,7 @@ +2007-08-18 Ivan N. Zlatev <contact@i-nz.net> + + * ContextStack.cs: Update to 2.0. + 2007-07-21 Gert Driesen <drieseng@users.sourceforge.net> * InstanceDescriptor.cs: Allow null members. Fixed exception messages. diff --git a/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs b/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs index 7c1bc952245..e7b0dd96066 100644 --- a/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs +++ b/mcs/class/System/System.ComponentModel.Design.Serialization/ContextStack.cs @@ -4,9 +4,11 @@ // Author: // Alejandro Sánchez Acosta (raciel@gnome.org) // Andreas Nahr (ClassDevelopment@A-SoftTech.com) +// Ivan N. Zlatev (contact@i-nz.net) // // (C) Alejandro Sánchez Acosta // (C) 2003 Andreas Nahr +// (C) 2007 Ivan N. Zlatev // // @@ -30,35 +32,33 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +using System; using System.Collections; namespace System.ComponentModel.Design.Serialization { public sealed class ContextStack { - private Stack stack; + private ArrayList _contextList; public ContextStack () { - stack = new Stack (); + _contextList = new ArrayList (); } public object Current { get { - try { - return stack.Peek (); - } - catch { - return null; - } + if (_contextList.Count > 0) + return _contextList[_contextList.Count-1]; + return null; } } public object this[Type type] { get { - foreach (object o in stack.ToArray()) - if (o.GetType () == type) - return o; + for (int i = _contextList.Count - 1; i >= 0; i--) + if (_contextList[i].GetType () == type) + return _contextList[i]; return null; } } @@ -67,29 +67,39 @@ namespace System.ComponentModel.Design.Serialization get { if (level < 0) throw new ArgumentException ("level has to be >= 0","level"); - Array A = stack.ToArray(); - if (level > (A.Length - 1)) - return null; - return A.GetValue(level); + if (_contextList.Count > 0 && _contextList.Count > level) + return _contextList[_contextList.Count - 1 - level]; + return null; } } public object Pop () { - return stack.Pop (); + object o = null; + if (_contextList.Count > 0) { + int lastItem = _contextList.Count - 1; + o = _contextList[lastItem]; + _contextList.RemoveAt (lastItem); + } + return o; } public void Push (object context) { - stack.Push (context); + if (context == null) + throw new ArgumentNullException ("context"); + + _contextList.Add (context); } #if NET_2_0 - [MonoNotSupported ("")] public void Append (object context) { - throw new NotImplementedException (); + if (context == null) + throw new ArgumentNullException ("context"); + _contextList.Insert (0, context); } #endif } } + diff --git a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog index b90ad03a6b5..919ee9804e6 100644 --- a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog +++ b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ChangeLog @@ -1,3 +1,7 @@ +2007-08-19 Ivan N. Zlatev <contact@i-nz.net> + + * ContextStackTest.cs: New unit tests for ContextStack. + 2007-07-21 Gert Driesen <drieseng@users.sourceforge.net> * InstanceDescriptorTest.cs: Improved ctor tests. Added tests for diff --git a/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs new file mode 100644 index 00000000000..ab625099820 --- /dev/null +++ b/mcs/class/System/Test/System.ComponentModel.Design.Serialization/ContextStackTest.cs @@ -0,0 +1,79 @@ +// +// ContextStackTest.cs - Unit tests for +// System.ComponentModel.Design.Serialization.ContextStack +// +// Author: +// Ivan N. Zlatev <contact@i-nz.net> +// +// Copyright (C) 2007 Ivan N. Zlatev <contact@i-nz.net> +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using NUnit.Framework; + +using System; +using System.ComponentModel; +using System.ComponentModel.Design.Serialization; +using System.Globalization; +using System.Reflection; +using System.Threading; + +namespace MonoTests.System.ComponentModel.Design.Serialization +{ + [TestFixture] + public class ContextStackTest + { + + [Test] + [NUnit.Framework.Category ("inz")] + public void IntegrityTest () + { + ContextStack stack = new ContextStack (); + + string one = "one"; + 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.AreEqual (one, stack.Pop (), "#4"); + + Assert.AreEqual (two, stack[typeof (string)], "#5"); + Assert.AreEqual (two, stack[0], "#6"); + Assert.AreEqual (two, stack.Current, "#7"); + + 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.AreEqual (two, stack.Pop (), "#11"); + + Assert.AreEqual (three, stack[typeof (string)], "#12"); + Assert.AreEqual (three, stack[0], "#13"); + Assert.AreEqual (three, stack.Current, "#14"); + } + } +} |