Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add Marshal.GetObjectForNativeVariant tests#31461

Merged
luqunl merged 2 commits intodotnet:masterfrom
hughbe:marshal-variant-primitive-tests
Sep 25, 2018
Merged

Add Marshal.GetObjectForNativeVariant tests#31461
luqunl merged 2 commits intodotnet:masterfrom
hughbe:marshal-variant-primitive-tests

Conversation

@hughbe
Copy link

@hughbe hughbe commented Jul 29, 2018

Tests all the various variant types apart from VT_ARRAY

}

#pragma warning disable 618
public const ushort VT_EMPTY = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do me a favor and mention the Windows header file for reference. // Taken from wtypes.h <- I think that is right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// VT_DATE => DateTime.
yield return new object[]
{
CreateVariant(VT_DATE, new UnionTypes { _date = 2958465.99999999 }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way you can make a local and have the raw value computed instead of hard coding 2958465...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


[Guid("0000002F-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
public interface IRecordInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we need to chat about. The entire ITypeLib interface family (IRecordInfo included) is in a weird state of support in CoreCLR. Can you please add a test ensures we fail on non-Windows platforms if APIs that use this type are called? Thanks.

cc @luqunl

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i'm slightly confused by what you mean. We have the following test already as non-Windows APIs do not implement GetObjectForNativeVariant (even though they probably could as this doesn't have any COM dependencies and the structure of ole variants is well documented, but the use case is minimal)

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
public void GetObjectForNativeVariant_Unix_ThrowsPlatformNotSupportedException()
{
    Assert.Throws<PlatformNotSupportedException>(() => Marshal.GetObjectForNativeVariant(IntPtr.Zero));
    Assert.Throws<PlatformNotSupportedException>(() => Marshal.GetObjectForNativeVariant<int>(IntPtr.Zero));
}

I don't see any other examples of IRecordInfo being used or any APIs that take ITypeLib being exposed in .NET Core

Copy link
Author

@hughbe hughbe Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like the tests don't pass against .NET Core - any ideas?

Unhandled Exception of Type System.ArgumentException
Message :
System.ArgumentException : The specified record cannot be mapped to a managed value class.
Stack Trace :
   at System.Runtime.InteropServices.Marshal.GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
   at System.Runtime.InteropServices.Tests.GetObjectForNativeVariantTests.GetObjectForNativeVariant(Variant variant) in D:\j\workspace\windows-TGrou---74aa877a\src\System.Runtime.InteropServices\tests\System\Runtime\InteropServices\Marshal\GetObjectForNativeVariantTests.cs:line 994
   at System.Runtime.InteropServices.Tests.GetObjectForNativeVariantTests.GetObjectForNativeVariant_Record_ReturnsExpected() in D:\j\workspace\windows-TGrou---74aa877a\src\System.Runtime.InteropServices\tests\System\Runtime\InteropServices\Marshal\GetObjectForNativeVariantTests.cs:line 699

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hughbe It absolutely has COM dependencies since the ITypeLib concept is based entirely around Automation/OLE - which is built on top of the COM system. My general concern was defining this interface which is an Automation interface that requires ITypeLib support because that is how the record is generated - from a TLB.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood - sorry if i'm misunderstanding but is there anything I should action on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you are fine. This is all good stuff. I was more concern about testing for things that we just don't want to bring in at this point. As you pointed out, there is a test for non supported platforms so at this point I am good if you are?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah there is one for non supported platforms to make sure this throws PNSE

@AaronRobinsonMSFT
Copy link
Member

@luqunl any other comments?

@karelz
Copy link
Member

karelz commented Aug 15, 2018

@luqunl ping?

// VT_BOOL => bool.
yield return new object[]
{
CreateVariant(VT_BOOL, new UnionTypes { _i1 = 1 }),
Copy link
Contributor

@luqunl luqunl Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For VT_BOOL, VARIANT_TRUE == -1, VARIANT_FALSE == 0. maybe We don't need "new UnionTypes { _i1 = 1 }" scenario

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this test for that specific reason - this is an unknown value so I was checking to see how the CLR would react to it. Makes sense to keep it IMO

};

// VT_RECORD.
yield return new object[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dup? line 600 and line 607?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks

Assert.Equal(d, GetObjectForNativeVariant(variant));
}

public static IEnumerable<object[]> GetObjectForNativeVariant_Array_TestData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more array scenario?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a future PR - is that OK?

Copy link
Contributor

@luqunl luqunl Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a future PR - is that OK?

of course.

@luqunl
Copy link
Contributor

luqunl commented Aug 29, 2018

@dotnet-bot test Linux x64 Release Build

@luqunl
Copy link
Contributor

luqunl commented Aug 29, 2018

@dotnet-bot test OSX x64 Debug Build

@luqunl
Copy link
Contributor

luqunl commented Aug 29, 2018

@dotnet-bot test Packaging All Configurations x64 Debug Build

@hughbe
Copy link
Author

hughbe commented Aug 30, 2018

@dotnet-bot test OSX x64 Debug Build
@dotnet-bot test Linux x64 Release Build

@karelz karelz added this to the 3.0 milestone Sep 6, 2018
@ViktorHofer
Copy link
Member

@dotnet-bot test this please

Copy link
Contributor

@luqunl luqunl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding these scenario.

@luqunl luqunl merged commit 988af46 into dotnet:master Sep 25, 2018
@hughbe hughbe deleted the marshal-variant-primitive-tests branch September 25, 2018 22:59
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants