Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,69 @@
2009-06-25 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2009-02-04 Zoltan Varga <vargaz@gmail.com>
* SerializationCallbackTest.cs: Make a few tests quiet.
2008-09-17 Robert Jordan <robertj@gmx.net>
* SerializationTest2.cs: Add test case for bug #421664.
2006-10-29 Robert Jordan <robertj@gmx.net>
* SerializationCallbackTest.cs: Add test case for bug #78594.
2005-12-21 Raja R Harinath <rharinath@novell.com>
* SerializationTest.cs: Use Assert.AreEqual instead of
Assertion.AssertEquals.
(ReadData): Fix order of 'expected' and 'actual' when validating
'list'.
(*.CheckEqual): Add new 'context' argument. Encodes the path
taken to get to th current object.
2005-12-15 Gert Driesen <drieseng@users.sourceforge.net>
* ObjectManagerTest.cs: New test for bug #76931.
2005-03-23 Lluis Sanchez Gual <lluis@ximian.com>
* ArraySerializationTest.cs: New serialization tests.
2005-03-04 Lluis Sanchez Gual <lluis@novell.com>
* SerializationTest.cs: Improved test.
2004-12-09 Lluis Sanchez Gual <lluis@ximian.com>
* SerializationTest.cs: Added test for bug #70104.
2004-05-13 Lluis Sanchez Gual <lluis@ximian.com>
* SerializationTest.cs: Test serialization of empty struct arrays. This
used to fail.
2003-07-23 Lluis Sanchez Gual <lluis@ximian.com>
* SerializationTest.cs: Fixed delegate invocation. Didn't compile
on windows.
2003-07-23 Lluis Sanchez Gual <lluis@ximian.com>
* SerializationTest.cs: Added.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-08-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* AllTests.cs: added FormatterServicesTests.
* FormatterServicesTests.cs: New file.
2002-06-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* AllTests.cs: New file to make 'make test' work.
* ChangeLog: New file.

View File

@@ -0,0 +1,127 @@
//
// System.Runtime.Serialization.FormatterServicesTests: NUnit test
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (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
{
public void TestClass1 ()
{
DerivedClass1 derived = new DerivedClass1 ();
derived.anotherInt = 69;
MemberInfo [] members = FormatterServices.GetSerializableMembers (derived.GetType ());
Assert.IsTrue (members != null, "#01");
Assert.AreEqual (3, members.Length, "#02");
object [] data = FormatterServices.GetObjectData (derived, members);
Assert.IsTrue (data != null, "#03");
Assert.AreEqual (3, data.Length, "#04");
DerivedClass1 o = (DerivedClass1) FormatterServices.GetUninitializedObject (derived.GetType ());
Assert.IsTrue (o != null, "#05");
o = (DerivedClass1) FormatterServices.PopulateObjectMembers (o, members, data);
Assert.IsTrue (o != null, "#06");
Assert.AreEqual ("hola", o.Hello, "#07");
Assert.AreEqual (21, o.IntBase, "#08");
Assert.AreEqual (1, o.IntDerived, "#09");
Assert.AreEqual (69, o.anotherInt, "#10");
Assert.AreEqual ("hey", DerivedClass1.hey, "#11");
}
}
[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;
}
}
}
}

View File

@@ -0,0 +1,83 @@
//
// System.Runtime.Serialization.ObjectIDGeneratorTests.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// (C) Ximian, Inc.
//
using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
public class ObjectIDGeneratorTests
{
ObjectIDGenerator generator;
string obj1 = "obj1";
int obj2 = 42;
long id;
[SetUp]
protected void SetUp ()
{
generator = new ObjectIDGenerator ();
}
//
// Tests adding an ID for a new object
//
public void TestGetId1 ()
{
bool testBool1;
id = generator.GetId (obj1, out testBool1);
Assert.AreEqual (1L, id); // should start at 1, "A1");
Assert.AreEqual (true, testBool1); // firstTime should be true, "A2");
}
//
// Tests getting the ID for an existing object
//
public void TestGetId2 ()
{
bool testBool1;
bool testBool2;
id = generator.GetId (obj1, out testBool1);
long testId1 = generator.GetId (obj1, out testBool2);
Assert.AreEqual (testId1, id); // same object, same ID, "B1");
Assert.AreEqual (false, testBool2); // no longer firstTime, "B2");
}
//
// Tests getting the ID for an existing object
//
public void TestHasId1 ()
{
bool testBool1;
bool testBool3;
id = generator.GetId (obj1, out testBool1);
long testId2 = generator.HasId (obj1, out testBool3);
Assert.AreEqual (false, testBool3); // this has been inserted before, "C1");
Assert.AreEqual (id, testId2); // we should get the same ID, "C2");
}
//
// Tests getting the ID for a non-existent object
//
public void TestHasId2 ()
{
bool testBool4;
long testId3 = generator.HasId (obj2, out testBool4);
Assert.AreEqual (0L, testId3, "D1");
Assert.AreEqual (true, testBool4, "D2");
}
}
}

View File

@@ -0,0 +1,132 @@
//
// System.Runtime.Serialization.ObjectManagerTest.cs
//
// Author: Martin Baulig (martin@ximian.com)
//
// (C) Novell
//
using System;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
public class ObjectManagerTest
{
[Test] // bug 76931
public void TestSerialization ()
{
using (MemoryStream ms = new MemoryStream ()) {
Bar bar = new Bar (8, 3, 5, 21);
bar.Save (ms);
ms.Position = 0;
bar = Bar.Load (ms);
Assert.AreEqual ("Bar [Foo (16),(Foo (6),Foo (10),Foo (42)]",
bar.ToString (), "#1");
}
}
}
public class Foo
{
public int Data;
public Foo (int data)
{
this.Data = data;
}
public override string ToString ()
{
return String.Format ("Foo ({0})", Data);
}
internal class SerializationSurrogate : ISerializationSurrogate
{
public void GetObjectData (object obj, SerializationInfo info, StreamingContext context)
{
Foo foo = (Foo) obj;
info.AddValue ("data", foo.Data);
}
public object SetObjectData (object obj, SerializationInfo info,
StreamingContext context,
ISurrogateSelector selector)
{
Foo foo = (Foo) obj;
foo.Data = info.GetInt32 ("data");
return new Foo (2 * foo.Data);
}
}
}
[Serializable]
public class Bar
{
public readonly Foo Foo;
public readonly Foo[] Array;
public Bar (int a, params int[] b)
{
Foo = new Foo (a);
Array = new Foo[b.Length];
for (int i = 0; i < b.Length; i++)
Array[i] = new Foo (b[i]);
}
public void Save (Stream stream)
{
SurrogateSelector ss = new SurrogateSelector ();
StreamingContext context = new StreamingContext (
StreamingContextStates.Persistence, this);
ss.AddSurrogate (typeof (Foo), context, new Foo.SerializationSurrogate ());
BinaryFormatter formatter = new BinaryFormatter (ss, context);
formatter.Serialize (stream, this);
}
public static Bar Load (Stream stream)
{
SurrogateSelector ss = new SurrogateSelector ();
StreamingContext context = new StreamingContext (
StreamingContextStates.Persistence, null);
ss.AddSurrogate (typeof (Foo), context, new Foo.SerializationSurrogate ());
BinaryFormatter formatter = new BinaryFormatter (ss, context);
return (Bar) formatter.Deserialize (stream);
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
sb.Append ("Bar [");
sb.Append (Foo);
sb.Append (",(");
for (int i = 0; i < Array.Length; i++) {
if (i > 0)
sb.Append (",");
sb.Append (Array[i]);
}
sb.Append ("]");
return sb.ToString ();
}
}
}

View File

@@ -0,0 +1,60 @@
//
// System.Runtime.Serialization.SerializationBinderTest.cs.
//
// Author: Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
public class SerializationBinderTest
{
#if NET_4_0
[Test]
public void BindToName ()
{
TestSerializationBinder binder = new TestSerializationBinder ();
string assembly_name;
string type_name;
binder.BindToName (typeof (SerializationBinder), out assembly_name, out type_name);
Assert.AreEqual (null, assembly_name, "#A0");
Assert.AreEqual (null, type_name, "#A1");
}
#endif
}
class TestSerializationBinder : SerializationBinder
{
public override Type BindToType (string assemblyName, string typeName)
{
return null;
}
}
}

View File

@@ -0,0 +1,241 @@
//
// System.Runtime.Serialization.SerializationCallbackTest.cs
//
// Author: Robert Jordan (robertj@gmx.net)
//
#if NET_2_0
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
public class SerializationCallbackTest
{
[Test]
public void Test ()
{
Log.Clear ();
Driver (new BinaryFormatter (), new A (new B()));
//Console.WriteLine (Log.Text);
Assert.AreEqual (Log.Text, "A1B1A2B2A3B3B4A4");
}
[Test]
public void TestInheritance ()
{
Log.Clear ();
Driver (new BinaryFormatter (), new C (new B()));
//Console.WriteLine (Log.Text);
Assert.AreEqual (Log.Text, "A1C1B1A2C2B2A3B3B4A4");
}
[Test]
public void TestISerializable ()
{
Log.Clear ();
Driver (new BinaryFormatter (), new A (new D()));
//Console.WriteLine (Log.Text);
Assert.AreEqual (Log.Text, "A1B1A2B2A3B3B4A4");
}
void Driver (IFormatter formatter, A a)
{
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, a);
stream.Position = 0;
a.CheckSerializationStatus ();
a = (A) formatter.Deserialize (stream);
a.CheckDeserializationStatus ();
}
}
class Log
{
static StringBuilder b = new StringBuilder ();
public static void Write (string msg)
{
b.Append (msg);
}
public static void Clear ()
{
b = new StringBuilder ();
}
public static string Text {
get { return b.ToString (); }
}
}
[Serializable]
class A : IDeserializationCallback
{
public int Status = 0;
B inner;
public A (B inner)
{
this.inner = inner;
this.inner.Outer = this;
}
public void CheckSerializationStatus ()
{
Assert.AreEqual (2, Status, "#A01");
}
public void CheckDeserializationStatus ()
{
Assert.AreEqual (2, Status, "#A01");
}
[OnSerializing]
void OnSerializing (StreamingContext ctx)
{
Log.Write ("A1");
Assert.AreEqual (0, Status, "#A01");
Assert.AreEqual (0, inner.Status, "#A02");
Status++;
}
[OnSerialized]
void OnSerialized (StreamingContext ctx)
{
Log.Write ("A2");
Assert.AreEqual (1, Status, "#A03");
Assert.AreEqual (1, inner.Status, "#A04");
// must have no effect after deserialization
Status++;
}
[OnDeserializing]
void OnDeserializing (StreamingContext ctx)
{
Log.Write ("A3");
Assert.IsNull (inner, "#A05");
Assert.AreEqual(0, Status, "#A06");
// must have no effect after deserialization
Status = 42;
}
[OnDeserialized]
void OnDeserialized (StreamingContext ctx)
{
Log.Write ("A4");
Assert.IsNotNull (inner, "#A07");
Assert.AreEqual(1, Status, "#A08");
Assert.AreEqual(1, inner.Status, "#A10");
Status++;
}
void IDeserializationCallback.OnDeserialization (object sender)
{
// don't log the order because it's undefined
CheckDeserializationStatus ();
}
}
[Serializable]
class B : IDeserializationCallback
{
public int Status = 0;
public A Outer;
[OnSerializing]
void OnSerializing (StreamingContext ctx)
{
Log.Write ("B1");
Assert.AreEqual (0, Status, "#B01");
Assert.AreEqual (1, Outer.Status, "#B01.2");
Status++;
}
[OnSerialized]
void OnSerialized (StreamingContext ctx)
{
Log.Write ("B2");
Assert.AreEqual (1, Status, "#B02");
Assert.AreEqual (2, Outer.Status, "#B03");
// must have no effect after deserialization
Status++;
}
[OnDeserializing]
void OnDeserializing (StreamingContext ctx)
{
Log.Write ("B3");
Assert.IsNull (Outer, "#B05");
Assert.AreEqual (0, Status, "#B06");
// must have no effect after deserialization
Status = 42;
}
[OnDeserialized]
void OnDeserialized (StreamingContext ctx)
{
Log.Write ("B4");
}
void IDeserializationCallback.OnDeserialization (object sender)
{
// don't log the order because it's undefined
Assert.AreEqual (1, Status);
}
}
[Serializable]
class C : A
{
public C (B inner) : base (inner)
{
}
[OnSerializing]
void OnSerializing (StreamingContext ctx)
{
Log.Write ("C1");
Assert.AreEqual (1, Status, "#C01");
}
[OnSerialized]
void OnSerialized (StreamingContext ctx)
{
Log.Write ("C2");
Assert.AreEqual (2, Status, "#C02");
}
}
[Serializable]
class D : B, ISerializable
{
public D ()
{
}
void ISerializable.GetObjectData (SerializationInfo info, StreamingContext ctx)
{
info.AddValue ("Status", Status);
info.AddValue ("Outer", Outer);
}
D (SerializationInfo info, StreamingContext ctx)
{
Status = info.GetInt32 ("Status");
Outer = (A) info.GetValue ("Outer", typeof (A));
}
}
}
#endif

View File

@@ -0,0 +1,107 @@
//
// System.Runtime.Serialization.SerializationInfoTest.cs.
//
// Author: Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Serialization;
using NUnit.Framework;
namespace MonoTests.System.Runtime.Serialization
{
[TestFixture]
public class SerializationInfoTest
{
[Test]
public void SetType ()
{
SerializationInfo sinfo = new SerializationInfo (typeof (DateTime), new FormatterConverter ());
Type point_type = typeof (Point);
sinfo.SetType (point_type);
Assert.AreEqual (point_type.FullName, sinfo.FullTypeName, "#A0");
Assert.AreEqual (point_type.Assembly.FullName, sinfo.AssemblyName, "#A1");
#if NET_4_0
Assert.AreEqual (point_type, sinfo.ObjectType, "#A2");
Assert.AreEqual (false, sinfo.IsAssemblyNameSetExplicit, "#A3");
Assert.AreEqual (false, sinfo.IsFullTypeNameSetExplicit, "#A4");
sinfo.FullTypeName = "Point2";
sinfo.AssemblyName = "NewAssembly";
Type datetime_type = typeof (DateTime);
sinfo.SetType (datetime_type);
Assert.AreEqual (datetime_type.FullName, sinfo.FullTypeName, "#B0");
Assert.AreEqual (datetime_type.Assembly.FullName, sinfo.AssemblyName, "#B1");
Assert.AreEqual (datetime_type, sinfo.ObjectType, "#B2");
Assert.AreEqual (false, sinfo.IsAssemblyNameSetExplicit, "#B3");
Assert.AreEqual (false, sinfo.IsFullTypeNameSetExplicit, "#B4");
#endif
}
#if NET_4_0
[Test]
public void ObjectType ()
{
SerializationInfo sinfo = new SerializationInfo (typeof (Point), new FormatterConverter ());
Assert.AreEqual (typeof (Point), sinfo.ObjectType, "#A0");
}
[Test]
public void IsAssemblyNameSetExplicit ()
{
SerializationInfo sinfo = new SerializationInfo (typeof (Point), new FormatterConverter ());
Assert.AreEqual (false, sinfo.IsAssemblyNameSetExplicit, "#A0");
string original_name = sinfo.AssemblyName;
sinfo.AssemblyName = "CustomAssemblyName";
Assert.AreEqual (true, sinfo.IsAssemblyNameSetExplicit, "#B0");
Assert.AreEqual ("CustomAssemblyName", sinfo.AssemblyName, "#B1");
sinfo.AssemblyName = original_name;
Assert.AreEqual (true, sinfo.IsAssemblyNameSetExplicit, "#C0");
Assert.AreEqual (original_name, sinfo.AssemblyName, "#C1");
}
[Test]
public void IsFullTypeNameSetExplicit ()
{
SerializationInfo sinfo = new SerializationInfo (typeof (Point), new FormatterConverter ());
Assert.AreEqual (false, sinfo.IsFullTypeNameSetExplicit, "#A0");
string original_name = sinfo.FullTypeName;
sinfo.FullTypeName = "CustomTypeName";
Assert.AreEqual (true, sinfo.IsFullTypeNameSetExplicit, "#B0");
Assert.AreEqual ("CustomTypeName", sinfo.FullTypeName, "#B1");
sinfo.FullTypeName = original_name;
Assert.AreEqual (true, sinfo.IsFullTypeNameSetExplicit, "#C0");
Assert.AreEqual (original_name, sinfo.FullTypeName, "#C1");
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
//
// System.Runtime.Serialization.SerializationTest2.cs
//
// Test case for bug #421664.
//
// Author: Robert Jordan <robertj@gmx.net>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
// We need a different namespace because we pollute it with
// a new ISerializable declaration.
namespace MonoTests.System.Runtime.Serialization2
{
public interface ISerializable
{
}
[Serializable]
public class Class : ISerializable
{
}
[TestFixture]
public class SerializationTest2
{
[Test]
public void TestSerialization ()
{
MemoryStream ms = new MemoryStream ();
new BinaryFormatter ().Serialize (ms, new Class ());
ms.Position = 0;
new BinaryFormatter ().Deserialize (ms);
}
}
}