Skip to content

Commit

Permalink
Cover diamond/reabstraction in IDynamicInterfaceCastable tests (dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored Aug 23, 2021
1 parent 2c93c89 commit 3d5d261
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/tests/Interop/IDynamicInterfaceCastable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ int ITest.CallImplemented(ImplementationToCall toCall)
}
}

[DynamicInterfaceCastableImplementation]
public interface ITestReabstracted : ITest
{
abstract Type ITest.GetMyType();
abstract ITest ITest.ReturnThis();
abstract int ITest.GetNumber();
abstract int ITest.CallImplemented(ImplementationToCall toCall);
}

[DynamicInterfaceCastableImplementation]
public interface IDiamondTest : ITestImpl, ITestReabstracted { }

public interface IOverrideTest : ITestImpl { }

[DynamicInterfaceCastableImplementation]
Expand Down Expand Up @@ -201,7 +213,9 @@ public enum InvalidReturn
NoDefaultImplementation,
CallNotImplemented,
UseOtherInterface,
ThrowException
ThrowException,
DiamondImplementation,
ReabstractedImplementation,
}

public InvalidReturn InvalidImplementation { get; set; }
Expand Down Expand Up @@ -235,6 +249,10 @@ public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle interfaceT
return typeof(ITestOtherImpl).TypeHandle;
case InvalidReturn.ThrowException:
throw new DynamicInterfaceCastableException(interfaceType);
case InvalidReturn.ReabstractedImplementation:
return typeof(ITestReabstracted).TypeHandle;
case InvalidReturn.DiamondImplementation:
return typeof(IDiamondTest).TypeHandle;
case InvalidReturn.DefaultHandle:
default:
return default(RuntimeTypeHandle);
Expand Down Expand Up @@ -464,6 +482,16 @@ private static void ValidateErrorHandling()
Assert.AreEqual(string.Format(DynamicInterfaceCastableException.ErrorFormat, typeof(ITest)), ex.Message);
Console.WriteLine($" ---- {ex.GetType().Name}: {ex.Message}");

Console.WriteLine(" -- Validate reabstracted implementation");
castableObj.InvalidImplementation = BadDynamicInterfaceCastable.InvalidReturn.ReabstractedImplementation;
ex = Assert.Throws<EntryPointNotFoundException>(() => { testObj.ReturnThis(); });
Console.WriteLine($" ---- {ex.GetType().Name}: {ex.Message}");

Console.WriteLine(" -- Validate diamond inheritance case");
castableObj.InvalidImplementation = BadDynamicInterfaceCastable.InvalidReturn.DiamondImplementation;
ex = Assert.Throws<System.Runtime.AmbiguousImplementationException>(() => { testObj.ReturnThis(); });
Console.WriteLine($" ---- {ex.GetType().Name}: {ex.Message}");

Console.WriteLine(" -- Validate return default handle");
castableObj.InvalidImplementation = BadDynamicInterfaceCastable.InvalidReturn.DefaultHandle;
ex = Assert.Throws<InvalidCastException>(() => testObj.GetMyType());
Expand Down

0 comments on commit 3d5d261

Please sign in to comment.