diff options
author | Yi Zhang (CLR) <yzha@microsoft.com> | 2016-04-09 21:59:35 -0700 |
---|---|---|
committer | Yi Zhang (CLR) <yzha@microsoft.com> | 2016-04-09 21:59:35 -0700 |
commit | ff26d6801b3ce0dec5918a5ad0d3ab90f9656e28 (patch) | |
tree | 5dd90d25cd8b95c4f8069fe526a117d1793f6b2c /tests/src/Interop | |
parent | 2ee084a216d42708074cb9a94b316db72c664c3f (diff) | |
parent | a1ffff4a8e305c1e06548aee8cdc43a091fab3ac (diff) | |
download | coreclr-ff26d6801b3ce0dec5918a5ad0d3ab90f9656e28.tar.gz coreclr-ff26d6801b3ce0dec5918a5ad0d3ab90f9656e28.tar.bz2 coreclr-ff26d6801b3ce0dec5918a5ad0d3ab90f9656e28.zip |
Merge pull request #4250 from yizhang82/nativevariant_fix
Fix GetObjectForNativeVariant test issue. It should roundtrip the actual object instead of IntPtr. Also add proper variant clean up code.
Fix #4192.
Diffstat (limited to 'tests/src/Interop')
-rw-r--r-- | tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs index 5880a74518..00710a37bc 100644 --- a/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs +++ b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs @@ -59,6 +59,15 @@ public class GetObjectForNativeVariantTest Assert.Throws<ArgumentNullException>(() => Marshal.GetObjectForNativeVariant<int>(IntPtr.Zero)); } + [DllImport(@"oleaut32.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)] + static extern Int32 VariantClear(IntPtr pvarg); + + private static void DeleteVariant(IntPtr pVariant) + { + VariantClear(pVariant); + Marshal.FreeHGlobal(pVariant); + } + public static void Decimal() { Variant v = new Variant(); @@ -66,6 +75,8 @@ public class GetObjectForNativeVariantTest Marshal.GetNativeVariantForObject(3.14m, pNative); decimal d = Marshal.GetObjectForNativeVariant<decimal>(pNative); Assert.AreEqual(3.14m, d); + + DeleteVariant(pNative); } public static void PrimitiveType() @@ -75,6 +86,8 @@ public class GetObjectForNativeVariantTest Marshal.GetNativeVariantForObject<ushort>(99, pNative); ushort actual = Marshal.GetObjectForNativeVariant<ushort>(pNative); Assert.AreEqual(99, actual); + + DeleteVariant(pNative); } public static void StringType() @@ -84,6 +97,8 @@ public class GetObjectForNativeVariantTest Marshal.GetNativeVariantForObject<string>("99", pNative); string actual = Marshal.GetObjectForNativeVariant<string>(pNative); Assert.AreEqual("99", actual); + + DeleteVariant(pNative); } public static void DoubleType() @@ -93,21 +108,30 @@ public class GetObjectForNativeVariantTest Marshal.GetNativeVariantForObject<double>(3.14, pNative); double actual = Marshal.GetObjectForNativeVariant<double>(pNative); Assert.AreEqual(3.14, actual); + + DeleteVariant(pNative); } public static void IUnknownType() { Variant v = new Variant(); - IntPtr pObj = Marshal.GetIUnknownForObject(new object()); + object obj = new object(); + + // Technically we don't need this - but this is necessary for forcing + // COM initialization + IntPtr pUnk = Marshal.GetIUnknownForObject(obj); IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); - Marshal.GetNativeVariantForObject<IntPtr>(pObj, pNative); - IntPtr pActualObj = Marshal.GetObjectForNativeVariant<IntPtr>(pNative); - Assert.AreEqual(pObj, pActualObj); + Marshal.GetNativeVariantForObject<object>(obj, pNative); + object actual = Marshal.GetObjectForNativeVariant<object>(pNative); + Assert.AreEqual(obj, actual); + Marshal.Release(pUnk); + + DeleteVariant(pNative); } public static int Main(String[] unusedArgs) { - //IUnknownType(); + IUnknownType(); DoubleType(); StringType(); PrimitiveType(); |