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:
authorMiguel de Icaza <miguel@gnome.org>2003-11-28 01:37:12 +0300
committerMiguel de Icaza <miguel@gnome.org>2003-11-28 01:37:12 +0300
commit9f4f71924985eb48ea83d8b27b8500ae3c519478 (patch)
tree481132c0e5713af5c4716f280beeba45fd92211f /mcs/tests/test-220.cs
parent5c30b86770e096e4b34d430a338765e143c62a13 (diff)
Add new test for bug 51446
svn path=/trunk/mcs/; revision=20557
Diffstat (limited to 'mcs/tests/test-220.cs')
-rw-r--r--mcs/tests/test-220.cs124
1 files changed, 124 insertions, 0 deletions
diff --git a/mcs/tests/test-220.cs b/mcs/tests/test-220.cs
new file mode 100644
index 00000000000..245eb381967
--- /dev/null
+++ b/mcs/tests/test-220.cs
@@ -0,0 +1,124 @@
+//
+// Tests for bug #51446, where MCS did not pick the right enumerator
+// from a class.
+//
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+
+namespace MonoBUG
+{
+
+ public class Bug
+ {
+ public static int Main(string[] args)
+ {
+ FooList l = new FooList();
+ Foo f1 = new Foo("First");
+ Foo f2 = new Foo("Second");
+
+ l.Add(f1);
+ l.Add(f2);
+
+ foreach (Foo f in l) {
+ }
+
+ if (FooList.foo_current_called != true)
+ return 1;
+ if (FooList.ienumerator_current_called != false)
+ return 2;
+ Console.WriteLine ("Test passes");
+ return 0;
+ }
+ }
+
+ public class Foo
+ {
+ private string m_name;
+
+ public Foo(string name)
+ {
+ m_name = name;
+ }
+
+ public string Name {
+ get { return m_name; }
+ }
+ }
+
+ [Serializable()]
+ public class FooList : DictionaryBase
+ {
+ public static bool foo_current_called = false;
+ public static bool ienumerator_current_called = false;
+
+ public FooList()
+ {
+ }
+
+ public void Add(Foo value)
+ {
+ Dictionary.Add(value.Name, value);
+ }
+
+ public new FooEnumerator GetEnumerator()
+ {
+ return new FooEnumerator(this);
+ }
+
+ public class FooEnumerator : object, IEnumerator
+ {
+
+ private IEnumerator baseEnumerator;
+
+ private IEnumerable temp;
+
+ public FooEnumerator(FooList mappings)
+ {
+ this.temp = (IEnumerable) (mappings);
+ this.baseEnumerator = temp.GetEnumerator();
+ }
+
+ public Foo Current
+ {
+ get
+ {
+ Console.WriteLine("Foo Current()");
+ foo_current_called = true;
+ return (Foo) ((DictionaryEntry) (baseEnumerator.Current)).Value;
+ }
+ }
+
+ object IEnumerator.Current
+ {
+ get
+ {
+ Console.WriteLine("object IEnumerator.Current()");
+ ienumerator_current_called = true;
+ return baseEnumerator.Current;
+ }
+ }
+
+ public bool MoveNext()
+ {
+ return baseEnumerator.MoveNext();
+ }
+
+ bool IEnumerator.MoveNext()
+ {
+ return baseEnumerator.MoveNext();
+ }
+
+ public void Reset()
+ {
+ baseEnumerator.Reset();
+ }
+
+ void IEnumerator.Reset()
+ {
+ baseEnumerator.Reset();
+ }
+ }
+ }
+}