[w32file] Move MonoIO.Find{First,Next,Close} to managed
[mono.git] / mcs / tests / test-220.cs
1 //
2 // Tests for bug #51446, where MCS did not pick the right enumerator
3 // from a class.
4 //
5
6 using System;
7 using System.Collections;
8 using System.Collections.Specialized;
9
10 namespace MonoBUG
11 {
12
13         public class Bug
14         {
15                 public static int Main(string[] args)
16                 {
17                         FooList l = new FooList();
18                         Foo f1 = new Foo("First");
19                         Foo f2 = new Foo("Second");
20
21                         l.Add(f1);
22                         l.Add(f2);
23
24                         foreach (Foo f in l) {
25                         }
26
27                         if (FooList.foo_current_called != true)
28                                 return 1;
29                         if (FooList.ienumerator_current_called != false)
30                                 return 2;
31                         Console.WriteLine ("Test passes");
32                         return 0;
33                 }
34         }
35
36         public class Foo
37         {
38                 private string m_name;
39                 
40                 public Foo(string name)
41                 {
42                         m_name = name;
43                 }
44                 
45                 public string Name {
46                         get { return m_name; }
47                 }
48         }
49
50         [Serializable()]
51         public class FooList : DictionaryBase  
52         {
53                 public static bool foo_current_called = false;
54                 public static bool ienumerator_current_called = false;
55                         
56                 public FooList() 
57                 {
58                 }
59                 
60                 public void Add(Foo value) 
61                 {
62                         Dictionary.Add(value.Name, value);
63                 }
64                 
65                 public new FooEnumerator GetEnumerator() 
66                 {
67                         return new FooEnumerator(this);
68                 }
69                 
70                 public class FooEnumerator : object, IEnumerator 
71                 {
72                         
73                         private IEnumerator baseEnumerator;
74                         
75                         private IEnumerable temp;
76                         
77                         public FooEnumerator(FooList mappings) 
78                         {
79                                 this.temp = (IEnumerable) (mappings);
80                                 this.baseEnumerator = temp.GetEnumerator();
81                         }
82                         
83                         public Foo Current 
84                         {
85                                 get 
86                                 {
87                                         Console.WriteLine("Foo Current()");
88                                         foo_current_called = true;
89                                         return (Foo) ((DictionaryEntry) (baseEnumerator.Current)).Value;
90                                 }
91                         }
92                         
93                         object IEnumerator.Current 
94                         {
95                                 get 
96                                 {
97                                         Console.WriteLine("object IEnumerator.Current()");
98                                         ienumerator_current_called = true;
99                                         return baseEnumerator.Current;
100                                 }
101                         }
102                         
103                         public bool MoveNext() 
104                         {
105                                 return baseEnumerator.MoveNext();
106                         }
107                         
108                         bool IEnumerator.MoveNext() 
109                         {
110                                 return baseEnumerator.MoveNext();
111                         }
112                         
113                         public void Reset() 
114                         {
115                                 baseEnumerator.Reset();
116                         }
117                         
118                         void IEnumerator.Reset() 
119                         {
120                                 baseEnumerator.Reset();
121                         }
122                 }
123         }
124 }