Skip to content

Commit

Permalink
Prep tests for CoreCLR/CoreRT [Serializable] cleanup (dotnet#20035)
Browse files Browse the repository at this point in the history
Fixes tests that depend on types in System.Private.CoreLib being serializable that won't be serializable soon.
  • Loading branch information
morganbr authored and krwq committed Jun 1, 2017
1 parent 5818162 commit 55896e9
Show file tree
Hide file tree
Showing 18 changed files with 3 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class Dictionary_Generic_Tests_Keys_AsICollection : ICollection_NonGeneri
protected override bool IsReadOnly => true;
protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
protected override Type ICollection_NonGeneric_CopyTo_ArrayOfEnumType_ThrowType => typeof(ArgumentException);
protected override bool SupportsSerialization => false;

protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Dictionary_Generic_Tests_Values_AsICollection : ICollection_NonGene
protected override bool Enumerator_Current_UndefinedOperation_Throws => true;
protected override Type ICollection_NonGeneric_CopyTo_ArrayOfEnumType_ThrowType => typeof(ArgumentException);
protected override IEnumerable<ModifyEnumerable> ModifyEnumerables => new List<ModifyEnumerable>();
protected override bool SupportsSerialization => false;

protected override Type ICollection_NonGeneric_CopyTo_IndexLargerThanArrayCount_ThrowType => typeof(ArgumentOutOfRangeException);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,5 @@ public static void ConstructorWithMessageAndInnerException()
Assert.Equal(message, mmre.Message);
Assert.Same(innerException, mmre.InnerException);
}

[Fact]
public void Serialization()
{
const string message = "FATAL ERROR: The pizza could not be found.";
var ex = new MissingManifestResourceException(message);
BinaryFormatterHelpers.AssertRoundtrips(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,5 @@ public void ConstructorWithMessageAndInnerException()
Assert.Equal(message, msae.Message);
Assert.Same(innerException, msae.InnerException);
}

[Fact]
public void Serialization()
{
const string cultureName = "fr-FR";
MissingSatelliteAssemblyException msae = new MissingSatelliteAssemblyException("message", cultureName);
BinaryFormatterHelpers.AssertRoundtrips(msae);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@
<Compile Include="System\Runtime\InteropServices\ComAliasNameAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComCompatibleVersionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComConversionLossAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\COMExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComRegisterFunctionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComUnregisterFunctionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComVisibleAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\HandleRefTests.cs" />
<Compile Include="System\Runtime\InteropServices\InvalidComObjectExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\InvalidOleVariantTypeExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\LCIDConversionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\MarshalDirectiveExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\PrimaryInteropAssemblyAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ProgIdAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\SafeArrayRankMismatchExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\SafeArrayTypeMismatchExceptionTests.cs" />
<Compile Include="System\Runtime\InteropServices\SEHExceptionTests.cs" />
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public static IEnumerable<object> SerializableObjects()
yield return TimeSpan.FromDays(7);
yield return new Version(1, 2, 3, 4);
yield return new Guid("0CACAA4D-C6BD-420A-B660-2F557337CA89");
yield return new AttributeUsageAttribute(AttributeTargets.Class);
yield return new List<int>();
yield return new List<int>() { 1, 2, 3, 4, 5 };
yield return new Dictionary<int, string>() { { 1, "test" }, { 2, "another test" } };
Expand Down Expand Up @@ -135,10 +134,6 @@ public static IEnumerable<object> SerializableObjects()
arr.SetValue("hello", new[] { 3, 5 });
yield return arr;

// Various globalization types
yield return CultureInfo.CurrentCulture;
yield return CultureInfo.InvariantCulture;

// Internal specialized equality comparers
yield return EqualityComparer<byte>.Default;
yield return EqualityComparer<int>.Default;
Expand Down Expand Up @@ -294,74 +289,8 @@ public void SameObjectRepeatedInArray()

public static IEnumerable<object[]> SerializableExceptions()
{
yield return new object[] { new AbandonedMutexException() };
yield return new object[] { new AggregateException(new FieldAccessException(), new MemberAccessException()) };
yield return new object[] { new AmbiguousMatchException() };
yield return new object[] { new ArgumentException("message", "paramName") };
yield return new object[] { new ArgumentNullException("paramName") };
yield return new object[] { new ArgumentOutOfRangeException("paramName", 42, "message") };
yield return new object[] { new ArithmeticException() };
yield return new object[] { new ArrayTypeMismatchException("message") };
yield return new object[] { new BadImageFormatException("message", "filename") };
yield return new object[] { new COMException() };
yield return new object[] { new CultureNotFoundException() };
yield return new object[] { new DataMisalignedException("message") };
yield return new object[] { new DecoderFallbackException() };
yield return new object[] { new DirectoryNotFoundException() };
yield return new object[] { new DivideByZeroException() };
yield return new object[] { new DllNotFoundException() };
yield return new object[] { new EncoderFallbackException() };
yield return new object[] { new EndOfStreamException() };
yield return new object[] { new EventSourceException() };
yield return new object[] { new AggregateException(new Exception(), new Exception("message")) };
yield return new object[] { new Exception("message") };
yield return new object[] { new FieldAccessException("message", new FieldAccessException()) };
yield return new object[] { new FileLoadException() };
yield return new object[] { new FileNotFoundException() };
yield return new object[] { new FormatException("message") };
yield return new object[] { new IndexOutOfRangeException() };
yield return new object[] { new InsufficientExecutionStackException() };
yield return new object[] { new InvalidCastException() };
yield return new object[] { new InvalidComObjectException() };
yield return new object[] { new InvalidOleVariantTypeException() };
yield return new object[] { new InvalidOperationException() };
yield return new object[] { new InvalidProgramException() };
yield return new object[] { new InvalidTimeZoneException() };
yield return new object[] { new IOException() };
yield return new object[] { new KeyNotFoundException() };
yield return new object[] { new LockRecursionException() };
yield return new object[] { new MarshalDirectiveException() };
yield return new object[] { new MemberAccessException() };
yield return new object[] { new MethodAccessException() };
yield return new object[] { new MissingFieldException() };
yield return new object[] { new MissingMemberException() };
yield return new object[] { new NotImplementedException() };
yield return new object[] { new NotSupportedException() };
yield return new object[] { new NullReferenceException() };
yield return new object[] { new ObjectDisposedException("objectName") };
yield return new object[] { new OperationCanceledException(new CancellationTokenSource().Token) };
yield return new object[] { new OutOfMemoryException() };
yield return new object[] { new OverflowException() };
yield return new object[] { new PathTooLongException() };
yield return new object[] { new PlatformNotSupportedException() };
yield return new object[] { new RankException() };
yield return new object[] { new SafeArrayRankMismatchException() };
yield return new object[] { new SafeArrayTypeMismatchException() };
yield return new object[] { new SecurityException() };
yield return new object[] { new SEHException() };
yield return new object[] { new SemaphoreFullException() };
yield return new object[] { new SerializationException() };
yield return new object[] { new SynchronizationLockException() };
yield return new object[] { new TargetInvocationException("message", new Exception()) };
yield return new object[] { new TargetParameterCountException() };
yield return new object[] { new TaskCanceledException(Task.CompletedTask) };
yield return new object[] { new TaskSchedulerException() };
yield return new object[] { new TimeoutException() };
yield return new object[] { new TypeAccessException() };
yield return new object[] { new TypeInitializationException(typeof(string).FullName, new Exception()) };
yield return new object[] { new TypeLoadException() };
yield return new object[] { new UnauthorizedAccessException("message", new ArgumentNullException()) };
yield return new object[] { new VerificationException() };
yield return new object[] { new WaitHandleCannotBeOpenedException() };
}

[Theory]
Expand All @@ -373,47 +302,6 @@ public void Roundtrip_Exceptions(Exception expected)

private static int Identity(int i) => i;

[Fact]
public void Roundtrip_Delegates_NoTarget()
{
Func<int, int> expected = Identity;
Assert.Null(expected.Target);

Func<int, int> actual = FormatterClone(expected);

Assert.NotSame(expected, actual);
Assert.Same(expected.GetMethodInfo(), actual.GetMethodInfo());
Assert.Equal(expected(42), actual(42));
}

[Fact]
public void Roundtrip_Delegates_Target()
{
var owsam = new ObjectWithStateAndMethod { State = 42 };
Func<int> expected = owsam.GetState;
Assert.Same(owsam, expected.Target);

Func<int> actual = FormatterClone(expected);

Assert.NotSame(expected, actual);
Assert.NotSame(expected.Target, actual.Target);
Assert.Equal(expected(), actual());
}

public static IEnumerable<object[]> SerializableObjectsWithFuncOfObjectToCompare()
{
object target = 42;
yield return new object[] { new Random(), new Func<object, object>(o => ((Random)o).Next()) };
}

[Theory]
[MemberData(nameof(SerializableObjectsWithFuncOfObjectToCompare))]
public void Roundtrip_ObjectsWithComparers(object obj, Func<object, object> getResult)
{
object actual = FormatterClone(obj);
Assert.Equal(getResult(obj), getResult(actual));
}

public static IEnumerable<object[]> ValidateNonSerializableTypes_MemberData()
{
foreach (object obj in NonSerializableObjects())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3028,28 +3028,6 @@ public static void DCS_BasicRoundtripDCRVerifyWireformatScenarios()
SerializationTestTypes.ComparisonHelper.CompareRecursively(value3, actual3);
}

[Fact]
public static void DCS_BasicRoundtripDCRDelegates()
{
var dataContractSerializerSettings = new DataContractSerializerSettings()
{
DataContractResolver = new VerySimpleResolver(),
};

string coreAssemblyName = typeof(System.Delegate).Assembly.FullName;
string assemblyName = typeof(DelegateClass).Assembly.FullName;
string baseline = $@"<DelegateClass xmlns=""http://schemas.datacontract.org/2004/07/"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><container i:type=""a:Del"" z:FactoryType=""b:System.DelegateSerializationHolder"" xmlns:a=""{assemblyName}"" xmlns:b=""{coreAssemblyName}"" xmlns:z=""http://schemas.microsoft.com/2003/10/Serialization/""><Delegate i:type=""b:System.DelegateSerializationHolder+DelegateEntry"" xmlns=""""><assembly xmlns=""http://schemas.datacontract.org/2004/07/System"">{assemblyName}</assembly><delegateEntry i:nil=""true"" xmlns=""http://schemas.datacontract.org/2004/07/System""/><methodName xmlns=""http://schemas.datacontract.org/2004/07/System"">TestingTheDelegate</methodName><target i:nil=""true"" xmlns=""http://schemas.datacontract.org/2004/07/System""/><targetTypeAssembly xmlns=""http://schemas.datacontract.org/2004/07/System"">{assemblyName}</targetTypeAssembly><targetTypeName xmlns=""http://schemas.datacontract.org/2004/07/System"">DelegateClass</targetTypeName><type xmlns=""http://schemas.datacontract.org/2004/07/System"">Del</type></Delegate><method0 i:type=""b:System.Reflection.RuntimeMethodInfo"" z:FactoryType=""b:System.Reflection.MemberInfoSerializationHolder"" xmlns=""""><Name i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">TestingTheDelegate</Name><AssemblyName i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">{assemblyName}</AssemblyName><ClassName i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">DelegateClass</ClassName><Signature i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">Void TestingTheDelegate(People)</Signature><Signature2 i:type=""c:string"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">System.Void TestingTheDelegate(People)</Signature2><MemberType i:type=""c:int"" xmlns:c=""http://www.w3.org/2001/XMLSchema"">8</MemberType><GenericArguments i:nil=""true""/></method0></container></DelegateClass>";
var value = new DelegateClass();
Del handle = DelegateClass.TestingTheDelegate;
value.container = handle;
People people = new People();
var actual = SerializeAndDeserialize(value, baseline, dataContractSerializerSettings);
((Del)actual.container).Invoke(people);
Assert.NotNull(actual);
Assert.NotNull(actual.container);
Assert.Equal(DelegateClass.delegateVariable, "Verifying the Delegate Test");
}

[Fact]
public static void DCS_ResolveNameVariationTest()
{
Expand Down
Loading

0 comments on commit 55896e9

Please sign in to comment.