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