PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/corlib/Test/System/ArrayTest.cs

https://bitbucket.org/danipen/mono
C# | 3465 lines | 3015 code | 374 blank | 76 comment | 85 complexity | a473661e89722761313731330b3b72a7 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  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. using NUnit.Framework;
  10. using System;
  11. using System.Collections;
  12. using System.Globalization;
  13. using System.Reflection;
  14. using System.Collections.Generic;
  15. namespace MonoTests.System
  16. {
  17. //Auxiliary Things
  18. enum enua {hola,adios,mas,menos};
  19. class AClass
  20. {
  21. public AClass()
  22. {
  23. }
  24. }
  25. class BClass : AClass
  26. {
  27. }
  28. class CClass : AClass
  29. {
  30. }
  31. struct AStruct
  32. {
  33. public string s;
  34. public string a;
  35. }
  36. class DataEqual
  37. {
  38. public override bool Equals (object obj)
  39. {
  40. return true;
  41. }
  42. public override int GetHashCode ()
  43. {
  44. return 0;
  45. }
  46. }
  47. //End Auxiliary Things
  48. [TestFixture]
  49. public class ArrayTest
  50. {
  51. char [] arrsort = {'d', 'b', 'f', 'e', 'a', 'c'};
  52. public ArrayTest() {}
  53. [Test]
  54. public void TestIsFixedSize() {
  55. char[] a1 = {'a'};
  56. Assert.IsTrue (a1.IsFixedSize, "All arrays are fixed");
  57. }
  58. [Test]
  59. public void TestIsReadOnly() {
  60. char[] a1 = {'a'};
  61. Assert.IsTrue (!a1.IsReadOnly, "No array is readonly");
  62. }
  63. [Test]
  64. public void TestIsSynchronized() {
  65. char[] a1 = {'a'};
  66. Assert.IsTrue (!a1.IsSynchronized, "No array is synchronized");
  67. }
  68. [Test]
  69. public void TestLength() {
  70. {
  71. char[] a1 = { };
  72. Assert.AreEqual (0, a1.Length, "Zero length array");
  73. }
  74. {
  75. char[] a1 = {'c'};
  76. Assert.AreEqual (1, a1.Length, "One-length array");
  77. }
  78. {
  79. char[] a1 = {'c', 'c'};
  80. Assert.AreEqual (2, a1.Length, "Two-length array");
  81. }
  82. }
  83. [Test]
  84. public void TestRank() {
  85. char[] a1 = { 'c', 'd', 'e' };
  86. Assert.AreEqual (1, a1.Rank, "Rank one");
  87. char[,] a2 = new Char[3,3];
  88. Assert.AreEqual (2, a2.Rank, "Rank two");
  89. char[,,] a3 = new Char[3,3,3];
  90. Assert.AreEqual (3, a3.Rank, "Rank three");
  91. }
  92. [Test]
  93. public void TestBinarySearch1() {
  94. bool errorThrown = false;
  95. try {
  96. Array.BinarySearch(null, "blue");
  97. } catch (ArgumentNullException) {
  98. errorThrown = true;
  99. }
  100. Assert.IsTrue (errorThrown, "#B01");
  101. errorThrown = false;
  102. try {
  103. char[,] c1 = new Char[2,2];
  104. Array.BinarySearch(c1, "needle");
  105. } catch (RankException) {
  106. errorThrown = true;
  107. }
  108. Assert.IsTrue (errorThrown, "#B02");
  109. {
  110. char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  111. Assert.IsTrue (Array.BinarySearch(arr, 'c') >= 3, "#B05");
  112. Assert.IsTrue (Array.BinarySearch(arr, 'c') < 6, "#B06");
  113. }
  114. {
  115. char[] arr = {'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
  116. Assert.AreEqual (-4, Array.BinarySearch(arr, 'c'), "#B07");
  117. }
  118. {
  119. char[] arr = {'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  120. Assert.AreEqual (-9, Array.BinarySearch(arr, 'e'), "#B08");
  121. }
  122. }
  123. [Test]
  124. public void TestBinarySearch2() {
  125. bool errorThrown = false;
  126. try {
  127. Array.BinarySearch(null, 0, 1, "blue");
  128. } catch (ArgumentNullException) {
  129. errorThrown = true;
  130. }
  131. Assert.IsTrue (errorThrown, "#B20");
  132. errorThrown = false;
  133. try {
  134. char[,] c1 = new Char[2,2];
  135. Array.BinarySearch(c1, 0, 1, "needle");
  136. } catch (RankException) {
  137. errorThrown = true;
  138. }
  139. Assert.IsTrue (errorThrown, "#B21");
  140. errorThrown = false;
  141. try {
  142. char[] c1 = {'a'};
  143. Array.BinarySearch(c1, -1, 1, 'a');
  144. } catch (ArgumentOutOfRangeException) {
  145. errorThrown = true;
  146. }
  147. Assert.IsTrue (errorThrown, "#B22");
  148. errorThrown = false;
  149. try {
  150. char[] c1 = {'a'};
  151. Array.BinarySearch(c1, 0, -1, 'a');
  152. } catch (ArgumentOutOfRangeException) {
  153. errorThrown = true;
  154. }
  155. Assert.IsTrue (errorThrown, "#B23");
  156. errorThrown = false;
  157. try {
  158. char[] c1 = {'a'};
  159. Array.BinarySearch(c1, 0, 4, 'a');
  160. } catch (ArgumentException) {
  161. errorThrown = true;
  162. }
  163. Assert.IsTrue (errorThrown, "#B24");
  164. {
  165. char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  166. Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') >= 5, "#B26");
  167. Assert.IsTrue (Array.BinarySearch(arr, 2, 8, 'c') < 8, "#B27");
  168. }
  169. {
  170. char[] arr = {'z', 'z', 'a', 'b', 'b', 'd', 'd', 'd', 'e', 'e'};
  171. Assert.AreEqual (-6, Array.BinarySearch(arr, 2, 8, 'c'), "#B28");
  172. }
  173. {
  174. char[] arr = {'z', 'z', 'a', 'b', 'b', 'c', 'c', 'c', 'd', 'd'};
  175. Assert.AreEqual (-11, Array.BinarySearch(arr, 2, 8, 'e'), "#B29");
  176. }
  177. }
  178. public void TestBinarySearch3()
  179. {
  180. int[] array = new int[100];
  181. for (int i = 0; i < 100; i++)
  182. array[i] = 10;
  183. Assert.AreEqual (49, Array.BinarySearch(array, 10), "#B30");
  184. }
  185. [Test]
  186. public void BinarySearch_NullValue ()
  187. {
  188. int[] array = new int[1];
  189. Assert.AreEqual (-1, Array.BinarySearch (array, null), "I=a,o");
  190. Assert.AreEqual (-1, Array.BinarySearch (array, null, null), "I=a,o,c");
  191. Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null), "I=a,i,i,o");
  192. Assert.AreEqual (-1, Array.BinarySearch (array, 0, 1, null, null), "I=a,i,i,o,c");
  193. object[] o = new object [3] { this, this, null };
  194. Assert.AreEqual (-1, Array.BinarySearch (o, null), "O=a,o");
  195. Assert.AreEqual (-1, Array.BinarySearch (o, null, null), "O=a,o,c");
  196. Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null), "O=a,i,i,o");
  197. Assert.AreEqual (-1, Array.BinarySearch (o, 0, 3, null, null), "O=a,i,i,o,c");
  198. }
  199. class TestComparer7 : IComparer<int>
  200. {
  201. public int Compare (int x, int y)
  202. {
  203. if (y != 7)
  204. throw new ApplicationException ();
  205. return x.CompareTo (y);
  206. }
  207. }
  208. [Test]
  209. public void BinarySearch_WithComparer ()
  210. {
  211. var a = new int[] { 2, 6, 9 };
  212. Assert.AreEqual (-3, Array.BinarySearch (a, 7, new TestComparer7 ()));
  213. }
  214. [Test]
  215. public void TestClear() {
  216. bool errorThrown = false;
  217. try {
  218. Array.Clear(null, 0, 1);
  219. } catch (ArgumentNullException) {
  220. errorThrown = true;
  221. }
  222. Assert.IsTrue (errorThrown, "#C01");
  223. int[] i1 = { 1, 2, 3, 4 };
  224. {
  225. int[] compare = {1,2,3,4};
  226. Assert.AreEqual (compare[0], i1[0], "#C02");
  227. Assert.AreEqual (compare[1], i1[1], "#C03");
  228. Assert.AreEqual (compare[2], i1[2], "#C04");
  229. Assert.AreEqual (compare[3], i1[3], "#C05");
  230. }
  231. Array.Clear(i1, 3, 1);
  232. {
  233. int[] compare = {1,2,3,0};
  234. Assert.AreEqual (compare[0], i1[0], "#C06");
  235. Assert.AreEqual (compare[1], i1[1], "#C07");
  236. Assert.AreEqual (compare[2], i1[2], "#C08");
  237. Assert.AreEqual (compare[3], i1[3], "#C09");
  238. }
  239. Array.Clear(i1, 1, 1);
  240. {
  241. int[] compare = {1,0,3,0};
  242. Assert.AreEqual (compare[0], i1[0], "#C10");
  243. Assert.AreEqual (compare[1], i1[1], "#C11");
  244. Assert.AreEqual (compare[2], i1[2], "#C12");
  245. Assert.AreEqual (compare[3], i1[3], "#C13");
  246. }
  247. Array.Clear(i1, 1, 3);
  248. {
  249. int[] compare = {1,0,0,0};
  250. Assert.AreEqual (compare[0], i1[0], "#C14");
  251. Assert.AreEqual (compare[1], i1[1], "#C15");
  252. Assert.AreEqual (compare[2], i1[2], "#C16");
  253. Assert.AreEqual (compare[3], i1[3], "#C17");
  254. }
  255. string[] s1 = { "red", "green", "blue" };
  256. Array.Clear(s1, 0, 3);
  257. {
  258. string[] compare = {null, null, null};
  259. Assert.AreEqual (compare[0], s1[0], "#C18");
  260. Assert.AreEqual (compare[1], s1[1], "#C19");
  261. Assert.AreEqual (compare[2], s1[2], "#C20");
  262. }
  263. }
  264. [Test]
  265. public void TestClone() {
  266. char[] c1 = {'a', 'b', 'c'};
  267. char[] c2 = (char[])c1.Clone();
  268. Assert.AreEqual (c1[0], c2[0], "#D01");
  269. Assert.AreEqual (c1[1], c2[1], "#D02");
  270. Assert.AreEqual (c1[2], c2[2], "#D03");
  271. char[] d10 = {'a', 'b'};
  272. char[] d11 = {'a', 'c'};
  273. char[] d12 = {'b', 'c'};
  274. char[][] d1 = {d10, d11, d12};
  275. char[][] d2 = (char[][])d1.Clone();
  276. Assert.AreEqual (d1[0], d2[0], "#D04");
  277. Assert.AreEqual (d1[1], d2[1], "#D05");
  278. Assert.AreEqual (d1[2], d2[2], "#D06");
  279. d1[0][0] = 'z';
  280. Assert.AreEqual (d1[0], d2[0], "#D07");
  281. }
  282. [Test]
  283. public void TestMemberwiseClone () {
  284. int[] array = new int[] { 1, 2, 3 };
  285. MethodBase mi = array.GetType ().GetMethod("MemberwiseClone",
  286. BindingFlags.Instance | BindingFlags.NonPublic);
  287. int[] res = (int[])mi.Invoke (array, null);
  288. Assert.AreEqual (3, res.Length);
  289. }
  290. [Test] public void TestIndexer ()
  291. {
  292. int [] a = new int [10];
  293. IList b = a;
  294. try {
  295. object c = b [-1];
  296. Assert.Fail ("IList.this [-1] should throw");
  297. } catch (IndexOutOfRangeException) {
  298. // Good
  299. } catch (Exception){
  300. Assert.Fail ("Should have thrown an IndexOutOfRangeException");
  301. }
  302. }
  303. [Test]
  304. public void TestCopy() {
  305. {
  306. bool errorThrown = false;
  307. try {
  308. Char[] c1 = {};
  309. Array.Copy(c1, null, 1);
  310. } catch (ArgumentNullException) {
  311. errorThrown = true;
  312. }
  313. Assert.IsTrue (errorThrown, "#E01");
  314. }
  315. {
  316. bool errorThrown = false;
  317. try {
  318. Char[] c1 = {};
  319. Array.Copy(null, c1, 1);
  320. } catch (ArgumentNullException) {
  321. errorThrown = true;
  322. }
  323. Assert.IsTrue (errorThrown, "#E02");
  324. }
  325. {
  326. bool errorThrown = false;
  327. try {
  328. Char[] c1 = new Char[1];
  329. Char[,] c2 = new Char[1,1];
  330. Array.Copy(c1, c2, 1);
  331. } catch (RankException) {
  332. errorThrown = true;
  333. }
  334. Assert.IsTrue (errorThrown, "#E03");
  335. }
  336. {
  337. bool errorThrown = false;
  338. try {
  339. Char[] c1 = new Char[1];
  340. string[] s1 = new String[1];
  341. Array.Copy(c1, s1, 1);
  342. } catch (ArrayTypeMismatchException) {
  343. errorThrown = true;
  344. }
  345. Assert.IsTrue (errorThrown, "#E04");
  346. }
  347. {
  348. bool errorThrown = false;
  349. try {
  350. Char[] c1 = new Char[1];
  351. Object[] o1 = new Object[1];
  352. o1[0] = "hello";
  353. Array.Copy(o1, c1, 1);
  354. } catch (InvalidCastException) {
  355. errorThrown = true;
  356. }
  357. Assert.IsTrue (errorThrown, "#E05");
  358. }
  359. {
  360. bool errorThrown = false;
  361. try {
  362. Char[] c1 = new Char[1];
  363. Char[] c2 = new Char[1];
  364. Array.Copy(c1, c2, -1);
  365. } catch (ArgumentOutOfRangeException) {
  366. errorThrown = true;
  367. }
  368. Assert.IsTrue (errorThrown, "#E06");
  369. }
  370. {
  371. bool errorThrown = false;
  372. try {
  373. Char[] c1 = new Char[1];
  374. Char[] c2 = new Char[2];
  375. Array.Copy(c1, c2, 2);
  376. } catch (ArgumentException) {
  377. errorThrown = true;
  378. }
  379. Assert.IsTrue (errorThrown, "#E07");
  380. }
  381. {
  382. bool errorThrown = false;
  383. try {
  384. Char[] c1 = new Char[1];
  385. Char[] c2 = new Char[2];
  386. Array.Copy(c2, c1, 2);
  387. } catch (ArgumentException) {
  388. errorThrown = true;
  389. }
  390. Assert.IsTrue (errorThrown, "#E08");
  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. Assert.AreEqual (orig[i], copy[i], "#E09(" + i + ")");
  397. }
  398. Array.Clear(copy, 0, copy.Length);
  399. for (int i = 0; i < orig.Length; i++) {
  400. Assert.AreEqual ((char)0, copy[i], "#E10(" + i + ")");
  401. }
  402. Array.Copy(orig, copy, 2);
  403. Assert.AreEqual (orig[0], copy[0], "#E11");
  404. Assert.AreEqual (orig[1], copy[1], "#E12");
  405. Assert.IsTrue (orig[2] != copy[2], "#E13");
  406. Assert.IsTrue (orig[3] != copy[3], "#E14");
  407. }
  408. [Test]
  409. public void TestCopy2() {
  410. {
  411. bool errorThrown = false;
  412. try {
  413. Char[] c1 = new Char[2];
  414. Char[] c2 = new Char[2];
  415. Array.Copy(c2, 1, c1, 0, 2);
  416. } catch (ArgumentException) {
  417. errorThrown = true;
  418. }
  419. Assert.IsTrue (errorThrown, "#E31");
  420. }
  421. {
  422. bool errorThrown = false;
  423. try {
  424. Char[] c1 = new Char[2];
  425. Char[] c2 = new Char[2];
  426. Array.Copy(c2, 0, c1, 1, 2);
  427. } catch (ArgumentException) {
  428. errorThrown = true;
  429. }
  430. Assert.IsTrue (errorThrown, "#E32");
  431. }
  432. char[] orig = {'a', 'b', 'd', 'a'};
  433. char[] copy = new Char[4];
  434. Array.Copy(orig, 1, copy, 1, 3);
  435. Assert.IsTrue (copy[0] != orig[0], "#E33");
  436. for (int i = 1; i < orig.Length; i++) {
  437. Assert.AreEqual (orig[i], copy[i], "#E34(" + i + ")");
  438. }
  439. Array.Clear(copy, 0, copy.Length);
  440. Array.Copy(orig, 1, copy, 0, 2);
  441. Assert.AreEqual (orig[1], copy[0], "#E35");
  442. Assert.AreEqual (orig[2], copy[1], "#E36");
  443. Assert.IsTrue (copy[2] != orig[2], "#E37");
  444. Assert.IsTrue (copy[3] != orig[3], "#E38");
  445. }
  446. [Test]
  447. [ExpectedException (typeof (InvalidCastException))]
  448. public void Copy_InvalidCast () {
  449. object[] arr1 = new object [10];
  450. Type[] arr2 = new Type [10];
  451. arr1 [0] = new object ();
  452. Array.Copy (arr1, 0, arr2, 0, 10);
  453. }
  454. [Test]
  455. public void TestCopyTo() {
  456. {
  457. bool errorThrown = false;
  458. try {
  459. Char[] c1 = new Char[2];
  460. c1.CopyTo(null, 2);
  461. } catch (ArgumentNullException) {
  462. errorThrown = true;
  463. }
  464. Assert.IsTrue (errorThrown, "#E61");
  465. }
  466. {
  467. bool errorThrown = false;
  468. try {
  469. Char[] c1 = new Char[2];
  470. Char[,] c2 = new Char[2,2];
  471. c1.CopyTo(c2, 2);
  472. } catch (ArgumentException) {
  473. errorThrown = true;
  474. }
  475. #if TARGET_JVM // This is really implementation dependent behaviour.
  476. catch (RankException) {
  477. errorThrown = true;
  478. }
  479. #endif // TARGET_JVM
  480. Assert.IsTrue (errorThrown, "#E62");
  481. }
  482. {
  483. bool errorThrown = false;
  484. try {
  485. Char[,] c1 = new Char[2,2];
  486. Char[] c2 = new Char[2];
  487. c1.CopyTo(c2, -1);
  488. } catch (RankException) {
  489. errorThrown = true;
  490. }
  491. Assert.IsTrue (errorThrown, "#E63");
  492. }
  493. {
  494. bool errorThrown = false;
  495. try {
  496. Char[,] c1 = new Char[2,2];
  497. Char[] c2 = new Char[2];
  498. c1.CopyTo(c2, 2);
  499. } catch (RankException) {
  500. errorThrown = true;
  501. }
  502. Assert.IsTrue (errorThrown, "#E64");
  503. }
  504. {
  505. bool errorThrown = false;
  506. try {
  507. Char[] c1 = new Char[2];
  508. Char[] c2 = new Char[2];
  509. c1.CopyTo(c2, -1);
  510. } catch (ArgumentOutOfRangeException) {
  511. errorThrown = true;
  512. }
  513. Assert.IsTrue (errorThrown, "#E65");
  514. }
  515. {
  516. bool errorThrown = false;
  517. try {
  518. Char[] c1 = new Char[2];
  519. Char[] c2 = new Char[2];
  520. c1.CopyTo(c2, 3);
  521. } catch (ArgumentException) {
  522. errorThrown = true;
  523. }
  524. Assert.IsTrue (errorThrown, "#E66");
  525. }
  526. {
  527. bool errorThrown = false;
  528. try {
  529. Char[] c1 = new Char[2];
  530. Char[] c2 = new Char[2];
  531. c1.CopyTo(c2, 1);
  532. } catch (ArgumentException) {
  533. errorThrown = true;
  534. }
  535. Assert.IsTrue (errorThrown, "#E67");
  536. }
  537. {
  538. bool errorThrown = false;
  539. try {
  540. String[] c1 = new String[2];
  541. // TODO: this crashes mono if there are null
  542. // values in the array.
  543. c1[1] = "hey";
  544. c1[0] = "you";
  545. Char[] c2 = new Char[2];
  546. c2[1] = 'a';
  547. c2[0] = 'z';
  548. c1.CopyTo(c2, 0);
  549. } catch (ArrayTypeMismatchException) {
  550. errorThrown = true;
  551. }
  552. Assert.IsTrue (errorThrown, "#E68");
  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. Assert.AreEqual ((char)0, copy[0], "#E69");
  559. Assert.AreEqual ((char)0, copy[1], "#E70");
  560. Assert.AreEqual ((char)0, copy[2], "#E71");
  561. Assert.AreEqual (orig[0], copy[3], "#E72");
  562. Assert.AreEqual (orig[1], copy[4], "#E73");
  563. Assert.AreEqual (orig[2], copy[5], "#E74");
  564. Assert.AreEqual (orig[3], copy[6], "#E75");
  565. Assert.AreEqual ((char)0, copy[7], "#E76");
  566. Assert.AreEqual ((char)0, copy[8], "#E77");
  567. Assert.AreEqual ((char)0, copy[9], "#E78");
  568. {
  569. // The following is valid and must not throw an exception.
  570. bool errorThrown = false;
  571. try {
  572. int[] src = new int [0];
  573. int[] dest = new int [0];
  574. src.CopyTo (dest, 0);
  575. } catch (ArgumentException) {
  576. errorThrown = true;
  577. }
  578. Assert.IsTrue (!errorThrown, "#E79");
  579. }
  580. {
  581. // bug #38812
  582. bool errorThrown = false;
  583. try {
  584. CClass[] src = new CClass [] { new CClass () };
  585. BClass[] dest = new BClass [1];
  586. src.CopyTo (dest, 0);
  587. } catch (ArrayTypeMismatchException) {
  588. errorThrown = true;
  589. }
  590. Assert.IsTrue (errorThrown, "#E80");
  591. }
  592. }
  593. [Test]
  594. public void TestCreateInstance() {
  595. {
  596. bool errorThrown = false;
  597. try {
  598. Array.CreateInstance(null, 12);
  599. } catch (ArgumentNullException) {
  600. errorThrown = true;
  601. }
  602. Assert.IsTrue (errorThrown, "#F01");
  603. }
  604. {
  605. bool errorThrown = false;
  606. try {
  607. Array.CreateInstance(Type.GetType("System.Char"), -3);
  608. } catch (ArgumentOutOfRangeException) {
  609. errorThrown = true;
  610. }
  611. Assert.IsTrue (errorThrown, "#F02");
  612. }
  613. {
  614. bool errorThrown = false;
  615. try {
  616. Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
  617. } catch (ArgumentNullException) {
  618. errorThrown = true;
  619. }
  620. Assert.IsTrue (errorThrown, "#F03a");
  621. }
  622. {
  623. bool errorThrown = false;
  624. try {
  625. Array.CreateInstance(Type.GetType("System.Char"), (int [])null);
  626. } catch (ArgumentNullException) {
  627. errorThrown = true;
  628. }
  629. Assert.IsTrue (errorThrown, "#F03b");
  630. }
  631. #if !TARGET_JVM // Arrays lower bounds are not supported for TARGET_JVM
  632. {
  633. bool errorThrown = false;
  634. try {
  635. Array.CreateInstance(Type.GetType("System.Char"), null, null);
  636. } catch (ArgumentNullException) {
  637. errorThrown = true;
  638. }
  639. Assert.IsTrue (errorThrown, "#F04");
  640. }
  641. #endif // TARGET_JVM
  642. {
  643. bool errorThrown = false;
  644. try {
  645. int[] lengths = new int [0];
  646. Array.CreateInstance(Type.GetType("System.Char"), lengths);
  647. } catch (ArgumentException) {
  648. errorThrown = true;
  649. }
  650. Assert.IsTrue (errorThrown, "#F05");
  651. }
  652. #if !TARGET_JVM // CreateInstance with lower bounds not supported for TARGET_JVM
  653. {
  654. bool errorThrown = false;
  655. try {
  656. int[] lengths = new int [1];
  657. int[] bounds = new int [2];
  658. Array.CreateInstance(Type.GetType("System.Char"), lengths, bounds);
  659. errorThrown = true;
  660. } catch (ArgumentException) {
  661. errorThrown = true;
  662. }
  663. Assert.IsTrue (errorThrown, "#F06");
  664. }
  665. char[] c1 = (char[])Array.CreateInstance(Type.GetType("System.Char"), 12);
  666. Assert.AreEqual (12, c1.Length, "#F07");
  667. Array c2 = Array.CreateInstance(Type.GetType("System.Char"), 12, 5);
  668. Assert.AreEqual (2, c2.Rank, "#F08");
  669. Assert.AreEqual (60, c2.Length, "#F09");
  670. {
  671. int[] lengths = { 3 };
  672. int[] bounds = { 5 };
  673. int[] src = { 512, 718, 912 };
  674. Array array = Array.CreateInstance(typeof(int), lengths, bounds);
  675. Assert.AreEqual (3, array.Length, "#F10");
  676. Assert.AreEqual (5, array.GetLowerBound(0), "#F11");
  677. Assert.AreEqual (7, array.GetUpperBound(0), "#F12");
  678. src.CopyTo (array, 5);
  679. for (int i = 0; i < src.Length; i++)
  680. Assert.AreEqual (src[i], array.GetValue(i+5), "#F13(" + i + ")");
  681. }
  682. // Test that a 1 dimensional array with 0 lower bound is the
  683. // same as an szarray
  684. Type szarrayType = new int [10].GetType ();
  685. Assert.IsTrue (szarrayType == (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0})).GetType ());
  686. Assert.IsTrue (szarrayType != (Array.CreateInstance (typeof (int), new int[] {1}, new int[] {1})).GetType ());
  687. #endif // TARGET_JVM
  688. }
  689. [Test]
  690. [ExpectedException (typeof (ArgumentNullException))]
  691. public void TestCreateInstance2 ()
  692. {
  693. Array.CreateInstance (typeof (Int32), (int[])null);
  694. }
  695. [Test]
  696. [ExpectedException (typeof (ArgumentNullException))]
  697. public void TestCreateInstance2b ()
  698. {
  699. Array.CreateInstance (typeof (Int32), (long[])null);
  700. }
  701. [Test]
  702. public void TestGetEnumerator() {
  703. String[] s1 = {"this", "is", "a", "test"};
  704. IEnumerator en = s1.GetEnumerator ();
  705. Assert.IsNotNull (en, "#G01");
  706. Assert.IsTrue (en.MoveNext (), "#G02");
  707. Assert.AreEqual ("this", en.Current, "#G03");
  708. Assert.IsTrue (en.MoveNext (), "#G04");
  709. Assert.AreEqual ("is", en.Current, "#G05");
  710. Assert.IsTrue (en.MoveNext (), "#G06");
  711. Assert.AreEqual ("a", en.Current, "#G07");
  712. Assert.IsTrue (en.MoveNext (), "#G08");
  713. Assert.AreEqual ("test", en.Current, "#G09");
  714. Assert.IsTrue (!en.MoveNext (), "#G10");
  715. en.Reset ();
  716. Assert.IsTrue (en.MoveNext (), "#G11");
  717. Assert.AreEqual ("this", en.Current, "#G12");
  718. // mutation does not invalidate array enumerator!
  719. s1.SetValue ("change", 1);
  720. Assert.IsTrue (en.MoveNext (), "#G13");
  721. Assert.AreEqual ("change", en.Current, "#G14");
  722. }
  723. [Test]
  724. public void TestGetEnumeratorMultipleDimension() {
  725. String[,] s1 = {{"this", "is"}, {"a", "test"}};
  726. IEnumerator en = s1.GetEnumerator ();
  727. Assert.IsNotNull (en, "#AA01");
  728. Assert.IsTrue (en.MoveNext (), "#AA02");
  729. Assert.AreEqual ("this", en.Current, "#AA03");
  730. Assert.IsTrue (en.MoveNext (), "#AA04");
  731. Assert.AreEqual ("is", en.Current, "#AA05");
  732. Assert.IsTrue (en.MoveNext (), "#AA06");
  733. Assert.AreEqual ("a", en.Current, "#AA07");
  734. Assert.IsTrue (en.MoveNext (), "#AA08");
  735. Assert.AreEqual ("test", en.Current, "#AA09");
  736. Assert.IsTrue (!en.MoveNext (), "#AA10");
  737. en.Reset ();
  738. Assert.IsTrue (en.MoveNext (), "#AA11");
  739. Assert.AreEqual ("this", en.Current, "#AA12");
  740. int[] idxs = {0,1};
  741. // mutation does not invalidate array enumerator!
  742. s1.SetValue ("change", idxs);
  743. Assert.IsTrue (en.MoveNext (), "#AA13");
  744. Assert.AreEqual ("change", en.Current, "#AA14");
  745. }
  746. [Test]
  747. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  748. public void TestGetEnumeratorNonZeroLowerBounds() {
  749. int[] myLengthsArray = new int[2] { 3, 5 };
  750. int[] myBoundsArray = new int[2] { 2, 3 };
  751. Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray );
  752. for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
  753. for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ ) {
  754. int[] myIndicesArray = new int[2] { i, j };
  755. myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
  756. }
  757. IEnumerator en = myArray.GetEnumerator ();
  758. Assert.IsNotNull (en, "#AB01");
  759. // check the first couple of values
  760. Assert.IsTrue (en.MoveNext (), "#AB02");
  761. Assert.AreEqual ("23", en.Current, "#AB03");
  762. Assert.IsTrue (en.MoveNext (), "#AB04");
  763. Assert.AreEqual ("24", en.Current, "#AB05");
  764. // then check the last element's value
  765. string lastElement;
  766. do {
  767. lastElement = (string)en.Current;
  768. } while (en.MoveNext());
  769. Assert.AreEqual ("47", lastElement, "#AB06");
  770. }
  771. [Test]
  772. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  773. public void TestIList_Add () {
  774. int[] myLengthsArray = new int[2] { 3, 5 };
  775. int[] myBoundsArray = new int[2] { 2, 3 };
  776. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  777. try {
  778. ((IList)myArray).Add ("can not");
  779. Assert.Fail ("IList.Add should throw");
  780. }
  781. catch (NotSupportedException) {
  782. return;
  783. }
  784. catch (Exception) {
  785. Assert.Fail ("IList.Add threw wrong exception type");
  786. }
  787. Assert.Fail ("IList.Add shouldn't get this far");
  788. }
  789. [Test]
  790. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  791. public void TestIList_Insert () {
  792. int[] myLengthsArray = new int[2] { 3, 5 };
  793. int[] myBoundsArray = new int[2] { 2, 3 };
  794. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  795. try {
  796. ((IList)myArray).Insert (0, "can not");
  797. Assert.Fail ("IList.Insert should throw");
  798. }
  799. catch (NotSupportedException) {
  800. return;
  801. }
  802. catch (Exception) {
  803. Assert.Fail ("IList.Insert threw wrong exception type");
  804. }
  805. Assert.Fail ("IList.Insert shouldn't get this far");
  806. }
  807. [Test]
  808. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  809. public void TestIList_Remove () {
  810. int[] myLengthsArray = new int[2] { 3, 5 };
  811. int[] myBoundsArray = new int[2] { 2, 3 };
  812. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  813. try {
  814. ((IList)myArray).Remove ("can not");
  815. Assert.Fail ("IList.Remove should throw");
  816. }
  817. catch (NotSupportedException) {
  818. return;
  819. }
  820. catch (Exception) {
  821. Assert.Fail ("IList.Remove threw wrong exception type");
  822. }
  823. Assert.Fail ("IList.Remove shouldn't get this far");
  824. }
  825. [Test]
  826. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  827. public void TestIList_RemoveAt () {
  828. int[] myLengthsArray = new int[2] { 3, 5 };
  829. int[] myBoundsArray = new int[2] { 2, 3 };
  830. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  831. try {
  832. ((IList)myArray).RemoveAt (0);
  833. Assert.Fail ("IList.RemoveAt should throw");
  834. }
  835. catch (NotSupportedException) {
  836. return;
  837. }
  838. catch (Exception) {
  839. Assert.Fail ("IList.RemoveAt threw wrong exception type");
  840. }
  841. Assert.Fail ("IList.RemoveAt shouldn't get this far");
  842. }
  843. [Test]
  844. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  845. public void TestIList_Contains () {
  846. int[] myLengthsArray = new int[2] { 3, 5 };
  847. int[] myBoundsArray = new int[2] { 2, 3 };
  848. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  849. try {
  850. bool b = ((IList)myArray).Contains ("23");
  851. Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
  852. }
  853. catch (RankException) {
  854. int[] iArr = new int[3] { 1, 2, 3};
  855. // check the first and last items
  856. Assert.IsTrue (((IList)iArr).Contains (1), "AC01");
  857. Assert.IsTrue (((IList)iArr).Contains (3), "AC02");
  858. // and one that is definately not there
  859. Assert.IsTrue (!((IList)iArr).Contains (42), "AC03");
  860. return;
  861. }
  862. Assert.Fail ("Should not get here");
  863. }
  864. [Test]
  865. [Category ("TargetJvmNotSupported")] // Arrays lower bounds are not supported for TARGET_JVM
  866. public void TestIList_IndexOf () {
  867. int[] myLengthsArray = new int[2] { 3, 5 };
  868. int[] myBoundsArray = new int[2] { 2, 3 };
  869. Array myArray=Array.CreateInstance ( typeof(String), myLengthsArray, myBoundsArray );
  870. try {
  871. bool b = ((IList)myArray).Contains ("23");
  872. Assert.Fail ("IList.Contains should throw with multi-dimensional arrays");
  873. }
  874. catch (RankException) {
  875. int[] iArr = new int[3] { 1, 2, 3};
  876. // check the first and last items
  877. Assert.AreEqual (0, ((IList)iArr).IndexOf (1), "AD01");
  878. Assert.AreEqual (2, ((IList)iArr).IndexOf (3), "AD02");
  879. // and one that is definately not there
  880. Assert.AreEqual (-1, ((IList)iArr).IndexOf (42), "AD03");
  881. }
  882. catch (Exception e) {
  883. Assert.Fail ("Unexpected exception: " + e.ToString());
  884. }
  885. // check that wierd case whem lowerbound is Int32.MinValue,
  886. // so that IndexOf() needs to return Int32.MaxValue when it cannot find the object
  887. int[] myLengthArray = new int[1] { 3 };
  888. int[] myBoundArray = new int[1] { Int32.MinValue };
  889. Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
  890. Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
  891. }
  892. [Test]
  893. public void TestGetLength() {
  894. {
  895. bool errorThrown = false;
  896. try {
  897. char[] c1 = {'a', 'b', 'c'};
  898. c1.GetLength(-1);
  899. } catch (IndexOutOfRangeException) {
  900. errorThrown = true;
  901. }
  902. Assert.IsTrue (errorThrown, "#H01");
  903. }
  904. {
  905. bool errorThrown = false;
  906. try {
  907. char[] c1 = {'a', 'b', 'c'};
  908. c1.GetLength(1);
  909. } catch (IndexOutOfRangeException) {
  910. errorThrown = true;
  911. }
  912. Assert.IsTrue (errorThrown, "#H02");
  913. }
  914. char[] c2 = new Char[5];
  915. Assert.AreEqual (5, c2.GetLength(0), "#H03");
  916. char[,] c3 = new Char[6,7];
  917. Assert.AreEqual (6, c3.GetLength(0), "#H04");
  918. Assert.AreEqual (7, c3.GetLength(1), "#H05");
  919. }
  920. [Test]
  921. public void TestGetLowerBound() {
  922. {
  923. bool errorThrown = false;
  924. try {
  925. char[] c = {'a', 'b', 'c'};
  926. c.GetLowerBound(-1);
  927. } catch (IndexOutOfRangeException) {
  928. errorThrown = true;
  929. }
  930. Assert.IsTrue (errorThrown, "#H31");
  931. }
  932. {
  933. bool errorThrown = false;
  934. try {
  935. char[] c = {'a', 'b', 'c'};
  936. c.GetLowerBound(1);
  937. } catch (IndexOutOfRangeException) {
  938. errorThrown = true;
  939. }
  940. Assert.IsTrue (errorThrown, "#H32");
  941. }
  942. char[] c1 = new Char[5];
  943. Assert.AreEqual (0, c1.GetLowerBound(0), "#H33");
  944. char[,] c2 = new Char[4,4];
  945. Assert.AreEqual (0, c2.GetLowerBound(0), "#H34");
  946. Assert.AreEqual (0, c2.GetLowerBound(1), "#H35");
  947. }
  948. [Test]
  949. public void TestGetUpperBound() {
  950. {
  951. bool errorThrown = false;
  952. try {
  953. char[] c = {'a', 'b', 'c'};
  954. c.GetUpperBound(-1);
  955. } catch (IndexOutOfRangeException) {
  956. errorThrown = true;
  957. }
  958. Assert.IsTrue (errorThrown, "#H61");
  959. }
  960. {
  961. bool errorThrown = false;
  962. try {
  963. char[] c = {'a', 'b', 'c'};
  964. c.GetUpperBound(1);
  965. } catch (IndexOutOfRangeException) {
  966. errorThrown = true;
  967. }
  968. Assert.IsTrue (errorThrown, "#H62");
  969. }
  970. char[] c1 = new Char[5];
  971. Assert.AreEqual (4, c1.GetUpperBound(0), "#H63");
  972. char[,] c2 = new Char[4,6];
  973. Assert.AreEqual (3, c2.GetUpperBound(0), "#H64");
  974. Assert.AreEqual (5, c2.GetUpperBound(1), "#H65");
  975. }
  976. [Test]
  977. public void TestGetValue1() {
  978. {
  979. bool errorThrown = false;
  980. try {
  981. char[,] c = new Char[2,2];
  982. c.GetValue(1);
  983. } catch (ArgumentException) {
  984. errorThrown = true;
  985. }
  986. Assert.IsTrue (errorThrown, "#I01");
  987. }
  988. {
  989. bool errorThrown = false;
  990. try {
  991. char[] c = {'a', 'b', 'c'};
  992. c.GetValue(-1);
  993. } catch (IndexOutOfRangeException) {
  994. errorThrown = true;
  995. }
  996. Assert.IsTrue (errorThrown, "#I02");
  997. }
  998. {
  999. bool errorThrown = false;
  1000. try {
  1001. char[] c = {'a', 'b', 'c'};
  1002. c.GetValue(4);
  1003. } catch (IndexOutOfRangeException) {
  1004. errorThrown = true;
  1005. }
  1006. Assert.IsTrue (errorThrown, "#I03");
  1007. }
  1008. char[] c1 = {'a', 'b', 'c', 'd'};
  1009. for (int i = 0; i < c1.Length; i++) {
  1010. Assert.AreEqual (c1[i], c1.GetValue(i), "#I04(" + i + ")");
  1011. }
  1012. }
  1013. [Test]
  1014. public void TestGetValue2() {
  1015. {
  1016. bool errorThrown = false;
  1017. try {
  1018. char[] c = new Char[2];
  1019. c.GetValue(1,1);
  1020. } catch (ArgumentException) {
  1021. errorThrown = true;
  1022. }
  1023. Assert.IsTrue (errorThrown, "#I21");
  1024. }
  1025. {
  1026. bool errorThrown = false;
  1027. try {
  1028. char[,] c = new Char[2,2];
  1029. c.GetValue(-1, 1);
  1030. } catch (IndexOutOfRangeException) {
  1031. errorThrown = true;
  1032. }
  1033. Assert.IsTrue (errorThrown, "#I22");
  1034. }
  1035. {
  1036. bool errorThrown = false;
  1037. try {
  1038. char[,] c = new Char[2,2];
  1039. c.GetValue(4,1);
  1040. } catch (IndexOutOfRangeException) {
  1041. errorThrown = true;
  1042. }
  1043. Assert.IsTrue (errorThrown, "#I23");
  1044. }
  1045. char[,] c1 = new Char[4,6];
  1046. for (int i = 0; i < 24; i++) {
  1047. int first = i / 6;
  1048. int second = i % 6;
  1049. c1[first,second] = (char)(((int)'a')+i);
  1050. }
  1051. for (int i = 0; i < c1.GetLength(0); i++) {
  1052. for (int j = 0; j < c1.GetLength(1); j++) {
  1053. Assert.AreEqual (c1[i, j], c1.GetValue(i, j), "#I24(" + i + "," + j + ")");
  1054. }
  1055. }
  1056. }
  1057. [Test]
  1058. public void TestGetValue3() {
  1059. {
  1060. bool errorThrown = false;
  1061. try {
  1062. char[] c = new Char[2];
  1063. c.GetValue(1,1,1);
  1064. } catch (ArgumentException) {
  1065. errorThrown = true;
  1066. }
  1067. Assert.IsTrue (errorThrown, "#I41");
  1068. }
  1069. {
  1070. bool errorThrown = false;
  1071. try {
  1072. char[,,] c = new Char[2,2,2];
  1073. c.GetValue(-1, 1, 1);
  1074. } catch (IndexOutOfRangeException) {
  1075. errorThrown = true;
  1076. }
  1077. Assert.IsTrue (errorThrown, "#I42");
  1078. }
  1079. {
  1080. bool errorThrown = false;
  1081. try {
  1082. char[,,] c = new Char[2,2,2];
  1083. c.GetValue(4,1,1);
  1084. } catch (IndexOutOfRangeException) {
  1085. errorThrown = true;
  1086. }
  1087. Assert.IsTrue (errorThrown, "#I43");
  1088. }
  1089. char[,,] c1 = new Char[4,2,3];
  1090. for (int i = 0; i < 24; i++) {
  1091. int first = i / 6;
  1092. int remains = i % 6;
  1093. int second = remains / 3;
  1094. int third = remains % 3;
  1095. c1[first,second, third] = (char)(((int)'a')+i);
  1096. }
  1097. for (int i = 0; i < c1.GetLength(0); i++) {
  1098. for (int j = 0; j < c1.GetLength(1); j++) {
  1099. for (int k = 0; k < c1.GetLength(2); k++) {
  1100. Assert.AreEqual (c1[i, j, k], c1.GetValue(i, j, k), "#I44(" + i + "," + j + ")");
  1101. }
  1102. }
  1103. }
  1104. }
  1105. [Test]
  1106. [ExpectedException (typeof (ArgumentNullException))]
  1107. public void TestGetValueLongArray ()
  1108. {
  1109. char[] c = new Char[2];
  1110. c.GetValue((long [])null);
  1111. }
  1112. [Test]
  1113. public void TestGetValueN() {
  1114. {
  1115. bool errorThrown = false;
  1116. try {
  1117. char[] c = new Char[2];
  1118. c.GetValue((int [])null);
  1119. } catch (ArgumentNullException) {
  1120. errorThrown = true;
  1121. }
  1122. Assert.IsTrue (errorThrown, "#I61a");
  1123. }
  1124. {
  1125. bool errorThrown = false;
  1126. try {
  1127. char[] c = new Char[2];
  1128. int[] coords = {1, 1};
  1129. c.GetValue(coords);
  1130. } catch (ArgumentException) {
  1131. errorThrown = true;
  1132. }
  1133. Assert.IsTrue (errorThrown, "#I62");
  1134. }
  1135. {
  1136. bool errorThrown = false;
  1137. try {
  1138. char[,] c = new Char[2,2];
  1139. int[] coords = {-1, 1};
  1140. c.GetValue(coords);
  1141. } catch (IndexOutOfRangeException) {
  1142. errorThrown = true;
  1143. }
  1144. Assert.IsTrue (errorThrown, "#I63");
  1145. }
  1146. {
  1147. bool errorThrown = false;
  1148. try {
  1149. char[,] c = new Char[2,2];
  1150. int[] coords = {4, 1};
  1151. c.GetValue(coords);
  1152. } catch (IndexOutOfRangeException) {
  1153. errorThrown = true;
  1154. }
  1155. Assert.IsTrue (errorThrown, "#I64");
  1156. }
  1157. char[,] c1 = new Char[4,6];
  1158. for (int i = 0; i < 24; i++) {
  1159. int first = i / 6;
  1160. int second = i % 6;
  1161. c1[first,second] = (char)(((int)'a')+i);
  1162. }
  1163. for (int i = 0; i < c1.GetLength(0); i++) {
  1164. for (int j = 0; j < c1.GetLength(1); j++) {
  1165. int[] coords = {i, j};
  1166. Assert.AreEqual (c1[i, j], c1.GetValue(coords), "#I65(" + i + "," + j + ")");
  1167. }
  1168. }
  1169. }
  1170. [Test]
  1171. public void TestIndexOf1() {
  1172. {
  1173. bool errorThrown = false;
  1174. try {
  1175. Array.IndexOf(null, "huh?");
  1176. } catch (ArgumentNullException) {
  1177. errorThrown = true;
  1178. }
  1179. Assert.IsTrue (errorThrown, "#J01");
  1180. }
  1181. {
  1182. bool errorThrown = false;
  1183. try {
  1184. char[,] c = new Char[2,2];
  1185. Array.IndexOf(c, "huh?");
  1186. } catch (RankException) {
  1187. errorThrown = true;
  1188. }
  1189. Assert.IsTrue (errorThrown, "#J02");
  1190. }
  1191. String[] s1 = {"this", "is", "a", "test"};
  1192. Assert.AreEqual (-1, Array.IndexOf(s1, null), "#J03");
  1193. Assert.AreEqual (-1, Array.IndexOf(s1, "nothing"), "#J04");
  1194. Assert.AreEqual (0, Array.IndexOf(s1, "this"), "#J05");
  1195. Assert.AreEqual (3, Array.IndexOf(s1, "test"), "#J06");
  1196. }
  1197. [Test]
  1198. public void TestIndexOf2() {
  1199. {
  1200. bool errorThrown = false;
  1201. try {
  1202. Array.IndexOf(null, "huh?", 0);
  1203. } catch (ArgumentNullException) {
  1204. errorThrown = true;
  1205. }
  1206. Assert.IsTrue (errorThrown, "#J21");
  1207. }
  1208. {
  1209. bool errorThrown = false;
  1210. try {
  1211. char[,] c = new Char[2,2];
  1212. Array.IndexOf(c, "huh?", 0);
  1213. } catch (RankException) {
  1214. errorThrown = true;
  1215. }
  1216. Assert.IsTrue (errorThrown, "#J22");
  1217. }
  1218. {
  1219. bool errorThrown = false;
  1220. try {
  1221. char[] c = new Char[2];
  1222. Array.IndexOf(c, "huh?", 3);
  1223. } catch (ArgumentOutOfRangeException) {
  1224. errorThrown = true;
  1225. }
  1226. Assert.IsTrue (errorThrown, "#J23");
  1227. }
  1228. String[] s1 = {"this", "is", "really", "a", "test"};
  1229. Assert.AreEqual (-1, Array.IndexOf(s1, null, 1), "#J24");
  1230. Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1), "#J25");
  1231. Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1), "#J26");
  1232. Assert.AreEqual (1, Array.IndexOf(s1, "is", 1), "#J27");
  1233. Assert.AreEqual (4, Array.IndexOf(s1, "test", 1), "#J28");
  1234. }
  1235. [Test]
  1236. public void TestIndexOf3() {
  1237. {
  1238. bool errorThrown = false;
  1239. try {
  1240. Array.IndexOf(null, "huh?", 0, 1);
  1241. } catch (ArgumentNullException) {
  1242. errorThrown = true;
  1243. }
  1244. Assert.IsTrue (errorThrown, "#J41");
  1245. }
  1246. {
  1247. bool errorThrown = false;
  1248. try {
  1249. char[,] c = new Char[2,2];
  1250. Array.IndexOf(c, "huh?", 0, 1);
  1251. } catch (RankException) {
  1252. errorThrown = true;
  1253. }
  1254. Assert.IsTrue (errorThrown, "#J42");
  1255. }
  1256. {
  1257. bool errorThrown = false;
  1258. try {
  1259. char[] c = new Char[2];
  1260. Array.IndexOf(c, "huh?", 3, 1);
  1261. } catch (ArgumentOutOfRangeException) {
  1262. errorThrown = true;
  1263. }
  1264. Assert.IsTrue (errorThrown, "#J43");
  1265. }
  1266. {
  1267. bool errorThrown = false;
  1268. try {
  1269. char[] c = new Char[2];
  1270. Array.IndexOf(c, "huh?", 0, 5);
  1271. } catch (ArgumentOutOfRangeException) {
  1272. errorThrown = true;
  1273. }
  1274. Assert.IsTrue (errorThrown, "#J44");
  1275. }
  1276. String[] s1 = {"this", "is", "really", "a", "test"};
  1277. Assert.AreEqual (-1, Array.IndexOf(s1, null, 1, 3), "#J45");
  1278. Assert.AreEqual (-1, Array.IndexOf(s1, "nothing", 1, 3), "#J46");
  1279. Assert.AreEqual (-1, Array.IndexOf(s1, "this", 1, 3), "#J47");
  1280. Assert.AreEqual (1, Array.IndexOf(s1, "is", 1, 3), "#J48");
  1281. Assert.AreEqual (-1, Array.IndexOf(s1, "test", 1, 3), "#J49");
  1282. Assert.AreEqual (3, Array.IndexOf(s1, "a", 1, 3), "#J50");
  1283. }
  1284. [Test]
  1285. public void TestIndexOf_CustomEqual ()
  1286. {
  1287. DataEqual[] test = new DataEqual [] { new DataEqual () };
  1288. Assert.AreEqual (0, Array.IndexOf (test, "asdfas", 0));
  1289. IList array = (IList)test;
  1290. Assert.AreEqual (0, array.IndexOf ("asdfas"));
  1291. }
  1292. [Test]
  1293. public void TestLastIndexOf1() {
  1294. {
  1295. bool errorThrown = false;
  1296. try {
  1297. Array.LastIndexOf(null, "huh?");
  1298. } catch (ArgumentNullException) {
  1299. errorThrown = true;
  1300. }
  1301. Assert.IsTrue (errorThrown, "#K01");
  1302. }
  1303. {
  1304. bool errorThrown = false;
  1305. try {
  1306. char[,] c = new Char[2,2];
  1307. Array.LastIndexOf(c, "huh?");
  1308. } catch (RankException) {
  1309. errorThrown = true;
  1310. }
  1311. Assert.IsTrue (errorThrown, "#K02");
  1312. }
  1313. String[] s1 = {"this", "is", "a", "a", "test"};
  1314. Assert.AreEqual (-1, Array.LastIndexOf(s1, null), "#K03");
  1315. Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing"), "#K04");
  1316. Assert.AreEqual (0, Array.LastIndexOf(s1, "this"), "#K05");
  1317. Assert.AreEqual (4, Array.LastIndexOf(s1, "test"), "#K06");
  1318. Assert.AreEqual (3, Array.LastIndexOf(s1, "a"), "#K07");
  1319. Assert.AreEqual (-1, Array.LastIndexOf (new String [0], "foo"));
  1320. }
  1321. [Test]
  1322. public void TestLastIndexOf2() {
  1323. {
  1324. bool errorThrown = false;
  1325. try {
  1326. Array.LastIndexOf(null, "huh?", 0);
  1327. } catch (ArgumentNullException) {
  1328. errorThrown = true;
  1329. }
  1330. Assert.IsTrue (errorThrown, "#K21");
  1331. }
  1332. {
  1333. bool errorThrown = false;
  1334. try {
  1335. char[,] c = new Char[2,2];
  1336. Array.LastIndexOf(c, "huh?", 0);
  1337. } catch (RankException) {
  1338. errorThrown = true;
  1339. }
  1340. Assert.IsTrue (errorThrown, "#K22");
  1341. }
  1342. {
  1343. bool errorThrown = false;
  1344. try {
  1345. char[] c = new Char[2];
  1346. Array.LastIndexOf(c, "huh?", 3);
  1347. } catch (ArgumentOutOfRangeException) {
  1348. errorThrown = true;
  1349. }
  1350. Assert.IsTrue (errorThrown, "#K23");
  1351. }
  1352. String[] s1 = {"this", "is", "really", "a", "test"};
  1353. Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3), "#K24");
  1354. Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3), "#K25");
  1355. Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3), "#K26");
  1356. Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3), "#K27");
  1357. Assert.AreEqual (0, Array.LastIndexOf(s1, "this", 3), "#K28");
  1358. }
  1359. [Test]
  1360. public void TestLastIndexOf3() {
  1361. {
  1362. bool errorThrown = false;
  1363. try {
  1364. Array.LastIndexOf(null, "huh?", 0, 1);
  1365. } catch (ArgumentNullException) {
  1366. errorThrown = true;
  1367. }
  1368. Assert.IsTrue (errorThrown, "#K41");
  1369. }
  1370. {
  1371. bool errorThrown = false;
  1372. try {
  1373. char[,] c = new Char[2,2];
  1374. Array.LastIndexOf(c, "huh?", 0, 1);
  1375. } catch (RankException) {
  1376. errorThrown = true;
  1377. }
  1378. Assert.IsTrue (errorThrown, "#K42");
  1379. }
  1380. {
  1381. bool errorThrown = false;
  1382. try {
  1383. char[] c = new Char[2];
  1384. Array.LastIndexOf(c, "huh?", 3, 1);
  1385. } catch (ArgumentOutOfRangeException) {
  1386. errorThrown = true;
  1387. }
  1388. Assert.IsTrue (errorThrown, "#K43");
  1389. }
  1390. {
  1391. bool errorThrown = false;
  1392. try {
  1393. char[] c = new Char[2];
  1394. Array.LastIndexOf(c, "huh?", 0, 5);
  1395. } catch (ArgumentOutOfRangeException) {
  1396. errorThrown = true;
  1397. }
  1398. Assert.IsTrue (errorThrown, "#K44");
  1399. }
  1400. String[] s1 = {"this", "is", "really", "a", "test"};
  1401. Assert.AreEqual (-1, Array.LastIndexOf(s1, null, 3, 3), "#K45");
  1402. Assert.AreEqual (-1, Array.LastIndexOf(s1, "nothing", 3, 3), "#K46");
  1403. Assert.AreEqual (-1, Array.LastIndexOf(s1, "this", 3, 3), "#K47");
  1404. Assert.AreEqual (1, Array.LastIndexOf(s1, "is", 3, 3), "#K48");
  1405. Assert.AreEqual (-1, Array.LastIndexOf(s1, "test", 3, 3), "#K49");
  1406. Assert.AreEqual (3, Array.LastIndexOf(s1, "a", 3, 3), "#K50");
  1407. }
  1408. [Test]
  1409. public void TestLastIndexOf4 ()
  1410. {
  1411. short [] a = new short [] { 19, 238, 317, 6, 565, 0, -52, 60, -563, 753, 238, 238};
  1412. try {
  1413. Array.LastIndexOf (a, (object)16, -1);
  1414. NUnit.Framework.Assert.Fail ("#1");
  1415. } catch (ArgumentOutOfRangeException) { }
  1416. try {
  1417. Array.LastIndexOf<short> (a, 16, -1);
  1418. NUnit.Framework.Assert.Fail ("#2");
  1419. } catch (ArgumentOutOfRangeException) { }
  1420. }
  1421. [Test]
  1422. public void TestLastIndexOf5 ()
  1423. {
  1424. char [] a = new char [] {'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'j', 'i', 'h'};
  1425. string s;
  1426. int retval;
  1427. bool error = false;
  1428. for (int i = a.Length - 1; i >= 0 ; i--) {
  1429. s = i.ToString ();
  1430. retval = Array.LastIndexOf(a, a [i], i, i + 1);
  1431. if (retval != i)
  1432. error = true;
  1433. }
  1434. Assert.IsTrue (!error);
  1435. }
  1436. [Test]
  1437. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  1438. public void LastIndexOf_StartIndexOverflow ()
  1439. {
  1440. // legal - no exception
  1441. byte[] array = new byte [16];
  1442. Array.LastIndexOf (array, this, Int32.MaxValue, 1);
  1443. }
  1444. [Test]
  1445. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  1446. public void LastIndexOf_CountOverflow ()
  1447. {
  1448. // legal - no exception
  1449. byte[] array = new byte [16];
  1450. Array.LastIndexOf (array, this, 1, Int32.MaxValue);
  1451. }
  1452. [Test]
  1453. public void LastIndexOf_0LengthArray ()
  1454. {
  1455. Array array = Array.CreateInstance (typeof (char), 0);
  1456. int idx = Array.LastIndexOf (array, (object) null, -1, 0);
  1457. Assert.IsTrue (idx == -1, "#01");
  1458. idx = Array.LastIndexOf (array, (object) null, -1, 10);
  1459. Assert.IsTrue (idx == -1, "#02");
  1460. idx = Array.LastIndexOf (array, (object) null, -100, 10);
  1461. Assert.IsTrue (idx == -1, "#02");
  1462. array = Array.CreateInstance (typeof (char), 1);
  1463. try {
  1464. Array.LastIndexOf (array, (object) null, -1, 0);
  1465. Assert.Fail ("#04");
  1466. } catch (ArgumentOutOfRangeException e) {
  1467. }
  1468. try {
  1469. Array.LastIndexOf (array, (object) null, -1, 10);
  1470. Assert.Fail ("#05");
  1471. } catch (ArgumentOutOfRangeException e) {
  1472. }
  1473. try {
  1474. Array.LastIndexOf (array, (object) null, -100, 10);
  1475. Assert.Fail ("#06");
  1476. } catch (ArgumentOutOfRangeException e) {
  1477. }
  1478. }
  1479. [Test]
  1480. public void TestReverse() {
  1481. {
  1482. bool errorThrown = false;
  1483. try {
  1484. Array.Reverse(null);
  1485. } catch (ArgumentNullException) {
  1486. errorThrown = true;
  1487. }
  1488. Assert.IsTrue (errorThrown, "#L01");
  1489. }
  1490. {
  1491. bool errorThrown = false;
  1492. try {
  1493. char[,] c = new Char[2,2];
  1494. Array.Reverse(c);
  1495. } catch (RankException) {
  1496. errorThrown = true;
  1497. }
  1498. Assert.IsTrue (errorThrown, "#L02");
  1499. }
  1500. char[] c1 = {'a', 'b', 'c', 'd'};
  1501. Array.Reverse(c1);
  1502. Assert.AreEqual ('d', c1[0], "#L03");
  1503. Assert.AreEqual ('c', c1[1], "#L04");
  1504. Assert.AreEqual ('b', c1[2], "#L05");
  1505. Assert.AreEqual ('a', c1[3], "#L06");
  1506. {
  1507. bool errorThrown = false;
  1508. try {
  1509. Array.Reverse(null, 0, 0);
  1510. } catch (ArgumentNullException) {
  1511. errorThrown = true;
  1512. }
  1513. Assert.IsTrue (errorThrown, "#L07");
  1514. }
  1515. {
  1516. bool errorThrown = false;
  1517. try {
  1518. char[,] c = new Char[2,2];
  1519. Array.Reverse(c, 0, 0);
  1520. } catch (RankException) {
  1521. errorThrown = true;
  1522. }
  1523. Assert.IsTrue (errorThrown, "#L08");
  1524. }
  1525. //{
  1526. //bool errorThrown = false;
  1527. //try {
  1528. // char[] c = new Char[2];
  1529. // Array.Reverse(c, 0, 3);
  1530. //} catch (ArgumentOutOfRangeException) {
  1531. // errorThrown = true;
  1532. //}
  1533. //Assert.IsTrue (errorThrown, "#L09");
  1534. //}
  1535. //{
  1536. //bool errorThrown = false;
  1537. //try {
  1538. // char[] c = new Char[2];
  1539. // Array.Reverse(c, 3, 0);
  1540. //} catch (ArgumentOutOfRangeException) {
  1541. // errorThrown = true;
  1542. //}
  1543. //Assert.IsTrue (errorThrown, "#L10");
  1544. //}
  1545. char[] c2 = { 'a', 'b', 'c', 'd'};
  1546. Array.Reverse(c2, 1, 2);
  1547. Assert.AreEqual ('a', c2[0], "#L11");
  1548. Assert.AreEqual ('c', c2[1], "#L12");
  1549. Assert.AreEqual ('b', c2[2], "#L13");
  1550. Assert.AreEqual ('d', c2[3], "#L14");
  1551. }
  1552. [Test]
  1553. // #8904
  1554. public void ReverseStruct () {
  1555. BStruct[] c3 = new BStruct[2];
  1556. c3 [0] = new BStruct () { i1 = 1, i2 = 2, i3 = 3 };
  1557. c3 [1] = new BStruct () { i1 = 4, i2 = 5, i3 = 6 };
  1558. Array.Reverse (c3);
  1559. Assert.AreEqual (4, c3 [0].i1);
  1560. Assert.AreEqual (5, c3 [0].i2);
  1561. Assert.AreEqual (6, c3 [0].i3);
  1562. Assert.AreEqual (1, c3 [1].i1);
  1563. Assert.AreEqual (2, c3 [1].i2);
  1564. Assert.AreEqual (3, c3 [1].i3);
  1565. }
  1566. struct BStruct {
  1567. public int i1, i2, i3;
  1568. }
  1569. [Test]
  1570. public void TestSetValue1() {
  1571. {
  1572. bool errorThrown = false;
  1573. try {
  1574. char[,] c = new Char[2,2];
  1575. c.SetValue("buh", 1);
  1576. } catch (ArgumentException) {
  1577. errorThrown = true;
  1578. }
  1579. Assert.IsTrue (errorThrown, "#M01");
  1580. }
  1581. {
  1582. bool errorThrown = false;
  1583. try {
  1584. char[] c = {'a', 'b', 'c'};
  1585. c.SetValue("buh", -1);
  1586. } catch (IndexOutOfRangeException) {
  1587. errorThrown = true;
  1588. }
  1589. Assert.IsTrue (errorThrown, "#M02");
  1590. }
  1591. {
  1592. bool errorThrown = false;
  1593. try {
  1594. char[] c = {'a', 'b', 'c'};
  1595. c.SetValue("buh", 4);
  1596. } catch (IndexOutOfRangeException) {
  1597. errorThrown = true;
  1598. }
  1599. Assert.IsTrue (errorThrown, "#M03");
  1600. }
  1601. char[] c1 = {'a', 'b', 'c', 'd'};
  1602. char[] c2 = new char[4];
  1603. for (int i = 0; i < c1.Length; i++) {
  1604. c2.SetValue(c1[i], i);
  1605. }
  1606. for (int i = 0; i < c1.Length; i++) {
  1607. Assert.AreEqual (c1[i], c2[i], "#M04(" + i + ")");
  1608. }
  1609. int[] c3 = { 1, 2, 3 };
  1610. long[] c4 = new long [3];
  1611. for (int i = 0; i < c3.Length; i++)
  1612. c4.SetValue (c3 [i], i);
  1613. try {
  1614. c3.CopyTo (c4, 0);
  1615. } catch (Exception e) {
  1616. Assert.Fail ("c3.CopyTo(): e=" + e);
  1617. }
  1618. for (int i = 0; i < c3.Length; i++)
  1619. Assert.IsTrue (c3[i] == c4[i], "#M05(" + i + ")");
  1620. Object[] c5 = new Object [3];
  1621. long[] c6 = new long [3];
  1622. try {
  1623. c4.CopyTo (c5, 0);
  1624. } catch (Exception e) {
  1625. Assert.Fail ("c4.CopyTo(): e=" + e);
  1626. }
  1627. try {
  1628. c5.CopyTo (c6, 0);
  1629. } catch (Exception e) {
  1630. Assert.Fail ("c5.CopyTo(): e=" + e);
  1631. }
  1632. // for (int i = 0; i < c5.Length; i++)
  1633. // Assert.IsTrue (c5[i] == c6[i], "#M06(" + i + ")");
  1634. }
  1635. [Test]
  1636. public void TestSetValue2() {
  1637. {
  1638. bool errorThrown = false;
  1639. try {
  1640. char[] c = new Char[2];
  1641. c.SetValue("buh", 1,1);
  1642. } catch (ArgumentException) {
  1643. errorThrown = true;
  1644. }
  1645. Assert.IsTrue (errorThrown, "#M21");
  1646. }
  1647. {
  1648. bool errorThrown = false;
  1649. try {
  1650. char[,] c = new Char[2,2];
  1651. c.SetValue("buh", -1, 1);
  1652. } catch (IndexOutOfRangeException) {
  1653. errorThrown = true;
  1654. }
  1655. Assert.IsTrue (errorThrown, "#M22");
  1656. }
  1657. {
  1658. bool errorThrown = false;
  1659. try {
  1660. char[,] c = new Char[2,2];
  1661. c.SetValue("buh", 4,1);
  1662. } catch (IndexOutOfRangeException) {
  1663. errorThrown = true;
  1664. }
  1665. Assert.IsTrue (errorThrown, "#M23");
  1666. }
  1667. char[,] c1 = new Char[4,6];
  1668. char[,] c2 = new Char[4,6];
  1669. for (int i = 0; i < 24; i++) {
  1670. int first = i / 6;
  1671. int second = i % 6;
  1672. c1[first,second] = (char)(((int)'a')+i);
  1673. c2.SetValue(c1[first,second], first, second);
  1674. }
  1675. for (int i = 0; i < c1.GetLength(0); i++) {
  1676. for (int j = 0; j < c1.GetLength(1); j++) {
  1677. Assert.AreEqual (c1[i, j], c2[i, j], "#M24(" + i + "," + j + ")");
  1678. }
  1679. }
  1680. }
  1681. [Test]
  1682. public void TestSetValue3() {
  1683. {
  1684. bool errorThrown = false;
  1685. try {
  1686. char[] c = new Char[2];
  1687. c.SetValue("buh", 1,1,1);
  1688. } catch (ArgumentException) {
  1689. errorThrown = true;
  1690. }
  1691. Assert.IsTrue (errorThrown, "#M41");
  1692. }
  1693. {
  1694. bool errorThrown = false;
  1695. try {
  1696. char[,,] c = new Char[2,2,2];
  1697. c.SetValue("buh", -1, 1, 1);
  1698. } catch (IndexOutOfRangeException) {
  1699. errorThrown = true;
  1700. }
  1701. Assert.IsTrue (errorThrown, "#M42");
  1702. }
  1703. {
  1704. bool errorThrown = false;
  1705. try {
  1706. char[,,] c = new Char[2,2,2];
  1707. c.SetValue("buh", 4,1,1);
  1708. } catch (IndexOutOfRangeException) {
  1709. errorThrown = true;
  1710. }
  1711. Assert.IsTrue (errorThrown, "#M43");
  1712. }
  1713. char[,,] c1 = new Char[4,2,3];
  1714. char[,,] c2 = new Char[4,2,3];
  1715. for (int i = 0; i < 24; i++) {
  1716. int first = i / 6;
  1717. int remains = i % 6;
  1718. int second = remains / 3;
  1719. int third = remains % 3;
  1720. c1[first,second, third] = (char)(((int)'a')+i);
  1721. c2.SetValue(c1[first, second, third], first, second, third);
  1722. }
  1723. for (int i = 0; i < c1.GetLength(0); i++) {
  1724. for (int j = 0; j < c1.GetLength(1); j++) {
  1725. for (int k = 0; k < c1.GetLength(2); k++) {
  1726. Assert.AreEqual (c1[i, j, k], c2[i, j, k], "#M44(" + i + "," + j + " )");
  1727. }
  1728. }
  1729. }
  1730. }
  1731. [Test]
  1732. [ExpectedException (typeof (ArgumentNullException))]
  1733. public void TestSetValueLongArray ()
  1734. {
  1735. char[] c = new Char[2];
  1736. c.SetValue("buh", (long [])null);
  1737. }
  1738. [Test]
  1739. public void TestSetValueN() {
  1740. {
  1741. bool errorThrown = false;
  1742. try {
  1743. char[] c = new Char[2];
  1744. c.SetValue("buh", (int [])null);
  1745. } catch (ArgumentNullException) {
  1746. errorThrown = true;
  1747. }
  1748. Assert.IsTrue (errorThrown, "#M61a");
  1749. }
  1750. {
  1751. bool errorThrown = false;
  1752. try {
  1753. char[] c = new Char[2];
  1754. int[] coords = {1, 1};
  1755. c.SetValue("buh", coords);
  1756. } catch (ArgumentException) {
  1757. errorThrown = true;
  1758. }
  1759. Assert.IsTrue (errorThrown, "#M62");
  1760. }
  1761. {
  1762. bool errorThrown = false;
  1763. try {
  1764. char[,] c = new Char[2,2];
  1765. int[] coords = {-1, 1};
  1766. c.SetValue("buh", coords);
  1767. } catch (IndexOutOfRangeException) {
  1768. errorThrown = true;
  1769. }
  1770. Assert.IsTrue (errorThrown, "#M63");
  1771. }
  1772. {
  1773. bool errorThrown = false;
  1774. try {
  1775. char[,] c = new Char[2,2];
  1776. int[] coords = {4, 1};
  1777. c.SetValue("buh", coords);
  1778. } catch (IndexOutOfRangeException) {
  1779. errorThrown = true;
  1780. }
  1781. Assert.IsTrue (errorThrown, "#M64");
  1782. }
  1783. char[,] c1 = new Char[4,6];
  1784. char[,] c2 = new Char[4,6];
  1785. for (int i = 0; i < 24; i++) {
  1786. int first = i / 6;
  1787. int second = i % 6;
  1788. c1[first,second] = (char)(((int)'a')+i);
  1789. int[] coords = {first, second};
  1790. c2.SetValue(c1[first,second], coords);
  1791. }
  1792. for (int i = 0; i < c1.GetLength(0); i++) {
  1793. for (int j = 0; j < c1.GetLength(1); j++) {
  1794. Assert.AreEqual (c1[i, j], c2[i, j], "#M65(" + i + "," + j + ")");
  1795. }
  1796. }
  1797. }
  1798. [Test]
  1799. public void TestSetValue4() {
  1800. {
  1801. int[] c1 = { 1, 2, 3 };
  1802. long[] c2 = new long [3];
  1803. for (int i = 0; i < c1.Length; i++)
  1804. c2.SetValue (c1 [i], i);
  1805. for (int i = 0; i < c1.Length; i++) {
  1806. Assert.IsTrue (c1[i] == c2[i], "#M81(" + i + ")");
  1807. Assert.AreEqual (typeof (long), c2[i].GetType (), "#M82(" + i + ")");
  1808. }
  1809. }
  1810. {
  1811. long[] c1 = { 1, 2, 3 };
  1812. int[] c2 = new int [3];
  1813. bool errorThrown = false;
  1814. try {
  1815. c2.SetValue (c1 [0], 0);
  1816. } catch (ArgumentException) {
  1817. errorThrown = true;
  1818. }
  1819. Assert.IsTrue (errorThrown, "#M83");
  1820. }
  1821. {
  1822. int[] c1 = { 1, 2, 3 };
  1823. Object[] c2 = new Object [3];
  1824. for (int i = 0; i < c1.Length; i++)
  1825. c2.SetValue (c1 [i], i);
  1826. for (int i = 0; i < c1.Length; i++)
  1827. Assert.AreEqual (c1[i], Convert.ToInt32 (c2[i]), "#M84(" + i + ")");
  1828. }
  1829. {
  1830. Object[] c1 = new Object [3];
  1831. Object[] c2 = new Object [3];
  1832. c1[0] = new Object ();
  1833. for (int i = 0; i < c1.Length; i++)
  1834. c2.SetValue (c1 [i], i);
  1835. for (int i = 0; i < c1.Length; i++)
  1836. Assert.AreEqual (c1[i], c2[i], "#M85(" + i + ")");
  1837. }
  1838. {
  1839. Object[] c1 = new Object [3];
  1840. string[] c2 = new String [3];
  1841. string test = "hello";
  1842. c1[0] = test;
  1843. c2.SetValue (c1 [0], 0);

Large files files are truncated, but you can click here to view the full file