Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enable IDynamicInterfaceCastable tests disabled on fixed bug #108376

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions src/tests/Interop/IDynamicInterfaceCastable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,38 +393,26 @@ public static void ValidateGenericInterface()
Console.WriteLine(" -- Validate cast");

// ITestGeneric<int, int> -> ITestGenericIntImpl
if (!TestLibrary.Utilities.IsNativeAot) // https://github.com/dotnet/runtime/issues/108229
{
Assert.True(castableObj is ITestGeneric<int, int>, $"Should be castable to {nameof(ITestGeneric<int, int>)} via is");
Assert.NotNull(castableObj as ITestGeneric<int, int>);
}
Assert.True(castableObj is ITestGeneric<int, int>, $"Should be castable to {nameof(ITestGeneric<int, int>)} via is");
Assert.NotNull(castableObj as ITestGeneric<int, int>);
ITestGeneric<int, int> testInt = (ITestGeneric<int, int>)castableObj;

// ITestGeneric<string, string> -> ITestGenericImpl<string, string>
if (!TestLibrary.Utilities.IsNativeAot) // https://github.com/dotnet/runtime/issues/108229
{
Assert.True(castableObj is ITestGeneric<string, string>, $"Should be castable to {nameof(ITestGeneric<string, string>)} via is");
Assert.NotNull(castableObj as ITestGeneric<string, string>);
}
Assert.True(castableObj is ITestGeneric<string, string>, $"Should be castable to {nameof(ITestGeneric<string, string>)} via is");
Assert.NotNull(castableObj as ITestGeneric<string, string>);
ITestGeneric<string, string> testStr = (ITestGeneric<string, string>)castableObj;

// Validate Variance
// ITestGeneric<string, object> -> ITestGenericImpl<object, string>
if (!TestLibrary.Utilities.IsNativeAot) // https://github.com/dotnet/runtime/issues/108229
{
Assert.True(castableObj is ITestGeneric<string, object>, $"Should be castable to {nameof(ITestGeneric<string, object>)} via is");
Assert.NotNull(castableObj as ITestGeneric<string, object>);
}
Assert.True(castableObj is ITestGeneric<string, object>, $"Should be castable to {nameof(ITestGeneric<string, object>)} via is");
Assert.NotNull(castableObj as ITestGeneric<string, object>);
ITestGeneric<string, object> testVar = (ITestGeneric<string, object>)castableObj;

if (!TestLibrary.Utilities.IsNativeAot) // https://github.com/dotnet/runtime/issues/108229
{
// ITestGeneric<bool, bool> is not recognized
Assert.False(castableObj is ITestGeneric<bool, bool>, $"Should not be castable to {nameof(ITestGeneric<bool, bool>)} via is");
Assert.Null(castableObj as ITestGeneric<bool, bool>);
var ex = Assert.Throws<DynamicInterfaceCastableException>(() => { var _ = (ITestGeneric<bool, bool>)castableObj; });
Assert.Equal(string.Format(DynamicInterfaceCastableException.ErrorFormat, typeof(ITestGeneric<bool, bool>)), ex.Message);
}
// ITestGeneric<bool, bool> is not recognized
Assert.False(castableObj is ITestGeneric<bool, bool>, $"Should not be castable to {nameof(ITestGeneric<bool, bool>)} via is");
Assert.Null(castableObj as ITestGeneric<bool, bool>);
var ex = Assert.Throws<DynamicInterfaceCastableException>(() => { var _ = (ITestGeneric<bool, bool>)castableObj; });
Assert.Equal(string.Format(DynamicInterfaceCastableException.ErrorFormat, typeof(ITestGeneric<bool, bool>)), ex.Message);

int expectedInt = 42;
string expectedStr = "str";
Expand Down