Просмотр исходного кода

2002-08-20 Gonzalo Paniagua Javier <[email protected]>

	* AllTests.cs: added FormatterServicesTests.
	* FormatterServicesTests.cs: New file.

svn path=/trunk/mcs/; revision=6780
Gonzalo Paniagua Javier 23 лет назад
Родитель
Сommit
b520de41c5

+ 3 - 2
mcs/class/corlib/Test/System.Runtime.Serialization/AllTests.cs

@@ -18,8 +18,9 @@ namespace MonoTests.System.Runtime.Serialization {
                 public static ITest Suite 
                 { 
                         get {
-                                TestSuite suite =  new TestSuite();
-                                suite.AddTest(ObjectIDGeneratorTests.Suite);
+                                TestSuite suite =  new TestSuite ();
+                                suite.AddTest (ObjectIDGeneratorTests.Suite);
+                                suite.AddTest (FormatterServicesTests.Suite);
                                 return suite;
                         }
                 }

+ 5 - 0
mcs/class/corlib/Test/System.Runtime.Serialization/ChangeLog

@@ -1,3 +1,8 @@
+2002-08-20  Gonzalo Paniagua Javier <[email protected]>
+
+	* AllTests.cs: added FormatterServicesTests.
+	* FormatterServicesTests.cs: New file.
+
 2002-06-24  Gonzalo Paniagua Javier <[email protected]>
 
 	* AllTests.cs: New file to make 'make test' work.

+ 142 - 0
mcs/class/corlib/Test/System.Runtime.Serialization/FormatterServicesTests.cs

@@ -0,0 +1,142 @@
+//
+// System.Runtime.Serialization.FormatterServicesTests: NUnit test
+//
+// Authors: 
+// 	Gonzalo Paniagua Javier ([email protected])
+//
+// (c) 2002 Ximian Inc. (http://www.ximian.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Reflection;
+using System.Runtime.Serialization;
+
+namespace MonoTests.System.Runtime.Serialization
+{
+	public class FormatterServicesTests : TestCase
+	{
+		public static ITest Suite {
+			get {
+				return new TestSuite (typeof (FormatterServicesTests));
+			}
+		}
+
+		public FormatterServicesTests () :
+			base ("MonoTests.System.Runtime.Serialization.FormatterServicesTests testcase")
+		{
+		}
+
+		public FormatterServicesTests (string name) : base (name)
+		{
+		}
+
+		public void TestClass1 ()
+		{
+			DerivedClass1 derived = new DerivedClass1 ();
+			derived.anotherInt = 69;
+			MemberInfo [] members = FormatterServices.GetSerializableMembers (derived.GetType ());
+			Assert ("#01", members != null);
+			AssertEquals ("#02", 3, members.Length);
+
+			object [] data = FormatterServices.GetObjectData (derived, members);
+			Assert ("#03", data != null);
+			AssertEquals ("#04", 3, data.Length);
+
+			DerivedClass1 o = (DerivedClass1) FormatterServices.GetUninitializedObject (derived.GetType ());
+			Assert ("#05", o != null);
+
+			o = (DerivedClass1) FormatterServices.PopulateObjectMembers (o, members, data);
+			Assert ("#06", o != null);
+			AssertEquals ("#07", "hola", o.Hello);
+			AssertEquals ("#08", 21, o.IntBase);
+			AssertEquals ("#09", 1, o.IntDerived);
+			AssertEquals ("#10", 69, o.anotherInt);
+			AssertEquals ("#11", "hey", DerivedClass1.hey);
+		}
+	}
+
+	[Serializable]
+	class BaseClass1
+	{
+		public string hello = "hola";
+		static int intBase = 21;
+
+		public override int GetHashCode ()
+		{
+			return base.GetHashCode ();
+		}
+
+		public override bool Equals (object o)
+		{
+			BaseClass1 bc = o  as BaseClass1;
+			if (o == null)
+				return false;
+
+			if (hello != "hola")
+				return false;
+
+			return (hello == bc.hello);
+		}
+
+		public string Hello
+		{
+			get {
+				return hello;
+			}
+		}
+
+		public int IntBase
+		{
+			get {
+				return intBase;
+			}
+		}
+	}
+	
+	[Serializable]
+	class DerivedClass1 : BaseClass1
+	{
+		private int intDerived = 1;
+		[NonSerialized] public int publicint = 2;
+		public int anotherInt = 22;
+		public static string hey = "hey";
+
+		public string Name 
+		{
+			get {
+				return "Ahem";
+			}
+		}
+
+		public void SomeMethod ()
+		{
+			/* Does nothing */
+		}
+
+		public override int GetHashCode ()
+		{
+			return base.GetHashCode ();
+		}
+
+		public override bool Equals (object o)
+		{
+			DerivedClass1 dc = o  as DerivedClass1;
+			if (o == null)
+				return false;
+
+			if (anotherInt != 22 || hey != "hey")
+				return false;
+			
+			return (anotherInt == dc.anotherInt);
+		}
+
+		public int IntDerived
+		{
+			get {
+				return intDerived;
+			}
+		}
+	}
+}
+