[w32file] Move MonoIO.Find{First,Next,Close} to managed
[mono.git] / mcs / tests / gtest-collectioninit-01.cs
1
2 // Tests collection initialization
3
4 using System;
5 using System.Collections;
6 using System.Collections.Generic;
7
8 public class Test
9 {
10         class Wrap
11         {
12                 ArrayList numbers = new ArrayList ();
13                 public int Id;
14                 public Wrap Next;
15                 
16                 public Wrap ()
17                 {
18                         Next = new Wrap (100);
19                 }
20                 
21                 public Wrap (int i)
22                 {
23                         Next = this;
24                 }
25                 
26                 public ArrayList Numbers { 
27                         get { 
28                                 return numbers;
29                         }
30                 }
31         }
32         
33         static void TestList (List<int> list, int expectedCount)
34         {
35                 if (list.Count != expectedCount)
36                         throw new ApplicationException (expectedCount.ToString ());
37                 
38                 foreach (int i in list)
39                         Console.WriteLine (i);
40         }
41         
42         public static int Main ()
43         {
44                 ArrayList collection = new ArrayList { "Foo", null, 1 };
45                 if (collection.Count != 3)
46                         return 1;
47                         
48                 if ((string)collection [0] != "Foo")
49                         return 2;
50                         
51                 if ((int)collection [2] != 1)
52                         return 3;
53                                         
54                 List<string> generic_collection = new List<string> { "Hello", "World" };
55                 foreach (string s in generic_collection)
56                         if (s.Length != 5)
57                                 return 4;
58                 
59                 List<Wrap> a = null;
60                 a = new List<Wrap> () {         
61                         new Wrap (0) {
62                                 Id = 0,
63                                 Numbers = { 5, 10 },
64                                 Next = { Id = 55 }
65                         },
66                         new Wrap {
67                                 Id = 1,
68                                 Numbers = { collection, }
69                         },
70                         new Wrap {
71                                 Id = 2,
72                                 Numbers = { },
73                         },
74                         null
75                 };
76                 
77                 if (a.Count != 4)
78                         return 5;
79                 
80                 if ((int)a [0].Numbers [1] != 10)
81                         return 6;
82                 
83                 new List<int> { 1, 2, 3, 4 };
84                 TestList (new List<int> { 1, 2, 3, 4 }, 4);
85                 
86                 new List<int> { };
87                 
88                 Console.WriteLine ("OK");
89                 return 0;
90         }
91 }
92