2005-03-23 Lluis Sanchez Gual <lluis@ximian.com>
authorLluis Sanchez <lluis@novell.com>
Wed, 23 Mar 2005 19:13:44 +0000 (19:13 -0000)
committerLluis Sanchez <lluis@novell.com>
Wed, 23 Mar 2005 19:13:44 +0000 (19:13 -0000)
* ArraySerializationTest.cs: New serialization tests.

svn path=/trunk/mcs/; revision=42163

mcs/class/corlib/Test/System.Runtime.Serialization/ArraySerializationTest.cs [new file with mode: 0644]
mcs/class/corlib/Test/System.Runtime.Serialization/ChangeLog

diff --git a/mcs/class/corlib/Test/System.Runtime.Serialization/ArraySerializationTest.cs b/mcs/class/corlib/Test/System.Runtime.Serialization/ArraySerializationTest.cs
new file mode 100644 (file)
index 0000000..2b5e59f
--- /dev/null
@@ -0,0 +1,197 @@
+// ArraySerializationTest.cs\r
+//\r
+// Author:\r
+//   Lluis Sanchez Gual (lluis@ideary.com)\r
+//\r
+// (C) 2005 Lluis Sanchez Gual\r
+\r
+//\r
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+\r
+using System;\r
+using System.IO;\r
+using System.Runtime.Serialization;\r
+using System.Runtime.Serialization.Formatters.Binary;\r
+using System.Reflection;\r
+using System.Collections;\r
+using NUnit.Framework;\r
+\r
+namespace MonoTests.System.Runtime.Serialization\r
+{\r
+       [TestFixture]\r
+       public class ArraySerializationTest\r
+       {\r
+               [Test]\r
+               public void TestBoolArray ()\r
+               {\r
+                       bool[] array = new bool[2000];\r
+                       for (int n=0; n<2000; n++)\r
+                               array [n] = (n % 3) == 0;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestByteArray ()\r
+               {\r
+                       byte[] array = new byte[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (byte) (n % 253);\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestCharArray ()\r
+               {\r
+                       char[] array = new char[2000];\r
+                       for (int n=0; n<2000; n++)\r
+                               array [n] = (char) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestDateTimeArray ()\r
+               {\r
+                       DateTime[] array = new DateTime[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = new DateTime (n);\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestDecimalArray ()\r
+               {\r
+                       decimal[] array = new decimal[2000];\r
+                       for (int n=0; n<2000; n++)\r
+                               array [n] = decimal.MaxValue / (decimal) (n+1);\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestDoubleArray ()\r
+               {\r
+                       double[] array = new double[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (double) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestShortArray ()\r
+               {\r
+                       short[] array = new short[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (short) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestIntArray ()\r
+               {\r
+                       int[] array = new int[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestLongArray ()\r
+               {\r
+                       long[] array = new long[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestSByteArray ()\r
+               {\r
+                       sbyte[] array = new sbyte[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (sbyte) (n % 121);\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestFloatArray ()\r
+               {\r
+                       float[] array = new float[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (float) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestUShortArray ()\r
+               {\r
+                       ushort[] array = new ushort[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (ushort) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestUIntArray ()\r
+               {\r
+                       uint[] array = new uint[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (uint) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestULongArray ()\r
+               {\r
+                       ulong[] array = new ulong[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = (ulong) n;\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               [Test]\r
+               public void TestStringArray ()\r
+               {\r
+                       string[] array = new string[10000];\r
+                       for (int n=0; n<10000; n++)\r
+                               array [n] = n.ToString ();\r
+                       CheckArray (array);\r
+               }\r
+               \r
+               void CheckArray (Array src)\r
+               {\r
+                       MemoryStream ms = new MemoryStream ();\r
+                       BinaryFormatter bf = new BinaryFormatter ();\r
+                       bf.Serialize (ms, src);\r
+                       ms.Position = 0;\r
+                       Array des = (Array) bf.Deserialize (ms);\r
+                       CompareArrays (src.GetType().ToString(), src, des);\r
+               }\r
+               \r
+               void CompareArrays (string txt, Array a1, Array a2)\r
+               {\r
+                       Assertion.AssertEquals (txt + " length", a1.Length, a2.Length);\r
+                       for (int n=0; n<a1.Length; n++)\r
+                               Assertion.AssertEquals (txt + " [" + n + "]", a1.GetValue (n), a2.GetValue (n));\r
+               }\r
+       }\r
+}\r
index 1ad55c84ee0af49472b394a9e4c6cc55f1293825..8ce8c9838cbedf1a4f786c3b95a6b9c4be730c15 100644 (file)
@@ -1,3 +1,7 @@
+2005-03-23  Lluis Sanchez Gual  <lluis@ximian.com>\r
+\r
+       * ArraySerializationTest.cs: New serialization tests.\r
+\r
 2005-03-04  Lluis Sanchez Gual <lluis@novell.com>\r
 \r
        * SerializationTest.cs: Improved test.\r