summaryrefslogtreecommitdiff
path: root/tests/src/Loader/binding/assemblies/generics/arilistienum/methods/exceptions.cs
blob: c5f2ed5a348a2772cd60df98a4511e2a67a3dfcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//array<T> IList properties

using System;
using System.IO;
using System.Reflection;
using System.Collections;

public class GenClass<T>
{
	public T fld;
}

public class PropsArIList  
{

	public static int Main()  
	{

		int result = 0;
		int i;
		try
		{
			//Part 1 - GenClass <int>
			Console.WriteLine("\ntest GenClass<int>");

			GenClass<int> obj1;
			obj1 = new GenClass<int>();
			obj1.fld = 3;
			Console.WriteLine (obj1.fld);

			GenClass<int>[] arGen;
			arGen = new GenClass<int>[5];
			
			for (i=0;i<5;i++) 
			{
				arGen[i] = new GenClass<int>();
				arGen[i].fld = i;
				Console.Write (arGen[i].fld + "\t");
			}
			Console.WriteLine();

			IList interf1 = (IList) arGen;

			try 
			{
				interf1.Add(obj1);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try 
			{
				interf1.Insert(1, obj1);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try 
			{
				interf1.Remove(arGen[0]);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try
			{
				interf1.RemoveAt (1);
			}
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			//Part 2 - GenClass <string>
			Console.WriteLine("\ntest GenClass<string>");

			GenClass<string> obj2;
			obj2 = new GenClass<string>();
			obj2.fld = "name";
			Console.WriteLine (obj2.fld);

			GenClass<string>[] arGenS;
			arGenS = new GenClass<string>[5];
			string aux = "none";
			for (i=0;i<5;i++) 
			{
				arGenS[i] = new GenClass<string>();
				aux = Convert.ToString(i);
				arGenS[i].fld = aux;
				Console.Write (arGenS[i].fld + "\t");
			}
			Console.WriteLine();

			IList interf2 = (IList) arGenS;

			try 
			{
				interf2.Add(obj2);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try 
			{
				interf2.Insert(1, obj2);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try 
			{
				interf2.Remove(arGenS[0]);
			} 
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			try
			{
				interf2.RemoveAt (1);
			}
			catch (NotSupportedException e)
			{
				Console.WriteLine ("expected: " + e);
			}

			result = 100; //pass
	
		}
		catch (Exception e)
		{
			Console.WriteLine ("unexpected exception..");
			Console.WriteLine (e); 
			Console.WriteLine ("test failed");
			return 101;
		}

		if (result==100) Console.WriteLine ("test passed");
		else Console.WriteLine ("test failed");

		return result;
	}
}