remove TARGET_JVM
[mono.git] / mcs / class / corlib / Test / System / ArrayTest.cs
1 // ArrayTest.cs - NUnit Test Cases for the System.Array class
2 //
3 // David Brandt (bucky@keystreams.com)
4 // Eduardo Garcia (kiwnix@yahoo.es)
5 // 
6 // (C) Ximian, Inc.  http://www.ximian.com
7 // Copyright (C) 2004 Novell (http://www.novell.com)
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.Globalization;
14
15 #if NET_2_0
16 using System.Collections.Generic;
17 #endif
18
19 namespace MonoTests.System
20 {
21
22
23         //Auxiliary Things
24         enum enua  {hola,adios,mas,menos};
25
26         class AClass
27         {
28                 public AClass()
29                 {
30
31                 }
32         }
33
34         class BClass : AClass
35         {
36     }
37
38         class CClass : AClass
39     {
40     }
41
42         struct AStruct
43         {
44                 public string s;
45                 public string a;
46         }
47         //End Auxiliary Things
48
49 [TestFixture]
50 public class ArrayTest : Assertion
51 {
52         char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
53
54         public ArrayTest() {}
55
56         [Test]
57         public void TestIsFixedSize() {
58                 char[] a1 = {'a'};
59                 Assert("All arrays are fixed", a1.IsFixedSize);
60         }
61         
62         [Test]
63         public void TestIsReadOnly() {
64                 char[] a1 = {'a'};
65                 Assert("No array is readonly", !a1.IsReadOnly);
66         }
67
68         [Test]
69         public void TestIsSynchronized() {
70                 char[] a1 = {'a'};
71                 Assert("No array is synchronized", !a1.IsSynchronized);
72         }
73
74         [Test]
75         public void TestLength() {
76                 {
77                         char[] a1 = { };
78                         AssertEquals("Zero length array", 0, a1.Length);
79                 }
80                 {
81                         char[] a1 = {'c'};
82                         AssertEquals("One-length array", 1, a1.Length);
83                 }
84                 {
85                         char[] a1 = {'c', 'c'};
86                         AssertEquals("Two-length array", 2, a1.Length);
87                 }
88         }
89
90         [Test]
91         public void TestRank() {
92                 char[] a1 = { 'c', 'd', 'e' };
93                 AssertEquals("Rank one", 1, a1.Rank);
94
95                 char[,] a2 = new Char[3,3];
96                 AssertEquals("Rank two", 2, a2.Rank);
97
98                 char[,,] a3 = new Char[3,3,3];
99                 AssertEquals("Rank three", 3, a3.Rank);
100         }
101
102         [Test]
103         public void TestBinarySearch1() {
104                 bool errorThrown = false;
105                 try {
106                         Array.BinarySearch(null, "blue");
107                 } catch (ArgumentNullException) {
108                         errorThrown = true;
109                 }
110                 Assert("#B01", errorThrown);
111                 errorThrown = false;
112                 try {
113                         char[,] c1 = new Char[2,2];
114                         Array.BinarySearch(c1, "needle");
115                 } catch (RankException) {
116                         errorThrown = true;
117                 }
118                 Assert("#B02", errorThrown);
119
120                 {
121                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
122                         Assert("#B05", 
123                                Array.BinarySearch(arr, 'c') >= 3);
124                         Assert("#B06", 
125                                Array.BinarySearch(arr, 'c') < 6);
126                 }
127                 {
128                         char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
129                         AssertEquals("#B07", 
130                                      -4, Array.BinarySearch(arr, 'c'));
131                 }
132                 {
133                         char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
134                         AssertEquals("#B08", 
135                                      -9, Array.BinarySearch(arr, 'e'));
136                 }
137         }
138
139         [Test]
140         public void TestBinarySearch2() {
141                 bool errorThrown = false;
142                 try {
143                         Array.BinarySearch(null, 0, 1, "blue");
144                 } catch (ArgumentNullException) {
145                         errorThrown = true;
146                 }
147                 Assert("#B20", errorThrown);
148                 errorThrown = false;
149                 try {
150                         char[,] c1 = new Char[2,2];
151                         Array.BinarySearch(c1, 0, 1, "needle");
152                 } catch (RankException) {
153                         errorThrown = true;
154                 }
155                 Assert("#B21", errorThrown);
156                 errorThrown = false;
157                 try {
158                         char[] c1 = {'a'};
159                         Array.BinarySearch(c1, -1, 1, 'a');
160                 } catch (ArgumentOutOfRangeException) {
161                         errorThrown = true;
162                 }
163                 Assert("#B22", errorThrown);
164                 errorThrown = false;
165                 try {
166                         char[] c1 = {'a'};
167                         Array.BinarySearch(c1, 0, -1, 'a');
168                 } catch (ArgumentOutOfRangeException) {
169                         errorThrown = true;
170                 }
171                 Assert("#B23", errorThrown);
172                 errorThrown = false;
173                 try {
174                         char[] c1 = {'a'};
175                         Array.BinarySearch(c1, 0, 4, 'a');
176                 } catch (ArgumentException) {
177                         errorThrown = true;
178                 }
179                 Assert("#B24", errorThrown);
180
181                 {
182                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
183                         Assert("#B26", 
184                                Array.BinarySearch(arr, 2, 8, 'c') >= 5);
185                         Assert("#B27", 
186                                Array.BinarySearch(arr, 2, 8, 'c') < 8);
187                 }
188                 {
189                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
190                         AssertEquals("#B28", 
191                                      -6, Array.BinarySearch(arr, 2, 8, 'c'));
192                 }
193                 {
194                         char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
195                         AssertEquals("#B29", 
196                                      -11, Array.BinarySearch(arr, 2, 8, 'e'));
197                 }
198         }
199
200         public void TestBinarySearch3()
201         {
202                 int[] array = new int[100];
203
204                 for (int i = 0; i < 100; i++)
205                         array[i] = 10;
206
207                 AssertEquals("#B30", 49, Array.BinarySearch(array, 10));
208         }
209
210         [Test]
211         public void BinarySearch_NullValue () 
212         {
213                 int[] array = new int[1];
214                 AssertEquals ("I=a,o", -1, Array.BinarySearch (array, null));
215                 AssertEquals ("I=a,o,c", -1, Array.BinarySearch (array, null, null));
216                 AssertEquals ("I=a,i,i,o", -1, Array.BinarySearch (array, 0, 1, null));
217                 AssertEquals ("I=a,i,i,o,c", -1, Array.BinarySearch (array, 0, 1, null,null));
218
219                 object[] o = new object [3] { this, this, null };
220                 AssertEquals ("O=a,o", -1, Array.BinarySearch (o, null));
221                 AssertEquals ("O=a,o,c", -1, Array.BinarySearch (o, null, null));
222                 AssertEquals ("O=a,i,i,o", -1, Array.BinarySearch (o, 0, 3, null));
223                 AssertEquals ("O=a,i,i,o,c", -1, Array.BinarySearch (o, 0, 3, null, null));
224         }
225
226         // TODO - testBinarySearch with explicit IComparer args
227
228         [Test]
229         public void TestClear() {
230                 bool errorThrown = false;
231                 try {
232                         Array.Clear(null, 0, 1);
233                 } catch (ArgumentNullException) {
234                         errorThrown = true;
235                 }
236                 Assert("#C01", errorThrown);
237
238                 int[] i1 = { 1, 2, 3, 4 };
239                 {
240                         int[] compare = {1,2,3,4};
241                         AssertEquals("#C02", compare[0], i1[0]);
242                         AssertEquals("#C03", compare[1], i1[1]);
243                         AssertEquals("#C04", compare[2], i1[2]);
244                         AssertEquals("#C05", compare[3], i1[3]);
245                 }
246                 Array.Clear(i1, 3, 1);
247                 {
248                         int[] compare = {1,2,3,0};
249                         AssertEquals("#C06", compare[0], i1[0]);
250                         AssertEquals("#C07", compare[1], i1[1]);
251                         AssertEquals("#C08", compare[2], i1[2]);
252                         AssertEquals("#C09", compare[3], i1[3]);
253                 }
254                 Array.Clear(i1, 1, 1);
255                 {
256                         int[] compare = {1,0,3,0};
257                         AssertEquals("#C10", compare[0], i1[0]);
258                         AssertEquals("#C11", compare[1], i1[1]);
259                         AssertEquals("#C12", compare[2], i1[2]);
260                         AssertEquals("#C13", compare[3], i1[3]);
261                 }
262                 Array.Clear(i1, 1, 3);
263                 {
264                         int[] compare = {1,0,0,0};
265                         AssertEquals("#C14", compare[0], i1[0]);
266                         AssertEquals("#C15", compare[1], i1[1]);
267                         AssertEquals("#C16", compare[2], i1[2]);
268                         AssertEquals("#C17", compare[3], i1[3]);
269                 }
270
271                 string[] s1 = { "red", "green", "blue" };
272                 Array.Clear(s1, 0, 3);
273                 {
274                         string[] compare = {null, null, null};
275                         AssertEquals("#C18", compare[0], s1[0]);
276                         AssertEquals("#C19", compare[1], s1[1]);
277                         AssertEquals("#C20", compare[2], s1[2]);
278                 }
279         }
280
281         [Test]
282         public void TestClone() {
283                 char[] c1 = {'a', 'b', 'c'};
284                 char[] c2 = (char[])c1.Clone();
285                 AssertEquals("#D01", c1[0], c2[0]);
286                 AssertEquals("#D02", c1[1], c2[1]);
287                 AssertEquals("#D03", c1[2], c2[2]);
288
289                 char[] d10 = {'a', 'b'};
290                 char[] d11 = {'a', 'c'};
291                 char[] d12 = {'b', 'c'};
292                 char[][] d1 = {d10, d11, d12};
293                 char[][] d2 = (char[][])d1.Clone();
294                 AssertEquals("#D04", d1[0], d2[0]);
295                 AssertEquals("#D05", d1[1], d2[1]);
296                 AssertEquals("#D06", d1[2], d2[2]);
297
298                 d1[0][0] = 'z';
299                 AssertEquals("#D07", d1[0], d2[0]);
300         }
301
302         [Test]
303         public void TestCopy() {
304                 {
305                         bool errorThrown = false;
306                         try {
307                                 Char[] c1 = {};
308                                 Array.Copy(c1, null, 1);
309                         } catch (ArgumentNullException) {
310                                 errorThrown = true;
311                         }
312                         Assert("#E01", errorThrown);
313                 }
314                 {
315                         bool errorThrown = false;
316                         try {
317                                 Char[] c1 = {};
318                                 Array.Copy(null, c1, 1);
319                         } catch (ArgumentNullException) {
320                                 errorThrown = true;
321                         }
322                         Assert("#E02", errorThrown);
323                 }
324                 {
325                         bool errorThrown = false;
326                         try {
327                                 Char[] c1 = new Char[1];
328                                 Char[,] c2 = new Char[1,1];
329                                 Array.Copy(c1, c2, 1);
330                         } catch (RankException) {
331                                 errorThrown = true;
332                         }
333                         Assert("#E03", errorThrown);
334                 }
335                 {
336                         bool errorThrown = false;
337                         try {
338                                 Char[] c1 = new Char[1];
339                                 string[] s1 = new String[1];
340                                 Array.Copy(c1, s1, 1);
341                         } catch (ArrayTypeMismatchException) {
342                                 errorThrown = true;
343                         }
344                         Assert("#E04", errorThrown);
345                 }
346                 {
347                         bool errorThrown = false;
348                         try {
349                                 Char[] c1 = new Char[1];
350                                 Object[] o1 = new Object[1];
351                                 o1[0] = "hello";
352                                 Array.Copy(o1, c1, 1);
353                         } catch (InvalidCastException) {
354                                 errorThrown = true;
355                         }
356                         Assert("#E05", errorThrown);
357                 }
358                 {
359                         bool errorThrown = false;
360                         try {
361                                 Char[] c1 = new Char[1];
362                                 Char[] c2 = new Char[1];
363                                 Array.Copy(c1, c2, -1);
364                         } catch (ArgumentOutOfRangeException) {
365                                 errorThrown = true;
366                         }
367                         Assert("#E06", errorThrown);
368                 }
369                 {
370                         bool errorThrown = false;
371                         try {
372                                 Char[] c1 = new Char[1];
373                                 Char[] c2 = new Char[2];
374                                 Array.Copy(c1, c2, 2);
375                         } catch (ArgumentException) {
376                                 errorThrown = true;
377                         }
378                         Assert("#E07", errorThrown);
379                 }
380                 {
381                         bool errorThrown = false;
382                         try {
383                                 Char[] c1 = new Char[1];
384                                 Char[] c2 = new Char[2];
385                                 Array.Copy(c2, c1, 2);
386                         } catch (ArgumentException) {
387                                 errorThrown = true;
388                         }
389                         Assert("#E08", errorThrown);
390                 }
391
392                 char[] orig = {'a', 'b', 'd', 'a'};
393                 char[] copy = new Char[4];
394                 Array.Copy(orig, copy, 4);
395                 for (int i = 0; i < orig.Length; i++) {
396                         AssertEquals("#E09(" + i + ")",
397                                      orig[i], copy[i]);
398                 }
399                 Array.Clear(copy, 0, copy.Length);
400                 for (int i = 0; i < orig.Length; i++) {
401                         AssertEquals("#E10(" + i + ")",
402                                      (char)0, copy[i]);
403                 }
404                 Array.Copy(orig, copy, 2);
405                 AssertEquals("#E11", orig[0], copy[0]);
406                 AssertEquals("#E12", orig[1], copy[1]);
407                 Assert("#E13", orig[2] != copy[2]);
408                 Assert("#E14", orig[3] != copy[3]);
409         }
410
411         [Test]
412         public void TestCopy2() {
413                 {
414                         bool errorThrown = false;
415                         try {
416                                 Char[] c1 = new Char[2];
417                                 Char[] c2 = new Char[2];
418                                 Array.Copy(c2, 1, c1, 0, 2);
419                         } catch (ArgumentException) {
420                                 errorThrown = true;
421                         }
422                         Assert("#E31", errorThrown);
423                 }
424                 {
425                         bool errorThrown = false;
426                         try {
427                                 Char[] c1 = new Char[2];
428                                 Char[] c2 = new Char[2];
429                                 Array.Copy(c2, 0, c1, 1, 2);
430                         } catch (ArgumentException) {
431                                 errorThrown = true;
432                         }
433                         Assert("#E32", errorThrown);
434                 }
435                 
436                 char[] orig = {'a', 'b', 'd', 'a'};
437                 char[] copy = new Char[4];
438                 Array.Copy(orig, 1, copy, 1, 3);
439                 Assert("#E33", copy[0] != orig[0]);
440                 for (int i = 1; i < orig.Length; i++) {
441                         AssertEquals("#E34(" + i + ")",
442                                      orig[i], copy[i]);
443                 }
444                 Array.Clear(copy, 0, copy.Length);
445                 Array.Copy(orig, 1, copy, 0, 2);
446                 AssertEquals("#E35", orig[1], copy[0]);
447                 AssertEquals("#E36", orig[2], copy[1]);
448                 Assert("#E37", copy[2] != orig[2]);
449                 Assert("#E38", copy[3] != orig[3]);
450         }
451
452         [Test]
453         public void TestCopyTo() {
454                 {
455                         bool errorThrown = false;
456                         try {
457                                 Char[] c1 = new Char[2];
458                                 c1.CopyTo(null, 2);
459                         } catch (ArgumentNullException) {
460                                 errorThrown = true;
461                         }
462                         Assert("#E61", errorThrown);
463                 }
464                 {
465                         bool errorThrown = false;
466                         try {
467                                 Char[] c1 = new Char[2];
468                                 Char[,] c2 = new Char[2,2];
469                                 c1.CopyTo(c2, 2);
470                         } catch (ArgumentException) {
471                                 errorThrown = true;
472                         }
473                         Assert("#E62", errorThrown);
474                 }
475                 {
476                         bool errorThrown = false;
477                         try {
478                                 Char[,] c1 = new Char[2,2];
479                                 Char[] c2 = new Char[2];
480                                 c1.CopyTo(c2, -1);
481                         } catch (RankException) {
482                                 errorThrown = true;
483                         }
484                         Assert("#E63", errorThrown);
485                 }
486                 {
487                         bool errorThrown = false;
488                         try {
489                                 Char[,] c1 = new Char[2,2];
490                                 Char[] c2 = new Char[2];
491                                 c1.CopyTo(c2, 2);
492                         } catch (RankException) {
493                                 errorThrown = true;
494                         }
495                         Assert("#E64", errorThrown);
496                 }
497                 {
498                         bool errorThrown = false;
499                         try {
500                                 Char[] c1 = new Char[2];
501                                 Char[] c2 = new Char[2];
502                                 c1.CopyTo(c2, -1);
503                         } catch (ArgumentOutOfRangeException) {
504                                 errorThrown = true;
505                         }
506                         Assert("#E65", errorThrown);
507                 }
508                 {
509                         bool errorThrown = false;
510                         try {
511                                 Char[] c1 = new Char[2];
512                                 Char[] c2 = new Char[2];
513                                 c1.CopyTo(c2, 3);
514                         } catch (ArgumentException) {
515                                 errorThrown = true;
516                         }
517                         Assert("#E66", errorThrown);
518                 }
519                 {
520                         bool errorThrown = false;
521                         try {
522                                 Char[] c1 = new Char[2];
523                                 Char[] c2 = new Char[2];
524                                 c1.CopyTo(c2, 1);
525                         } catch (ArgumentException) {
526                                 errorThrown = true;
527                         }
528                         Assert("#E67", errorThrown);
529                 }
530
531                 {
532                         bool errorThrown = false;
533                         try {
534                                 String[] c1 = new String[2];
535                                 // TODO: this crashes mono if there are null
536                                 // values in the array.
537                                 c1[1] = "hey";
538                                 c1[0] = "you";
539                                 Char[] c2 = new Char[2];
540                                 c2[1] = 'a';
541                                 c2[0] = 'z';
542                                 c1.CopyTo(c2, 0);
543                         } catch (ArrayTypeMismatchException) {
544                                 errorThrown = true;
545                         }
546                         Assert("#E68", errorThrown);
547                 }
548
549                 Char[] orig = {'a', 'b', 'c', 'd'};
550                 Char[] copy = new Char[10];
551                 Array.Clear(copy, 0, copy.Length);
552                 orig.CopyTo(copy, 3);
553                 AssertEquals("#E69", (char)0, copy[0]);
554                 AssertEquals("#E70", (char)0, copy[1]);
555                 AssertEquals("#E71", (char)0, copy[2]);
556                 AssertEquals("#E72", orig[0], copy[3]);
557                 AssertEquals("#E73", orig[1], copy[4]);
558                 AssertEquals("#E74", orig[2], copy[5]);
559                 AssertEquals("#E75", orig[3], copy[6]);
560                 AssertEquals("#E76", (char)0, copy[7]);
561                 AssertEquals("#E77", (char)0, copy[8]);
562                 AssertEquals("#E78", (char)0, copy[9]);
563
564                 {
565                         // The following is valid and must not throw an exception.
566                         bool errorThrown = false;
567                         try {
568                                 int[] src = new int [0];
569                                 int[] dest = new int [0];
570                                 src.CopyTo (dest, 0);
571                         } catch (ArgumentException) {
572                                 errorThrown = true;
573                         }
574                         Assert("#E79", !errorThrown);
575                 }
576
577                 {
578                         // bug #38812
579                         bool errorThrown = false;
580                         try {
581                                 CClass[] src = new CClass [] { new CClass () };
582                                 BClass[] dest = new BClass [1];
583
584                                 src.CopyTo (dest, 0);
585
586                         } catch (ArrayTypeMismatchException) {
587                                 errorThrown = true;
588                         }
589                         Assert("#E80", errorThrown);
590                 }
591         }
592
593         [Test]
594         public void TestCreateInstance() {
595                 {
596                         bool errorThrown = false;
597                         try {
598                                 Array.CreateInstance(null, 12);
599                         } catch (ArgumentNullException) {
600                                 errorThrown = true;
601                         }
602                         Assert("#F01", errorThrown);
603                 }
604                 {
605                         bool errorThrown = false;
606                         try {
607                                 Array.CreateInstance(Type.GetType("System.Char"), -3);
608                         } catch (ArgumentOutOfRangeException) {
609                                 errorThrown = true;
610                         }
611                         Assert("#F02", errorThrown);
612                 }
613                 {
614                         bool errorThrown = false;
615                         try {
616                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
617                         } catch (ArgumentNullException) {
618                                 errorThrown = true;
619                         }
620                         Assert("#F03a", errorThrown);
621                 }
622 #if NET_1_1
623                 {
624                         bool errorThrown = false;
625                         try {
626                                 Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
627                         } catch (ArgumentNullException) {
628                                 errorThrown = true;
629                         }
630                         Assert("#F03b", errorThrown);
631                 }
632 #endif
633                 {
634                         bool errorThrown = false;
635                         try {
636                                 Array.CreateInstance(Type.GetType("System.Char"), null, null);
637                         } catch (ArgumentNullException) {
638                                 errorThrown = true;
639                         }
640                         Assert("#F04", errorThrown);
641                 }
642                 {
643                         bool errorThrown = false;
644                         try {
645                                 int[] lengths = new int [0];
646                                 Array.CreateInstance(Type.GetType("System.Char"), lengths);
647                         } catch (ArgumentException) {
648                                 errorThrown = true;
649                         }
650                         Assert("#F05", errorThrown);
651                 }
652                 {
653                         bool errorThrown = false;
654                         try {
655                                 int[] lengths = new int [1];
656                                 int[] bounds = new int [2];
657                                 Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
658                                 errorThrown = true;
659                         } catch (ArgumentException) {
660                                 errorThrown = true;
661                         }
662                         Assert("#F06", errorThrown);
663                 }
664
665                 char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
666                 AssertEquals("#F07", 12, c1.Length);
667
668                 Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
669                 AssertEquals("#F08", 2, c2.Rank);
670                 AssertEquals("#F09", 60, c2.Length);
671
672
673                 {
674                         int[] lengths = { 3 };
675                         int[] bounds = { 5 };
676                         int[] src = { 512, 718, 912 };
677                         Array array = Array.CreateInstance(typeof(int), lengths, bounds);
678
679                         AssertEquals("#F10", 3, array.Length);
680                         AssertEquals("#F11", 5, array.GetLowerBound(0));
681                         AssertEquals("#F12", 7, array.GetUpperBound(0));
682
683                         src.CopyTo (array, 5);
684
685                         for (int i = 0; i < src.Length; i++)
686                                 AssertEquals("#F13(" + i + ")", src[i], array.GetValue(i+5));
687                 }
688
689                 // Test that a 1 dimensional array with 0 lower bound is the
690                 // same as an szarray
691                 Type szarrayType = new int [10].GetType ();
692                 Assert (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
693                 Assert (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
694         }
695         
696         [Test]
697         [ExpectedException (typeof (ArgumentNullException))]
698         public void TestCreateInstance2 ()
699         {
700                 Array a = Array.CreateInstance (typeof (Int32), (int[])null);
701         }
702
703         [Test]
704 #if NET_2_0
705         [ExpectedException (typeof (ArgumentNullException))]
706 #else
707         [ExpectedException (typeof (NullReferenceException))]
708 #endif
709         public void TestCreateInstance2b ()
710         {
711                 Array a = Array.CreateInstance (typeof (Int32), (long[])null);
712         }
713
714         [Test]
715         public void TestGetEnumerator() {
716                 String[] s1 = {"this", "is", "a", "test"};
717                 IEnumerator en = s1.GetEnumerator ();
718                 AssertNotNull ("#G01", en);
719
720                 Assert ("#G02", en.MoveNext ());
721                 AssertEquals ("#G03", "this", en.Current);
722                 Assert ("#G04", en.MoveNext ());
723                 AssertEquals ("#G05", "is", en.Current);
724                 Assert ("#G06", en.MoveNext ());
725                 AssertEquals ("#G07", "a", en.Current);
726                 Assert ("#G08", en.MoveNext ());
727                 AssertEquals ("#G09", "test", en.Current);
728                 Assert ("#G10", !en.MoveNext ());
729
730                 en.Reset ();
731                 Assert("#G11", en.MoveNext ());
732                 AssertEquals ("#G12", "this", en.Current);
733
734                 // mutation does not invalidate array enumerator!
735                 s1.SetValue ("change", 1);
736                 Assert ("#G13", en.MoveNext ());
737                 AssertEquals ("#G14", "change", en.Current);
738         }
739
740         [Test]
741         public void TestGetEnumeratorMultipleDimension() {
742                 String[,] s1 = {{"this", "is"}, {"a", "test"}};
743                 IEnumerator en = s1.GetEnumerator ();
744                 AssertNotNull ("#AA01", en);
745
746                 Assert ("#AA02", en.MoveNext ());
747                 AssertEquals ("#AA03", "this", en.Current);
748                 Assert ("#AA04", en.MoveNext ());
749                 AssertEquals ("#AA05", "is", en.Current);
750                 Assert ("#AA06", en.MoveNext ());
751                 AssertEquals ("#AA07", "a", en.Current);
752                 Assert ("#AA08", en.MoveNext ());
753                 AssertEquals ("#AA09", "test", en.Current);
754                 Assert ("#AA10", !en.MoveNext ());
755
756                 en.Reset ();
757                 Assert("#AA11", en.MoveNext ());
758                 AssertEquals ("#AA12", "this", en.Current);
759
760                 int[] idxs = {0,1};
761                 // mutation does not invalidate array enumerator!
762                 s1.SetValue ("change", idxs);
763                 Assert ("#AA13", en.MoveNext ());
764                 AssertEquals ("#AA14", "change", en.Current);
765         }
766
767         [Test]
768         public void TestGetEnumeratorNonZeroLowerBounds() {
769                 int[] myLengthsArray = new int[2] { 3, 5 };
770                 int[] myBoundsArray = new int[2] { 2, 3 };
771
772                 Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
773                 for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
774                         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
775                                 int[] myIndicesArray = new int[2] { i, j };
776                                 myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
777                         }
778                 IEnumerator en = myArray.GetEnumerator ();
779                 AssertNotNull ("#AB01", en);
780
781                 // check the first couple of values
782                 Assert ("#AB02", en.MoveNext ());
783                 AssertEquals ("#AB03", "23", en.Current);
784                 Assert ("#AB04", en.MoveNext ());
785                 AssertEquals ("#AB05", "24", en.Current);
786
787                 // then check the last element's value
788                 string lastElement;
789                 do {  
790                         lastElement = (string)en.Current;
791                 } while (en.MoveNext());
792                 AssertEquals ("#AB06", "47", lastElement);
793         }
794
795         [Test]
796         public void TestIList_Add () {
797                 int[] myLengthsArray = new int[2] { 3, 5 };
798                 int[] myBoundsArray = new int[2] { 2, 3 };
799
800                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
801                 try {
802                         ((IList)myArray).Add ("can not");
803                         Fail ("IList.Add should throw");    
804                 }
805                 catch (NotSupportedException) {
806                         return;
807                 }
808                 catch (Exception) {
809                         Fail ("IList.Add threw wrong exception type");    
810                 }
811
812                 Fail("IList.Add shouldn't get this far");
813         }
814
815         [Test]
816         public void TestIList_Insert () {
817                 int[] myLengthsArray = new int[2] { 3, 5 };
818                 int[] myBoundsArray = new int[2] { 2, 3 };
819
820                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
821                 try {
822                         ((IList)myArray).Insert (0, "can not");
823                         Fail ("IList.Insert should throw");    
824                 }
825                 catch (NotSupportedException) {
826                         return;
827                 }
828                 catch (Exception) {
829                         Fail ("IList.Insert threw wrong exception type");    
830                 }
831
832                 Fail("IList.Insert shouldn't get this far");
833         }
834
835         [Test]
836         public void TestIList_Remove () {
837                 int[] myLengthsArray = new int[2] { 3, 5 };
838                 int[] myBoundsArray = new int[2] { 2, 3 };
839
840                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
841                 try {
842                         ((IList)myArray).Remove ("can not");
843                         Fail ("IList.Remove should throw");    
844                 }
845                 catch (NotSupportedException) {
846                         return;
847                 }
848                 catch (Exception) {
849                         Fail ("IList.Remove threw wrong exception type");    
850                 }
851
852                 Fail("IList.Remove shouldn't get this far");
853         }
854
855         [Test]
856         public void TestIList_RemoveAt () {
857                 int[] myLengthsArray = new int[2] { 3, 5 };
858                 int[] myBoundsArray = new int[2] { 2, 3 };
859
860                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
861                 try {
862                         ((IList)myArray).RemoveAt (0);
863                         Fail ("IList.RemoveAt should throw");    
864                 }
865                 catch (NotSupportedException) {
866                         return;
867                 }
868                 catch (Exception) {
869                         Fail ("IList.RemoveAt threw wrong exception type");    
870                 }
871
872                 Fail("IList.RemoveAt shouldn't get this far");
873         }
874
875         [Test]
876         public void TestIList_Contains () {
877                 int[] myLengthsArray = new int[2] { 3, 5 };
878                 int[] myBoundsArray = new int[2] { 2, 3 };
879
880                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
881
882                 try {
883                         bool b = ((IList)myArray).Contains ("23");
884                         Fail("IList.Contains should throw with multi-dimensional arrays");
885                 }
886                 catch (RankException) {
887                         int[] iArr = new int[3] { 1, 2, 3};
888                         // check the first and last items
889                         Assert("AC01", ((IList)iArr).Contains (1));
890                         Assert("AC02", ((IList)iArr).Contains (3));
891
892                         // and one that is definately not there
893                         Assert("AC03", !((IList)iArr).Contains (42));
894                         return;
895                 }
896
897                 Fail("Should not get here");
898         }
899
900         [Test]
901         public void TestIList_IndexOf () {
902                 int[] myLengthsArray = new int[2] { 3, 5 };
903                 int[] myBoundsArray = new int[2] { 2, 3 };
904
905                 Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
906
907                 try {
908                         bool b = ((IList)myArray).Contains ("23");
909                         Fail("IList.Contains should throw with multi-dimensional arrays");
910                 }
911                 catch (RankException) {
912                         int[] iArr = new int[3] { 1, 2, 3};
913                         // check the first and last items
914                         AssertEquals("AD01", 0, ((IList)iArr).IndexOf (1));
915                         AssertEquals("AD02", 2, ((IList)iArr).IndexOf (3));
916
917                         // and one that is definately not there
918                         AssertEquals("AD03", -1, ((IList)iArr).IndexOf (42));
919                 }
920                 catch (Exception e) {
921                         Fail("Unexpected exception: " + e.ToString());
922                 }
923
924                 // check that wierd case whem lowerbound is Int32.MinValue,
925                 // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
926                 int[] myLengthArray = new int[1] { 3 };
927                 int[] myBoundArray = new int[1] { Int32.MinValue };
928                 Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
929                 AssertEquals("AD04", Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42));
930
931         }
932
933         [Test]
934         public void TestGetLength() {
935                 {
936                         bool errorThrown = false;
937                         try {
938                                 char[] c1 = {'a', 'b', 'c'};
939                                 c1.GetLength(-1);
940                         } catch (IndexOutOfRangeException) {
941                                 errorThrown = true;
942                         }
943                         Assert("#H01", errorThrown);
944                 }
945                 {
946                         bool errorThrown = false;
947                         try {
948                                 char[] c1 = {'a', 'b', 'c'};
949                                 c1.GetLength(1);
950                         } catch (IndexOutOfRangeException) {
951                                 errorThrown = true;
952                         }
953                         Assert("#H02", errorThrown);
954                 }
955
956                 char[] c2 = new Char[5];
957                 AssertEquals("#H03", 
958                              5, c2.GetLength(0));
959
960                 char[,] c3 = new Char[6,7];
961                 AssertEquals("#H04", 
962                              6, c3.GetLength(0));
963                 AssertEquals("#H05", 
964                              7, c3.GetLength(1));
965         }
966
967         [Test]
968         public void TestGetLowerBound() {
969                 {
970                         bool errorThrown = false;
971                         try {
972                                 char[] c = {'a', 'b', 'c'};
973                                 c.GetLowerBound(-1);
974                         } catch (IndexOutOfRangeException) {
975                                 errorThrown = true;
976                         }
977                         Assert("#H31", errorThrown);
978                 }
979                 {
980                         bool errorThrown = false;
981                         try {
982                                 char[] c = {'a', 'b', 'c'};
983                                 c.GetLowerBound(1);
984                         } catch (IndexOutOfRangeException) {
985                                 errorThrown = true;
986                         }
987                         Assert("#H32", errorThrown);
988                 }
989
990                 char[] c1 = new Char[5];
991                 AssertEquals("#H33", 
992                              0, c1.GetLowerBound(0));
993
994                 char[,] c2 = new Char[4,4];
995                 AssertEquals("#H34", 
996                              0, c2.GetLowerBound(0));
997                 AssertEquals("#H35", 
998                              0, c2.GetLowerBound(1));
999         }
1000
1001         [Test]
1002         public void TestGetUpperBound() {
1003                 {
1004                         bool errorThrown = false;
1005                         try {
1006                                 char[] c = {'a', 'b', 'c'};
1007                                 c.GetUpperBound(-1);
1008                         } catch (IndexOutOfRangeException) {
1009                                 errorThrown = true;
1010                         }
1011                         Assert("#H61", errorThrown);
1012                 }
1013                 {
1014                         bool errorThrown = false;
1015                         try {
1016                                 char[] c = {'a', 'b', 'c'};
1017                                 c.GetUpperBound(1);
1018                         } catch (IndexOutOfRangeException) {
1019                                 errorThrown = true;
1020                         }
1021                         Assert("#H62", errorThrown);
1022                 }
1023
1024                 char[] c1 = new Char[5];
1025                 AssertEquals("#H63", 
1026                              4, c1.GetUpperBound(0));
1027
1028                 char[,] c2 = new Char[4,6];
1029                 AssertEquals("#H64", 
1030                              3, c2.GetUpperBound(0));
1031                 AssertEquals("#H65", 
1032                              5, c2.GetUpperBound(1));
1033         }
1034
1035         [Test]
1036         public void TestGetValue1() {
1037                 {
1038                         bool errorThrown = false;
1039                         try {
1040                                 char[,] c = new Char[2,2];
1041                                 c.GetValue(1);
1042                         } catch (ArgumentException) {
1043                                 errorThrown = true;
1044                         }
1045                         Assert("#I01", errorThrown);
1046                 }
1047                 {
1048                         bool errorThrown = false;
1049                         try {
1050                                 char[] c = {'a', 'b', 'c'};
1051                                 c.GetValue(-1);
1052                         } catch (IndexOutOfRangeException) {
1053                                 errorThrown = true;
1054                         }
1055                         Assert("#I02", errorThrown);
1056                 }
1057                 {
1058                         bool errorThrown = false;
1059                         try {
1060                                 char[] c = {'a', 'b', 'c'};
1061                                 c.GetValue(4);
1062                         } catch (IndexOutOfRangeException) {
1063                                 errorThrown = true;
1064                         }
1065                         Assert("#I03", errorThrown);
1066                 }
1067
1068                 char[] c1 = {'a', 'b', 'c', 'd'};
1069                 for (int i = 0; i < c1.Length; i++) {
1070                         AssertEquals("#I04(" + i + ")", c1[i], c1.GetValue(i));
1071                 }
1072         }
1073
1074         [Test]
1075         public void TestGetValue2() {
1076                 {
1077                         bool errorThrown = false;
1078                         try {
1079                                 char[] c = new Char[2];
1080                                 c.GetValue(1,1);
1081                         } catch (ArgumentException) {
1082                                 errorThrown = true;
1083                         }
1084                         Assert("#I21", errorThrown);
1085                 }
1086                 {
1087                         bool errorThrown = false;
1088                         try {
1089                                 char[,] c = new Char[2,2];
1090                                 c.GetValue(-1, 1);
1091                         } catch (IndexOutOfRangeException) {
1092                                 errorThrown = true;
1093                         }
1094                         Assert("#I22", errorThrown);
1095                 }
1096                 {
1097                         bool errorThrown = false;
1098                         try {
1099                                 char[,] c = new Char[2,2];
1100                                 c.GetValue(4,1);
1101                         } catch (IndexOutOfRangeException) {
1102                                 errorThrown = true;
1103                         }
1104                         Assert("#I23", errorThrown);
1105                 }
1106
1107                 char[,] c1 = new Char[4,6];
1108                 for (int i = 0; i < 24; i++) {
1109                         int first = i / 6;
1110                         int second = i % 6;
1111                         c1[first,second] = (char)(((int)'a')+i);
1112                 }
1113                 for (int i = 0; i < c1.GetLength(0); i++) {
1114                         for (int j = 0; j < c1.GetLength(1); j++) {
1115                                 AssertEquals("#I24(" + i + "," + j + ")",
1116                                              c1[i,j], c1.GetValue(i, j));
1117                         }
1118                 }
1119         }
1120
1121         [Test]
1122         public void TestGetValue3() {
1123                 {
1124                         bool errorThrown = false;
1125                         try {
1126                                 char[] c = new Char[2];
1127                                 c.GetValue(1,1,1);
1128                         } catch (ArgumentException) {
1129                                 errorThrown = true;
1130                         }
1131                         Assert("#I41", errorThrown);
1132                 }
1133                 {
1134                         bool errorThrown = false;
1135                         try {
1136                                 char[,,] c = new Char[2,2,2];
1137                                 c.GetValue(-1, 1, 1);
1138                         } catch (IndexOutOfRangeException) {
1139                                 errorThrown = true;
1140                         }
1141                         Assert("#I42", errorThrown);
1142                 }
1143                 {
1144                         bool errorThrown = false;
1145                         try {
1146                                 char[,,] c = new Char[2,2,2];
1147                                 c.GetValue(4,1,1);
1148                         } catch (IndexOutOfRangeException) {
1149                                 errorThrown = true;
1150                         }
1151                         Assert("#I43", errorThrown);
1152                 }
1153
1154                 char[,,] c1 = new Char[4,2,3];
1155                 for (int i = 0; i < 24; i++) {
1156                         int first = i / 6;
1157                         int remains = i % 6;
1158                         int second = remains / 3;
1159                         int third = remains % 3;
1160                         c1[first,second, third] = (char)(((int)'a')+i);
1161                 }
1162                 for (int i = 0; i < c1.GetLength(0); i++) {
1163                         for (int j = 0; j < c1.GetLength(1); j++) {
1164                                 for (int k = 0; k < c1.GetLength(2); k++) {
1165                                         AssertEquals("#I44(" + i + "," + j + ")",
1166                                                      c1[i,j,k], c1.GetValue(i,j,k));
1167                                 }
1168                         }
1169                 }
1170         }
1171
1172         [Test]
1173 #if NET_2_0
1174         [ExpectedException (typeof (ArgumentNullException))]
1175 #else
1176         [ExpectedException (typeof (NullReferenceException))]
1177 #endif
1178         public void TestGetValueLongArray ()
1179         {
1180                 char[] c = new Char[2];
1181                 c.GetValue((long [])null);
1182         }
1183
1184         [Test]
1185         public void TestGetValueN() {
1186                 {
1187                         bool errorThrown = false;
1188                         try {
1189                                 char[] c = new Char[2];
1190                                 c.GetValue((int [])null);
1191                         } catch (ArgumentNullException) {
1192                                 errorThrown = true;
1193                         }
1194                         Assert("#I61a", errorThrown);
1195                 }
1196                 {
1197                         bool errorThrown = false;
1198                         try {
1199                                 char[] c = new Char[2];
1200                                 int[] coords = {1, 1};
1201                                 c.GetValue(coords);
1202                         } catch (ArgumentException) {
1203                                 errorThrown = true;
1204                         }
1205                         Assert("#I62", errorThrown);
1206                 }
1207                 {
1208                         bool errorThrown = false;
1209                         try {
1210                                 char[,] c = new Char[2,2];
1211                                 int[] coords = {-1, 1};
1212                                 c.GetValue(coords);
1213                         } catch (IndexOutOfRangeException) {
1214                                 errorThrown = true;
1215                         }
1216                         Assert("#I63", errorThrown);
1217                 }
1218                 {
1219                         bool errorThrown = false;
1220                         try {
1221                                 char[,] c = new Char[2,2];
1222                                 int[] coords = {4, 1};
1223                                 c.GetValue(coords);
1224                         } catch (IndexOutOfRangeException) {
1225                                 errorThrown = true;
1226                         }
1227                         Assert("#I64", errorThrown);
1228                 }
1229
1230                 char[,] c1 = new Char[4,6];
1231                 for (int i = 0; i < 24; i++) {
1232                         int first = i / 6;
1233                         int second = i % 6;
1234                         c1[first,second] = (char)(((int)'a')+i);
1235                 }
1236                 for (int i = 0; i < c1.GetLength(0); i++) {
1237                         for (int j = 0; j < c1.GetLength(1); j++) {
1238                                 int[] coords = {i, j};
1239                                 AssertEquals("#I65(" + i + "," + j + ")",
1240                                              c1[i,j], c1.GetValue(coords));
1241                         }
1242                 }
1243         }
1244
1245         [Test]
1246         public void TestIndexOf1() {
1247                 {
1248                         bool errorThrown = false;
1249                         try {
1250                                 Array.IndexOf(null, "huh?");
1251                         } catch (ArgumentNullException) {
1252                                 errorThrown = true;
1253                         }
1254                         Assert("#J01", errorThrown);
1255                 }
1256                 {
1257                         bool errorThrown = false;
1258                         try {
1259                                 char[,] c = new Char[2,2];
1260                                 Array.IndexOf(c, "huh?");
1261                         } catch (RankException) {
1262                                 errorThrown = true;
1263                         }
1264                         Assert("#J02", errorThrown);
1265                 }
1266
1267                 String[] s1 = {"this", "is", "a", "test"};
1268                 AssertEquals("#J03", -1, Array.IndexOf(s1, null));
1269                 AssertEquals("#J04", -1, Array.IndexOf(s1, "nothing"));
1270                 AssertEquals("#J05", 0, Array.IndexOf(s1, "this"));
1271                 AssertEquals("#J06", 3, Array.IndexOf(s1, "test"));
1272         }
1273
1274         [Test]
1275         public void TestIndexOf2() {
1276                 {
1277                         bool errorThrown = false;
1278                         try {
1279                                 Array.IndexOf(null, "huh?", 0);
1280                         } catch (ArgumentNullException) {
1281                                 errorThrown = true;
1282                         }
1283                         Assert("#J21", errorThrown);
1284                 }
1285                 {
1286                         bool errorThrown = false;
1287                         try {
1288                                 char[,] c = new Char[2,2];
1289                                 Array.IndexOf(c, "huh?", 0);
1290                         } catch (RankException) {
1291                                 errorThrown = true;
1292                         }
1293                         Assert("#J22", errorThrown);
1294                 }
1295                 {
1296                         bool errorThrown = false;
1297                         try {
1298                                 char[] c = new Char[2];
1299                                 Array.IndexOf(c, "huh?", 3);
1300                         } catch (ArgumentOutOfRangeException) {
1301                                 errorThrown = true;
1302                         }
1303                         Assert("#J23", errorThrown);
1304                 }
1305
1306                 String[] s1 = {"this", "is", "really", "a", "test"};
1307                 AssertEquals("#J24", -1, Array.IndexOf(s1, null, 1));
1308                 AssertEquals("#J25", -1, Array.IndexOf(s1, "nothing", 1));
1309                 AssertEquals("#J26", -1, Array.IndexOf(s1, "this", 1));
1310                 AssertEquals("#J27", 1, Array.IndexOf(s1, "is", 1));
1311                 AssertEquals("#J28", 4, Array.IndexOf(s1, "test", 1));
1312         }
1313
1314         [Test]
1315         public void TestIndexOf3() {
1316                 {
1317                         bool errorThrown = false;
1318                         try {
1319                                 Array.IndexOf(null, "huh?", 0, 1);
1320                         } catch (ArgumentNullException) {
1321                                 errorThrown = true;
1322                         }
1323                         Assert("#J41", errorThrown);
1324                 }
1325                 {
1326                         bool errorThrown = false;
1327                         try {
1328                                 char[,] c = new Char[2,2];
1329                                 Array.IndexOf(c, "huh?", 0, 1);
1330                         } catch (RankException) {
1331                                 errorThrown = true;
1332                         }
1333                         Assert("#J42", errorThrown);
1334                 }
1335                 {
1336                         bool errorThrown = false;
1337                         try {
1338                                 char[] c = new Char[2];
1339                                 Array.IndexOf(c, "huh?", 3, 1);
1340                         } catch (ArgumentOutOfRangeException) {
1341                                 errorThrown = true;
1342                         }
1343                         Assert("#J43", errorThrown);
1344                 }
1345                 {
1346                         bool errorThrown = false;
1347                         try {
1348                                 char[] c = new Char[2];
1349                                 Array.IndexOf(c, "huh?", 0, 5);
1350                         } catch (ArgumentOutOfRangeException) {
1351                                 errorThrown = true;
1352                         }
1353                         Assert("#J44", errorThrown);
1354                 }
1355
1356                 String[] s1 = {"this", "is", "really", "a", "test"};
1357                 AssertEquals("#J45", -1, Array.IndexOf(s1, null, 1, 3));
1358                 AssertEquals("#J46", -1, Array.IndexOf(s1, "nothing", 1, 3));
1359                 AssertEquals("#J47", -1, Array.IndexOf(s1, "this", 1, 3));
1360                 AssertEquals("#J48", 1, Array.IndexOf(s1, "is", 1, 3));
1361                 AssertEquals("#J49", -1, Array.IndexOf(s1, "test", 1, 3));
1362                 AssertEquals("#J50", 3, Array.IndexOf(s1, "a", 1, 3));
1363         }
1364         
1365         [Test]
1366         public void TestLastIndexOf1() {
1367                 {
1368                         bool errorThrown = false;
1369                         try {
1370                                 Array.LastIndexOf(null, "huh?");
1371                         } catch (ArgumentNullException) {
1372                                 errorThrown = true;
1373                         }
1374                         Assert("#K01", errorThrown);
1375                 }
1376                 {
1377                         bool errorThrown = false;
1378                         try {
1379                                 char[,] c = new Char[2,2];
1380                                 Array.LastIndexOf(c, "huh?");
1381                         } catch (RankException) {
1382                                 errorThrown = true;
1383                         }
1384                         Assert("#K02", errorThrown);
1385                 }
1386
1387                 String[] s1 = {"this", "is", "a", "a", "test"};
1388                 AssertEquals("#K03", -1, Array.LastIndexOf(s1, null));
1389                 AssertEquals("#K04", -1, Array.LastIndexOf(s1, "nothing"));
1390                 AssertEquals("#K05", 0, Array.LastIndexOf(s1, "this"));
1391                 AssertEquals("#K06", 4, Array.LastIndexOf(s1, "test"));
1392                 AssertEquals("#K07", 3, Array.LastIndexOf(s1, "a"));
1393         }
1394
1395         [Test]
1396         public void TestLastIndexOf2() {
1397                 {
1398                         bool errorThrown = false;
1399                         try {
1400                                 Array.LastIndexOf(null, "huh?", 0);
1401                         } catch (ArgumentNullException) {
1402                                 errorThrown = true;
1403                         }
1404                         Assert("#K21", errorThrown);
1405                 }
1406                 {
1407                         bool errorThrown = false;
1408                         try {
1409                                 char[,] c = new Char[2,2];
1410                                 Array.LastIndexOf(c, "huh?", 0);
1411                         } catch (RankException) {
1412                                 errorThrown = true;
1413                         }
1414                         Assert("#K22", errorThrown);
1415                 }
1416                 {
1417                         bool errorThrown = false;
1418                         try {
1419                                 char[] c = new Char[2];
1420                                 Array.LastIndexOf(c, "huh?", 3);
1421                         } catch (ArgumentOutOfRangeException) {
1422                                 errorThrown = true;
1423                         }
1424                         Assert("#K23", errorThrown);
1425                 }
1426
1427                 String[] s1 = {"this", "is", "really", "a", "test"};
1428                 AssertEquals("#K24", -1, Array.LastIndexOf(s1, null, 3));
1429                 AssertEquals("#K25", -1, Array.LastIndexOf(s1, "nothing", 3));
1430                 AssertEquals("#K26", -1, Array.LastIndexOf(s1, "test", 3));
1431                 AssertEquals("#K27", 3, Array.LastIndexOf(s1, "a", 3));
1432                 AssertEquals("#K28", 0, Array.LastIndexOf(s1, "this", 3));
1433         }
1434
1435         [Test]
1436         public void TestLastIndexOf3() {
1437                 {
1438                         bool errorThrown = false;
1439                         try {
1440                                 Array.LastIndexOf(null, "huh?", 0, 1);
1441                         } catch (ArgumentNullException) {
1442                                 errorThrown = true;
1443                         }
1444                         Assert("#K41", errorThrown);
1445                 }
1446                 {
1447                         bool errorThrown = false;
1448                         try {
1449                                 char[,] c = new Char[2,2];
1450                                 Array.LastIndexOf(c, "huh?", 0, 1);
1451                         } catch (RankException) {
1452                                 errorThrown = true;
1453                         }
1454                         Assert("#K42", errorThrown);
1455                 }
1456                 {
1457                         bool errorThrown = false;
1458                         try {
1459                                 char[] c = new Char[2];
1460                                 Array.LastIndexOf(c, "huh?", 3, 1);
1461                         } catch (ArgumentOutOfRangeException) {
1462                                 errorThrown = true;
1463                         }
1464                         Assert("#K43", errorThrown);
1465                 }
1466                 {
1467                         bool errorThrown = false;
1468                         try {
1469                                 char[] c = new Char[2];
1470                                 Array.LastIndexOf(c, "huh?", 0, 5);
1471                         } catch (ArgumentOutOfRangeException) {
1472                                 errorThrown = true;
1473                         }
1474                         Assert("#K44", errorThrown);
1475                 }
1476
1477                 String[] s1 = {"this", "is", "really", "a", "test"};
1478                 AssertEquals("#K45", 
1479                              -1, Array.LastIndexOf(s1, null, 3, 3));
1480                 AssertEquals("#K46", 
1481                              -1, Array.LastIndexOf(s1, "nothing", 3, 3));
1482                 AssertEquals("#K47", 
1483                              -1, Array.LastIndexOf(s1, "this", 3, 3));
1484                 AssertEquals("#K48",
1485                              1, Array.LastIndexOf(s1, "is", 3, 3));
1486                 AssertEquals("#K49", 
1487                              -1, Array.LastIndexOf(s1, "test", 3, 3));
1488                 AssertEquals("#K50", 
1489                              3, Array.LastIndexOf(s1, "a", 3, 3));
1490         }
1491
1492         [Test]
1493         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1494         public void TestLastIndexOf4 ()
1495         {
1496                 short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
1497                 Array.LastIndexOf (a, 16, -1);
1498         }
1499
1500         [Test]
1501         public void TestLastIndexOf5 ()
1502         {
1503                 char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
1504                 string s;
1505                 int retval;
1506                 bool error = false;
1507
1508                 for (int i = a.Length - 1; i >= 0 ; i--) {
1509                         s = i.ToString ();
1510                         retval = Array.LastIndexOf(a, a [i], i, i + 1);
1511                         if (retval != i)
1512                                 error = true;
1513                 }
1514                 Assert (!error);
1515         }
1516
1517         [Test]
1518         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1519         public void LastIndexOf_StartIndexOverflow ()
1520         {
1521                 // legal - no exception
1522                 byte[] array = new byte [16];
1523                 Array.LastIndexOf (array, this, Int32.MaxValue, 1);
1524         }
1525
1526         [Test]
1527         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1528         public void LastIndexOf_CountOverflow ()
1529         {
1530                 // legal - no exception
1531                 byte[] array = new byte [16];
1532                 Array.LastIndexOf (array, this, 1, Int32.MaxValue);
1533         }
1534
1535         [Test]
1536         public void TestReverse() {
1537                 {
1538                         bool errorThrown = false;
1539                         try {
1540                                 Array.Reverse(null);
1541                         } catch (ArgumentNullException) {
1542                                 errorThrown = true;
1543                         }
1544                         Assert("#L01", errorThrown);
1545                 }
1546                 {
1547                         bool errorThrown = false;
1548                         try {
1549                                 char[,] c = new Char[2,2];
1550                                 Array.Reverse(c);
1551                         } catch (RankException) {
1552                                 errorThrown = true;
1553                         }
1554                         Assert("#L02", errorThrown);
1555                 }
1556                 
1557                 char[] c1 = {'a', 'b', 'c', 'd'};
1558                 Array.Reverse(c1);
1559                 AssertEquals("#L03", 'd', c1[0]);
1560                 AssertEquals("#L04", 'c', c1[1]);
1561                 AssertEquals("#L05", 'b', c1[2]);
1562                 AssertEquals("#L06", 'a', c1[3]);
1563
1564                 {
1565                         bool errorThrown = false;
1566                         try {
1567                                 Array.Reverse(null, 0, 0);
1568                         } catch (ArgumentNullException) {
1569                                 errorThrown = true;
1570                         }
1571                         Assert("#L07", errorThrown);
1572                 }
1573                 {
1574                         bool errorThrown = false;
1575                         try {
1576                                 char[,] c = new Char[2,2];
1577                                 Array.Reverse(c, 0, 0);
1578                         } catch (RankException) {
1579                                 errorThrown = true;
1580                         }
1581                         Assert("#L08", errorThrown);
1582                 }
1583                 //{
1584                 //bool errorThrown = false;
1585                 //try {
1586                 //      char[] c = new Char[2];
1587                 //      Array.Reverse(c, 0, 3);
1588                 //} catch (ArgumentOutOfRangeException) {
1589                 //      errorThrown = true;
1590                 //}
1591                 //Assert("#L09", errorThrown);
1592                 //}
1593                 //{
1594                 //bool errorThrown = false;
1595                 //try {
1596                 //      char[] c = new Char[2];
1597                 //      Array.Reverse(c, 3, 0);
1598                 //} catch (ArgumentOutOfRangeException) {
1599                 //      errorThrown = true;
1600                 //}
1601                 //Assert("#L10", errorThrown);
1602                 //}
1603
1604                 char[] c2 = { 'a', 'b', 'c', 'd'};
1605                 Array.Reverse(c2, 1, 2);
1606                 AssertEquals("#L11", 'a', c2[0]);
1607                 AssertEquals("#L12", 'c', c2[1]);
1608                 AssertEquals("#L13", 'b', c2[2]);
1609                 AssertEquals("#L14", 'd', c2[3]);
1610         }
1611
1612         [Test]
1613         public void TestSetValue1() {
1614                 {
1615                         bool errorThrown = false;
1616                         try {
1617                                 char[,] c = new Char[2,2];
1618                                 c.SetValue("buh", 1);
1619                         } catch (ArgumentException) {
1620                                 errorThrown = true;
1621                         }
1622                         Assert("#M01", errorThrown);
1623                 }
1624                 {
1625                         bool errorThrown = false;
1626                         try {
1627                                 char[] c = {'a', 'b', 'c'};
1628                                 c.SetValue("buh", -1);
1629                         } catch (IndexOutOfRangeException) {
1630                                 errorThrown = true;
1631                         }
1632                         Assert("#M02", errorThrown);
1633                 }
1634                 {
1635                         bool errorThrown = false;
1636                         try {
1637                                 char[] c = {'a', 'b', 'c'};
1638                                 c.SetValue("buh", 4);
1639                         } catch (IndexOutOfRangeException) {
1640                                 errorThrown = true;
1641                         }
1642                         Assert("#M03", errorThrown);
1643                 }
1644
1645                 char[] c1 = {'a', 'b', 'c', 'd'};
1646                 char[] c2 = new char[4];
1647                 for (int i = 0; i < c1.Length; i++) {
1648                         c2.SetValue(c1[i], i);
1649                 }
1650                 for (int i = 0; i < c1.Length; i++) {
1651                         AssertEquals("#M04(" + i + ")", c1[i], c2[i]);
1652                 }
1653
1654                 int[] c3 = { 1, 2, 3 };
1655                 long[] c4 = new long [3];
1656
1657                 for (int i = 0; i < c3.Length; i++)
1658                         c4.SetValue (c3 [i], i);
1659
1660                 try {
1661                         c3.CopyTo (c4, 0);
1662                 } catch (Exception e) {
1663                         Fail ("c3.CopyTo(): e=" + e);
1664                 }
1665                 for (int i = 0; i < c3.Length; i++)
1666                         Assert ("#M05(" + i + ")", c3[i] == c4[i]);
1667
1668                 Object[] c5 = new Object [3];
1669                 long[] c6 = new long [3];
1670
1671                 try {
1672                         c4.CopyTo (c5, 0);
1673                 } catch (Exception e) {
1674                         Fail ("c4.CopyTo(): e=" + e);
1675                 }
1676
1677                 try {
1678                         c5.CopyTo (c6, 0);
1679                 } catch (Exception e) {
1680                         Fail ("c5.CopyTo(): e=" + e);
1681                 }
1682                 // for (int i = 0; i < c5.Length; i++)
1683                 // Assert ("#M06(" + i + ")", c5[i] == c6[i]);
1684         }
1685
1686         [Test]
1687         public void TestSetValue2() {
1688                 {
1689                         bool errorThrown = false;
1690                         try {
1691                                 char[] c = new Char[2];
1692                                 c.SetValue("buh", 1,1);
1693                         } catch (ArgumentException) {
1694                                 errorThrown = true;
1695                         }
1696                         Assert("#M21", errorThrown);
1697                 }
1698                 {
1699                         bool errorThrown = false;
1700                         try {
1701                                 char[,] c = new Char[2,2];
1702                                 c.SetValue("buh", -1, 1);
1703                         } catch (IndexOutOfRangeException) {
1704                                 errorThrown = true;
1705                         }
1706                         Assert("#M22", errorThrown);
1707                 }
1708                 {
1709                         bool errorThrown = false;
1710                         try {
1711                                 char[,] c = new Char[2,2];
1712                                 c.SetValue("buh", 4,1);
1713                         } catch (IndexOutOfRangeException) {
1714                                 errorThrown = true;
1715                         }
1716                         Assert("#M23", errorThrown);
1717                 }
1718
1719                 char[,] c1 = new Char[4,6];
1720                 char[,] c2 = new Char[4,6];
1721                 for (int i = 0; i < 24; i++) {
1722                         int first = i / 6;
1723                         int second = i % 6;
1724                         c1[first,second] = (char)(((int)'a')+i);
1725                         c2.SetValue(c1[first,second], first, second);
1726                 }
1727                 for (int i = 0; i < c1.GetLength(0); i++) {
1728                         for (int j = 0; j < c1.GetLength(1); j++) {
1729                                 AssertEquals("#M24(" + i + "," + j + ")",
1730                                              c1[i,j], c2[i, j]);
1731                         }
1732                 }
1733         }
1734
1735         [Test]
1736         public void TestSetValue3() {
1737                 {
1738                         bool errorThrown = false;
1739                         try {
1740                                 char[] c = new Char[2];
1741                                 c.SetValue("buh", 1,1,1);
1742                         } catch (ArgumentException) {
1743                                 errorThrown = true;
1744                         }
1745                         Assert("#M41", errorThrown);
1746                 }
1747                 {
1748                         bool errorThrown = false;
1749                         try {
1750                                 char[,,] c = new Char[2,2,2];
1751                                 c.SetValue("buh", -1, 1, 1);
1752                         } catch (IndexOutOfRangeException) {
1753                                 errorThrown = true;
1754                         }
1755                         Assert("#M42", errorThrown);
1756                 }
1757                 {
1758                         bool errorThrown = false;
1759                         try {
1760                                 char[,,] c = new Char[2,2,2];
1761                                 c.SetValue("buh", 4,1,1);
1762                         } catch (IndexOutOfRangeException) {
1763                                 errorThrown = true;
1764                         }
1765                         Assert("#M43", errorThrown);
1766                 }
1767
1768                 char[,,] c1 = new Char[4,2,3];
1769                 char[,,] c2 = new Char[4,2,3];
1770                 for (int i = 0; i < 24; i++) {
1771                         int first = i / 6;
1772                         int remains = i % 6;
1773                         int second = remains / 3;
1774                         int third = remains % 3;
1775                         c1[first,second, third] = (char)(((int)'a')+i);
1776                         c2.SetValue(c1[first, second, third], first, second, third);
1777                 }
1778                 for (int i = 0; i < c1.GetLength(0); i++) {
1779                         for (int j = 0; j < c1.GetLength(1); j++) {
1780                                 for (int k = 0; k < c1.GetLength(2); k++) {
1781                                         AssertEquals("#M44(" + i + "," + j + " )",
1782                                                      c1[i,j,k], c2[i,j,k]);
1783                                 }
1784                         }
1785                 }
1786         }
1787
1788         [Test]
1789 #if NET_2_0
1790         [ExpectedException (typeof (ArgumentNullException))]
1791 #else
1792         [ExpectedException (typeof (NullReferenceException))]
1793 #endif
1794         public void TestSetValueLongArray ()
1795         {
1796                 char[] c = new Char[2];
1797                 c.SetValue("buh", (long [])null);
1798         }
1799
1800         [Test]
1801         public void TestSetValueN() {
1802                 {
1803                         bool errorThrown = false;
1804                         try {
1805                                 char[] c = new Char[2];
1806                                 c.SetValue("buh", (int [])null);
1807                         } catch (ArgumentNullException) {
1808                                 errorThrown = true;
1809                         }
1810                         Assert("#M61a", errorThrown);
1811                 }
1812                 {
1813                         bool errorThrown = false;
1814                         try {
1815                                 char[] c = new Char[2];
1816                                 int[] coords = {1, 1};
1817                                 c.SetValue("buh", coords);
1818                         } catch (ArgumentException) {
1819                                 errorThrown = true;
1820                         }
1821                         Assert("#M62", errorThrown);
1822                 }
1823                 {
1824                         bool errorThrown = false;
1825                         try {
1826                                 char[,] c = new Char[2,2];
1827                                 int[] coords = {-1, 1};
1828                                 c.SetValue("buh", coords);
1829                         } catch (IndexOutOfRangeException) {
1830                                 errorThrown = true;
1831                         }
1832                         Assert("#M63", errorThrown);
1833                 }
1834                 {
1835                         bool errorThrown = false;
1836                         try {
1837                                 char[,] c = new Char[2,2];
1838                                 int[] coords = {4, 1};
1839                                 c.SetValue("buh", coords);
1840                         } catch (IndexOutOfRangeException) {
1841                                 errorThrown = true;
1842                         }
1843                         Assert("#M64", errorThrown);
1844                 }
1845
1846                 char[,] c1 = new Char[4,6];
1847                 char[,] c2 = new Char[4,6];
1848                 for (int i = 0; i < 24; i++) {
1849                         int first = i / 6;
1850                         int second = i % 6;
1851                         c1[first,second] = (char)(((int)'a')+i);
1852                         int[] coords = {first, second};
1853                         c2.SetValue(c1[first,second], coords);
1854                 }
1855                 for (int i = 0; i < c1.GetLength(0); i++) {
1856                         for (int j = 0; j < c1.GetLength(1); j++) {
1857                                 AssertEquals("#M65(" + i + "," + j + ")",
1858                                              c1[i,j], c2[i,j]);
1859                         }
1860                 }
1861         }
1862
1863         [Test]
1864         public void TestSetValue4() {
1865                 {
1866                         int[] c1 = { 1, 2, 3 };
1867                         long[] c2 = new long [3];
1868
1869                         for (int i = 0; i < c1.Length; i++)
1870                                 c2.SetValue (c1 [i], i);
1871
1872                         for (int i = 0; i < c1.Length; i++) {
1873                                 Assert ("#M81(" + i + ")", c1[i] == c2[i]);
1874                                 AssertEquals ("#M82(" + i + ")", typeof (long), c2[i].GetType ());
1875                         }
1876                 }
1877                 {
1878                         long[] c1 = { 1, 2, 3 };
1879                         int[] c2 = new int [3];
1880                         bool errorThrown = false;
1881                         try {
1882                                 c2.SetValue (c1 [0], 0);
1883                         } catch (ArgumentException) {
1884                                 errorThrown = true;
1885                         }
1886                         Assert("#M83", errorThrown);
1887                 }
1888                 {
1889                         int[] c1 = { 1, 2, 3 };
1890                         Object[] c2 = new Object [3];
1891
1892                         for (int i = 0; i < c1.Length; i++)
1893                                 c2.SetValue (c1 [i], i);
1894
1895                         for (int i = 0; i < c1.Length; i++)
1896                                 AssertEquals ("#M84(" + i + ")", c1[i], Convert.ToInt32 (c2[i]));
1897                 }
1898                 {
1899                         Object[] c1 = new Object [3];
1900                         Object[] c2 = new Object [3];
1901                         c1[0] = new Object ();
1902
1903                         for (int i = 0; i < c1.Length; i++)
1904                                 c2.SetValue (c1 [i], i);
1905
1906                         for (int i = 0; i < c1.Length; i++)
1907                                 AssertEquals ("#M85(" + i + ")", c1[i], c2[i]);
1908                 }
1909                 {
1910                         Object[] c1 = new Object [3];
1911                         string[] c2 = new String [3];
1912                         string test = "hello";
1913                         c1[0] = test;
1914
1915                         c2.SetValue (c1 [0], 0);
1916                         AssertEquals ("#M86", c1[0], c2[0]);
1917                         AssertEquals ("#M87", "hello", c2[0]);
1918                 }
1919                 {
1920                         char[] c1 = { 'a', 'b', 'c' };
1921                         string[] c2 = new string [3];
1922                         try {
1923                                 c2.SetValue (c1 [0], 0);
1924                                 Fail ("#M88");
1925                         } catch (InvalidCastException) {}
1926                 }
1927                 {
1928                         Single[] c1 = { 1.2F, 2.3F, 3.4F, 4.5F };
1929                         long[] c2 = new long [3];
1930                         try {
1931                                 c2.SetValue (c1 [0], 0);
1932                                 Fail ("#M89");
1933                         } catch (ArgumentException) {}
1934                 }
1935                 {
1936                         Type[] types = {
1937                                 typeof (Boolean),
1938                                 typeof (Byte),
1939                                 typeof (Char),
1940                                 typeof (Double),
1941                                 typeof (Int16),
1942                                 typeof (Int32),
1943                                 typeof (Int64),
1944                                 typeof (SByte),
1945                                 typeof (Single),
1946                                 typeof (UInt16),
1947                                 typeof (UInt32),
1948                                 typeof (UInt64)
1949                         };
1950
1951                         bool v1 = true;
1952                         Byte v2 = 1;
1953                         Char v3 = 'a';
1954                         Double v4 = -1.2;
1955                         Int16 v5 = -32;
1956                         Int32 v6 = -234;
1957                         Int64 v7 = -34523;
1958                         SByte v8 = -1;
1959                         Single v9 = -4.8F;
1960                         UInt16 v10 = 24234;
1961                         UInt32 v11 = 235354;
1962                         UInt64 v12 = 234552;
1963
1964                         Object[] va1 = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 };
1965                         Object[] va2 = { "true", "1", "a", "-1.2", "-32", "-234", "-34523", "-1",
1966                                          "-4.8F", "24234", "235354", "234552" };
1967
1968                         Object[][] vt = { va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1, va1 };
1969
1970                         int[] arg_ex = {
1971                                 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1972                                 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
1973                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
1974                                 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1975                                 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
1976                                 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,
1977                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1,
1978                                 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1979                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,
1980                                 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
1981                                 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,
1982                                 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0
1983                         };
1984
1985                         // SetValue
1986
1987                         for (int i = 0; i < types.Length; i++) {
1988                                 for (int j = 0; j < types.Length; j++) {
1989                                         Array array = Array.CreateInstance (types [j], 2);
1990
1991                                         Object value = vt[j][i];
1992
1993                                         bool errorThrown = false;
1994                                         try {
1995                                                 array.SetValue (value, 0);
1996                                         } catch (ArgumentException) {
1997                                                 errorThrown = true;
1998                                         }
1999
2000                                         int ex_index = (i * types.Length) + j;
2001
2002                                         AssertEquals ("#M90(" + types [i] + "," + types [j] + ")",
2003                                                       errorThrown, arg_ex [ex_index] == 1);
2004                                 }
2005                         }
2006
2007                         for (int i = 0; i < types.Length; i++) {
2008                                 String[] array = new String [2];
2009
2010                                 Object value = va1 [i];
2011
2012                                 bool errorThrown = false;
2013                                 try {
2014                                         array.SetValue (value, 0);
2015                                 } catch (InvalidCastException) {
2016                                         errorThrown = true;
2017                                 }
2018
2019                                 Assert ("#M91(" + types [i] + ")", errorThrown);
2020                         }
2021
2022                         for (int i = 0; i < types.Length; i++) {
2023                                 Array array = Array.CreateInstance (types [i], 2);
2024
2025                                 Object value = va2 [i];
2026
2027                                 bool errorThrown = false;
2028                                 try {
2029                                         array.SetValue (value, 0);
2030                                 } catch (InvalidCastException) {
2031                                         errorThrown = true;
2032                                 }
2033
2034                                 Assert ("#M92(" + types [i] + ")", errorThrown);
2035                         }
2036
2037                         for (int i = 0; i < types.Length; i++) {
2038                                 Array array = Array.CreateInstance (types [i], 2);
2039
2040                                 Object value = null;
2041
2042                                 bool errorThrown = false;
2043                                 try {
2044                                         array.SetValue (value, 0);
2045                                 } catch (InvalidCastException) {
2046                                         errorThrown = true;
2047                                 }
2048
2049                                 Assert ("#M93(" + types [i] + ")", !errorThrown);
2050                         }
2051
2052                         // Copy
2053
2054                         for (int i = 0; i < types.Length; i++) {
2055                                 for (int j = 0; j < types.Length; j++) {
2056                                         Array source = Array.CreateInstance (types [i], 2);
2057                                         Array array = Array.CreateInstance (types [j], 2);
2058
2059                                         source.SetValue (vt[j][i], 0);
2060                                         source.SetValue (vt[j][i], 1);
2061
2062                                         bool errorThrown = false;
2063                                         try {
2064                                                 Array.Copy (source, array, 2);
2065                                         } catch (ArrayTypeMismatchException) {
2066                                                 errorThrown = true;
2067                                         }
2068
2069                                         int ex_index = (i * types.Length) + j;
2070
2071                                         AssertEquals ("#M94(" + types [i] + "," + types [j] + ")",
2072                                                       errorThrown, arg_ex [ex_index] == 1);
2073                                 }
2074                         }
2075
2076                         for (int i = 0; i < types.Length; i++) {
2077                                 Array source = Array.CreateInstance (types [i], 2);
2078                                 String[] array = new String [2];
2079
2080                                 source.SetValue (va1 [i], 0);
2081                                 source.SetValue (va1 [i], 1);
2082
2083                                 bool errorThrown = false;
2084                                 try {
2085                                         Array.Copy (source, array, 2);
2086                                 } catch (ArrayTypeMismatchException) {
2087                                         errorThrown = true;
2088                                 }
2089
2090                                 Assert ("#M95(" + types [i] + ")", errorThrown);
2091                         }
2092
2093                         for (int i = 0; i < types.Length; i++) {
2094                                 String[] source = new String [2];
2095                                 Array array = Array.CreateInstance (types [i], 2);
2096
2097                                 source.SetValue (va2 [i], 0);
2098                                 source.SetValue (va2 [i], 1);
2099
2100                                 bool errorThrown = false;
2101                                 try {
2102                                         Array.Copy (source, array, 2);
2103                                 } catch (ArrayTypeMismatchException) {
2104                                         errorThrown = true;
2105                                 }
2106
2107                                 Assert ("#M96(" + types [i] + ")", errorThrown);
2108                         }
2109                 }
2110         }
2111
2112         [Test]
2113         public void TestSort() {
2114                 {
2115                         bool errorThrown = false;
2116                         try {
2117                                 Array.Sort(null);
2118                         } catch (ArgumentNullException) {
2119                                 errorThrown = true;
2120                         }
2121                         Assert("#N01", errorThrown);
2122                 }
2123                 {
2124                         bool errorThrown = false;
2125                         try {
2126                                 Array.Sort(null, 0, 1);
2127                         } catch (ArgumentNullException) {
2128                                 errorThrown = true;
2129                         }
2130                         Assert("#N02", errorThrown);
2131                 }
2132                 {
2133                         bool errorThrown = false;
2134                         try {
2135                                 char[] c1 = new Char[2];
2136                                 Array.Sort(null, c1);
2137                         } catch (ArgumentNullException) {
2138                                 errorThrown = true;
2139                         }
2140                         Assert("#N03", errorThrown);
2141                 }
2142                 {
2143                         bool errorThrown = false;
2144                         try {
2145                                 char[] c1 = new Char[2];
2146                                 Array.Sort(null, c1, 0, 1);
2147                         } catch (ArgumentNullException) {
2148                                 errorThrown = true;
2149                         }
2150                         Assert("#N04", errorThrown);
2151                 }
2152                 {
2153                         int tc = 5;
2154                         char[] arr = {'d', 'b', 'f', 'e', 'a', 'c'};
2155                         
2156                         try {
2157                                 Array.Sort (null, 0, 1);
2158                                 Fail ("#N" + tc.ToString ());
2159                         }
2160                         catch (ArgumentException) {}
2161                         catch (Exception) { Fail ("#N" + tc.ToString ()); }
2162                         tc++;
2163                         
2164                         try {
2165                                 Array.Sort (arr, -1, 3);
2166                                 Fail ("#N" + tc.ToString ());
2167                         }
2168                         catch (ArgumentException) {}
2169                         catch (Exception) { Fail ("#N" + tc.ToString ()); }
2170                         tc++;
2171                         
2172                         try {
2173                                 Array.Sort (arr, 1, -3);
2174                                 Fail ("#N" + tc.ToString ());
2175                         }
2176                         catch (ArgumentException) {}
2177                         catch (Exception) { Fail ("#N" + tc.ToString ()); }
2178                         tc++;
2179                         
2180                         try {
2181                                 Array.Sort (arr, arr.Length, arr.Length + 2);
2182                                 Fail ("#N" + tc.ToString ());
2183                         }
2184                         catch (ArgumentException) {}
2185                         catch (Exception) { Fail ("#N" + tc.ToString ()); }
2186                 }
2187                 
2188                 // note: null second array => just sort first array
2189                 char[] starter = {'d', 'b', 'f', 'e', 'a', 'c'};
2190                 int[] starter1 = {1,2,3,4,5,6};
2191                 {
2192                         char[] c1 = (char[])starter.Clone();
2193                         Array.Sort(c1);
2194                         AssertEquals("#N21", 'a', c1[0]);
2195                         AssertEquals("#N22", 'b', c1[1]);
2196                         AssertEquals("#N23", 'c', c1[2]);
2197                         AssertEquals("#N24", 'd', c1[3]);
2198                         AssertEquals("#N25", 'e', c1[4]);
2199                         AssertEquals("#N26", 'f', c1[5]);
2200                 }
2201                 {
2202                         char[] c1 = (char[])starter.Clone();
2203                         int[] i1 = (int[])starter1.Clone();
2204                         Array.Sort(c1, i1);
2205                         AssertEquals("#N41", 'a', c1[0]);
2206                         AssertEquals("#N42", 'b', c1[1]);
2207                         AssertEquals("#N43", 'c', c1[2]);
2208                         AssertEquals("#N44", 'd', c1[3]);
2209                         AssertEquals("#N45", 'e', c1[4]);
2210                         AssertEquals("#N46", 'f', c1[5]);
2211                         AssertEquals("#N47", 5, i1[0]);
2212                         AssertEquals("#N48", 2, i1[1]);
2213                         AssertEquals("#N49", 6, i1[2]);
2214                         AssertEquals("#N50", 1, i1[3]);
2215                         AssertEquals("#N51", 4, i1[4]);
2216                         AssertEquals("#N52", 3, i1[5]);
2217                 }
2218                 {
2219                         char[] c1 = (char[])starter.Clone();
2220                         Array.Sort(c1, 1, 4);
2221                         AssertEquals("#N61", 'd', c1[0]);
2222                         AssertEquals("#N62", 'a', c1[1]);
2223                         AssertEquals("#N63", 'b', c1[2]);
2224                         AssertEquals("#N64", 'e', c1[3]);
2225                         AssertEquals("#N65", 'f', c1[4]);
2226                         AssertEquals("#N66", 'c', c1[5]);
2227                 }
2228                 {
2229                         char[] c1 = (char[])starter.Clone();
2230                         int[] i1 = (int[])starter1.Clone();
2231                         Array.Sort(c1, i1, 1, 4);
2232                         AssertEquals("#N81", 'd', c1[0]);
2233                         AssertEquals("#N82", 'a', c1[1]);
2234                         AssertEquals("#N83", 'b', c1[2]);
2235                         AssertEquals("#N84", 'e', c1[3]);
2236                         AssertEquals("#N85", 'f', c1[4]);
2237                         AssertEquals("#N86", 'c', c1[5]);
2238                         AssertEquals("#N87", 1, i1[0]);
2239                         AssertEquals("#N88", 5, i1[1]);
2240                         AssertEquals("#N89", 2, i1[2]);
2241                         AssertEquals("#N90", 4, i1[3]);
2242                         AssertEquals("#N91", 3, i1[4]);
2243                         AssertEquals("#N92", 6, i1[5]);
2244                 }
2245         }
2246
2247         [Test]
2248         public void TestInitializeEmpty()
2249         {
2250                 bool catched=false;
2251                 int[] a = {};
2252                 try
2253                 {
2254                         a.Initialize();
2255                 }
2256                 catch(Exception)
2257                 {
2258                         catched=true;
2259                 }
2260                 Assert("#TI01",!catched);
2261         }
2262
2263         [Test]
2264         public void TestInitializeInt()
2265         {
2266                 int[] a = {1,2,0};
2267                 a.Initialize();
2268                 int[] b = {1,2,0};
2269                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2270                 {
2271                         AssertEquals("#TI02 " + i ,a[i],b[i]);
2272                 }
2273         }
2274
2275         [Test]
2276         public void TestInitializeDouble()
2277         {
2278                 double[] a = {1.0,2.0,0.0};
2279                 a.Initialize();
2280                 double[] b = {1.0,2.0,0.0};
2281                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2282                 {
2283                         AssertEquals("#TI03 " + i ,a[i],b[i]);
2284                 }
2285         }
2286
2287         [Test]
2288         public void TestInitializeFloat()
2289         {
2290                 float[] a = {1.0F,2.0F,0.0F};
2291                 a.Initialize();
2292                 float[] b = {1.0F,2.0F,0.0F};
2293                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2294                 {
2295                         AssertEquals("#TI04 " + i ,a[i],b[i]);
2296                 }
2297         }
2298
2299         [Test]
2300         public void TestInitializeChar()
2301         {
2302                 char[] a = {'1','.','0','F','2','.','0','F'};
2303                 a.Initialize();
2304                 char[] b = {'1','.','0','F','2','.','0','F'};
2305                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2306                 {
2307                         AssertEquals("#TI05 " + i ,a[i],b[i]);
2308                 }
2309         }
2310
2311         [Test]
2312         public void TestInitializeString()
2313         {
2314                 string[] a = {"hola","adios","menos","mas"};
2315                 a.Initialize();
2316                 string[] b = {"hola","adios","menos","mas"};
2317                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2318                 {
2319                         AssertEquals("#TI06 " + i ,a[i],b[i]);
2320                 }
2321         }
2322
2323         [Test]
2324         public void TestInitializeEnum()
2325         {
2326                 enua[] a = {enua.hola,enua.adios,enua.menos,enua.mas};
2327                 a.Initialize();
2328                 enua[] b = {enua.hola,enua.adios,enua.menos,enua.mas};
2329                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2330                 {
2331                         AssertEquals("#TI07 " + i ,a[i],b[i]);
2332                 }
2333         }
2334         
2335         [Test]
2336         public void TestInitializeIntNI()
2337         {
2338                 int[] a = new int[20];
2339                 a.Initialize();
2340                 foreach(int b in a)
2341                 {
2342                         AssertEquals("#TI08",b,0);
2343                 }
2344         }
2345         
2346         [Test]
2347         public void TestInitializeCharNI()
2348         {
2349                 char[] a = new char[20];
2350                 a.Initialize();
2351                 foreach(char b in a)
2352                 {
2353                         AssertEquals("#TI09",b,0);
2354                 }
2355         }
2356         
2357         [Test]
2358         public void TestInitializeDoubleNI()
2359         {
2360                 double[] a = new double[20];
2361                 a.Initialize();
2362                 foreach(double b in a)
2363                 {
2364                         AssertEquals("#TI09",b,0.0);
2365                 }
2366         }
2367         
2368         [Test]
2369         public void TestInitializeStringNI()
2370         {
2371                 string[] a = new string[20];
2372                 a.Initialize();
2373                 foreach(string b in a)
2374                 {
2375                         AssertEquals("#TI10",b,null);
2376                 }
2377         }
2378         
2379         [Test]
2380         public void TestInitializeObjectNI()
2381         {
2382                 object[] a = new object[20];
2383                 a.Initialize();
2384                 foreach(object b in a)
2385                 {
2386                         AssertEquals("#TI11",b,null);
2387                 }
2388         }
2389
2390         [Test]
2391         public void TestInitializeAClassNI()
2392         {
2393                 AClass[] a = new AClass[20];
2394                 a.Initialize();
2395                 foreach(AClass b in a)
2396                 {
2397                         AssertEquals("#TI12",b,null);
2398                 }
2399         }
2400
2401
2402         [Test]
2403         public void TestInitializeAStructNI()
2404         {
2405                 AStruct[] a = new AStruct[20];
2406                 a.Initialize();
2407                 foreach(AStruct b in a)
2408                 {
2409                         AssertEquals("#TI14",b,new AStruct());
2410                 }
2411         }
2412
2413         [Test]
2414         public void TestInitializeAStruct()
2415         {
2416                 AStruct[] a = new AStruct[3];
2417                 a[1].a = "ADIOS";
2418                 a[1].s = "HOLA";
2419                 a.Initialize();
2420                 AStruct[] b = new AStruct[3];
2421                 b[1].a = "ADIOS";
2422                 b[1].s = "HOLA";
2423                 for(int i=a.GetLowerBound(0);i<=a.GetUpperBound(0);i++)
2424                 {
2425                         AssertEquals("#TI15 " + i ,a[i],b[i]);
2426                 }
2427         }
2428
2429         [Test]
2430         public void TestInitializeDateTimeNI()
2431         {
2432                 DateTime[] a = new DateTime[20];
2433                 a.Initialize();
2434                 foreach(DateTime b in a)
2435                 {
2436                         AssertEquals("#TI16",b,new DateTime());
2437                 }
2438         }
2439         
2440         [Test]
2441         [ExpectedException (typeof (ArgumentNullException))]
2442         public void MoreSort1 ()
2443         {
2444                 Array.Sort (null, 0, 1);
2445         }
2446
2447         [Test]
2448         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2449         public void MoreSort2 ()
2450         {
2451                 Array.Sort (arrsort, -1, 3);
2452         }
2453
2454         [Test]
2455         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2456         public void MoreSort3 ()
2457         {
2458                 Array.Sort (arrsort, 1, -3);
2459         }
2460
2461         [Test]
2462         [ExpectedException (typeof (ArgumentException))]
2463         public void MoreSort4 ()
2464         {
2465                 Array.Sort (arrsort, arrsort.Length, arrsort.Length + 2);
2466         }
2467
2468         [Test]
2469         [ExpectedException (typeof (RankException))]
2470         public void MoreSort5 ()
2471         {
2472                 char [,] arr = new char [,] {{'a'}, {'b'}};
2473                 Array.Sort (arr, 0, 1);
2474         }
2475
2476         [Test]
2477         public void MoreSort6 ()
2478         {
2479                 Array.Sort (arrsort, 0, 0);
2480         }
2481
2482         [Test]
2483         [ExpectedException (typeof (ArgumentException))]
2484         public void MoreSort7 ()
2485         {
2486                 Array.Sort (arrsort, arrsort.Length - 1, 2);
2487         }
2488
2489         [Test]
2490         [ExpectedException (typeof (ArgumentException))]
2491         public void MoreSort8 ()
2492         {
2493                 Array.Sort (arrsort, 0, arrsort.Length + 1);
2494         }
2495
2496         [Test]
2497         public void MoreSort9 ()
2498         {
2499                 Array.Sort (arrsort, null, 0, arrsort.Length, null);
2500         }
2501
2502         [Test]
2503         [ExpectedException (typeof (InvalidOperationException))]
2504         public void MoreSort10 ()
2505         {
2506                 object [] array = {true, 'k', SByte.MinValue, Byte.MinValue, (short) 2, 634, (long) 436, (float) 1.1, 1.23, "Hello World"};
2507                 Array.Sort (array, (IComparer) null);
2508         }
2509
2510         [Test]
2511         public void ClearJaggedArray () 
2512         {
2513                 byte[][] matrix = new byte [8][];
2514                 for (int i=0; i < 8; i++) {
2515                         matrix [i] = new byte [8];
2516                         for (int j=0; j < 8; j++) {
2517                                 matrix [i][j] = 1;
2518                         }
2519                 }
2520                 Array.Clear (matrix, 0, 8);
2521                 for (int i=0; i < 8; i++) {
2522                         AssertNull (i.ToString (), matrix [i]);
2523                 }
2524         }
2525
2526         [Test]
2527         public void ClearMultidimentionalArray () 
2528         {
2529                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2530                 Array.Clear (matrix, 0, 2);
2531                 AssertEquals ("0,0", 0, matrix [0,0]);
2532                 AssertEquals ("0,1", 0, matrix [0,1]);
2533                 AssertEquals ("1,0", 2, matrix [1,0]);
2534                 AssertEquals ("1,1", 2, matrix [1,1]);
2535         }
2536
2537         [Test]
2538         [ExpectedException (typeof (IndexOutOfRangeException))]
2539         public void ClearOutsideMultidimentionalArray () 
2540         {
2541                 byte[,] matrix = new byte [2,2] { {1, 1}, {2, 2} };
2542                 Array.Clear (matrix, 0, 5);
2543         }
2544
2545         [Test]
2546         [ExpectedException (typeof (IndexOutOfRangeException))]
2547         public void Clear_IndexOverflow () 
2548         {
2549                 byte[] array = new byte [16];
2550                 Array.Clear (array, 4, Int32.MaxValue);
2551         }
2552
2553         [Test]
2554         [ExpectedException (typeof (IndexOutOfRangeException))]
2555         public void Clear_LengthOverflow () 
2556         {
2557                 byte[] array = new byte [16];
2558                 Array.Clear (array, Int32.MaxValue, 4);
2559         }
2560
2561         [Test]
2562         [ExpectedException (typeof (ArgumentException))]
2563         public void Copy_SourceIndexOverflow () 
2564         {
2565                 byte[] array = new byte [16];
2566                 Array.Copy (array, Int32.MaxValue, array, 8, 8);
2567         }
2568
2569         [Test]
2570         [ExpectedException (typeof (ArgumentException))]
2571         public void Copy_DestinationIndexOverflow () 
2572         {
2573                 byte[] array = new byte [16];
2574                 Array.Copy (array, 8, array, Int32.MaxValue, 8);
2575         }
2576
2577         [Test]
2578         [ExpectedException (typeof (ArgumentException))]
2579         public void Copy_LengthOverflow () 
2580         {
2581                 byte[] array = new byte [16];
2582                 Array.Copy (array, 8, array, 8, Int32.MaxValue);
2583         }
2584
2585         [Test]
2586         [ExpectedException (typeof (ArgumentException))]
2587         public void Reverse_IndexOverflow () 
2588         {
2589                 byte[] array = new byte [16];
2590                 Array.Reverse (array, Int32.MaxValue, 8);
2591         }
2592
2593         [Test]
2594         [ExpectedException (typeof (ArgumentException))]
2595         public void Reverse_LengthOverflow () 
2596         {
2597                 byte[] array = new byte [16];
2598                 Array.Reverse (array, 8, Int32.MaxValue);
2599         }
2600         
2601         public struct CharX : IComparable {
2602                 public char c;
2603         
2604                 public CharX (char c)
2605                 {
2606                         this.c = c;
2607                 }
2608         
2609                 public int CompareTo (object obj)
2610                 {
2611                         if (obj is CharX)
2612                                 return c.CompareTo (((CharX) obj).c);
2613                         else
2614                                 return c.CompareTo (obj);
2615                 }
2616         }
2617
2618         [Test]
2619         public void BinarySearch_ArgPassingOrder ()
2620         {
2621                 //
2622                 // This tests that arguments are passed to the comprer in the correct
2623                 // order. The IComparable of the *array* elements must get called, not
2624                 // that of the search object.
2625                 //
2626                 CharX [] x = { new CharX ('a'), new CharX ('b'), new CharX ('c') };
2627                 AssertEquals (1, Array.BinarySearch (x, 'b'));
2628         }
2629
2630         class Comparer: IComparer {
2631
2632                 private bool called = false;
2633
2634                 public bool Called {
2635                         get {
2636                                 bool result = called;
2637                                 called = false;
2638                                 return called;
2639                         }
2640                 }
2641
2642                 public int Compare (object x, object y)
2643                 {
2644                         called = true;
2645                         return 0;
2646                 }
2647         }
2648
2649         [Test]
2650         public void BinarySearch1_EmptyList ()
2651         {
2652                 int[] array = new int[0];
2653                 AssertEquals ("BinarySearch", - 1, Array.BinarySearch (array, 0));
2654         }
2655
2656         [Test]
2657         public void BinarySearch2_EmptyList ()
2658         {
2659                 int[] array = new int[0];
2660                 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, 0));
2661         }
2662
2663         [Test]
2664         public void BinarySearch3_EmptyList ()
2665         {
2666                 Comparer comparer = new Comparer ();
2667                 int[] array = new int[0];
2668                 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, comparer));
2669                 // bug 77030 - the comparer isn't called for an empty array/list
2670                 Assert ("Called", !comparer.Called);
2671         }
2672
2673         [Test]
2674         public void BinarySearch4_EmptyList ()
2675         {
2676                 Comparer comparer = new Comparer ();
2677                 int[] array = new int[0];
2678                 AssertEquals ("BinarySearch", -1, Array.BinarySearch (array, 0, 0, comparer));
2679                 // bug 77030 - the comparer isn't called for an empty array/list
2680                 Assert ("Called", !comparer.Called);
2681         }
2682
2683 #if NET_2_0
2684         [Test]
2685         [ExpectedException (typeof (ArgumentNullException))]
2686         public void AsReadOnly_NullArray ()
2687         {
2688                 Array.AsReadOnly <int> (null);
2689         }
2690
2691         [Test]
2692         public void ReadOnly_Count ()
2693         {
2694                 AssertEquals (10, Array.AsReadOnly (new int [10]).Count);
2695         }
2696
2697         [Test]
2698         public void ReadOnly_Contains ()
2699         {
2700                 int[] arr = new int [2];
2701                 arr [0] = 3;
2702                 arr [1] = 5;
2703                 IList<int> a = Array.AsReadOnly (arr);
2704
2705                 Assert (a.Contains (3));
2706                 Assert (!a.Contains (6));
2707         }
2708
2709         [Test]
2710         public void ReadOnly_IndexOf ()
2711         {
2712                 int[] arr = new int [2];
2713                 arr [0] = 3;
2714                 arr [1] = 5;
2715                 IList<int> a = Array.AsReadOnly (arr);
2716
2717                 AssertEquals (0, a.IndexOf (3));
2718                 AssertEquals (1, a.IndexOf (5));
2719                 AssertEquals (-1, a.IndexOf (6));
2720         }
2721
2722         [Test]
2723         public void ReadOnly_Indexer ()
2724         {
2725                 int[] arr = new int [2];
2726                 arr [0] = 3;
2727                 arr [1] = 5;
2728                 IList<int> a = Array.AsReadOnly (arr);
2729
2730                 AssertEquals (3, a [0]);
2731                 AssertEquals (5, a [1]);
2732
2733                 /* Check that modifications to the original array are visible */
2734                 arr [0] = 6;
2735                 AssertEquals (6, a [0]);
2736         }
2737
2738         [Test]
2739         public void ReadOnly_Enumerator ()
2740         {
2741                 int[] arr = new int [10];
2742
2743                 for (int i = 0; i < 10; ++i)
2744                         arr [i] = i;
2745
2746                 int sum = 0;
2747                 foreach (int i in Array.AsReadOnly (arr))
2748                         sum += i;
2749
2750                 AssertEquals (45, sum);
2751         }
2752
2753         [Test]
2754         public void Resize_null ()
2755         {
2756                 int [] arr = null;
2757                 Array.Resize (ref arr, 10);
2758                 AssertEquals (arr.Length, 10);
2759         }
2760
2761         [Test]
2762         public void Test_ContainsAndIndexOf_EquatableItem ()
2763         {
2764                 EquatableClass[] list = new EquatableClass[] {new EquatableClass (0), new EquatableClass (1), new EquatableClass (0)};
2765
2766                 AssertEquals ("#0", 0, Array.IndexOf<EquatableClass> (list, list[0]));
2767                 AssertEquals ("#1", 0, Array.IndexOf<EquatableClass> (list, new EquatableClass (0)));
2768                 AssertEquals ("#2", 2, Array.LastIndexOf<EquatableClass> (list, list[0]));
2769                 AssertEquals ("#3", 2, Array.LastIndexOf<EquatableClass> (list, new EquatableClass (0)));
2770         }
2771
2772         public class EquatableClass : IEquatable<EquatableClass>
2773         {
2774         int _x;
2775         public EquatableClass (int x)
2776         {
2777                 _x = x;
2778         }
2779
2780         public bool Equals (EquatableClass other)
2781         {
2782                 return this._x == other._x;
2783         }
2784
2785         }
2786
2787         [Test]
2788         // From bug #80563
2789         public void ICollectionNull ()
2790         {
2791                 ICollection<object> test;
2792                 
2793                 test = new List<object>();
2794                 AssertEquals ("list<o>", test.Contains (null), false);
2795
2796                 test = new object[] {};
2797                 AssertEquals ("empty array", test.Contains (null), false);
2798
2799                 test = new object[] {null};
2800                 AssertEquals ("array with null", test.Contains (null), true);
2801
2802                 test = new List<object>(test);
2803                 AssertEquals ("List<object> with test", test.Contains (null), true);
2804                 
2805                 test = new object[] {new object()};
2806                 AssertEquals ("array with object", test.Contains (null), false);
2807
2808                 test = new List<object>(test);
2809                 AssertEquals ("array with test", test.Contains (null), false);
2810         }
2811 #endif
2812
2813         #region Bug 80299
2814
2815         enum ByteEnum : byte {}
2816         enum IntEnum : int {}
2817
2818         [Test]
2819         public void TestByteEnumArrayToByteArray ()
2820         {
2821                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2822                 byte[] b = new byte[a.Length];
2823                 a.CopyTo (b, 0);
2824         }
2825
2826         [Test]
2827         public void TestByteEnumArrayToIntArray ()
2828         {
2829                 ByteEnum[] a = new ByteEnum[] {(ByteEnum) 1, (ByteEnum) 2};
2830                 int[] b = new int[a.Length];
2831                 a.CopyTo (b, 0);
2832         }
2833
2834         [Test]
2835         [ExpectedException (typeof (ArrayTypeMismatchException))]
2836         public void TestIntEnumArrayToByteArray ()
2837         {
2838                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2839                 byte[] b = new byte[a.Length];
2840                 a.CopyTo (b, 0);
2841         }
2842
2843         [Test]
2844         public void TestIntEnumArrayToIntArray ()
2845         {
2846                 IntEnum[] a = new IntEnum[] {(IntEnum) 1, (IntEnum) 2};
2847                 int[] b = new int[a.Length];
2848                 a.CopyTo (b, 0);
2849         }
2850
2851         #endregion
2852 }
2853
2854 }