Add PNSE CustomMarshaler tests (for Tlbimp compat) (#21438)
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Sat, 8 Dec 2018 05:36:01 +0000 (21:36 -0800)
committerJan Kotas <jkotas@microsoft.com>
Sat, 8 Dec 2018 05:36:01 +0000 (21:36 -0800)
tests/src/Interop/CMakeLists.txt
tests/src/Interop/PInvoke/CustomMarshalers/CMakeLists.txt [new file with mode: 0644]
tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersNative.cpp [new file with mode: 0644]
tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.cs [new file with mode: 0644]
tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.csproj [new file with mode: 0644]

index ab5d94f..5685e79 100644 (file)
@@ -73,6 +73,7 @@ if(WIN32)
     # This test doesn't necessarily need to be Windows-only, but the implementation is very tied to Windows APIs
     add_subdirectory(PInvoke/DateTime)
     add_subdirectory(PInvoke/IEnumerator)
+    add_subdirectory(PInvoke/CustomMarshalers)
     add_subdirectory(ArrayMarshalling/SafeArray)
     add_subdirectory(COM/NativeServer)
     add_subdirectory(COM/NativeClients/Primitives)
diff --git a/tests/src/Interop/PInvoke/CustomMarshalers/CMakeLists.txt b/tests/src/Interop/PInvoke/CustomMarshalers/CMakeLists.txt
new file mode 100644 (file)
index 0000000..bd32dd5
--- /dev/null
@@ -0,0 +1,11 @@
+cmake_minimum_required (VERSION 2.6)
+project (CustomMarshalersNative)
+include_directories(${INC_PLATFORM_DIR})
+set(SOURCES CustomMarshalersNative.cpp )
+
+# add the executable
+add_library (CustomMarshalersNative SHARED ${SOURCES})
+target_link_libraries(CustomMarshalersNative ${LINK_LIBRARIES_ADDITIONAL}) 
+
+# add the install targets
+install (TARGETS CustomMarshalersNative DESTINATION bin)
diff --git a/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersNative.cpp b/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersNative.cpp
new file mode 100644 (file)
index 0000000..5d20fde
--- /dev/null
@@ -0,0 +1,9 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include <xplatform.h>
+
+extern "C" DLL_EXPORT void STDMETHODCALLTYPE Unsupported(void* ptr)
+{
+}
diff --git a/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.cs b/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.cs
new file mode 100644 (file)
index 0000000..150e250
--- /dev/null
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Globalization;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.Expando;
+using TestLibrary;
+
+using Console = Internal.Console;
+
+namespace PInvokeTests
+{
+    static class CustomMarshalersNative
+    {
+        [DllImport(nameof(CustomMarshalersNative))]
+        public static extern void Unsupported(
+            [MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.TypeToTypeInfoMarshaler")]
+            Type type
+        );
+
+        [DllImport(nameof(CustomMarshalersNative))]
+        public static extern void Unsupported(
+            [MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.ExpandoToDispatchExMarshaler")]
+            IReflect expando
+        );
+    }
+
+    public static class CustomMarshalersTests
+    {
+        public static int Main()
+        {
+            try
+            {
+                Assert.Throws<PlatformNotSupportedException>(() => CustomMarshalersNative.Unsupported(typeof(object)));
+                Assert.Throws<PlatformNotSupportedException>(() => CustomMarshalersNative.Unsupported((IReflect)typeof(object)));
+            }
+            catch (System.Exception e)
+            {
+                Console.WriteLine(e.ToString());
+                return 101;
+            }
+
+            return 100;
+        }
+    }
+}
diff --git a/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.csproj b/tests/src/Interop/PInvoke/CustomMarshalers/CustomMarshalersTest.csproj
new file mode 100644 (file)
index 0000000..f92a778
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <Import Project="../../Interop.settings.targets" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>CustomMarshalersTest</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+    <OutputType>exe</OutputType>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+    <ReferenceSystemPrivateCoreLib>true</ReferenceSystemPrivateCoreLib>
+
+    <!-- CustomMarshalers unsupported outside of windows -->
+    <TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
+    <DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="*.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="CMakeLists.txt"/>
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>