1 // ArraySerializationTest.cs
4 // Lluis Sanchez Gual (lluis@ideary.com)
6 // (C) 2005 Lluis Sanchez Gual
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Runtime.Serialization;
35 using System.Runtime.Serialization.Formatters.Binary;
36 using System.Reflection;
37 using System.Collections;
38 using NUnit.Framework;
40 namespace MonoTests.System.Runtime.Serialization
43 public class ArraySerializationTest
46 public void TestBoolArray ()
48 bool[] array = new bool[2000];
49 for (int n=0; n<2000; n++)
50 array [n] = (n % 3) == 0;
55 public void TestByteArray ()
57 byte[] array = new byte[10000];
58 for (int n=0; n<10000; n++)
59 array [n] = (byte) (n % 253);
64 public void TestCharArray ()
66 char[] array = new char[2000];
67 for (int n=0; n<2000; n++)
73 public void TestDateTimeArray ()
75 DateTime[] array = new DateTime[10000];
76 for (int n=0; n<10000; n++)
77 array [n] = new DateTime (n);
82 public void TestDecimalArray ()
84 decimal[] array = new decimal[2000];
85 for (int n=0; n<2000; n++)
86 array [n] = decimal.MaxValue / (decimal) (n+1);
91 public void TestDoubleArray ()
93 double[] array = new double[10000];
94 for (int n=0; n<10000; n++)
95 array [n] = (double) n;
100 public void TestShortArray ()
102 short[] array = new short[10000];
103 for (int n=0; n<10000; n++)
104 array [n] = (short) n;
109 public void TestIntArray ()
111 int[] array = new int[10000];
112 for (int n=0; n<10000; n++)
118 public void TestLongArray ()
120 long[] array = new long[10000];
121 for (int n=0; n<10000; n++)
127 public void TestSByteArray ()
129 sbyte[] array = new sbyte[10000];
130 for (int n=0; n<10000; n++)
131 array [n] = (sbyte) (n % 121);
136 public void TestFloatArray ()
138 float[] array = new float[10000];
139 for (int n=0; n<10000; n++)
140 array [n] = (float) n;
145 public void TestUShortArray ()
147 ushort[] array = new ushort[10000];
148 for (int n=0; n<10000; n++)
149 array [n] = (ushort) n;
154 public void TestUIntArray ()
156 uint[] array = new uint[10000];
157 for (int n=0; n<10000; n++)
158 array [n] = (uint) n;
163 public void TestULongArray ()
165 ulong[] array = new ulong[10000];
166 for (int n=0; n<10000; n++)
167 array [n] = (ulong) n;
172 public void TestStringArray ()
174 string[] array = new string[10000];
175 for (int n=0; n<10000; n++)
176 array [n] = n.ToString ();
180 void CheckArray (Array src)
182 MemoryStream ms = new MemoryStream ();
183 BinaryFormatter bf = new BinaryFormatter ();
184 bf.Serialize (ms, src);
186 Array des = (Array) bf.Deserialize (ms);
187 CompareArrays (src.GetType().ToString(), src, des);
190 void CompareArrays (string txt, Array a1, Array a2)
192 Assertion.AssertEquals (txt + " length", a1.Length, a2.Length);
193 for (int n=0; n<a1.Length; n++)
194 Assertion.AssertEquals (txt + " [" + n + "]", a1.GetValue (n), a2.GetValue (n));